From ffc4fb00bda0b152bd16fbb8471f903d46341ba9 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sat, 24 Mar 2007 03:29:01 +0000 Subject: [PATCH] Set the hardware sample rate first. There seems to be an issue with setting the stream format's sample rate and then the device's sample rate before initializing the AudioUnit. Once initialized, it handles device format changes. I'm not sure why it doesn't before initialization. --- .../src/arch/Sound/RageSoundDriver_AU.cpp | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/stepmania/src/arch/Sound/RageSoundDriver_AU.cpp b/stepmania/src/arch/Sound/RageSoundDriver_AU.cpp index 2d3792bc75..45cece097a 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_AU.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_AU.cpp @@ -99,6 +99,24 @@ RString RageSoundDriver_AU::Init() if( streamFormat.mSampleRate <= 0 ) streamFormat.mSampleRate = 44100.0; m_iSampleRate = int( streamFormat.mSampleRate ); + + // Try to set the hardware sample rate. + { + AudioDeviceID OutputDevice; + UInt32 size = sizeof( AudioDeviceID ); + + if( (error = AudioUnitGetProperty(m_OutputUnit, kAudioOutputUnitProperty_CurrentDevice, + kAudioUnitScope_Global, 0, &OutputDevice, &size)) ) + { + LOG->Warn( WERROR("No output device", error) ); + } + else if( (error = AudioDeviceSetProperty(OutputDevice, NULL, 0, false, kAudioDevicePropertyNominalSampleRate, + sizeof(Float64), &streamFormat.mSampleRate)) ) + { + LOG->Warn( WERROR("Couldn't set the device's sample rate", error) ); + } + } + error = AudioUnitSetProperty( m_OutputUnit, kAudioUnitProperty_StreamFormat, @@ -118,25 +136,7 @@ RString RageSoundDriver_AU::Init() sizeof(renderQuality) ); if( error != noErr ) LOG->Warn( WERROR("Failed to set the maximum render quality", error) ); - - // Try to set the hardware sample rate. - { - AudioDeviceID OutputDevice; - UInt32 size = sizeof( AudioDeviceID ); - if( (error = AudioUnitGetProperty(m_OutputUnit, kAudioOutputUnitProperty_CurrentDevice, - kAudioUnitScope_Global, 0, &OutputDevice, &size)) ) - { - LOG->Warn( WERROR("No output device", error) ); - } - else if( (error = AudioDeviceSetProperty(OutputDevice, NULL, 0, false, kAudioDevicePropertyNominalSampleRate, - sizeof(Float64), &streamFormat.mSampleRate)) ) - { - LOG->Warn( WERROR("Couldn't set the device's sample rate", error) ); - } - } - - // Initialize the AU. if( (error = AudioUnitInitialize(m_OutputUnit)) ) return ERROR( "Could not initialize the AudioUnit", error );