From 720fe3c075358075261402e36bbf854519b7d2ae Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Thu, 11 Mar 2010 07:03:04 +0000 Subject: [PATCH] added check for sample rates --- mac/sound.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/mac/sound.cpp b/mac/sound.cpp index 1d28f48d..e0d232aa 100755 --- a/mac/sound.cpp +++ b/mac/sound.cpp @@ -124,7 +124,7 @@ void CSound::OpenCoreAudio() input.inputProcRefCon = this; if ( AudioUnitSetProperty ( audioInputUnit, - kAudioOutputUnitProperty_SetInputCallback,//kAudioUnitProperty_SetRenderCallback,// + kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &input, @@ -159,7 +159,7 @@ void CSound::OpenCoreAudio() output.inputProcRefCon = this; if ( AudioUnitSetProperty ( audioOutputUnit, - kAudioUnitProperty_SetRenderCallback,//kAudioOutputUnitProperty_SetInputCallback,// + kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, 0, &output, @@ -201,9 +201,37 @@ void CSound::OpenCoreAudio() throw CGenErr ( tr ( "CoreAudio stream format set property failed" ) ); } + // check input device sample rate + size = sizeof ( Float64 ); + Float64 inputSampleRate; + AudioUnitGetProperty ( audioInputUnit, + kAudioUnitProperty_SampleRate, + kAudioUnitScope_Input, + 1, + &inputSampleRate, + &size ); + if ( static_cast ( inputSampleRate ) != SYSTEM_SAMPLE_RATE ) + { +// TODO better error message, showing current/desired sample rate and tell how to change + throw CGenErr ( tr ( "Current system input device sample rate not supported" ) ); + } + + // check output device sample rate + size = sizeof ( Float64 ); + Float64 outputSampleRate; + AudioUnitGetProperty ( audioOutputUnit, + kAudioUnitProperty_SampleRate, + kAudioUnitScope_Output, + 0, + &outputSampleRate, + &size ); -// TODO check for required sample rate, if not available, throw error message + if ( static_cast ( outputSampleRate ) != SYSTEM_SAMPLE_RATE ) + { +// TODO better error message, showing current/desired sample rate and tell how to change + throw CGenErr ( tr ( "Current system output device sample rate not supported" ) ); + } // TEST