pa_mac_core_blocking.h

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

Generated on Thu Feb 21 15:24:38 2008 for PortAudio by  doxygen 1.5.4