Add more logging: Check that the sample rate we just set matches what the device declares as it's sample rate; log if the device's sample rate changes while it's running.

This commit is contained in:
Steve Checkoway
2006-05-17 07:40:54 +00:00
parent a84d30b92e
commit 060b68ff00
@@ -38,6 +38,9 @@ Desc::Desc( Float64 sampleRate, UInt32 formatID, UInt32 formatFlags, UInt32 byte
mReserved = 0; mReserved = 0;
} }
static OSStatus SampleRateChanged( AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput,
AudioDevicePropertyID inPropertyID, void *inData );
/* temporary hack: */ /* temporary hack: */
static float g_fLastIOProcTime = 0; static float g_fLastIOProcTime = 0;
static const int NUM_MIX_TIMES = 16; static const int NUM_MIX_TIMES = 16;
@@ -135,16 +138,28 @@ RString RageSound_CA::Init()
m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
Float64 nominalSampleRate = m_iSampleRate; Float64 nominalSampleRate = m_iSampleRate;
Float64 actualSampleRate;
if( (error = AudioDeviceSetProperty(m_OutputDevice, NULL, 0, kAudioDeviceSectionGlobal, if( (error = AudioDeviceSetProperty(m_OutputDevice, NULL, 0, kAudioDeviceSectionGlobal,
kAudioDevicePropertyNominalSampleRate, sizeof(Float64), &nominalSampleRate)) ) kAudioDevicePropertyNominalSampleRate, sizeof(Float64), &nominalSampleRate)) )
{ {
LOG->Warn( WERROR("Couldn't set the nominal sample rate", error) ); LOG->Warn( WERROR("Couldn't set the nominal sample rate", error) );
nominalSampleRate = 0.0;
}
size = sizeof(Float64); size = sizeof(Float64);
AudioDeviceGetProperty( m_OutputDevice, 0, kAudioDeviceSectionGlobal, if( (error = AudioDeviceGetProperty(m_OutputDevice, 0, kAudioDeviceSectionGlobal,
kAudioDevicePropertyNominalSampleRate, &size, &nominalSampleRate ); kAudioDevicePropertyNominalSampleRate, &size, &actualSampleRate)) )
m_iSampleRate = int( nominalSampleRate ); {
LOG->Warn( "Device's nominal sample rate is %f", nominalSampleRate ); return ERROR( "Couldn't get the nominal sample rate", error );
}
if( actualSampleRate == nominalSampleRate )
{
LOG->Info( "Set the nominal sample rate to %f.", nominalSampleRate );
}
else
{
LOG->Warn( "Reported nominal sample rate of %f.", actualSampleRate );
m_iSampleRate = int( actualSampleRate );
} }
AudioStreamID *streams, stream; AudioStreamID *streams, stream;
@@ -169,10 +184,11 @@ RString RageSound_CA::Init()
AddListener( kAudioDeviceProcessorOverload, OverloadListener, "overload" ); AddListener( kAudioDeviceProcessorOverload, OverloadListener, "overload" );
AddListener( kAudioDevicePropertyDeviceHasChanged, DeviceChanged, "device changed" ); AddListener( kAudioDevicePropertyDeviceHasChanged, DeviceChanged, "device changed" );
AddListener( kAudioDevicePropertyJackIsConnected, JackChanged, "jack changed" ); AddListener( kAudioDevicePropertyJackIsConnected, JackChanged, "jack changed" );
AddListener( kAudioDevicePropertyActualSampleRate, SampleRateChanged, "sample rate changed" );
// The canonical format // The canonical format
Desc IOProcFormat( nominalSampleRate, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked, 8, 1, 8, 2, 32 ); Desc IOProcFormat( actualSampleRate, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked, 8, 1, 8, 2, 32 );
const Desc SMFormat( nominalSampleRate, kAudioFormatLinearPCM, kFormatFlags, kBytesPerPacket, const Desc SMFormat( actualSampleRate, kAudioFormatLinearPCM, kFormatFlags, kBytesPerPacket,
kFramesPerPacket, kBytesPerFrame, kChannelsPerFrame, kBitsPerChannel ); kFramesPerPacket, kBytesPerFrame, kChannelsPerFrame, kBitsPerChannel );
if( (error = AudioStreamSetProperty(stream, NULL, 0, kAudioDevicePropertyStreamFormat, if( (error = AudioStreamSetProperty(stream, NULL, 0, kAudioDevicePropertyStreamFormat,
@@ -401,6 +417,19 @@ OSStatus RageSound_CA::JackChanged( AudioDeviceID inDevice, UInt32 inChannel, Bo
return noErr; return noErr;
} }
OSStatus SampleRateChanged( AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput,
AudioDevicePropertyID inPropertyID, void *inData )
{
if( isInput )
return noErr;
Float64 sampleRate;
UInt32 size = sizeof( sampleRate );
AudioDeviceGetProperty( inDevice, inChannel, 0, inPropertyID, &size, &sampleRate );
LOG->Warn( "Sample rate changed to %f.", sampleRate );
return noErr;
}
void RageSound_CA::SetupDecodingThread() void RageSound_CA::SetupDecodingThread()
{ {