2
* Helper and utility functions for pa_mac_core.c (Apple AUHAL implementation)
4
* PortAudio Portable Real-Time Audio Library
5
* Latest Version at: http://www.portaudio.com
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)
10
* Dominic's code was based on code by Phil Burk, Darren Gibbs,
11
* Gord Peters, Stephane Letz, and Greg Pfiel.
13
* The following people also deserve acknowledgements:
15
* Olivier Tristan for feedback and testing
16
* Glenn Zelniker and Z-Systems engineering for sponsoring the Blocking I/O
20
* Based on the Open Source API proposed by Ross Bencina
21
* Copyright (c) 1999-2002 Ross Bencina, Phil Burk
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:
31
* The above copyright notice and this permission notice shall be
32
* included in all copies or substantial portions of the Software.
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.
44
* The text above constitutes the entire PortAudio license; however,
45
* the PortAudio community also makes the following non-binding requests:
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
59
#ifndef PA_MAC_CORE_UTILITIES_H__
60
#define PA_MAC_CORE_UTILITIES_H__
63
#include "portaudio.h"
65
#include <AudioUnit/AudioUnit.h>
66
#include <AudioToolbox/AudioToolbox.h>
69
#define MIN(a, b) (((a)<(b))?(a):(b))
73
#define MAX(a, b) (((a)<(b))?(b):(a))
76
#define ERR(mac_error) PaMacCore_SetError(mac_error, __LINE__, 1 )
77
#define WARNING(mac_error) PaMacCore_SetError(mac_error, __LINE__, 0 )
80
/* Help keep track of AUHAL element numbers */
81
#define INPUT_ELEMENT (1)
82
#define OUTPUT_ELEMENT (0)
84
/* Normal level of debugging: fine for most apps that don't mind the occational warning being printf'ed */
87
#define MAC_CORE_DEBUG
89
# define DBUG(MSG) do { printf("||PaMacCore (AUHAL)|| "); printf MSG ; fflush(stdout); } while(0)
94
/* Verbose Debugging: useful for developement */
96
#define MAC_CORE_VERBOSE_DEBUG
98
#ifdef MAC_CORE_VERBOSE_DEBUG
99
# define VDBUG(MSG) do { printf("||PaMacCore (v )|| "); printf MSG ; fflush(stdout); } while(0)
104
/* Very Verbose Debugging: Traces every call. */
106
#define MAC_CORE_VERY_VERBOSE_DEBUG
108
#ifdef MAC_CORE_VERY_VERBOSE_DEBUG
109
# define VVDBUG(MSG) do { printf("||PaMacCore (vv)|| "); printf MSG ; fflush(stdout); } while(0)
118
#define UNIX_ERR(err) PaMacCore_SetUnixError( err, __LINE__ )
120
PaError PaMacCore_SetUnixError( int err, int line );
123
* Translates MacOS generated errors into PaErrors
125
PaError PaMacCore_SetError(OSStatus error, int line, int isError);
128
* This function computes an appropriate ring buffer size given
129
* a requested latency (in seconds), sample rate and framesPerBuffer.
131
* The returned ringBufferSize is computed using the following
133
* - it must be at least 4.
134
* - it must be at least 3x framesPerBuffer.
135
* - it must be at least 2x the suggestedLatency.
136
* - it must be a power of 2.
137
* This function attempts to compute the minimum such size.
140
long computeRingBufferSize( const PaStreamParameters *inputParameters,
141
const PaStreamParameters *outputParameters,
142
long inputFramesPerBuffer,
143
long outputFramesPerBuffer,
146
OSStatus propertyProc(
147
AudioDeviceID inDevice,
150
AudioDevicePropertyID inPropertyID,
151
void* inClientData );
153
/* sets the value of the given property and waits for the change to
154
be acknowledged, and returns the final value, which is not guaranteed
155
by this function to be the same as the desired value. Obviously, this
156
function can only be used for data whose input and output are the
157
same size and format, and their size and format are known in advance.*/
158
PaError AudioDeviceSetPropertyNowAndWaitForChange(
159
AudioDeviceID inDevice,
162
AudioDevicePropertyID inPropertyID,
163
UInt32 inPropertyDataSize,
164
const void *inPropertyData,
165
void *outPropertyData );
168
* Sets the sample rate the HAL device.
169
* if requireExact: set the sample rate or fail.
171
* otherwise : set the exact sample rate.
172
* If that fails, check for available sample rates, and choose one
173
* higher than the requested rate. If there isn't a higher one,
174
* just use the highest available.
176
PaError setBestSampleRateForDevice( const AudioDeviceID device,
178
const bool requireExact,
179
const Float64 desiredSrate );
181
Attempts to set the requestedFramesPerBuffer. If it can't set the exact
182
value, it settles for something smaller if available. If nothing smaller
183
is available, it uses the smallest available size.
184
actualFramesPerBuffer will be set to the actual value on successful return.
185
OK to pass NULL to actualFramesPerBuffer.
186
The logic is very simmilar too setBestSampleRate only failure here is
187
not usually catastrophic.
189
PaError setBestFramesPerBuffer( const AudioDeviceID device,
191
UInt32 requestedFramesPerBuffer,
192
UInt32 *actualFramesPerBuffer );
195
/*********************
199
*********************/
201
OSStatus xrunCallback(
202
AudioDeviceID inDevice,
205
AudioDevicePropertyID inPropertyID,
206
void* inClientData ) ;
208
/** returns zero on success or a unix style error code. */
209
int initializeXRunListenerList();
210
/** returns zero on success or a unix style error code. */
211
int destroyXRunListenerList();
213
/**Returns the list, so that it can be passed to CorAudio.*/
214
void *addToXRunListenerList( void *stream );
215
/**Returns the number of Listeners in the list remaining.*/
216
int removeFromXRunListenerList( void *stream );
218
#endif /* PA_MAC_CORE_UTILITIES_H__*/