Set sample rate of the device, if possible.

This commit is contained in:
Steve Checkoway
2006-11-17 17:37:51 +00:00
parent db89c28b25
commit 5f9ee5c5bd
+34 -18
View File
@@ -98,8 +98,6 @@ RString RageSound_AU::Init()
streamFormat.mSampleRate = 44100.0; streamFormat.mSampleRate = 44100.0;
m_iSampleRate = int( streamFormat.mSampleRate ); m_iSampleRate = int( streamFormat.mSampleRate );
// XXX Try to set the hardware sample rate.
error = AudioUnitSetProperty( m_OutputUnit, error = AudioUnitSetProperty( m_OutputUnit,
kAudioUnitProperty_StreamFormat, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, kAudioUnitScope_Input,
@@ -119,31 +117,49 @@ RString RageSound_AU::Init()
if( error != noErr ) if( error != noErr )
LOG->Warn( WERROR("Failed to set the maximum render quality", error) ); 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. // Initialize the AU.
error = AudioUnitInitialize( m_OutputUnit ); if( (error = AudioUnitInitialize(m_OutputUnit)) )
if( error != noErr )
return ERROR( "Could not initialize the AudioUnit", error ); return ERROR( "Could not initialize the AudioUnit", error );
StartDecodeThread(); StartDecodeThread();
// Get the HAL's runloop and attach an observer. // Get the HAL's runloop and attach an observer.
CFRunLoopObserverRef observerRef; {
CFRunLoopRef runLoopRef; CFRunLoopObserverRef observerRef;
CFRunLoopObserverContext context = { 0, this, NULL, NULL, NULL }; CFRunLoopRef runLoopRef;
UInt32 size = sizeof( CFRunLoopRef ); CFRunLoopObserverContext context = { 0, this, NULL, NULL, NULL };
UInt32 size = sizeof( CFRunLoopRef );
if( (error = AudioHardwareGetProperty(kAudioHardwarePropertyRunLoop, &size, &runLoopRef)) ) if( (error = AudioHardwareGetProperty(kAudioHardwarePropertyRunLoop, &size, &runLoopRef)) )
return ERROR( "Couldn't get the HAL's run loop", error); return ERROR( "Couldn't get the HAL's run loop", error);
observerRef = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopAllActivities, false, 0, NameHALThread, &context ); observerRef = CFRunLoopObserverCreate( kCFAllocatorDefault, kCFRunLoopAllActivities, false, 0, NameHALThread, &context );
CFRunLoopAddObserver( runLoopRef, observerRef, kCFRunLoopDefaultMode ); CFRunLoopAddObserver( runLoopRef, observerRef, kCFRunLoopDefaultMode );
CFRunLoopWakeUp( runLoopRef ); CFRunLoopWakeUp( runLoopRef );
m_Semaphore.Wait(); m_Semaphore.Wait();
CFRunLoopObserverInvalidate( observerRef ); CFRunLoopObserverInvalidate( observerRef );
CFRelease( observerRef ); CFRelease( observerRef );
}
error = AudioOutputUnitStart( m_OutputUnit ); if( (error = AudioOutputUnitStart(m_OutputUnit)) )
if( error != noErr )
return ERROR( "Could not start the AudioUnit", error ); return ERROR( "Could not start the AudioUnit", error );
m_bStarted = true; m_bStarted = true;
return RString(); return RString();