Minor optimization: don't call AudioGetHostClockFrequency() or do a double precision divide over and over.
This commit is contained in:
@@ -98,9 +98,10 @@ RString RageSoundDriver_AU::Init()
|
|||||||
streamFormat.mChannelsPerFrame = kChannelsPerFrame;
|
streamFormat.mChannelsPerFrame = kChannelsPerFrame;
|
||||||
streamFormat.mBitsPerChannel = kBitsPerChannel;
|
streamFormat.mBitsPerChannel = kBitsPerChannel;
|
||||||
|
|
||||||
if( streamFormat.mSampleRate <= 0 )
|
if( streamFormat.mSampleRate <= 0.0 )
|
||||||
streamFormat.mSampleRate = 44100.0;
|
streamFormat.mSampleRate = 44100.0;
|
||||||
m_iSampleRate = int( streamFormat.mSampleRate );
|
m_iSampleRate = int( streamFormat.mSampleRate );
|
||||||
|
m_TimeScale = streamFormat.mSampleRate / AudioGetHostClockFrequency();
|
||||||
|
|
||||||
// Try to set the hardware sample rate.
|
// Try to set the hardware sample rate.
|
||||||
{
|
{
|
||||||
@@ -184,8 +185,7 @@ RageSoundDriver_AU::~RageSoundDriver_AU()
|
|||||||
|
|
||||||
int64_t RageSoundDriver_AU::GetPosition() const
|
int64_t RageSoundDriver_AU::GetPosition() const
|
||||||
{
|
{
|
||||||
double scale = m_iSampleRate / AudioGetHostClockFrequency();
|
return int64_t( m_TimeScale * AudioGetCurrentHostTime() );
|
||||||
return int64_t( scale * AudioGetCurrentHostTime() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -291,9 +291,8 @@ OSStatus RageSoundDriver_AU::Render( void *inRefCon,
|
|||||||
This->m_pIOThread = new RageThreadRegister( "HAL I/O thread" );
|
This->m_pIOThread = new RageThreadRegister( "HAL I/O thread" );
|
||||||
|
|
||||||
AudioBuffer &buf = ioData->mBuffers[0];
|
AudioBuffer &buf = ioData->mBuffers[0];
|
||||||
double scale = This->m_iSampleRate / AudioGetHostClockFrequency();
|
int64_t now = int64_t( This->m_TimeScale * AudioGetCurrentHostTime() );
|
||||||
int64_t now = int64_t( scale * AudioGetCurrentHostTime() );
|
int64_t next = int64_t( This->m_TimeScale * inTimeStamp->mHostTime );
|
||||||
int64_t next = int64_t( scale * inTimeStamp->mHostTime );
|
|
||||||
|
|
||||||
This->Mix( (float *)buf.mData, inNumberFrames, next, now );
|
This->Mix( (float *)buf.mData, inNumberFrames, next, now );
|
||||||
if( unlikely(This->m_bDone) )
|
if( unlikely(This->m_bDone) )
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ private:
|
|||||||
AudioBufferList *ioData );
|
AudioBufferList *ioData );
|
||||||
static void NameHALThread( CFRunLoopObserverRef, CFRunLoopActivity activity, void *inRefCon );
|
static void NameHALThread( CFRunLoopObserverRef, CFRunLoopActivity activity, void *inRefCon );
|
||||||
|
|
||||||
|
double m_TimeScale;
|
||||||
AudioUnit m_OutputUnit;
|
AudioUnit m_OutputUnit;
|
||||||
int m_iSampleRate;
|
int m_iSampleRate;
|
||||||
bool m_bDone;
|
bool m_bDone;
|
||||||
|
|||||||
Reference in New Issue
Block a user