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;
}
static OSStatus SampleRateChanged( AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput,
AudioDevicePropertyID inPropertyID, void *inData );
/* temporary hack: */
static float g_fLastIOProcTime = 0;
static const int NUM_MIX_TIMES = 16;
@@ -135,16 +138,28 @@ RString RageSound_CA::Init()
m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
Float64 nominalSampleRate = m_iSampleRate;
Float64 actualSampleRate;
if( (error = AudioDeviceSetProperty(m_OutputDevice, NULL, 0, kAudioDeviceSectionGlobal,
kAudioDevicePropertyNominalSampleRate, sizeof(Float64), &nominalSampleRate)) )
{
LOG->Warn( WERROR("Couldn't set the nominal sample rate", error) );
size = sizeof(Float64);
AudioDeviceGetProperty( m_OutputDevice, 0, kAudioDeviceSectionGlobal,
kAudioDevicePropertyNominalSampleRate, &size, &nominalSampleRate );
m_iSampleRate = int( nominalSampleRate );
LOG->Warn( "Device's nominal sample rate is %f", nominalSampleRate );
nominalSampleRate = 0.0;
}
size = sizeof(Float64);
if( (error = AudioDeviceGetProperty(m_OutputDevice, 0, kAudioDeviceSectionGlobal,
kAudioDevicePropertyNominalSampleRate, &size, &actualSampleRate)) )
{
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;
@@ -169,10 +184,11 @@ RString RageSound_CA::Init()
AddListener( kAudioDeviceProcessorOverload, OverloadListener, "overload" );
AddListener( kAudioDevicePropertyDeviceHasChanged, DeviceChanged, "device changed" );
AddListener( kAudioDevicePropertyJackIsConnected, JackChanged, "jack changed" );
AddListener( kAudioDevicePropertyActualSampleRate, SampleRateChanged, "sample rate changed" );
// The canonical format
Desc IOProcFormat( nominalSampleRate, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked, 8, 1, 8, 2, 32 );
const Desc SMFormat( nominalSampleRate, kAudioFormatLinearPCM, kFormatFlags, kBytesPerPacket,
Desc IOProcFormat( actualSampleRate, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked, 8, 1, 8, 2, 32 );
const Desc SMFormat( actualSampleRate, kAudioFormatLinearPCM, kFormatFlags, kBytesPerPacket,
kFramesPerPacket, kBytesPerFrame, kChannelsPerFrame, kBitsPerChannel );
if( (error = AudioStreamSetProperty(stream, NULL, 0, kAudioDevicePropertyStreamFormat,
@@ -400,6 +416,19 @@ OSStatus RageSound_CA::JackChanged( AudioDeviceID inDevice, UInt32 inChannel, Bo
This->m_iOffset = This->m_iLastSampleTime - int64_t( time.mSampleTime );
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()