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 00058 #ifndef PA_MAC_CORE_BLOCKING_H_ 00059 #define PA_MAC_CORE_BLOCKING_H_ 00060 00061 #include "ringbuffer.h" 00062 #include "portaudio.h" 00063 #include "pa_mac_core_utilities.h" 00064 00065 /* 00066 * Number of miliseconds to busy wait whil waiting for data in blocking calls. 00067 */ 00068 #define PA_MAC_BLIO_BUSY_WAIT_SLEEP_INTERVAL (5) 00069 /* 00070 * Define exactly one of these blocking methods 00071 * PA_MAC_BLIO_MUTEX is not actively maintained. 00072 */ 00073 #define PA_MAC_BLIO_BUSY_WAIT 00074 /* 00075 #define PA_MAC_BLIO_MUTEX 00076 */ 00077 00078 typedef struct { 00079 RingBuffer inputRingBuffer; 00080 RingBuffer outputRingBuffer; 00081 PaSampleFormat inputSampleFormat; 00082 size_t inputSampleSize; 00083 PaSampleFormat outputSampleFormat; 00084 size_t outputSampleSize; 00085 00086 size_t framesPerBuffer; 00087 00088 int inChan; 00089 int outChan; 00090 00091 //PaStreamCallbackFlags statusFlags; 00092 uint32_t statusFlags; 00093 PaError errors; 00094 00095 /* Here we handle blocking, using condition variables. */ 00096 #ifdef PA_MAC_BLIO_MUTEX 00097 volatile bool isInputEmpty; 00098 pthread_mutex_t inputMutex; 00099 pthread_cond_t inputCond; 00100 00101 volatile bool isOutputFull; 00102 pthread_mutex_t outputMutex; 00103 pthread_cond_t outputCond; 00104 #endif 00105 } 00106 PaMacBlio; 00107 00108 /* 00109 * These functions operate on condition and related variables. 00110 */ 00111 00112 PaError initializeBlioRingBuffers( 00113 PaMacBlio *blio, 00114 PaSampleFormat inputSampleFormat, 00115 PaSampleFormat outputSampleFormat, 00116 size_t framesPerBuffer, 00117 long ringBufferSize, 00118 int inChan, 00119 int outChan ); 00120 PaError destroyBlioRingBuffers( PaMacBlio *blio ); 00121 PaError resetBlioRingBuffers( PaMacBlio *blio ); 00122 00123 int BlioCallback( 00124 const void *input, void *output, 00125 unsigned long frameCount, 00126 const PaStreamCallbackTimeInfo* timeInfo, 00127 PaStreamCallbackFlags statusFlags, 00128 void *userData ); 00129 00130 void waitUntilBlioWriteBufferIsFlushed( PaMacBlio *blio ); 00131 00132 #endif /*PA_MAC_CORE_BLOCKING_H_*/