From caee59aed32d51fe46c4f476b048b3428574c12b Mon Sep 17 00:00:00 2001 From: sletz Date: Tue, 4 Dec 2007 10:31:01 +0000 Subject: [PATCH] Add a sample_rate change listener in CoreAudio driver. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1721 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 4 ++++ macosx/JackCoreAudioDriver.cpp | 44 +++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3b01c469..30884412 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,10 @@ Kjetil S.Matheussen Jackdmp changes log --------------------------- +2007-12-04 Stephane Letz + + * Add a sample_rate change listener in CoreAudio driver. + 2007-12-03 Stephane Letz * Correct bug in CoreAudio driver sample rate management. diff --git a/macosx/JackCoreAudioDriver.cpp b/macosx/JackCoreAudioDriver.cpp index f2a0175a..d74552be 100644 --- a/macosx/JackCoreAudioDriver.cpp +++ b/macosx/JackCoreAudioDriver.cpp @@ -250,13 +250,32 @@ OSStatus JackCoreAudioDriver::DeviceNotificationCallback(AudioDeviceID inDevice, void* inClientData) { JackCoreAudioDriver* driver = (JackCoreAudioDriver*)inClientData; - if (inPropertyID == kAudioDeviceProcessorOverload) { - JackLog("JackCoreAudioDriver::NotificationCallback kAudioDeviceProcessorOverload\n"); -#ifdef DEBUG - //driver->fLogFile->Capture(AudioGetCurrentHostTime() - AudioConvertNanosToHostTime(LOG_SAMPLE_DURATION * 1000000), AudioGetCurrentHostTime(), true, "Captured Latency Log for I/O Cycle Overload\n"); -#endif - driver->NotifyXRun(GetMicroSeconds()); - } + switch (inPropertyID) { + + case kAudioDeviceProcessorOverload: + JackLog("JackCoreAudioDriver::NotificationCallback kAudioDeviceProcessorOverload\n"); + #ifdef DEBUG + //driver->fLogFile->Capture(AudioGetCurrentHostTime() - AudioConvertNanosToHostTime(LOG_SAMPLE_DURATION * 1000000), AudioGetCurrentHostTime(), true, "Captured Latency Log for I/O Cycle Overload\n"); + #endif + driver->NotifyXRun(GetMicroSeconds()); + break; + + case kAudioDevicePropertyNominalSampleRate: { + UInt32 outSize = sizeof(Float64); + Float64 sampleRate; + OSStatus err = AudioDeviceGetProperty(driver->fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate); + if (err != noErr) { + jack_error("Cannot get current sample rate"); + printError(err); + return kAudioHardwareUnsupportedOperationError; + } + JackLog("JackCoreAudioDriver::NotificationCallback kAudioDevicePropertyNominalSampleRate %ld\n", long(sampleRate)); + if (jack_nframes_t(sampleRate) != driver->fEngineControl->fSampleRate) { + jack_error("Critical error : new %ld sample rate, engine will not run correctly anymore", long(sampleRate)); + } + break; + } + } return noErr; } @@ -735,12 +754,18 @@ int JackCoreAudioDriver::Open(jack_nframes_t nframes, printError(err1); goto error; } + + err = AudioDeviceAddPropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback, this); + if (err != noErr) { + jack_error("Error calling AudioDeviceAddPropertyListener with kAudioDevicePropertyNominalSampleRate"); + printError(err1); + goto error; + } fDriverOutputData = 0; #if IO_CPU - - outSize = sizeof(float); + outSize = sizeof(float); iousage = 0.4f; err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyIOCycleUsage, outSize, &iousage); if (err != noErr) { @@ -769,6 +794,7 @@ int JackCoreAudioDriver::Close() AudioDeviceRemoveIOProc(fDeviceID, MeasureCallback); AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDeviceProcessorOverload, DeviceNotificationCallback); AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioHardwarePropertyDevices, DeviceNotificationCallback); + AudioDeviceRemovePropertyListener(fDeviceID, 0, true, kAudioDevicePropertyNominalSampleRate, DeviceNotificationCallback); free(fJackInputData); AudioUnitUninitialize(fAUHAL); CloseComponent(fAUHAL);