| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
#ifndef PA_MAC_CORE_UTILITIES_H__ |
| 60 |
#define PA_MAC_CORE_UTILITIES_H__ |
| 61 |
|
| 62 |
#include <pthread.h> |
| 63 |
#include "portaudio.h" |
| 64 |
#include "pa_util.h" |
| 65 |
#include <AudioUnit/AudioUnit.h> |
| 66 |
#include <AudioToolbox/AudioToolbox.h> |
| 67 |
|
| 68 |
#ifndef MIN |
| 69 |
#define MIN(a, b) (((a)<(b))?(a):(b)) |
| 70 |
#endif |
| 71 |
|
| 72 |
#ifndef MAX |
| 73 |
#define MAX(a, b) (((a)<(b))?(b):(a)) |
| 74 |
#endif |
| 75 |
|
| 76 |
#define ERR(mac_error) PaMacCore_SetError(mac_error, __LINE__, 1 ) |
| 77 |
#define WARNING(mac_error) PaMacCore_SetError(mac_error, __LINE__, 0 ) |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
#define INPUT_ELEMENT (1) |
| 82 |
#define OUTPUT_ELEMENT (0) |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
#define MAC_CORE_DEBUG |
| 88 |
#ifdef MAC_CORE_DEBUG |
| 89 |
# define DBUG(MSG) do { printf("||PaMacCore (AUHAL)|| "); printf MSG ; fflush(stdout); } while(0) |
| 90 |
#else |
| 91 |
# define DBUG(MSG) |
| 92 |
#endif |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
#ifdef MAC_CORE_VERBOSE_DEBUG |
| 99 |
# define VDBUG(MSG) do { printf("||PaMacCore (v )|| "); printf MSG ; fflush(stdout); } while(0) |
| 100 |
#else |
| 101 |
# define VDBUG(MSG) |
| 102 |
#endif |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
#ifdef MAC_CORE_VERY_VERBOSE_DEBUG |
| 109 |
# define VVDBUG(MSG) do { printf("||PaMacCore (vv)|| "); printf MSG ; fflush(stdout); } while(0) |
| 110 |
#else |
| 111 |
# define VVDBUG(MSG) |
| 112 |
#endif |
| 113 |
|
| 114 |
OSStatus PaMacCore_AudioHardwareGetProperty( |
| 115 |
AudioHardwarePropertyID inPropertyID, |
| 116 |
UInt32* ioPropertyDataSize, |
| 117 |
void* outPropertyData ); |
| 118 |
|
| 119 |
OSStatus PaMacCore_AudioHardwareGetPropertySize( |
| 120 |
AudioHardwarePropertyID inPropertyID, |
| 121 |
UInt32* outSize ); |
| 122 |
|
| 123 |
OSStatus PaMacCore_AudioDeviceGetProperty( |
| 124 |
AudioDeviceID inDevice, |
| 125 |
UInt32 inChannel, |
| 126 |
Boolean isInput, |
| 127 |
AudioDevicePropertyID inPropertyID, |
| 128 |
UInt32* ioPropertyDataSize, |
| 129 |
void* outPropertyData ); |
| 130 |
|
| 131 |
OSStatus PaMacCore_AudioDeviceSetProperty( |
| 132 |
AudioDeviceID inDevice, |
| 133 |
const AudioTimeStamp* inWhen, |
| 134 |
UInt32 inChannel, |
| 135 |
Boolean isInput, |
| 136 |
AudioDevicePropertyID inPropertyID, |
| 137 |
UInt32 inPropertyDataSize, |
| 138 |
const void* inPropertyData ); |
| 139 |
|
| 140 |
OSStatus PaMacCore_AudioDeviceGetPropertySize( |
| 141 |
AudioDeviceID inDevice, |
| 142 |
UInt32 inChannel, |
| 143 |
Boolean isInput, |
| 144 |
AudioDevicePropertyID inPropertyID, |
| 145 |
UInt32* outSize ); |
| 146 |
|
| 147 |
OSStatus PaMacCore_AudioDeviceAddPropertyListener( |
| 148 |
AudioDeviceID inDevice, |
| 149 |
UInt32 inChannel, |
| 150 |
Boolean isInput, |
| 151 |
AudioDevicePropertyID inPropertyID, |
| 152 |
AudioObjectPropertyListenerProc inProc, |
| 153 |
void* inClientData ); |
| 154 |
|
| 155 |
OSStatus PaMacCore_AudioDeviceRemovePropertyListener( |
| 156 |
AudioDeviceID inDevice, |
| 157 |
UInt32 inChannel, |
| 158 |
Boolean isInput, |
| 159 |
AudioDevicePropertyID inPropertyID, |
| 160 |
AudioObjectPropertyListenerProc inProc, |
| 161 |
void* inClientData ); |
| 162 |
|
| 163 |
OSStatus PaMacCore_AudioStreamGetProperty( |
| 164 |
AudioStreamID inStream, |
| 165 |
UInt32 inChannel, |
| 166 |
AudioDevicePropertyID inPropertyID, |
| 167 |
UInt32* ioPropertyDataSize, |
| 168 |
void* outPropertyData ); |
| 169 |
|
| 170 |
#define UNIX_ERR(err) PaMacCore_SetUnixError( err, __LINE__ ) |
| 171 |
|
| 172 |
PaError PaMacCore_SetUnixError( int err, int line ); |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
PaError PaMacCore_SetError(OSStatus error, int line, int isError); |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
long computeRingBufferSize( const PaStreamParameters *inputParameters, |
| 193 |
const PaStreamParameters *outputParameters, |
| 194 |
long inputFramesPerBuffer, |
| 195 |
long outputFramesPerBuffer, |
| 196 |
double sampleRate ); |
| 197 |
|
| 198 |
OSStatus propertyProc( |
| 199 |
AudioObjectID inObjectID, |
| 200 |
UInt32 inNumberAddresses, |
| 201 |
const AudioObjectPropertyAddress* inAddresses, |
| 202 |
void* inClientData ); |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
PaError AudioDeviceSetPropertyNowAndWaitForChange( |
| 210 |
AudioDeviceID inDevice, |
| 211 |
UInt32 inChannel, |
| 212 |
Boolean isInput, |
| 213 |
AudioDevicePropertyID inPropertyID, |
| 214 |
UInt32 inPropertyDataSize, |
| 215 |
const void *inPropertyData, |
| 216 |
void *outPropertyData ); |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
PaError setBestSampleRateForDevice( const AudioDeviceID device, |
| 228 |
const bool isOutput, |
| 229 |
const bool requireExact, |
| 230 |
const Float64 desiredSrate ); |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
PaError setBestFramesPerBuffer( const AudioDeviceID device, |
| 241 |
const bool isOutput, |
| 242 |
UInt32 requestedFramesPerBuffer, |
| 243 |
UInt32 *actualFramesPerBuffer ); |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
OSStatus xrunCallback( |
| 253 |
AudioObjectID inObjectID, |
| 254 |
UInt32 inNumberAddresses, |
| 255 |
const AudioObjectPropertyAddress* inAddresses, |
| 256 |
void * inClientData ); |
| 257 |
|
| 258 |
|
| 259 |
int initializeXRunListenerList( void ); |
| 260 |
|
| 261 |
int destroyXRunListenerList( void ); |
| 262 |
|
| 263 |
|
| 264 |
void *addToXRunListenerList( void *stream ); |
| 265 |
|
| 266 |
int removeFromXRunListenerList( void *stream ); |
| 267 |
|
| 268 |
#endif |