From c25e45e4ae5401a632fd09bb4cbb27a2fdd2cb06 Mon Sep 17 00:00:00 2001 From: sletz Date: Tue, 4 Dec 2007 08:23:42 +0000 Subject: [PATCH] Correct bug in CoreAudio driver sample rate management. git-svn-id: svn+ssh://jackaudio.org/trunk/jack@1069 0c269be4-1314-0410-8aa9-9f06e86f4224 --- configure.ac | 2 +- drivers/coreaudio/coreaudio_driver.c | 54 +++++++++------------------- drivers/coreaudio/coreaudio_driver.h | 10 ++++-- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/configure.ac b/configure.ac index 82306fb..82c56fd 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ dnl changes are made dnl --- JACK_MAJOR_VERSION=0 JACK_MINOR_VERSION=107 -JACK_MICRO_VERSION=5 +JACK_MICRO_VERSION=6 dnl --- dnl HOWTO: updating the jack protocol version diff --git a/drivers/coreaudio/coreaudio_driver.c b/drivers/coreaudio/coreaudio_driver.c index 7f1efd0..5f12f00 100755 --- a/drivers/coreaudio/coreaudio_driver.c +++ b/drivers/coreaudio/coreaudio_driver.c @@ -1,6 +1,6 @@ /* - Copyright © Grame, 2003. - Copyright © Johnny Petrantoni, 2003. + Copyright � Grame, 2003. + Copyright � Johnny Petrantoni, 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,6 +45,7 @@ May 17, 2006: S.Letz: Minor fix in driver_initialize. May 18, 2006: S.Letz: Document sample rate default value. May 31, 2006: S.Letz: Apply Rui patch for more consistent driver parameter naming. + Dec 04, 2007: S.Letz: Fix a bug in sample rate management (occuring in particular with "aggregate" devices). */ #include @@ -270,7 +271,7 @@ static OSStatus display_device_names() err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceName, &size, device_name); if (err != noErr) return err; - + printf("ICI\n"); printf("Device name = \'%s\', internal_name = \'%s\' (to be used as -d parameter)\n", device_name, internal_name); } @@ -555,7 +556,8 @@ static jack_driver_t *coreaudio_driver_new(char* name, ComponentResult err1; UInt32 outSize; UInt32 enableIO; - AudioStreamBasicDescription srcFormat, dstFormat, sampleRate; + AudioStreamBasicDescription srcFormat, dstFormat; + Float64 sampleRate; int in_nChannels = 0; int out_nChannels = 0; int i; @@ -695,44 +697,22 @@ static jack_driver_t *coreaudio_driver_new(char* name, } // Set sample rate - if (capturing && inchannels > 0) { - outSize = sizeof(AudioStreamBasicDescription); - err = AudioDeviceGetProperty(driver->device_id, 0, true, kAudioDevicePropertyStreamFormat, &outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot get current sample rate"); - printError(err); - goto error; - } - - if (samplerate != (unsigned long)sampleRate.mSampleRate) { - sampleRate.mSampleRate = (Float64)samplerate; - err = AudioDeviceSetProperty(driver->device_id, NULL, 0, true, kAudioDevicePropertyStreamFormat, outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot set sample rate = %ld", samplerate); - printError(err); - goto error; - } - } + outSize = sizeof(Float64); + err = AudioDeviceGetProperty(driver->device_id, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, &outSize, &sampleRate); + if (err != noErr) { + jack_error("Cannot get current sample rate"); + printError(err); + goto error; } - - if (playing && outchannels > 0) { - outSize = sizeof(AudioStreamBasicDescription); - err = AudioDeviceGetProperty(driver->device_id, 0, false, kAudioDevicePropertyStreamFormat, &outSize, &sampleRate); + + if (samplerate != (jack_nframes_t)sampleRate) { + sampleRate = (Float64)samplerate; + err = AudioDeviceSetProperty(driver->device_id, NULL, 0, kAudioDeviceSectionGlobal, kAudioDevicePropertyNominalSampleRate, outSize, &sampleRate); if (err != noErr) { - jack_error("Cannot get current sample rate"); + jack_error("Cannot set sample rate = %ld", samplerate); printError(err); goto error; } - - if (samplerate != (unsigned long)sampleRate.mSampleRate) { - sampleRate.mSampleRate = (Float64)samplerate; - err = AudioDeviceSetProperty(driver->device_id, NULL, 0, false, kAudioDevicePropertyStreamFormat, outSize, &sampleRate); - if (err != noErr) { - jack_error("Cannot set sample rate = %ld", samplerate); - printError(err); - goto error; - } - } } // AUHAL diff --git a/drivers/coreaudio/coreaudio_driver.h b/drivers/coreaudio/coreaudio_driver.h index b6a60ab..37f7955 100755 --- a/drivers/coreaudio/coreaudio_driver.h +++ b/drivers/coreaudio/coreaudio_driver.h @@ -1,6 +1,6 @@ /* - Copyright © Grame, 2003. - Copyright © Johnny Petrantoni, 2003. + Copyright � Grame, 2003. + Copyright � Johnny Petrantoni, 2003. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -72,4 +72,10 @@ typedef struct { #define kVersion 01 +typedef UInt8 CAAudioHardwareDeviceSectionID; +#define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01) +#define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00) +#define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00) +#define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF) + #endif /* __jack_coreaudio_driver_h__ */