00001 /* 00002 * Implementation of the PortAudio API for Apple AUHAL 00003 * 00004 * PortAudio Portable Real-Time Audio Library 00005 * Latest Version at: http://www.portaudio.com 00006 * 00007 * Written by Bjorn Roche of XO Audio LLC, from PA skeleton code. 00008 * Portions copied from code by Dominic Mazzoni (who wrote a HAL implementation) 00009 * 00010 * Dominic's code was based on code by Phil Burk, Darren Gibbs, 00011 * Gord Peters, Stephane Letz, and Greg Pfiel. 00012 * 00013 * Bjorn Roche and XO Audio LLC reserve no rights to this code. 00014 * The maintainers of PortAudio may redistribute and modify the code and 00015 * licenses as they deam appropriate. 00016 * 00017 * The following people also deserve acknowledgements: 00018 * 00019 * Olivier Tristan for feedback and testing 00020 * Glenn Zelniker and Z-Systems engineering for sponsoring the Blocking I/O 00021 * interface. 00022 * 00023 * 00024 * Based on the Open Source API proposed by Ross Bencina 00025 * Copyright (c) 1999-2002 Ross Bencina, Phil Burk 00026 * 00027 * Permission is hereby granted, free of charge, to any person obtaining 00028 * a copy of this software and associated documentation files 00029 * (the "Software"), to deal in the Software without restriction, 00030 * including without limitation the rights to use, copy, modify, merge, 00031 * publish, distribute, sublicense, and/or sell copies of the Software, 00032 * and to permit persons to whom the Software is furnished to do so, 00033 * subject to the following conditions: 00034 * 00035 * The above copyright notice and this permission notice shall be 00036 * included in all copies or substantial portions of the Software. 00037 * 00038 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00039 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00040 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00041 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 00042 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00043 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00044 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00045 */ 00046 00047 /* 00048 * The text above constitutes the entire PortAudio license; however, 00049 * the PortAudio community also makes the following non-binding requests: 00050 * 00051 * Any person wishing to distribute modifications to the Software is 00052 * requested to send the modifications to the original developer so that 00053 * they can be incorporated into the canonical version. It is also 00054 * requested that these non-binding requests be included along with the 00055 * license above. 00056 */ 00057 00064 #ifndef PA_MAC_CORE_INTERNAL_H__ 00065 #define PA_MAC_CORE_INTERNAL_H__ 00066 00067 #include <AudioUnit/AudioUnit.h> 00068 #include <AudioToolbox/AudioToolbox.h> 00069 00070 00071 #include "portaudio.h" 00072 #include "pa_util.h" 00073 #include "pa_hostapi.h" 00074 #include "pa_stream.h" 00075 #include "pa_allocation.h" 00076 #include "pa_cpuload.h" 00077 #include "pa_process.h" 00078 #include "ringbuffer.h" 00079 00080 #include "pa_mac_core_blocking.h" 00081 00082 /* function prototypes */ 00083 00084 #ifdef __cplusplus 00085 extern "C" 00086 { 00087 #endif /* __cplusplus */ 00088 00089 PaError PaMacCore_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); 00090 00091 #ifdef __cplusplus 00092 } 00093 #endif /* __cplusplus */ 00094 00095 #define RING_BUFFER_ADVANCE_DENOMINATOR (4) 00096 00097 PaError ReadStream( PaStream* stream, void *buffer, unsigned long frames ); 00098 PaError WriteStream( PaStream* stream, const void *buffer, unsigned long frames ); 00099 signed long GetStreamReadAvailable( PaStream* stream ); 00100 signed long GetStreamWriteAvailable( PaStream* stream ); 00101 /* PaMacAUHAL - host api datastructure specific to this implementation */ 00102 typedef struct 00103 { 00104 PaUtilHostApiRepresentation inheritedHostApiRep; 00105 PaUtilStreamInterface callbackStreamInterface; 00106 PaUtilStreamInterface blockingStreamInterface; 00107 00108 PaUtilAllocationGroup *allocations; 00109 00110 /* implementation specific data goes here */ 00111 long devCount; 00112 AudioDeviceID *devIds; /*array of all audio devices*/ 00113 AudioDeviceID defaultIn; 00114 AudioDeviceID defaultOut; 00115 } 00116 PaMacAUHAL; 00117 00118 00119 00120 /* stream data structure specifically for this implementation */ 00121 typedef struct PaMacCoreStream 00122 { 00123 PaUtilStreamRepresentation streamRepresentation; 00124 PaUtilCpuLoadMeasurer cpuLoadMeasurer; 00125 PaUtilBufferProcessor bufferProcessor; 00126 00127 /* implementation specific data goes here */ 00128 bool bufferProcessorIsInitialized; 00129 AudioUnit inputUnit; 00130 AudioUnit outputUnit; 00131 AudioDeviceID inputDevice; 00132 AudioDeviceID outputDevice; 00133 size_t userInChan; 00134 size_t userOutChan; 00135 size_t inputFramesPerBuffer; 00136 size_t outputFramesPerBuffer; 00137 PaMacBlio blio; 00138 /* We use this ring buffer when input and out devs are different. */ 00139 RingBuffer inputRingBuffer; 00140 /* We may need to do SR conversion on input. */ 00141 AudioConverterRef inputSRConverter; 00142 /* We need to preallocate an inputBuffer for reading data. */ 00143 AudioBufferList inputAudioBufferList; 00144 AudioTimeStamp startTime; 00145 volatile PaStreamCallbackFlags xrunFlags; 00146 volatile bool isTimeSet; 00147 volatile enum { 00148 STOPPED = 0, /* playback is completely stopped, 00149 and the user has called StopStream(). */ 00150 CALLBACK_STOPPED = 1, /* callback has requested stop, 00151 but user has not yet called StopStream(). */ 00152 STOPPING = 2, /* The stream is in the process of closing. 00153 This state is just used internally; 00154 externally it is indistinguishable from 00155 ACTIVE.*/ 00156 ACTIVE = 3 /* The stream is active and running. */ 00157 } state; 00158 double sampleRate; 00159 //these may be different from the stream sample rate due to SR conversion: 00160 double outDeviceSampleRate; 00161 double inDeviceSampleRate; 00162 } 00163 PaMacCoreStream; 00164 00165 #endif /* PA_MAC_CORE_INTERNAL_H__ */