diff --git a/ChangeLog b/ChangeLog index b4849e30..3b01c469 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,10 @@ Kjetil S.Matheussen Jackdmp changes log --------------------------- +2007-12-03 Stephane Letz + + * Correct bug in CoreAudio driver sample rate management. + 2007-11-30 Stephane Letz * Correct JackMachNotifyChannel::ClientNotify. diff --git a/macosx/JackCoreAudioDriver.cpp b/macosx/JackCoreAudioDriver.cpp index bef99867..f2a0175a 100644 --- a/macosx/JackCoreAudioDriver.cpp +++ b/macosx/JackCoreAudioDriver.cpp @@ -101,6 +101,12 @@ static void printError(OSStatus err) break; case kAudioDevicePermissionsError: JackLog("error code : kAudioDevicePermissionsError\n"); + break; + case kAudioHardwareBadObjectError: + JackLog("error code : kAudioHardwareBadObjectError\n"); + break; + case kAudioHardwareUnsupportedOperationError: + JackLog("error code : kAudioHardwareUnsupportedOperationError\n"); break; default: JackLog("error code : unknown\n"); @@ -404,7 +410,9 @@ int JackCoreAudioDriver::Open(jack_nframes_t nframes, ComponentResult err1; UInt32 outSize; UInt32 enableIO; - AudioStreamBasicDescription srcFormat, dstFormat, sampleRate; + AudioStreamBasicDescription srcFormat, dstFormat; + Float64 sampleRate; + long in_nChannels = 0; long out_nChannels = 0; char capture_driver_name[256]; @@ -525,46 +533,24 @@ int JackCoreAudioDriver::Open(jack_nframes_t nframes, } // Set sample rate - if (capturing && inchannels > 0) { - outSize = sizeof(AudioStreamBasicDescription); - err = AudioDeviceGetProperty(fDeviceID, 0, true, kAudioDevicePropertyStreamFormat, &outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot get current sample rate"); - printError(err); - return -1; - } - - if (samplerate != (unsigned long)sampleRate.mSampleRate) { - sampleRate.mSampleRate = (Float64)samplerate; - err = AudioDeviceSetProperty(fDeviceID, NULL, 0, true, kAudioDevicePropertyStreamFormat, outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot set sample rate = %ld", samplerate); - printError(err); - return -1; - } - } - } - - if (playing && outchannels > 0) { - outSize = sizeof(AudioStreamBasicDescription); - err = AudioDeviceGetProperty(fDeviceID, 0, false, kAudioDevicePropertyStreamFormat, &outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot get current sample rate"); - printError(err); - return -1; - } - - if (samplerate != (unsigned long)sampleRate.mSampleRate) { - sampleRate.mSampleRate = (Float64)samplerate; - err = AudioDeviceSetProperty(fDeviceID, NULL, 0, false, kAudioDevicePropertyStreamFormat, outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot set sample rate = %ld", samplerate); - printError(err); - return -1; - } - } - } - + outSize = sizeof(Float64); + err = AudioDeviceGetProperty(fDeviceID, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate); + if (err != noErr) { + jack_error("Cannot get current sample rate"); + printError(err); + return -1; + } + + if (samplerate != (jack_nframes_t)sampleRate) { + sampleRate = (Float64)samplerate; + err = AudioDeviceSetProperty(fDeviceID, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate); + if (err != noErr) { + jack_error("Cannot set sample rate = %ld", samplerate); + printError(err); + return -1; + } + } + // AUHAL ComponentDescription cd = {kAudioUnitType_Output, kAudioUnitSubType_HALOutput, kAudioUnitManufacturer_Apple, 0, 0}; Component HALOutput = FindNextComponent(NULL, &cd); diff --git a/macosx/JackCoreAudioDriver.h b/macosx/JackCoreAudioDriver.h index c514dbae..b59424ac 100644 --- a/macosx/JackCoreAudioDriver.h +++ b/macosx/JackCoreAudioDriver.h @@ -36,6 +36,13 @@ namespace Jack //#define IO_CPU 1 +typedef UInt8 CAAudioHardwareDeviceSectionID; +#define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01) +#define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00) +#define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00) +#define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF) + + /*! \brief The CoreAudio driver.