PortAudio
2.0
|
00001 /* 00002 * Internal interfaces for PortAudio Apple AUHAL implementation 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 * The following people also deserve acknowledgements: 00014 * 00015 * Olivier Tristan for feedback and testing 00016 * Glenn Zelniker and Z-Systems engineering for sponsoring the Blocking I/O 00017 * interface. 00018 * 00019 * 00020 * Based on the Open Source API proposed by Ross Bencina 00021 * Copyright (c) 1999-2002 Ross Bencina, Phil Burk 00022 * 00023 * Permission is hereby granted, free of charge, to any person obtaining 00024 * a copy of this software and associated documentation files 00025 * (the "Software"), to deal in the Software without restriction, 00026 * including without limitation the rights to use, copy, modify, merge, 00027 * publish, distribute, sublicense, and/or sell copies of the Software, 00028 * and to permit persons to whom the Software is furnished to do so, 00029 * subject to the following conditions: 00030 * 00031 * The above copyright notice and this permission notice shall be 00032 * included in all copies or substantial portions of the Software. 00033 * 00034 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00035 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00036 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00037 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 00038 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 00039 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00040 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00041 */ 00042 00043 /* 00044 * The text above constitutes the entire PortAudio license; however, 00045 * the PortAudio community also makes the following non-binding requests: 00046 * 00047 * Any person wishing to distribute modifications to the Software is 00048 * requested to send the modifications to the original developer so that 00049 * they can be incorporated into the canonical version. It is also 00050 * requested that these non-binding requests be included along with the 00051 * license above. 00052 */ 00053 00061 #ifndef PA_MAC_CORE_INTERNAL_H__ 00062 #define PA_MAC_CORE_INTERNAL_H__ 00063 00064 #include <CoreAudio/CoreAudio.h> 00065 #include <CoreServices/CoreServices.h> 00066 #include <AudioUnit/AudioUnit.h> 00067 #include <AudioToolbox/AudioToolbox.h> 00068 00069 #include "portaudio.h" 00070 #include "pa_util.h" 00071 #include "pa_hostapi.h" 00072 #include "pa_stream.h" 00073 #include "pa_allocation.h" 00074 #include "pa_cpuload.h" 00075 #include "pa_process.h" 00076 #include "pa_ringbuffer.h" 00077 00078 #include "pa_mac_core_blocking.h" 00079 00080 /* function prototypes */ 00081 00082 #ifdef __cplusplus 00083 extern "C" 00084 { 00085 #endif /* __cplusplus */ 00086 00087 PaError PaMacCore_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); 00088 00089 #ifdef __cplusplus 00090 } 00091 #endif /* __cplusplus */ 00092 00093 #define RING_BUFFER_ADVANCE_DENOMINATOR (4) 00094 00095 PaError ReadStream( PaStream* stream, void *buffer, unsigned long frames ); 00096 PaError WriteStream( PaStream* stream, const void *buffer, unsigned long frames ); 00097 signed long GetStreamReadAvailable( PaStream* stream ); 00098 signed long GetStreamWriteAvailable( PaStream* stream ); 00099 /* PaMacAUHAL - host api datastructure specific to this implementation */ 00100 typedef struct 00101 { 00102 PaUtilHostApiRepresentation inheritedHostApiRep; 00103 PaUtilStreamInterface callbackStreamInterface; 00104 PaUtilStreamInterface blockingStreamInterface; 00105 00106 PaUtilAllocationGroup *allocations; 00107 00108 /* implementation specific data goes here */ 00109 long devCount; 00110 AudioDeviceID *devIds; /*array of all audio devices*/ 00111 AudioDeviceID defaultIn; 00112 AudioDeviceID defaultOut; 00113 } 00114 PaMacAUHAL; 00115 00116 00117 00118 /* stream data structure specifically for this implementation */ 00119 typedef struct PaMacCoreStream 00120 { 00121 PaUtilStreamRepresentation streamRepresentation; 00122 PaUtilCpuLoadMeasurer cpuLoadMeasurer; 00123 PaUtilBufferProcessor bufferProcessor; 00124 00125 /* implementation specific data goes here */ 00126 bool bufferProcessorIsInitialized; 00127 AudioUnit inputUnit; 00128 AudioUnit outputUnit; 00129 AudioDeviceID inputDevice; 00130 AudioDeviceID outputDevice; 00131 size_t userInChan; 00132 size_t userOutChan; 00133 size_t inputFramesPerBuffer; 00134 size_t outputFramesPerBuffer; 00135 PaMacBlio blio; 00136 /* We use this ring buffer when input and out devs are different. */ 00137 PaUtilRingBuffer inputRingBuffer; 00138 /* We may need to do SR conversion on input. */ 00139 AudioConverterRef inputSRConverter; 00140 /* We need to preallocate an inputBuffer for reading data. */ 00141 AudioBufferList inputAudioBufferList; 00142 AudioTimeStamp startTime; 00143 /* FIXME: instead of volatile, these should be properly memory barriered */ 00144 volatile uint32_t xrunFlags; /*PaStreamCallbackFlags*/ 00145 volatile enum { 00146 STOPPED = 0, /* playback is completely stopped, 00147 and the user has called StopStream(). */ 00148 CALLBACK_STOPPED = 1, /* callback has requested stop, 00149 but user has not yet called StopStream(). */ 00150 STOPPING = 2, /* The stream is in the process of closing 00151 because the user has called StopStream. 00152 This state is just used internally; 00153 externally it is indistinguishable from 00154 ACTIVE.*/ 00155 ACTIVE = 3 /* The stream is active and running. */ 00156 } state; 00157 double sampleRate; 00158 //these may be different from the stream sample rate due to SR conversion: 00159 double outDeviceSampleRate; 00160 double inDeviceSampleRate; 00161 00162 /* data updated by main thread and notifications, protected by timingInformationMutex */ 00163 int timingInformationMutexIsInitialized; 00164 pthread_mutex_t timingInformationMutex; 00165 Float64 recipricalOfActualOutputSampleRate; 00166 UInt32 deviceOutputLatencySamples; 00167 UInt32 deviceInputLatencySamples; 00168 00169 /* while the io proc is active, the following values are only accessed and manipulated by the ioproc */ 00170 Float64 recipricalOfActualOutputSampleRate_ioProcCopy; 00171 UInt32 deviceOutputLatencySamples_ioProcCopy; 00172 UInt32 deviceInputLatencySamples_ioProcCopy; 00173 } 00174 PaMacCoreStream; 00175 00176 #endif /* PA_MAC_CORE_INTERNAL_H__ */