PortAudio  2.0
pa_mac_core_blocking.h
Go to the documentation of this file.
1 /*
2  * Internal blocking interfaces for PortAudio Apple AUHAL implementation
3  *
4  * PortAudio Portable Real-Time Audio Library
5  * Latest Version at: http://www.portaudio.com
6  *
7  * Written by Bjorn Roche of XO Audio LLC, from PA skeleton code.
8  * Portions copied from code by Dominic Mazzoni (who wrote a HAL implementation)
9  *
10  * Dominic's code was based on code by Phil Burk, Darren Gibbs,
11  * Gord Peters, Stephane Letz, and Greg Pfiel.
12  *
13  * The following people also deserve acknowledgements:
14  *
15  * Olivier Tristan for feedback and testing
16  * Glenn Zelniker and Z-Systems engineering for sponsoring the Blocking I/O
17  * interface.
18  *
19  *
20  * Based on the Open Source API proposed by Ross Bencina
21  * Copyright (c) 1999-2002 Ross Bencina, Phil Burk
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files
25  * (the "Software"), to deal in the Software without restriction,
26  * including without limitation the rights to use, copy, modify, merge,
27  * publish, distribute, sublicense, and/or sell copies of the Software,
28  * and to permit persons to whom the Software is furnished to do so,
29  * subject to the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
38  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
39  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  */
42 
43 /*
44  * The text above constitutes the entire PortAudio license; however,
45  * the PortAudio community also makes the following non-binding requests:
46  *
47  * Any person wishing to distribute modifications to the Software is
48  * requested to send the modifications to the original developer so that
49  * they can be incorporated into the canonical version. It is also
50  * requested that these non-binding requests be included along with the
51  * license above.
52  */
53 
59 #ifndef PA_MAC_CORE_BLOCKING_H_
60 #define PA_MAC_CORE_BLOCKING_H_
61 
62 #include "pa_ringbuffer.h"
63 #include "portaudio.h"
64 #include "pa_mac_core_utilities.h"
65 
66 /*
67  * Number of milliseconds to busy wait while waiting for data in blocking calls.
68  */
69 #define PA_MAC_BLIO_BUSY_WAIT_SLEEP_INTERVAL (5)
70 /*
71  * Define exactly one of these blocking methods
72  * PA_MAC_BLIO_MUTEX is not actively maintained.
73  */
74 #define PA_MAC_BLIO_BUSY_WAIT
75 /*
76 #define PA_MAC_BLIO_MUTEX
77 */
78 
79 typedef struct {
89 
90  int inChan;
91  int outChan;
92 
93  //PaStreamCallbackFlags statusFlags;
94  uint32_t statusFlags;
96 
97  /* Here we handle blocking, using condition variables. */
98 #ifdef PA_MAC_BLIO_MUTEX
99  volatile bool isInputEmpty;
100  pthread_mutex_t inputMutex;
101  pthread_cond_t inputCond;
102 
103  volatile bool isOutputFull;
104  pthread_mutex_t outputMutex;
105  pthread_cond_t outputCond;
106 #endif
107 }
108 PaMacBlio;
109 
110 /*
111  * These functions operate on condition and related variables.
112  */
113 
115  PaMacBlio *blio,
116  PaSampleFormat inputSampleFormat,
117  PaSampleFormat outputSampleFormat,
118  long ringBufferSizeInFrames,
119  int inChan,
120  int outChan );
123 
124 int BlioCallback(
125  const void *input, void *output,
126  unsigned long frameCount,
127  const PaStreamCallbackTimeInfo* timeInfo,
128  PaStreamCallbackFlags statusFlags,
129  void *userData );
130 
131 PaError waitUntilBlioWriteBufferIsEmpty( PaMacBlio *blio, double sampleRate,
132  size_t framesPerBuffer );
133 
134 #endif /*PA_MAC_CORE_BLOCKING_H_*/
PaUtilRingBuffer outputRingBuffer
Definition: pa_mac_core_blocking.h:81
PaError waitUntilBlioWriteBufferIsEmpty(PaMacBlio *blio, double sampleRate, size_t framesPerBuffer)
Definition: pa_mac_core_blocking.c:591
Single-reader single-writer lock-free ring buffer.
size_t outputSampleSizePow2
Definition: pa_mac_core_blocking.h:88
int outChan
Definition: pa_mac_core_blocking.h:91
PaError errors
Definition: pa_mac_core_blocking.h:95
PaError destroyBlioRingBuffers(PaMacBlio *blio)
Definition: pa_mac_core_blocking.c:309
int inChan
Definition: pa_mac_core_blocking.h:90
Definition: pa_ringbuffer.h:93
uint32_t statusFlags
Definition: pa_mac_core_blocking.h:94
size_t inputSampleSizeActual
Definition: pa_mac_core_blocking.h:84
The portable PortAudio API.
PaError initializeBlioRingBuffers(PaMacBlio *blio, PaSampleFormat inputSampleFormat, PaSampleFormat outputSampleFormat, long ringBufferSizeInFrames, int inChan, int outChan)
Definition: pa_mac_core_blocking.c:116
Definition: pa_mac_core_blocking.h:79
ring_buffer_size_t ringBufferFrames
Definition: pa_mac_core_blocking.h:82
long ring_buffer_size_t
Definition: pa_ringbuffer.h:83
PaSampleFormat outputSampleFormat
Definition: pa_mac_core_blocking.h:86
int PaError
Definition: portaudio.h:121
unsigned long PaStreamCallbackFlags
Definition: portaudio.h:712
unsigned long PaSampleFormat
Definition: portaudio.h:484
size_t inputSampleSizePow2
Definition: pa_mac_core_blocking.h:85
int BlioCallback(const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
Definition: pa_mac_core_blocking.c:341
size_t outputSampleSizeActual
Definition: pa_mac_core_blocking.h:87
PaSampleFormat inputSampleFormat
Definition: pa_mac_core_blocking.h:83
PaError resetBlioRingBuffers(PaMacBlio *blio)
Definition: pa_mac_core_blocking.c:265
PaUtilRingBuffer inputRingBuffer
Definition: pa_mac_core_blocking.h:80
Definition: portaudio.h:699