|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: /* ! 25: * audio_server.m ! 26: * ! 27: * Copyright (c) 1991, NeXT Computer, Inc. All rights reserved. ! 28: * ! 29: * Field user messages for audio driver. ! 30: * ! 31: * HISTORY ! 32: * 08/10/92/mtm Original coding from m68k version. ! 33: */ ! 34: ! 35: #import "audioLog.h" ! 36: #import <driverkit/IOAudioPrivate.h> ! 37: #import "InputStream.h" ! 38: #import "OutputStream.h" ! 39: #import "audio_server.h" ! 40: #import <bsd/dev/audioTypes.h> ! 41: #import "audioReply.h" ! 42: #import <driverkit/kernelDriver.h> // for IOVmTaskSelf() ! 43: #import <mach/vm_param.h> // PAGE_SIZE ! 44: #import <kernserv/prototypes.h> ! 45: ! 46: /* ! 47: * DO NOT PUT ANY STATIC DATA IN THIS FILE. ! 48: * These routines may be used by multiple IOAudio instances ! 49: * if more sound boards are added. ! 50: */ ! 51: ! 52: /* ! 53: * Mig calls this to convert the port a message is ! 54: * received on into each routine's first argument. ! 55: */ ! 56: audio_device_t audio_port_to_device(port_t port) ! 57: { ! 58: AudioChannel *chan = nil; ! 59: ! 60: if (chan = [IOAudio _channelForUserPort:port]) ! 61: return (audio_device_t)chan; ! 62: else { ! 63: log_error(("Audio: server can't translate port to channel\n")); ! 64: return (audio_device_t)0; ! 65: } ! 66: } ! 67: ! 68: /* ! 69: * Mig calls this to convert the port a message is ! 70: * received on into each routine's first argument. ! 71: */ ! 72: audio_stream_t audio_port_to_stream(port_t port) ! 73: { ! 74: AudioStream *stream = nil; ! 75: ! 76: if (stream = [AudioChannel streamForUserPort:port]) ! 77: return (audio_stream_t)stream; ! 78: else { ! 79: log_error(("Audio: server can't translate port to stream\n")); ! 80: return (audio_stream_t)0; ! 81: } ! 82: } ! 83: ! 84: /************************** ! 85: * Generic device routines. ! 86: **************************/ ! 87: ! 88: /* ! 89: * Get current exclusive stream owner, may be PORT_NULL. ! 90: */ ! 91: kern_return_t _NXAudioGetExclusiveUser(AudioChannel *chan, ! 92: port_t *stream_owner) ! 93: { ! 94: xpr_audio_user("AU: GetExclUser: chan=0x%x, owner=0x%x\n", chan, stream_owner, 3,4,5); ! 95: if (!chan) ! 96: return _NXAUDIO_ERR_PORT; ! 97: *stream_owner = [chan exclusiveUser]; ! 98: return _NXAUDIO_SUCCESS; ! 99: } ! 100: ! 101: /* ! 102: * Establish exclusive use of streams. ! 103: * If stream_owner is PORT_NULL, exclusive use is canceled. ! 104: */ ! 105: kern_return_t _NXAudioSetExclusiveUser(AudioChannel *chan, port_t stream_owner) ! 106: { ! 107: xpr_audio_user("AU: SetExclUser: chan=0x%x, owner=%d\n", chan, stream_owner,3,4,5); ! 108: if (!chan) ! 109: return _NXAUDIO_ERR_PORT; ! 110: [chan setExclusiveUser:stream_owner]; ! 111: return _NXAUDIO_SUCCESS; ! 112: } ! 113: ! 114: /* ! 115: * Get dma buffer size and count. ! 116: * (OBSOLETE but must still be supported.) ! 117: */ ! 118: kern_return_t _NXAudioGetBufferOptions(AudioChannel *chan, u_int *size, ! 119: u_int *count) ! 120: { ! 121: xpr_audio_user("AU: GetBufOpts: chan=0x%x, size=0x%x, count=0x%x\n", ! 122: chan, size, count, 4,5); ! 123: if (!chan) ! 124: return _NXAUDIO_ERR_PORT; ! 125: *size = [[chan audioDevice] _intValueForParameter:NX_SoundDeviceBufferSize ! 126: forObject:chan]; ! 127: *count = [[chan audioDevice] _intValueForParameter:NX_SoundDeviceBufferCount ! 128: forObject:chan]; ! 129: return _NXAUDIO_SUCCESS; ! 130: } ! 131: ! 132: /* ! 133: * Set dma buffer size and count. ! 134: * (OBSOLETE but must still be supported.) ! 135: */ ! 136: kern_return_t _NXAudioSetBufferOptions(AudioChannel *chan, ! 137: port_t stream_owner, ! 138: u_int size, u_int count) ! 139: { ! 140: xpr_audio_user("AU: SetBufOpts: chan=0x%x, owner=%d, size=%d, count=%d\n", ! 141: chan, stream_owner, size, count, 5); ! 142: if (!chan) ! 143: return _NXAUDIO_ERR_PORT; ! 144: if (![chan checkOwner:stream_owner]) ! 145: return _NXAUDIO_ERR_NOT_OWNER; ! 146: (void)[[chan audioDevice] _setParameter:NX_SoundDeviceBufferSize toInt:size ! 147: forObject:chan]; ! 148: (void)[[chan audioDevice] _setParameter:NX_SoundDeviceBufferCount toInt:count ! 149: forObject:chan]; ! 150: return _NXAUDIO_SUCCESS; ! 151: } ! 152: ! 153: /* ! 154: * Stream control of owned streams. ! 155: */ ! 156: kern_return_t _NXAudioControlStreams(AudioChannel *chan, port_t stream_owner, ! 157: int action) ! 158: { ! 159: xpr_audio_user("AU: ControlStreams: chan=0x%x, owner=%d, action=%d\n", ! 160: chan, stream_owner, action, 4,5); ! 161: if (!chan || !stream_owner) ! 162: return _NXAUDIO_ERR_PORT; ! 163: if (![chan checkOwner:stream_owner]) ! 164: return _NXAUDIO_ERR_NOT_OWNER; ! 165: if (!(action == _NXAUDIO_STREAM_PAUSE || ! 166: action == _NXAUDIO_STREAM_RESUME || ! 167: action == _NXAUDIO_STREAM_ABORT || ! 168: action == _NXAUDIO_STREAM_RETURN_DATA)) ! 169: return _NXAUDIO_ERR_CONTROL; ! 170: ! 171: [chan controlStreams:action]; ! 172: return _NXAUDIO_SUCCESS; ! 173: } ! 174: ! 175: /* ! 176: * Add a stream. ! 177: */ ! 178: kern_return_t _NXAudioAddStream(AudioChannel *chan, port_t *stream_port, ! 179: port_t stream_owner, int stream_id, ! 180: u_int stream_type) ! 181: ! 182: { ! 183: xpr_audio_user("AU: AddStream: chan=0x%x, stream=0x%x, owner=%d, id=%d, " ! 184: "type=%d\n", chan, stream_port, stream_owner, stream_id, ! 185: stream_type); ! 186: if (!chan || !stream_owner) ! 187: return _NXAUDIO_ERR_PORT; ! 188: if (![chan checkOwner:stream_owner]) ! 189: return _NXAUDIO_ERR_NOT_OWNER; ! 190: ! 191: return ([chan addStreamTag:stream_id user:stream_port ! 192: owner:stream_owner type:stream_type] ? ! 193: _NXAUDIO_SUCCESS : KERN_FAILURE); ! 194: } ! 195: ! 196: /* ! 197: * Get device peak options. ! 198: * (OBSOLETE but must still be supported.) ! 199: */ ! 200: kern_return_t _NXAudioGetDevicePeakOptions(AudioChannel *chan, u_int *enabled, ! 201: u_int *history) ! 202: { ! 203: xpr_audio_user("AU: GetDevPeakOpts: chan=0x%x, enabled=0x%x, " ! 204: "history=0x%x\n", chan, enabled, history, 4,5); ! 205: if (!chan) ! 206: return _NXAUDIO_ERR_PORT; ! 207: *enabled = [[chan audioDevice] ! 208: _intValueForParameter:NX_SoundDeviceDetectPeaks ! 209: forObject:chan]; ! 210: *history = 1; /* peak history no longer supported */ ! 211: return _NXAUDIO_SUCCESS; ! 212: } ! 213: ! 214: /* ! 215: * Set device peak options. ! 216: * (OBSOLETE but must still be supported.) ! 217: */ ! 218: kern_return_t _NXAudioSetDevicePeakOptions(AudioChannel *chan, ! 219: port_t stream_owner, ! 220: u_int enabled, ! 221: u_int history) ! 222: { ! 223: xpr_audio_user("AU: SetDevPeakOpts: chan=0x%x, owner=%d, enabled=%d, " ! 224: "history=%\n", chan, stream_owner, enabled, history, 5); ! 225: if (!chan) ! 226: return _NXAUDIO_ERR_PORT; ! 227: if (![chan checkOwner:stream_owner]) ! 228: return _NXAUDIO_ERR_NOT_OWNER; ! 229: (void)[[chan audioDevice] _setParameter:NX_SoundDeviceDetectPeaks ! 230: toInt:(enabled ? YES : NO) forObject:chan]; ! 231: /* peak history no longer supported */ ! 232: return _NXAUDIO_SUCCESS; ! 233: } ! 234: ! 235: /* ! 236: * Get device peak. ! 237: */ ! 238: kern_return_t _NXAudioGetDevicePeak(AudioChannel *chan, u_int *peak_left, ! 239: u_int *peak_right) ! 240: { ! 241: xpr_audio_user("AU: GetDevPeak: chan=0x%x, peak_l=0x%x, peak_r=0x%x\n", ! 242: chan, peak_left, peak_right, 4,5); ! 243: if (!chan) ! 244: return _NXAUDIO_ERR_PORT; ! 245: if (![[chan audioDevice] _intValueForParameter:NX_SoundDeviceDetectPeaks ! 246: forObject:chan]) ! 247: return _NXAUDIO_ERR_PEAK; ! 248: [chan getPeakLeft:peak_left right:peak_right]; ! 249: return _NXAUDIO_SUCCESS; ! 250: } ! 251: ! 252: /* ! 253: * Get clip count. ! 254: */ ! 255: kern_return_t _NXAudioGetClipCount(AudioChannel *chan, u_int *count) ! 256: { ! 257: xpr_audio_user("AU: GetClipCount: chan=0x%x, count=0x%x\n", chan, count, ! 258: 3,4,5); ! 259: if (!chan) ! 260: return _NXAUDIO_ERR_PORT; ! 261: *count = [chan clipCount]; ! 262: return _NXAUDIO_SUCCESS; ! 263: } ! 264: ! 265: /******************** ! 266: * Soundout routines. ! 267: ********************/ ! 268: ! 269: /* ! 270: * Get soundout options. ! 271: * (OBSOLETE but must still be supported.) ! 272: */ ! 273: kern_return_t _NXAudioGetSndoutOptions(AudioChannel *chan, u_int *bits) ! 274: { ! 275: IOAudio *dev; ! 276: ! 277: xpr_audio_user("AU: GetSndoutOpts: chan=0x%x, bits=0x%x\n", chan, bits, 3,4,5); ! 278: if (!chan) ! 279: return _NXAUDIO_ERR_PORT; ! 280: *bits = 0; ! 281: dev = [chan audioDevice]; ! 282: ! 283: if ([dev _intValueForParameter:NX_SoundDeviceInsertZeros ! 284: forObject:chan]) ! 285: *bits |= _NXAUDIO_SNDOUT_ZEROFILL; ! 286: if ([dev _intValueForParameter:NX_SoundDeviceRampUp ! 287: forObject:chan]) ! 288: *bits |= _NXAUDIO_SNDOUT_RAMPUP; ! 289: if ([dev _intValueForParameter:NX_SoundDeviceRampDown ! 290: forObject:chan]) ! 291: *bits |= _NXAUDIO_SNDOUT_RAMPDOWN; ! 292: if ([dev _intValueForParameter:NX_SoundDeviceDeemphasize ! 293: forObject:chan]) ! 294: *bits |= _NXAUDIO_SNDOUT_DEEMPHASIS; ! 295: if (![dev _intValueForParameter:NX_SoundDeviceMuteSpeaker ! 296: forObject:chan]) ! 297: *bits |= _NXAUDIO_SNDOUT_SPEAKER_ON; ! 298: ! 299: return _NXAUDIO_SUCCESS; ! 300: } ! 301: ! 302: /* ! 303: * Set soundout options. ! 304: * (OBSOLETE but must still be supported.) ! 305: */ ! 306: kern_return_t _NXAudioSetSndoutOptions(AudioChannel *chan, ! 307: port_t stream_owner, ! 308: u_int bits) ! 309: { ! 310: IOAudio *dev; ! 311: ! 312: xpr_audio_user("AU: SetSndoutOpts: chan=0x%x, owner=%d, bits=0x%x\n", chan, ! 313: stream_owner, bits, 4,5); ! 314: if (!chan) ! 315: return _NXAUDIO_ERR_PORT; ! 316: if (![chan checkOwner:stream_owner]) ! 317: return _NXAUDIO_ERR_NOT_OWNER; ! 318: dev = [chan audioDevice]; ! 319: ! 320: if (bits & _NXAUDIO_SNDOUT_ZEROFILL) ! 321: (void)[dev _setParameter:NX_SoundDeviceInsertZeros toInt:YES ! 322: forObject:chan]; ! 323: else ! 324: (void)[dev _setParameter:NX_SoundDeviceInsertZeros toInt:NO ! 325: forObject:chan]; ! 326: if (bits & _NXAUDIO_SNDOUT_RAMPUP) ! 327: (void)[dev _setParameter:NX_SoundDeviceRampUp toInt:YES ! 328: forObject:chan]; ! 329: else ! 330: (void)[dev _setParameter:NX_SoundDeviceRampUp toInt:NO ! 331: forObject:chan]; ! 332: if (bits & _NXAUDIO_SNDOUT_RAMPDOWN) ! 333: (void)[dev _setParameter:NX_SoundDeviceRampDown toInt:YES ! 334: forObject:chan]; ! 335: else ! 336: (void)[dev _setParameter:NX_SoundDeviceRampDown toInt:NO ! 337: forObject:chan]; ! 338: if (bits & _NXAUDIO_SNDOUT_DEEMPHASIS) ! 339: (void)[dev _setParameter:NX_SoundDeviceDeemphasize toInt:YES ! 340: forObject:chan]; ! 341: else ! 342: (void)[dev _setParameter:NX_SoundDeviceDeemphasize toInt:NO ! 343: forObject:chan]; ! 344: if (bits & _NXAUDIO_SNDOUT_SPEAKER_ON) ! 345: (void)[dev _setParameter:NX_SoundDeviceMuteSpeaker toInt:NO ! 346: forObject:chan]; ! 347: else ! 348: (void)[dev _setParameter:NX_SoundDeviceMuteSpeaker toInt:YES ! 349: forObject:chan]; ! 350: ! 351: return _NXAUDIO_SUCCESS; ! 352: } ! 353: ! 354: /* ! 355: * Get speaker attenuation. ! 356: * (OBSOLETE but must still be supported.) ! 357: */ ! 358: kern_return_t _NXAudioGetSpeaker(AudioChannel *chan, int *left, int *right) ! 359: { ! 360: xpr_audio_user("AU: GetSpeaker: chan=0x%x, left=0x%x, right=0x%x\n", chan, ! 361: left, right, 4,5); ! 362: if (!chan) ! 363: return _NXAUDIO_ERR_PORT; ! 364: *left = [[chan audioDevice] ! 365: _intValueForParameter:NX_SoundDeviceOutputAttenuationLeft ! 366: forObject:chan]; ! 367: *right = [[chan audioDevice] ! 368: _intValueForParameter:NX_SoundDeviceOutputAttenuationRight ! 369: forObject:chan]; ! 370: return _NXAUDIO_SUCCESS; ! 371: } ! 372: ! 373: /* ! 374: * Set speaker attenuation. ! 375: * (OBSOLETE but must still be supported.) ! 376: */ ! 377: kern_return_t _NXAudioSetSpeaker(AudioChannel *chan, ! 378: port_t stream_owner, ! 379: int left, int right) ! 380: { ! 381: xpr_audio_user("AU: SetSpeaker: chan=0x%x, owner=%d, left=%d, right=%d\n", ! 382: chan, stream_owner, left, right, 5); ! 383: if (!chan) ! 384: return _NXAUDIO_ERR_PORT; ! 385: if (![chan checkOwner:stream_owner]) ! 386: return _NXAUDIO_ERR_NOT_OWNER; ! 387: (void)[[chan audioDevice] ! 388: _setParameter:NX_SoundDeviceOutputAttenuationLeft toInt:left ! 389: forObject:chan]; ! 390: (void)[[chan audioDevice] ! 391: _setParameter:NX_SoundDeviceOutputAttenuationRight toInt:right ! 392: forObject:chan]; ! 393: return _NXAUDIO_SUCCESS; ! 394: } ! 395: ! 396: /************************** ! 397: * Generic stream routines. ! 398: **************************/ ! 399: ! 400: /* ! 401: * Set stream gain. ! 402: */ ! 403: kern_return_t _NXAudioSetStreamGain(OutputStream *stream, int left, int right) ! 404: { ! 405: xpr_audio_user("AU: SetStreamGain: stream=0x%x, left=%d, right=%d\n", ! 406: stream, left, right, 4,5); ! 407: [[[stream channel] audioDevice] _setParameter:NX_SoundStreamGainLeft ! 408: toInt:left forObject:stream]; ! 409: [[[stream channel] audioDevice] _setParameter:NX_SoundStreamGainRight ! 410: toInt:right forObject:stream]; ! 411: return _NXAUDIO_SUCCESS; ! 412: } ! 413: ! 414: /* ! 415: * Change stream owner of an existing stream. ! 416: */ ! 417: kern_return_t _NXAudioChangeStreamOwner(AudioStream *stream, ! 418: port_t stream_owner) ! 419: { ! 420: xpr_audio_user("AU: ChangeStreamOwner: stream=0x%x, owner=%d\n", ! 421: stream, stream_owner, 3,4,5); ! 422: if (!stream || !stream_owner) ! 423: return _NXAUDIO_ERR_PORT; ! 424: [stream setOwner:stream_owner]; ! 425: return _NXAUDIO_SUCCESS; ! 426: } ! 427: ! 428: /* ! 429: * Stream control. ! 430: */ ! 431: kern_return_t _NXAudioStreamControl(AudioStream *stream, int action, ! 432: audio_time_t time) ! 433: { ! 434: xpr_audio_user("AU: StreamControl: stream=0x%x, action=%d, time=%d:%d\n", ! 435: stream, action, time.tv_sec, time.tv_usec, 5); ! 436: if (!stream) ! 437: return _NXAUDIO_ERR_PORT; ! 438: if (![[stream channel] checkOwner:[stream ownerPort]]) ! 439: return _NXAUDIO_ERR_NOT_OWNER; ! 440: ! 441: switch (action) { ! 442: case _NXAUDIO_STREAM_ABORT: ! 443: [stream control:AC_ControlAbort atTime:time]; ! 444: break; ! 445: case _NXAUDIO_STREAM_PAUSE: ! 446: [stream control:AC_ControlPause atTime:time]; ! 447: break; ! 448: case _NXAUDIO_STREAM_RESUME: ! 449: [stream control:AC_ControlResume atTime:time]; ! 450: break; ! 451: case _NXAUDIO_STREAM_RETURN_DATA: ! 452: [stream returnRecordedData]; ! 453: break; ! 454: default: ! 455: return _NXAUDIO_ERR_CONTROL; ! 456: break; ! 457: } ! 458: return _NXAUDIO_SUCCESS; ! 459: } ! 460: ! 461: /* ! 462: * Stream info. ! 463: */ ! 464: kern_return_t _NXAudioStreamInfo(AudioStream *stream, u_int *bytes_processed, ! 465: u_int *time_stamp) ! 466: { ! 467: xpr_audio_user("AU: StreamInfo: stream=0x%x, bytes=0x%x\n", ! 468: stream, bytes_processed, 3,4,5); ! 469: if (!stream) ! 470: return _NXAUDIO_ERR_PORT; ! 471: (void) [stream bytesProcessed: bytes_processed atTime: time_stamp]; ! 472: return _NXAUDIO_SUCCESS; ! 473: } ! 474: ! 475: /* ! 476: * Remove a stream. ! 477: */ ! 478: kern_return_t _NXAudioRemoveStream(AudioStream *stream) ! 479: { ! 480: xpr_audio_user("AU: RemoveStream: stream=0x%x\n", stream, 2,3,4,5); ! 481: if (!stream) ! 482: return _NXAUDIO_ERR_PORT; ! 483: [[stream channel] removeStream:stream]; ! 484: return _NXAUDIO_SUCCESS; ! 485: } ! 486: ! 487: /*************************** ! 488: * Playback stream routines. ! 489: ***************************/ ! 490: ! 491: /* ! 492: * Enqueue play request to stream. ! 493: * (OBSOLETE but must still be supported.) ! 494: */ ! 495: kern_return_t _NXAudioPlayStream(OutputStream *stream, pointer_t data, ! 496: u_int count, int tag, int channel_count, ! 497: int sample_rate, ! 498: u_int left_gain, u_int right_gain, ! 499: u_int low_water, u_int high_water, ! 500: port_t reply_port, u_int messages) ! 501: { ! 502: kern_return_t ret, krtn; ! 503: audio_array_t params; ! 504: audio_array_t values; ! 505: ! 506: xpr_audio_user("AU: PlayStream: stream=0x%x %d %d %d %d\n", ! 507: stream, data, count, tag, channel_count); ! 508: ! 509: if (!stream) ! 510: return _NXAUDIO_ERR_PORT; ! 511: if (![[stream channel] checkOwner:[stream ownerPort]]) { ! 512: ret = _NXAUDIO_ERR_NOT_OWNER; ! 513: goto error_return; ! 514: } ! 515: if (!count) { ! 516: ret = _NXAUDIO_ERR_SIZE; ! 517: goto error_return; ! 518: } ! 519: ! 520: /* ! 521: * left and right gains no longer supported. ! 522: */ ! 523: params[0] = NX_SoundStreamChannelCount; ! 524: values[0] = channel_count; ! 525: params[1] = NX_SoundStreamSamplingRate; ! 526: /* ! 527: * In this interface, sample rate is an enum constant! ! 528: */ ! 529: values[1] = (sample_rate == _NXAUDIO_RATE_22050 ? 22050 : 44100); ! 530: params[2] = NX_SoundStreamLowWaterMark; ! 531: values[2] = low_water; ! 532: params[3] = NX_SoundStreamHighWaterMark; ! 533: values[3] = high_water; ! 534: (void)[[[stream channel] audioDevice] ! 535: _setParameters:(const NXSoundParameterTag *)params ! 536: toValues:values count:4 forObject:stream]; ! 537: ! 538: if ([stream playBuffer:(void *)data size:count ! 539: tag:tag ! 540: replyTo:reply_port ! 541: replyMsgs:messages]) ! 542: return _NXAUDIO_SUCCESS; ! 543: else ! 544: ret = _NXAUDIO_ERR_SIZE; ! 545: ! 546: error_return: ! 547: krtn = vm_deallocate(task_self(), data, count); ! 548: if (krtn != KERN_SUCCESS) ! 549: log_error(("Audio: audio server vm_deallocate error: %s (%d)\n", ! 550: mach_error_string(krtn), krtn)); ! 551: xpr_audio_user("AU: playStream returns err %d\n", krtn, 2,3,4,5); ! 552: return ret; ! 553: } ! 554: ! 555: /* ! 556: * Set stream peak options. ! 557: * (OBSOLETE but must still be supported.) ! 558: */ ! 559: kern_return_t _NXAudioSetStreamPeakOptions(OutputStream *stream, u_int enabled, ! 560: u_int history) ! 561: { ! 562: xpr_audio_user("AU: SetStreamPeakOpts: stream=0x%x, enabled=%d, " ! 563: "history=%d\n", stream, enabled, history, 4,5); ! 564: if (!stream) ! 565: return _NXAUDIO_ERR_PORT; ! 566: (void)[[[stream channel] audioDevice] ! 567: _setParameter:NX_SoundStreamDetectPeaks ! 568: toInt:(enabled ? YES : NO) forObject:stream]; ! 569: /* peak history no longer supported */ ! 570: return _NXAUDIO_SUCCESS; ! 571: } ! 572: ! 573: /* ! 574: * Get stream peak. ! 575: */ ! 576: kern_return_t _NXAudioGetStreamPeak(OutputStream *stream, ! 577: u_int *peak_left, u_int *peak_right) ! 578: { ! 579: xpr_audio_user("AU: GetStreamPeak: stream=0x%x, peak_l=0x%x, " ! 580: "peak_r=0x%x\n", stream, peak_left, peak_right, 4,5); ! 581: if (!stream) ! 582: return _NXAUDIO_ERR_PORT; ! 583: if (![[[stream channel] audioDevice] ! 584: _intValueForParameter:NX_SoundStreamDetectPeaks forObject:stream]) ! 585: return _NXAUDIO_ERR_PEAK; ! 586: [stream getPeakLeft:peak_left right:peak_right]; ! 587: return _NXAUDIO_SUCCESS; ! 588: } ! 589: ! 590: /**************************** ! 591: * Recording stream routines. ! 592: ****************************/ ! 593: ! 594: /* ! 595: * Enqueue record request to stream. ! 596: * (OBSOLETE but must still be supported.) ! 597: */ ! 598: kern_return_t _NXAudioRecordStream(InputStream *stream, u_int count, ! 599: int tag, ! 600: u_int low_water, u_int high_water, ! 601: port_t reply_port, u_int messages) ! 602: { ! 603: audio_array_t params; ! 604: audio_array_t values; ! 605: ! 606: xpr_audio_user("AU: RecordStream: stream=0x%x %d %d\n", ! 607: stream, count, tag, 4, 5); ! 608: if (!stream) ! 609: return _NXAUDIO_ERR_PORT; ! 610: if (![[stream channel] checkOwner:[stream ownerPort]]) ! 611: return _NXAUDIO_ERR_NOT_OWNER; ! 612: if (!count) ! 613: return _NXAUDIO_ERR_SIZE; ! 614: ! 615: params[0] = NX_SoundStreamLowWaterMark; ! 616: values[0] = low_water; ! 617: params[1] = NX_SoundStreamHighWaterMark; ! 618: values[1] = high_water; ! 619: (void)[[[stream channel] audioDevice] ! 620: _setParameters:(const NXSoundParameterTag *)params ! 621: toValues:values count:2 forObject:stream]; ! 622: ! 623: if ([stream recordSize:count tag:tag ! 624: replyTo:reply_port ! 625: replyMsgs:messages]) ! 626: return _NXAUDIO_SUCCESS; ! 627: else ! 628: return _NXAUDIO_ERR_SIZE; ! 629: } ! 630: ! 631: /* ! 632: * Deal with death of a port. ! 633: */ ! 634: void audio_port_gone(port_t port) ! 635: { ! 636: AudioStream *stream = nil; ! 637: AudioChannel *chan = nil; ! 638: boolean_t more = TRUE; ! 639: ! 640: if (port == PORT_NULL) ! 641: return; ! 642: ! 643: while (more) { ! 644: more = FALSE; ! 645: if (chan = [IOAudio _channelForExclusivePort:port]) { ! 646: xpr_audio_user("AU: audio_port_gone: chan 0x%x excl user %d\n", ! 647: chan, port, 3,4,5); ! 648: [chan setExclusiveUser:PORT_NULL]; ! 649: more = TRUE; ! 650: } else if (stream = [AudioChannel streamForOwnerPort:port]) { ! 651: xpr_audio_user("AU: audio_port_gone: stream 0x%x owner %d\n", ! 652: stream, port, 3,4,5); ! 653: _NXAudioRemoveStream(stream); ! 654: more = TRUE; ! 655: } ! 656: } ! 657: } ! 658: ! 659: /**************************** ! 660: * New for 3.1. ! 661: ****************************/ ! 662: ! 663: /* ! 664: * Play and record with current parameters. ! 665: */ ! 666: ! 667: kern_return_t _NXAudioPlayStreamData(OutputStream *stream, pointer_t data, ! 668: u_int count, int tag, ! 669: port_t reply_port, u_int messages) ! 670: { ! 671: xpr_audio_user("AU: playStreamData\n", 0,0,0,0,0); ! 672: if (!stream) ! 673: return _NXAUDIO_ERR_PORT; ! 674: ! 675: if ([stream playBuffer:(void *)data size:count tag:tag ! 676: replyTo:reply_port replyMsgs:messages]) ! 677: return _NXAUDIO_SUCCESS; ! 678: else ! 679: return _NXAUDIO_ERR_SIZE; ! 680: } ! 681: ! 682: kern_return_t _NXAudioRecordStreamData(InputStream *stream, u_int count, ! 683: int tag, ! 684: port_t reply_port, u_int messages) ! 685: { ! 686: xpr_audio_user("AU: recordStreamData\n", 0,0,0,0,0); ! 687: if (!stream) ! 688: return _NXAUDIO_ERR_PORT; ! 689: ! 690: if ([stream recordSize:count tag:tag ! 691: replyTo:reply_port replyMsgs:messages]) ! 692: return _NXAUDIO_SUCCESS; ! 693: else ! 694: return _NXAUDIO_ERR_SIZE; ! 695: } ! 696: ! 697: /* ! 698: * Generic parameter api. ! 699: */ ! 700: ! 701: kern_return_t _NXAudioGetDeviceName(AudioChannel *chan, audio_name_t name, ! 702: u_int *count) ! 703: { ! 704: if (!chan) ! 705: return _NXAUDIO_ERR_PORT; ! 706: strncpy(name, [[IOAudio _instance] name], _NXAUDIO_PARAM_MAX-1); ! 707: name[_NXAUDIO_PARAM_MAX-1] = '\0'; ! 708: *count = strlen(name); ! 709: return _NXAUDIO_SUCCESS; ! 710: } ! 711: ! 712: kern_return_t _NXAudioSetDeviceParameters(AudioChannel *chan, ! 713: port_t stream_owner, ! 714: audio_array_t params, u_int count, ! 715: audio_array_t values) ! 716: { ! 717: xpr_audio_user("AU: setDevParams\n", 0,0,0,0,0); ! 718: if (!chan) ! 719: return _NXAUDIO_ERR_PORT; ! 720: if (![chan checkOwner:stream_owner]) ! 721: return _NXAUDIO_ERR_NOT_OWNER; ! 722: return ([[chan audioDevice] ! 723: _setParameters:(const NXSoundParameterTag *)params ! 724: toValues:values count:count forObject:chan] ? ! 725: _NXAUDIO_SUCCESS : _NXAUDIO_ERR_PARAMETER); ! 726: } ! 727: ! 728: kern_return_t _NXAudioGetDeviceParameters(AudioChannel *chan, ! 729: audio_array_t params, u_int count, ! 730: audio_array_t values) ! 731: { ! 732: xpr_audio_user("AU: getDevParams\n", 0,0,0,0,0); ! 733: if (!chan) ! 734: return _NXAUDIO_ERR_PORT; ! 735: [[chan audioDevice] _getParameters:(const NXSoundParameterTag *)params ! 736: values:values count:count forObject:chan]; ! 737: return _NXAUDIO_SUCCESS; ! 738: } ! 739: ! 740: kern_return_t _NXAudioGetDeviceSupportedParameters(AudioChannel *chan, ! 741: audio_array_t params, ! 742: u_int *count) ! 743: { ! 744: xpr_audio_user("AU: getDevSupParams\n", 0,0,0,0,0); ! 745: *count = 0; ! 746: if (!chan) ! 747: return _NXAUDIO_ERR_PORT; ! 748: [[chan audioDevice] _getSupportedParameters: ! 749: (NXSoundParameterTag *)params ! 750: count:count forObject:chan]; ! 751: return _NXAUDIO_SUCCESS; ! 752: } ! 753: ! 754: kern_return_t _NXAudioGetDeviceParameterValues(AudioChannel *chan, int param, ! 755: audio_array_t values, ! 756: u_int *count) ! 757: { ! 758: xpr_audio_user("AU: getDevParamValues\n", 0,0,0,0,0); ! 759: *count = 0; ! 760: if (!chan) ! 761: return _NXAUDIO_ERR_PORT; ! 762: return ([[chan audioDevice] _getValues:(NXSoundParameterTag *)values ! 763: count:count forParameter:param forObject:chan] ? ! 764: _NXAUDIO_SUCCESS : _NXAUDIO_ERR_PARAMETER); ! 765: } ! 766: ! 767: kern_return_t _NXAudioGetSamplingRates(AudioChannel *chan, ! 768: int *continuous, ! 769: int *low, int *high, ! 770: audio_array_t rates, ! 771: u_int *count) ! 772: { ! 773: xpr_audio_user("AU: getRates\n", 0,0,0,0,0); ! 774: *count = 0; ! 775: if (!chan) ! 776: return _NXAUDIO_ERR_PORT; ! 777: *continuous = [[chan audioDevice] acceptsContinuousSamplingRates]; ! 778: [[chan audioDevice] getSamplingRatesLow:low high:high]; ! 779: [[chan audioDevice] getSamplingRates:rates count:count]; ! 780: return _NXAUDIO_SUCCESS; ! 781: } ! 782: ! 783: kern_return_t _NXAudioGetDataEncodings(AudioChannel *chan, ! 784: audio_array_t encodings, ! 785: u_int *count) ! 786: { ! 787: xpr_audio_user("AU: getEncodings\n", 0,0,0,0,0); ! 788: ! 789: *count = 0; ! 790: if (!chan) ! 791: return _NXAUDIO_ERR_PORT; ! 792: [[chan audioDevice] ! 793: getDataEncodings:(NXSoundParameterTag *)encodings ! 794: count:count]; ! 795: return _NXAUDIO_SUCCESS; ! 796: } ! 797: ! 798: kern_return_t _NXAudioGetChannelCountLimit(AudioChannel *chan, u_int *count) ! 799: { ! 800: xpr_audio_user("AU: getChans\n", 0,0,0,0,0); ! 801: *count = 0; ! 802: if (!chan) ! 803: return _NXAUDIO_ERR_PORT; ! 804: *count = [[chan audioDevice] channelCountLimit]; ! 805: return _NXAUDIO_SUCCESS; ! 806: } ! 807: ! 808: kern_return_t _NXAudioSetStreamParameters(AudioStream *stream, ! 809: audio_array_t params, u_int count, ! 810: audio_array_t values) ! 811: { ! 812: xpr_audio_user("AU: setStreamParams\n", 0,0,0,0,0); ! 813: if (!stream) ! 814: return _NXAUDIO_ERR_PORT; ! 815: return ([[[stream channel] audioDevice] ! 816: _setParameters:(const NXSoundParameterTag *)params ! 817: toValues:values count:count forObject:stream] ? ! 818: _NXAUDIO_SUCCESS : _NXAUDIO_ERR_PARAMETER); ! 819: } ! 820: ! 821: kern_return_t _NXAudioGetStreamParameters(AudioStream *stream, ! 822: audio_array_t params, u_int count, ! 823: audio_array_t values) ! 824: { ! 825: xpr_audio_user("AU: getStreamParams\n", 0,0,0,0,0); ! 826: if (!stream) ! 827: return _NXAUDIO_ERR_PORT; ! 828: ! 829: [[[stream channel] audioDevice] ! 830: _getParameters:(const NXSoundParameterTag *)params ! 831: values:values count:count forObject:stream]; ! 832: return _NXAUDIO_SUCCESS; ! 833: } ! 834: ! 835: kern_return_t _NXAudioGetStreamSupportedParameters(AudioStream *stream, ! 836: audio_array_t params, ! 837: u_int *count) ! 838: { ! 839: xpr_audio_user("AU: getStreamSupParams\n", 0,0,0,0,0); ! 840: *count = 0; ! 841: if (!stream) ! 842: return _NXAUDIO_ERR_PORT; ! 843: [[[stream channel] audioDevice] ! 844: _getSupportedParameters:(NXSoundParameterTag *)params ! 845: count:count forObject:stream]; ! 846: return _NXAUDIO_SUCCESS; ! 847: } ! 848: ! 849: kern_return_t _NXAudioGetStreamParameterValues(AudioStream *stream, int param, ! 850: audio_array_t values, ! 851: u_int *count) ! 852: { ! 853: xpr_audio_user("AU: getStreamParamValues\n", 0,0,0,0,0); ! 854: *count = 0; ! 855: if (!stream) ! 856: return _NXAUDIO_ERR_PORT; ! 857: return ([[[stream channel] audioDevice] ! 858: _getValues:(NXSoundParameterTag *)values ! 859: count:count forParameter:param forObject:stream] ? ! 860: _NXAUDIO_SUCCESS : _NXAUDIO_ERR_PARAMETER); ! 861: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.