This commit is contained in:
Steve Checkoway
2005-10-24 05:28:38 +00:00
parent 330f0a783c
commit a2c1b1443d
2 changed files with 67 additions and 67 deletions
+54 -54
View File
@@ -44,9 +44,9 @@ CString RageSound_CA::Init()
try try
{ {
AudioDeviceID dID = CAAudioHardwareSystem::GetDefaultDevice( false, false ); AudioDeviceID dID = CAAudioHardwareSystem::GetDefaultDevice( false, false );
mOutputDevice = new CAAudioHardwareDevice(dID); mOutputDevice = new CAAudioHardwareDevice( dID );
} }
catch (const CAException& e) catch( const CAException& e )
{ {
return "Couldn't create default output device."; return "Couldn't create default output device.";
} }
@@ -57,44 +57,43 @@ CString RageSound_CA::Init()
{ {
mOutputDevice->SetNominalSampleRate(nominalSampleRate); mOutputDevice->SetNominalSampleRate(nominalSampleRate);
} }
catch (const CAException& e) catch( const CAException& e )
{ {
LOG->Warn("Couldn't set the nominal sample rate."); LOG->Warn( "Couldn't set the nominal sample rate." );
nominalSampleRate = mOutputDevice->GetNominalSampleRate(); nominalSampleRate = mOutputDevice->GetNominalSampleRate();
LOG->Warn("Device's nominal sample rate is %f", nominalSampleRate); LOG->Warn( "Device's nominal sample rate is %f", nominalSampleRate );
} }
AudioStreamID sID = mOutputDevice->GetStreamByIndex( kAudioDeviceSectionOutput, 0 ); AudioStreamID sID = mOutputDevice->GetStreamByIndex( kAudioDeviceSectionOutput, 0 );
CAAudioHardwareStream stream( sID ); CAAudioHardwareStream stream( sID );
try try
{ {
mOutputDevice->AddPropertyListener(kAudioPropertyWildcardChannel, mOutputDevice->AddPropertyListener( kAudioPropertyWildcardChannel, kAudioPropertyWildcardSection,
kAudioPropertyWildcardSection, kAudioDeviceProcessorOverload, OverloadListener, this); kAudioDeviceProcessorOverload, OverloadListener, this );
} }
catch (const CAException& e) catch( const CAException& e )
{ {
LOG->Warn("Could not install the overload listener."); LOG->Warn("Could not install the overload listener.");
} }
// The canonical format // The canonical format
// XXX should this be nominalSampleRate or not? // XXX should this be nominalSampleRate or not?
Desc IOProcFormat(nominalSampleRate, kAudioFormatLinearPCM, 8, 1, 8, 2, 32, Desc IOProcFormat( nominalSampleRate, kAudioFormatLinearPCM, 8, 1, 8, 2, 32,
kAudioFormatFlagsNativeFloatPacked); kAudioFormatFlagsNativeFloatPacked);
const Desc SMFormat(44100.0, kAudioFormatLinearPCM, kBytesPerPacket, const Desc SMFormat( 44100.0, kAudioFormatLinearPCM, kBytesPerPacket, kFramesPerPacket, kBytesPerFrame,
kFramesPerPacket, kBytesPerFrame, kChannelsPerFrame, kChannelsPerFrame, kBitsPerChannel, kFormatFlags );
kBitsPerChannel, kFormatFlags);
try try
{ {
stream.SetCurrentIOProcFormat(IOProcFormat); stream.SetCurrentIOProcFormat( IOProcFormat );
} }
catch (const CAException& e) catch( const CAException& e )
{ {
LOG->Warn("Could not set the IOProc format to the canonical format."); LOG->Warn( "Could not set the IOProc format to the canonical format." );
stream.GetCurrentIOProcFormat(IOProcFormat); stream.GetCurrentIOProcFormat( IOProcFormat );
} }
if (AudioConverterNew(&SMFormat, &IOProcFormat, &mConverter)) if( A udioConverterNew(&SMFormat, &IOProcFormat, &mConverter) )
return "Couldn't create the audio converter"; return "Couldn't create the audio converter";
try try
@@ -102,7 +101,7 @@ CString RageSound_CA::Init()
UInt32 bufferSize = mOutputDevice->GetIOBufferSize(); UInt32 bufferSize = mOutputDevice->GetIOBufferSize();
LOG->Info("I/O Buffer size: %lu", bufferSize); LOG->Info("I/O Buffer size: %lu", bufferSize);
} }
catch (const CAException& e) catch( const CAException& e )
{ {
LOG->Warn("Could not determine buffer size."); LOG->Warn("Could not determine buffer size.");
} }
@@ -110,21 +109,23 @@ CString RageSound_CA::Init()
try try
{ {
UInt32 frames = mOutputDevice->GetLatency(kAudioDeviceSectionOutput); UInt32 frames = mOutputDevice->GetLatency(kAudioDeviceSectionOutput);
if (stream.HasProperty(0, kAudioDevicePropertyLatency)) if( stream.HasProperty(0, kAudioDevicePropertyLatency) )
{ {
UInt32 t, size = 4; UInt32 t, size = 4;
stream.GetPropertyData(0, kAudioDevicePropertyLatency, size, &t); stream.GetPropertyData( 0, kAudioDevicePropertyLatency, size, &t );
frames += t; frames += t;
LOG->Info("Frames of stream latency: %lu", t); LOG->Info( "Frames of stream latency: %lu", t );
} }
else else
LOG->Warn("Stream reports no latency."); {
LOG->Warn( "Stream reports no latency." );
}
mLatency = frames / 44100.0; mLatency = frames / 44100.0;
LOG->Info("Frames of latency: %lu\n" LOG->Info( "Frames of latency: %lu\n"
"Seconds of latency: %f", frames, mLatency); "Seconds of latency: %f", frames, mLatency );
} }
catch (const CAException& e) catch( const CAException& e )
{ {
return "Couldn't get latency."; return "Couldn't get latency.";
} }
@@ -133,10 +134,10 @@ CString RageSound_CA::Init()
try try
{ {
mOutputDevice->AddIOProc(GetData, this); mOutputDevice->AddIOProc( GetData, this );
mOutputDevice->StartIOProc(GetData); mOutputDevice->StartIOProc( GetData );
} }
catch(const CAException& e) catch( const CAException& e )
{ {
return "Couldn't start the IOProc."; return "Couldn't start the IOProc.";
} }
@@ -153,39 +154,39 @@ RageSound_CA::~RageSound_CA()
AudioConverterDispose( mConverter ); AudioConverterDispose( mConverter );
} }
int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const int64_t RageSound_CA::GetPosition( const RageSoundBase *sound ) const
{ {
AudioTimeStamp time; AudioTimeStamp time;
mOutputDevice->GetCurrentTime(time); mOutputDevice->GetCurrentTime( time );
return int64_t(time.mSampleTime); return int64_t( time.mSampleTime );
} }
OSStatus RageSound_CA::GetData(AudioDeviceID inDevice, OSStatus RageSound_CA::GetData( AudioDeviceID inDevice,
const AudioTimeStamp *inNow, const AudioTimeStamp *inNow,
const AudioBufferList *inInputData, const AudioBufferList *inInputData,
const AudioTimeStamp *inInputTime, const AudioTimeStamp *inInputTime,
AudioBufferList *outOutputData, AudioBufferList *outOutputData,
const AudioTimeStamp *inOutputTime, const AudioTimeStamp *inOutputTime,
void *inClientData) void *inClientData )
{ {
RageTimer tm; RageTimer tm;
RageSound_CA *This = (RageSound_CA *)inClientData; RageSound_CA *This = (RageSound_CA *)inClientData;
AudioBuffer& buf = outOutputData->mBuffers[0]; AudioBuffer& buf = outOutputData->mBuffers[0];
UInt32 dataPackets = buf.mDataByteSize >> 3; // 8 byes per packet UInt32 dataPackets = buf.mDataByteSize >> 3; // 8 byes per packet
int64_t decodePos = int64_t(inOutputTime->mSampleTime); int64_t decodePos = int64_t( inOutputTime->mSampleTime );
int64_t now = int64_t(inNow->mSampleTime); int64_t now = int64_t( inNow->mSampleTime );
RageTimer tm2; RageTimer tm2;
int16_t buffer[dataPackets * (kBytesPerPacket >> 1)]; int16_t buffer[ dataPackets * (kBytesPerPacket >> 1) ];
This->Mix(buffer, dataPackets, decodePos, now); This->Mix( buffer, dataPackets, decodePos, now) ;
g_fLastMixTimes[g_iLastMixTimePos] = tm2.GetDeltaTime(); g_fLastMixTimes[ g_iLastMixTimePos ] = tm2.GetDeltaTime();
++g_iLastMixTimePos; ++g_iLastMixTimePos;
wrap(g_iLastMixTimePos, NUM_MIX_TIMES); wrap( g_iLastMixTimePos, NUM_MIX_TIMES );
AudioConverterConvertBuffer(This->mConverter, dataPackets * kBytesPerPacket, AudioConverterConvertBuffer( This->mConverter, dataPackets * kBytesPerPacket,
buffer, &buf.mDataByteSize, buf.mData); buffer, &buf.mDataByteSize, buf.mData );
g_fLastIOProcTime = tm.GetDeltaTime(); g_fLastIOProcTime = tm.GetDeltaTime();
++g_iNumIOProcCalls; ++g_iNumIOProcCalls;
@@ -194,11 +195,11 @@ OSStatus RageSound_CA::GetData(AudioDeviceID inDevice,
} }
OSStatus RageSound_CA::OverloadListener(AudioDeviceID inDevice, OSStatus RageSound_CA::OverloadListener( AudioDeviceID inDevice,
UInt32 inChannel, UInt32 inChannel,
Boolean isInput, Boolean isInput,
AudioDevicePropertyID inPropertyID, AudioDevicePropertyID inPropertyID,
void *inData) void *inData )
{ {
CString Output; CString Output;
for( int i = NUM_MIX_TIMES-1; i >= 0; --i ) for( int i = NUM_MIX_TIMES-1; i >= 0; --i )
@@ -224,8 +225,7 @@ void RageSound_CA::SetupDecodingThread()
THREAD_PRECEDENCE_POLICY, (int *)&po, THREAD_PRECEDENCE_POLICY, (int *)&po,
THREAD_PRECEDENCE_POLICY_COUNT ); THREAD_PRECEDENCE_POLICY_COUNT );
if( ret != KERN_SUCCESS ) if( ret != KERN_SUCCESS )
LOG->Warn("thread_policy_set(THREAD_PRECEDENCE_POLICY) failed: %s", LOG->Warn( "thread_policy_set(THREAD_PRECEDENCE_POLICY) failed: %s", mach_error_string(ret) );
mach_error_string(ret));
} }
/* /*
+13 -13
View File
@@ -23,26 +23,26 @@ private:
CAAudioHardwareDevice *mOutputDevice; CAAudioHardwareDevice *mOutputDevice;
AudioConverterRef mConverter; AudioConverterRef mConverter;
static OSStatus GetData(AudioDeviceID inDevice, static OSStatus GetData( AudioDeviceID inDevice,
const AudioTimeStamp *inNow, const AudioTimeStamp *inNow,
const AudioBufferList *inInputData, const AudioBufferList *inInputData,
const AudioTimeStamp *inInputTime, const AudioTimeStamp *inInputTime,
AudioBufferList *outOutputData, AudioBufferList *outOutputData,
const AudioTimeStamp *inOutputTime, const AudioTimeStamp *inOutputTime,
void *inClientData); void *inClientData);
static OSStatus OverloadListener(AudioDeviceID inDevice, static OSStatus OverloadListener( AudioDeviceID inDevice,
UInt32 inChannel, UInt32 inChannel,
Boolean isInput, Boolean isInput,
AudioDevicePropertyID inPropertyID, AudioDevicePropertyID inPropertyID,
void *inData); void *inData);
public: public:
RageSound_CA(); RageSound_CA();
CString Init(); CString Init();
~RageSound_CA(); ~RageSound_CA();
float GetPlayLatency() const { return mLatency; } float GetPlayLatency() const { return mLatency; }
int64_t GetPosition(const RageSoundBase *sound) const; int64_t GetPosition( const RageSoundBase *sound ) const;
void SetupDecodingThread(); void SetupDecodingThread();
}; };
#define USE_RAGE_SOUND_CA #define USE_RAGE_SOUND_CA