/* First try with CFString */
UInt32 size = sizeof(nameRef);
- error = AudioDeviceGetProperty( hostApiDevice,
+ error = pa_AudioDeviceGetProperty( hostApiDevice,
channelIndex + 1,
input,
kAudioDevicePropertyChannelNameCFString,
{
/* try the C String */
size = 0;
- error = AudioDeviceGetPropertyInfo( hostApiDevice,
+ error = pa_AudioDeviceGetPropertySize( hostApiDevice,
channelIndex + 1,
input,
kAudioDevicePropertyChannelName,
- &size,
- NULL);
+ &size);
if( !error )
{
if( !ensureChannelNameSize( size ) )
return NULL;
-
- error = AudioDeviceGetProperty( hostApiDevice,
+
+ error = pa_AudioDeviceGetProperty( hostApiDevice,
channelIndex + 1,
input,
kAudioDevicePropertyChannelName,
Boolean isInput = 0;
if( macCoreHostApi->inheritedHostApiRep.deviceInfos[hostApiDeviceIndex]->maxOutputChannels == 0 )
isInput = 1;
-
- result = WARNING(AudioDeviceGetProperty( macCoreDeviceId, 0, isInput, kAudioDevicePropertyBufferFrameSizeRange, &propSize, &audioRange ) );
+
+ result = WARNING(pa_AudioDeviceGetProperty( macCoreDeviceId, 0, isInput, kAudioDevicePropertyBufferFrameSizeRange, &propSize, &audioRange ) );
*minBufferSizeFrames = audioRange.mMinimum;
*maxBufferSizeFrames = audioRange.mMaximum;
auhalHostApi->devIds = NULL;
/* -- figure out how many devices there are -- */
- AudioHardwareGetPropertyInfo( kAudioHardwarePropertyDevices,
- &propsize,
- NULL );
+ pa_AudioHardwareGetPropertySize( kAudioHardwarePropertyDevices,
+ &propsize);
auhalHostApi->devCount = propsize / sizeof( AudioDeviceID );
VDBUG( ( "Found %ld device(s).\n", auhalHostApi->devCount ) );
propsize );
if( !auhalHostApi->devIds )
return paInsufficientMemory;
- AudioHardwareGetProperty( kAudioHardwarePropertyDevices,
+ pa_AudioHardwareGetProperty( kAudioHardwarePropertyDevices,
&propsize,
auhalHostApi->devIds );
#ifdef MAC_CORE_VERBOSE_DEBUG
/* I am not sure how these calls to AudioHardwareGetProperty()
could fail, but in case they do, we use the first available
device as the default. */
- if( 0 != AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
+ if( 0 != pa_AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
&size,
&auhalHostApi->defaultIn) ) {
int i;
break;
}
}
- }
- if( 0 != AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
+ }
+ if( 0 != pa_AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
&size,
&auhalHostApi->defaultOut) ) {
int i;
UInt32 resultSize = desiredSize;
AudioValueRange audioRange;
UInt32 propSize = sizeof( audioRange );
- PaError err = WARNING(AudioDeviceGetProperty( macCoreDeviceId, 0, isInput, kAudioDevicePropertyBufferFrameSizeRange, &propSize, &audioRange ) );
+ PaError err = WARNING(pa_AudioDeviceGetProperty( macCoreDeviceId, 0, isInput, kAudioDevicePropertyBufferFrameSizeRange, &propSize, &audioRange ) );
resultSize = MAX( resultSize, audioRange.mMinimum );
resultSize = MIN( resultSize, audioRange.mMaximum );
*allowedSize = resultSize;
printf("Stream #%d = %d---------------------- \n", i, streamIDs[i] );
propSize = sizeof(UInt32);
- err = WARNING(AudioStreamGetProperty(streamIDs[i], 0, kAudioStreamPropertyLatency, &propSize, &streamLatency));
+ err = WARNING(p_AudioStreamGetProperty(streamIDs[i], 0, kAudioStreamPropertyLatency, &propSize, &streamLatency));
printf(" kAudioStreamPropertyLatency: err = %d, propSize = %d, value = %d\n", err, propSize, streamLatency );
}
}
// To get stream latency we have to get a streamID from the device.
// We are only going to look at the first stream so only fetch one stream.
propSize = sizeof(streamIDs);
- err = WARNING(AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreams, &propSize, &streamIDs[0]));
+ err = WARNING(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreams, &propSize, &streamIDs[0]));
if( err != paNoError ) goto error;
if( propSize == sizeof(AudioStreamID) )
{
propSize = sizeof(UInt32);
- err = WARNING(AudioStreamGetProperty(streamIDs[0], 0, kAudioStreamPropertyLatency, &propSize, &streamLatency));
+ err = WARNING(pa_AudioStreamGetProperty(streamIDs[0], 0, kAudioStreamPropertyLatency, &propSize, &streamLatency));
}
propSize = sizeof(UInt32);
- err = WARNING(AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertySafetyOffset, &propSize, &safetyOffset));
+ err = WARNING(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertySafetyOffset, &propSize, &safetyOffset));
if( err != paNoError ) goto error;
propSize = sizeof(UInt32);
- err = WARNING(AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyLatency, &propSize, &deviceLatency));
+ err = WARNING(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyLatency, &propSize, &deviceLatency));
if( err != paNoError ) goto error;
*fixedLatencyPtr = deviceLatency + streamLatency + safetyOffset;
// For high latency use the default device buffer size.
propSize = sizeof(UInt32);
- err = WARNING(AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyBufferFrameSize, &propSize, &bufferFrames));
+ err = WARNING(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyBufferFrameSize, &propSize, &bufferFrames));
if( err != paNoError ) goto error;
*lowLatencyFramesPtr = fixedLatency + clippedMinBufferSize;
/* Get the number of channels from the stream configuration.
Fail if we can't get this. */
- err = ERR(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreamConfiguration, &propSize, NULL));
+ err = ERR(pa_AudioDeviceGetPropertySize(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreamConfiguration, &propSize));
if (err)
return err;
buflist = PaUtil_AllocateMemory(propSize);
if( !buflist )
return paInsufficientMemory;
- err = ERR(AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreamConfiguration, &propSize, buflist));
+ err = ERR(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, isInput, kAudioDevicePropertyStreamConfiguration, &propSize, buflist));
if (err)
goto error;
/* Get the device name using CFString */
propSize = sizeof(nameRef);
- err = ERR(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceNameCFString, &propSize, &nameRef));
+ err = ERR(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceNameCFString, &propSize, &nameRef));
if (err)
{
/* Get the device name using c string. Fail if we can't get it. */
- err = ERR(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, NULL));
+ err = ERR(pa_AudioDeviceGetPropertySize(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize));
if (err)
return err;
name = PaUtil_GroupAllocateMemory(auhalHostApi->allocations,propSize+1);
if ( !name )
return paInsufficientMemory;
- err = ERR(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, name));
+ err = ERR(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, name));
if (err)
return err;
}
/* Try to get the default sample rate. Don't fail if we can't get this. */
propSize = sizeof(Float64);
- err = ERR(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyNominalSampleRate, &propSize, &sampleRate));
+ err = ERR(pa_AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyNominalSampleRate, &propSize, &sampleRate));
if (err)
deviceInfo->defaultSampleRate = 0.0;
else
Float64 sampleRate = 0.0;
UInt32 propSize = sizeof(Float64);
- OSStatus osErr = AudioDeviceGetProperty( deviceID, 0, isInput, sampleRatePropertyID, &propSize, &sampleRate);
+ OSStatus osErr = pa_AudioDeviceGetProperty( deviceID, 0, isInput, sampleRatePropertyID, &propSize, &sampleRate);
if( (osErr == noErr) && (sampleRate > 1000.0) ) /* avoid divide by zero if there's an error */
{
deviceProperties->sampleRate = sampleRate;
return osErr;
}
+#if PA_NEW_HAL
+static OSStatus AudioDevicePropertyActualSampleRateListenerProc(AudioObjectID inDevice, UInt32 inNumberAddresses, const AudioObjectPropertyAddress * inAddresses, void * inClientData)
+{
+ PaMacCoreStream * stream = (PaMacCoreStream *) inClientData;
+ bool isInput = inAddresses->mScope == kAudioDevicePropertyScopeInput;
+
+ // Make sure the callback is operating on a stream that is still valid!
+ assert(stream->streamRepresentation.magic == PA_STREAM_MAGIC);
+
+ OSStatus osErr = UpdateSampleRateFromDeviceProperty(stream, inDevice, isInput, kAudioDevicePropertyActualSampleRate);
+ if (osErr == noErr)
+ {
+ UpdateTimeStampOffsets(stream);
+ }
+ return osErr;
+}
+#else
static OSStatus AudioDevicePropertyActualSampleRateListenerProc( AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput, AudioDevicePropertyID inPropertyID, void *inClientData )
{
PaMacCoreStream *stream = (PaMacCoreStream*)inClientData;
}
return osErr;
}
-
+#endif
/* ================================================================================= */
static OSStatus QueryUInt32DeviceProperty( AudioDeviceID deviceID, Boolean isInput, AudioDevicePropertyID propertyID, UInt32 *outValue )
{
UInt32 propertyValue = 0;
UInt32 propertySize = sizeof(UInt32);
- OSStatus osErr = AudioDeviceGetProperty( deviceID, 0, isInput, propertyID, &propertySize, &propertyValue);
+ OSStatus osErr = pa_AudioDeviceGetProperty( deviceID, 0, isInput, propertyID, &propertySize, &propertyValue);
if( osErr == noErr )
{
*outValue = propertyValue;
return osErr;
}
+#if PA_NEW_HAL
+static OSStatus AudioDevicePropertyGenericListenerProc(AudioObjectID inDevice, UInt32 inNumberAddresses, const AudioObjectPropertyAddress * inAddresses, void * inClientData)
+{
+ OSStatus osErr = noErr;
+ PaMacCoreStream * stream = (PaMacCoreStream *) inClientData;
+ bool isInput = inAddresses->mScope == kAudioDevicePropertyScopeInput;
+ AudioDevicePropertyID inPropertyID = inAddresses->mSelector;
+
+ // Make sure the callback is operating on a stream that is still valid!
+ assert(stream->streamRepresentation.magic == PA_STREAM_MAGIC);
+
+ PaMacCoreDeviceProperties * deviceProperties = isInput ? &stream->inputProperties : &stream->outputProperties;
+ UInt32 * valuePtr = NULL;
+ switch (inPropertyID)
+ {
+ case kAudioDevicePropertySafetyOffset:
+ valuePtr = &deviceProperties->safetyOffset;
+ break;
+
+ case kAudioDevicePropertyLatency:
+ valuePtr = &deviceProperties->deviceLatency;
+ break;
+
+ case kAudioDevicePropertyBufferFrameSize:
+ valuePtr = &deviceProperties->bufferFrameSize;
+ break;
+ }
+ if (valuePtr != NULL)
+ {
+ osErr = QueryUInt32DeviceProperty(inDevice, isInput, inPropertyID, valuePtr);
+ if (osErr == noErr)
+ {
+ UpdateTimeStampOffsets(stream);
+ }
+ }
+ return osErr;
+}
+#else
static OSStatus AudioDevicePropertyGenericListenerProc( AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput, AudioDevicePropertyID inPropertyID, void *inClientData )
{
OSStatus osErr = noErr;
}
return osErr;
}
+#endif
/* ================================================================================= */
/*
kAudioDevicePropertyBufferFrameSize, &deviceProperties->bufferFrameSize )) != noErr ) return osErr;
if( (osErr = QueryUInt32DeviceProperty( deviceID, isInput,
kAudioDevicePropertySafetyOffset, &deviceProperties->safetyOffset )) != noErr ) return osErr;
-
- AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioDevicePropertyActualSampleRate,
+
+ pa_AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioDevicePropertyActualSampleRate,
AudioDevicePropertyActualSampleRateListenerProc, stream );
-
- AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioStreamPropertyLatency,
- AudioDevicePropertyGenericListenerProc, stream );
- AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioDevicePropertyBufferFrameSize,
- AudioDevicePropertyGenericListenerProc, stream );
- AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioDevicePropertySafetyOffset,
- AudioDevicePropertyGenericListenerProc, stream );
-
+
+ pa_AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioStreamPropertyLatency,
+ AudioDevicePropertyGenericListenerProc, stream );
+ pa_AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioDevicePropertyBufferFrameSize,
+ AudioDevicePropertyGenericListenerProc, stream );
+ pa_AudioDeviceAddPropertyListener( deviceID, 0, isInput, kAudioDevicePropertySafetyOffset,
+ AudioDevicePropertyGenericListenerProc, stream );
+
return osErr;
}
static void CleanupDevicePropertyListeners( PaMacCoreStream *stream, AudioDeviceID deviceID, Boolean isInput )
-{
- AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertyActualSampleRate,
- AudioDevicePropertyActualSampleRateListenerProc );
-
- AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertyLatency,
- AudioDevicePropertyGenericListenerProc );
- AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertyBufferFrameSize,
- AudioDevicePropertyGenericListenerProc );
- AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertySafetyOffset,
- AudioDevicePropertyGenericListenerProc );
+{
+ pa_AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertyActualSampleRate,
+ AudioDevicePropertyActualSampleRateListenerProc, stream );
+
+ pa_AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertyLatency,
+ AudioDevicePropertyGenericListenerProc, stream );
+ pa_AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertyBufferFrameSize,
+ AudioDevicePropertyGenericListenerProc, stream );
+ pa_AudioDeviceRemovePropertyListener( deviceID, 0, isInput, kAudioDevicePropertySafetyOffset,
+ AudioDevicePropertyGenericListenerProc, stream );
}
/* ================================================================================= */
sizeof(AudioDeviceID) ) );
}
/* -- add listener for dropouts -- */
- result = AudioDeviceAddPropertyListener( *audioDevice,
+ result = pa_AudioDeviceAddPropertyListener( *audioDevice,
0,
outStreamParams ? false : true,
kAudioDeviceProcessorOverload,
#define RING_BUFFER_EMPTY (1000)
-static OSStatus ringBufferIOProc( AudioConverterRef inAudioConverter,
- UInt32*ioDataSize,
- void** outData,
+#if PA_NEW_HAL
+static OSStatus ringBufferIOProc(
+ AudioConverterRef inAudioConverter,
+ UInt32* ioNumberDataPackets,
+ AudioBufferList* ioData,
+ AudioStreamPacketDescription** outDataPacketDescription,
+ void* inUserData)
+{
+ UInt32 * ioDataSize = &ioData->mBuffers[0].mDataByteSize;
+ void ** outData = &ioData->mBuffers[0].mData;
+
+ void *dummyData;
+ ring_buffer_size_t dummySize;
+ PaUtilRingBuffer *rb = (PaUtilRingBuffer *) inUserData;
+
+ VVDBUG(("ringBufferIOProc()\n"));
+
+ if( PaUtil_GetRingBufferReadAvailable( rb ) == 0 ) {
+ *outData = NULL;
+ *ioDataSize = 0;
+ return RING_BUFFER_EMPTY;
+ }
+ assert(sizeof(UInt32) == sizeof(ring_buffer_size_t));
+ assert( ( (*ioDataSize) / rb->elementSizeBytes ) * rb->elementSizeBytes == (*ioDataSize) ) ;
+ (*ioDataSize) /= rb->elementSizeBytes ;
+ PaUtil_GetRingBufferReadRegions( rb, *ioDataSize,
+ outData, (ring_buffer_size_t *)ioDataSize,
+ &dummyData, &dummySize );
+ assert( *ioDataSize );
+ PaUtil_AdvanceRingBufferReadIndex( rb, *ioDataSize );
+ (*ioDataSize) *= rb->elementSizeBytes ;
+ return noErr;
+}
+#else
+static OSStatus ringBufferIOProc( AudioConverterRef inAudioConverter,
+ UInt32*ioDataSize,
+ void** outData,
void*inUserData )
{
void *dummyData;
return noErr;
}
+#endif
/*
* Called by the AudioUnit API to process audio from the sound card.
UInt32 size;
float data[ inChan * frames ];
size = sizeof( data );
- err = AudioConverterFillBuffer(
+#if PA_NEW_HAL
+ AudioBufferList bufferList;
+ bufferList.mNumberBuffers = 1;
+ bufferList.mBuffers[0].mNumberChannels = inChan;
+ bufferList.mBuffers[0].mDataByteSize = size;
+ bufferList.mBuffers[0].mData = data;
+ err = AudioConverterFillComplexBuffer(
+ stream->inputSRConverter,
+ ringBufferIOProc,
+ &stream->inputRingBuffer,
+ &size,
+ &bufferList,
+ NULL);
+#else
+ err = AudioConverterFillBuffer(
stream->inputSRConverter,
ringBufferIOProc,
&stream->inputRingBuffer,
&size,
(void *)&data );
+#endif
if( err == RING_BUFFER_EMPTY )
{ /* the ring buffer callback underflowed */
err = 0;
long f;
size = sizeof( data );
- err = AudioConverterFillBuffer(
+#if PA_NEW_HAL
+ AudioBufferList bufferList;
+ bufferList.mNumberBuffers = 1;
+ bufferList.mBuffers[0].mNumberChannels = chan;
+ bufferList.mBuffers[0].mDataByteSize = size;
+ bufferList.mBuffers[0].mData = data;
+ err = AudioConverterFillComplexBuffer(
+ stream->inputSRConverter,
+ ringBufferIOProc,
+ &stream->inputRingBuffer,
+ &size,
+ &bufferList,
+ NULL);
+#else
+ err = AudioConverterFillBuffer(
stream->inputSRConverter,
ringBufferIOProc,
&stream->inputRingBuffer,
&size,
(void *)data );
+#endif
if( err != RING_BUFFER_EMPTY )
ERR( err );
if( err != noErr && err != RING_BUFFER_EMPTY )
if( stream->outputUnit ) {
int count = removeFromXRunListenerList( stream );
if( count == 0 )
- AudioDeviceRemovePropertyListener( stream->outputDevice,
+ pa_AudioDeviceRemovePropertyListener( stream->outputDevice,
0,
false,
kAudioDeviceProcessorOverload,
- xrunCallback );
+ xrunCallback, NULL ); //todo: do we need to pass actual node?
}
if( stream->inputUnit && stream->outputUnit != stream->inputUnit ) {
int count = removeFromXRunListenerList( stream );
if( count == 0 )
- AudioDeviceRemovePropertyListener( stream->inputDevice,
+ pa_AudioDeviceRemovePropertyListener( stream->inputDevice,
0,
true,
kAudioDeviceProcessorOverload,
- xrunCallback );
+ xrunCallback, NULL ); //todo: do we need to pass actual node?
}
if( stream->outputUnit && stream->outputUnit != stream->inputUnit ) {
AudioUnitUninitialize( stream->outputUnit );
#include <pthread.h>
#include <sys/time.h>
+OSStatus pa_AudioHardwareGetProperty(
+ AudioHardwarePropertyID inPropertyID,
+ UInt32* ioPropertyDataSize,
+ void* outPropertyData)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyAddress address = { inPropertyID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+ return AudioObjectGetPropertyData(kAudioObjectSystemObject, &address, 0, NULL, ioPropertyDataSize, outPropertyData);
+#else
+ macErr = AudioHardwareGetProperty(inPropertyID, ioPropertyDataSize, outPropertyData);
+#endif
+}
+
+OSStatus pa_AudioHardwareGetPropertySize(
+ AudioHardwarePropertyID inPropertyID,
+ UInt32* outSize)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyAddress address = { inPropertyID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+ return AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &address, 0, NULL, outSize);
+#else
+ macErr = AudioHardwareGetPropertyInfo(inPropertyID, outSize, NULL);
+#endif
+}
+
+OSStatus pa_AudioDeviceGetProperty(
+ AudioDeviceID inDevice,
+ UInt32 inChannel,
+ Boolean isInput,
+ AudioDevicePropertyID inPropertyID,
+ UInt32* ioPropertyDataSize,
+ void* outPropertyData)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyScope scope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+ AudioObjectPropertyAddress address = { inPropertyID, scope, inChannel };
+ return AudioObjectGetPropertyData(inDevice, &address, 0, NULL, ioPropertyDataSize, outPropertyData);
+#else
+ macErr = AudioDeviceGetProperty(inDevice, inChannel, isInput, inPropertyID, ioPropertyDataSize, outPropertyData);
+#endif
+}
+
+OSStatus pa_AudioDeviceSetProperty(
+ AudioDeviceID inDevice,
+ const AudioTimeStamp* inWhen,
+ UInt32 inChannel,
+ Boolean isInput,
+ AudioDevicePropertyID inPropertyID,
+ UInt32 inPropertyDataSize,
+ const void* inPropertyData)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyScope scope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+ AudioObjectPropertyAddress address = { inPropertyID, scope, inChannel };
+ return AudioObjectSetPropertyData(inDevice, &address, 0, NULL, inPropertyDataSize, inPropertyData);
+#else
+ return AudioDeviceSetProperty(inDevice, inWhen, inChannel, isInput, inPropertyID, inPropertyDataSize, inPropertyData);
+#endif
+}
+
+OSStatus pa_AudioDeviceGetPropertySize(
+ AudioDeviceID inDevice,
+ UInt32 inChannel,
+ Boolean isInput,
+ AudioDevicePropertyID inPropertyID,
+ UInt32* outSize)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyScope scope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+ AudioObjectPropertyAddress address = { inPropertyID, scope, inChannel };
+ return AudioObjectGetPropertyDataSize(inDevice, &address, 0, NULL, outSize);
+#else
+ return AudioDeviceGetPropertyInfo(inDevice, inChannel, isInput, inPropertyID, outSize, NULL);
+#endif
+}
+
+OSStatus pa_AudioDeviceAddPropertyListener(
+ AudioDeviceID inDevice,
+ UInt32 inChannel,
+ Boolean isInput,
+ AudioDevicePropertyID inPropertyID,
+ pa_AudioDevicePropertyListenerProc inProc,
+ void* inClientData)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyScope scope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+ AudioObjectPropertyAddress address = { inPropertyID, scope, inChannel };
+ return AudioObjectAddPropertyListener(inDevice, &address, inProc, inClientData);
+#else
+ return AudioDeviceAddPropertyListener(inDevice, inChannel, isInput, inPropertyID, inProc, inClientData);
+#endif
+}
+
+OSStatus pa_AudioDeviceRemovePropertyListener(
+ AudioDeviceID inDevice,
+ UInt32 inChannel,
+ Boolean isInput,
+ AudioDevicePropertyID inPropertyID,
+ pa_AudioDevicePropertyListenerProc inProc,
+ void* inClientData)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyScope scope = isInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
+ AudioObjectPropertyAddress address = { inPropertyID, scope, inChannel };
+ return AudioObjectRemovePropertyListener(inDevice, &address, inProc, inClientData);
+#else
+ return AudioDeviceRemovePropertyListener(inDevice, inChannel, isInput, inPropertyID, inProc);
+#endif
+}
+
+OSStatus pa_AudioStreamGetProperty(
+ AudioStreamID inStream,
+ UInt32 inChannel,
+ AudioDevicePropertyID inPropertyID,
+ UInt32* ioPropertyDataSize,
+ void* outPropertyData)
+{
+#if PA_NEW_HAL
+ AudioObjectPropertyAddress address = { inPropertyID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+ return AudioObjectGetPropertyData(inStream, &address, 0, NULL, ioPropertyDataSize, outPropertyData);
+#else
+ return AudioStreamGetProperty(inStream, inChannel, inPropertyID, ioPropertyDataSize, outPropertyData);
+#endif
+}
+
PaError PaMacCore_SetUnixError( int err, int line )
{
PaError ret;
case kAudioUnitErr_TooManyFramesToProcess:
errorText = "Audio Unit: Too Many Frames";
result = paInternalError; break;
+#if ! PA_NEW_HAL
case kAudioUnitErr_IllegalInstrument:
errorText = "Audio Unit: Illegal Instrument";
result = paInternalError; break;
case kAudioUnitErr_InstrumentTypeNotFound:
errorText = "Audio Unit: Instrument Type Not Found";
result = paInternalError; break;
+#endif
case kAudioUnitErr_InvalidFile:
errorText = "Audio Unit: Invalid File";
result = paInternalError; break;
* since it represents a theoretically better implementation.
*/
+#if PA_NEW_HAL
+OSStatus propertyProc(
+ AudioObjectID inObjectID,
+ UInt32 inNumberAddresses,
+ const AudioObjectPropertyAddress* inAddresses,
+ void* inClientData)
+{
+ // this is where we would set the condition variable
+ return noErr;
+}
+#else
OSStatus propertyProc(
AudioDeviceID inDevice,
UInt32 inChannel,
// this is where we would set the condition variable
return noErr;
}
+#endif
/* sets the value of the given property and waits for the change to
be acknowledged, and returns the final value, which is not guaranteed
UInt32 outPropertyDataSize = inPropertyDataSize;
/* First, see if it already has that value. If so, return. */
- macErr = AudioDeviceGetProperty( inDevice, inChannel,
- isInput, inPropertyID,
+ macErr = pa_AudioDeviceGetProperty( inDevice, inChannel,
+ isInput, inPropertyID,
&outPropertyDataSize, outPropertyData );
if( macErr ) {
memset( outPropertyData, 0, inPropertyDataSize );
/* If we were using a cond variable, we'd do something useful here,
but for now, this is just to make 10.6 happy. */
- macErr = AudioDeviceAddPropertyListener( inDevice, inChannel, isInput,
+ macErr = pa_AudioDeviceAddPropertyListener( inDevice, inChannel, isInput,
inPropertyID, propertyProc,
NULL );
if( macErr )
goto failMac;
/* set property */
- macErr = AudioDeviceSetProperty( inDevice, NULL, inChannel,
+ macErr = pa_AudioDeviceSetProperty( inDevice, NULL, inChannel,
isInput, inPropertyID,
inPropertyDataSize, inPropertyData );
if( macErr )
memcpy( &tv2, &tv1, sizeof( struct timeval ) );
while( tv2.tv_sec - tv1.tv_sec < 30 ) {
/* now read the property back out */
- macErr = AudioDeviceGetProperty( inDevice, inChannel,
- isInput, inPropertyID,
+ macErr = pa_AudioDeviceGetProperty( inDevice, inChannel,
+ isInput, inPropertyID,
&outPropertyDataSize, outPropertyData );
if( macErr ) {
memset( outPropertyData, 0, inPropertyDataSize );
}
/* and compare... */
if( 0==memcmp( outPropertyData, inPropertyData, outPropertyDataSize ) ) {
- AudioDeviceRemovePropertyListener( inDevice, inChannel, isInput, inPropertyID, propertyProc );
+ pa_AudioDeviceRemovePropertyListener( inDevice, inChannel, isInput, inPropertyID, propertyProc, NULL);
return paNoError;
}
/* No match yet, so let's sleep and try again. */
gettimeofday( &tv2, NULL );
}
DBUG( ("Timeout waiting for device setting.\n" ) );
-
- AudioDeviceRemovePropertyListener( inDevice, inChannel, isInput, inPropertyID, propertyProc );
+
+ pa_AudioDeviceRemovePropertyListener( inDevice, inChannel, isInput, inPropertyID, propertyProc, NULL );
return paNoError;
failMac:
- AudioDeviceRemovePropertyListener( inDevice, inChannel, isInput, inPropertyID, propertyProc );
+ pa_AudioDeviceRemovePropertyListener( inDevice, inChannel, isInput, inPropertyID, propertyProc, NULL );
return ERR( macErr );
}
return paInvalidSampleRate;
/* -- generate a list of available sample rates -- */
- err = AudioDeviceGetPropertyInfo( device, 0, isInput,
+ err = pa_AudioDeviceGetPropertySize( device, 0, isInput,
kAudioDevicePropertyAvailableNominalSampleRates,
- &propsize, NULL );
+ &propsize );
if( err )
return ERR( err );
ranges = (AudioValueRange *)calloc( 1, propsize );
if( !ranges )
return paInsufficientMemory;
- err = AudioDeviceGetProperty( device, 0, isInput,
+ err = pa_AudioDeviceGetProperty( device, 0, isInput,
kAudioDevicePropertyAvailableNominalSampleRates,
&propsize, ranges );
if( err )
}
/* -- try and set exact FPB -- */
- err = AudioDeviceSetProperty( device, NULL, 0, isInput,
+ err = pa_AudioDeviceSetProperty( device, NULL, 0, isInput,
kAudioDevicePropertyBufferFrameSize,
propsize, &requestedFramesPerBuffer);
- err = AudioDeviceGetProperty( device, 0, isInput,
+ err = pa_AudioDeviceGetProperty( device, 0, isInput,
kAudioDevicePropertyBufferFrameSize,
&propsize, actualFramesPerBuffer);
if( err )
// Clip requested value against legal range for the device.
propsize = sizeof(AudioValueRange);
- err = AudioDeviceGetProperty( device, 0, isInput,
+ err = pa_AudioDeviceGetProperty( device, 0, isInput,
kAudioDevicePropertyBufferFrameSizeRange,
&propsize, &range );
if( err )
/* --- set the buffer size (ignore errors) -- */
propsize = sizeof( UInt32 );
- err = AudioDeviceSetProperty( device, NULL, 0, isInput,
+ err = pa_AudioDeviceSetProperty( device, NULL, 0, isInput,
kAudioDevicePropertyBufferFrameSize,
propsize, &requestedFramesPerBuffer );
/* --- read the property to check that it was set -- */
- err = AudioDeviceGetProperty( device, 0, isInput,
+ err = pa_AudioDeviceGetProperty( device, 0, isInput,
kAudioDevicePropertyBufferFrameSize,
&propsize, actualFramesPerBuffer );
static int xRunListSize;
static pthread_mutex_t xrunMutex;
+#if PA_NEW_HAL
+OSStatus xrunCallback(
+ AudioObjectID inDevice,
+ UInt32 inNumberAddresses,
+ const AudioObjectPropertyAddress* inAddresses,
+ void * inClientData)
+{
+ PaMacXRunListNode *node = (PaMacXRunListNode *) inClientData;
+ bool isInput = inAddresses->mScope == kAudioDevicePropertyScopeInput;
+
+ int ret = pthread_mutex_trylock( &xrunMutex ) ;
+
+ if( ret == 0 ) {
+ node = node->next ; //skip the first node
+
+ for( ; node; node=node->next ) {
+ PaMacCoreStream *stream = node->stream;
+
+ if( stream->state != ACTIVE )
+ continue; //if the stream isn't active, we don't care if the device is dropping
+
+ if( isInput ) {
+ if( stream->inputDevice == inDevice )
+ OSAtomicOr32( paInputOverflow, &stream->xrunFlags );
+ } else {
+ if( stream->outputDevice == inDevice )
+ OSAtomicOr32( paOutputUnderflow, &stream->xrunFlags );
+ }
+ }
+
+ pthread_mutex_unlock( &xrunMutex );
+ }
+
+ return 0;
+}
+#else
OSStatus xrunCallback(
AudioDeviceID inDevice,
UInt32 inChannel,
return 0;
}
+#endif
int initializeXRunListenerList( void )
{