Cleanup
This commit is contained in:
@@ -228,21 +228,8 @@ RageSound_CA::RageSound_CA()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (mFormat)
|
mOutputDevice->AddIOProc(GetData, this);
|
||||||
{
|
mOutputDevice->StartIOProc(GetData);
|
||||||
case EXACT:
|
|
||||||
mOutputDevice->AddIOProc(GetDataExact, this);
|
|
||||||
mOutputDevice->StartIOProc(GetDataExact);
|
|
||||||
break;
|
|
||||||
case CANONICAL:
|
|
||||||
mOutputDevice->AddIOProc(GetDataCanonical, this);
|
|
||||||
mOutputDevice->StartIOProc(GetDataCanonical);
|
|
||||||
break;
|
|
||||||
case OTHER:
|
|
||||||
mOutputDevice->AddIOProc(GetDataOther, this);
|
|
||||||
mOutputDevice->StartIOProc(GetDataOther);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(const CAException& e)
|
catch(const CAException& e)
|
||||||
{
|
{
|
||||||
@@ -254,20 +241,9 @@ RageSound_CA::RageSound_CA()
|
|||||||
|
|
||||||
RageSound_CA::~RageSound_CA()
|
RageSound_CA::~RageSound_CA()
|
||||||
{
|
{
|
||||||
switch (mFormat)
|
mOutputDevice->StopIOProc(GetData);
|
||||||
{
|
|
||||||
case EXACT:
|
|
||||||
mOutputDevice->StopIOProc(GetDataExact);
|
|
||||||
break;
|
|
||||||
case CANONICAL:
|
|
||||||
mOutputDevice->StopIOProc(GetDataCanonical);
|
|
||||||
break;
|
|
||||||
case OTHER:
|
|
||||||
mOutputDevice->StopIOProc(GetDataOther);
|
|
||||||
delete gConverter;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
delete mOutputDevice;
|
delete mOutputDevice;
|
||||||
|
delete gConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const
|
int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const
|
||||||
@@ -278,79 +254,18 @@ int64_t RageSound_CA::GetPosition(const RageSoundBase *sound) const
|
|||||||
return int64_t(time.mSampleTime);
|
return int64_t(time.mSampleTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus RageSound_CA::GetDataExact(AudioDeviceID inDevice,
|
|
||||||
const AudioTimeStamp *inNow,
|
|
||||||
const AudioBufferList *inInputData,
|
|
||||||
const AudioTimeStamp *inInputTime,
|
|
||||||
AudioBufferList *outOutputData,
|
|
||||||
const AudioTimeStamp *inOutputTime,
|
|
||||||
void *inClientData)
|
|
||||||
{
|
|
||||||
RageTimer tm;
|
|
||||||
RageSound_CA *This = (RageSound_CA *)inClientData;
|
|
||||||
AudioBuffer& buf = outOutputData->mBuffers[0];
|
|
||||||
UInt32 dataPackets = buf.mDataByteSize / kBytesPerPacket;
|
|
||||||
int64_t decodePos = int64_t(inOutputTime->mSampleTime);
|
|
||||||
RageTimer mixTM;
|
|
||||||
|
|
||||||
This->Mix((int16_t *)buf.mData, dataPackets, decodePos,
|
|
||||||
int64_t(inNow->mSampleTime));
|
|
||||||
g_fLastMixTimes[g_fLastMixTimePos] = tm.GetDeltaTime();
|
|
||||||
++g_fLastMixTimePos;
|
|
||||||
wrap(g_fLastMixTimePos, NUM_MIX_TIMES);
|
|
||||||
|
|
||||||
g_fLastIOProcTime = tm.GetDeltaTime();
|
|
||||||
++g_iNumIOProcCalls;
|
|
||||||
|
|
||||||
return noErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
OSStatus RageSound_CA::GetDataCanonical(AudioDeviceID inDevice,
|
|
||||||
const AudioTimeStamp *inNow,
|
|
||||||
const AudioBufferList *inInputData,
|
|
||||||
const AudioTimeStamp *inInputTime,
|
|
||||||
AudioBufferList *outOutputData,
|
|
||||||
const AudioTimeStamp *inOutputTime,
|
|
||||||
void *inClientData)
|
|
||||||
{
|
|
||||||
RageTimer tm;
|
|
||||||
RageSound_CA *This = (RageSound_CA *)inClientData;
|
|
||||||
AudioBuffer& buf = outOutputData->mBuffers[0];
|
|
||||||
UInt32 dataPackets = buf.mDataByteSize / 8;
|
|
||||||
int64_t decodePos = int64_t(inOutputTime->mSampleTime);
|
|
||||||
int16_t buffer[dataPackets * kBytesPerPacket];
|
|
||||||
RageTimer mixTM;
|
|
||||||
|
|
||||||
This->Mix(buffer, dataPackets, decodePos, int64_t(inNow->mSampleTime));
|
|
||||||
g_fLastMixTimes[g_fLastMixTimePos] = tm.GetDeltaTime();
|
|
||||||
++g_fLastMixTimePos;
|
|
||||||
wrap(g_fLastMixTimePos, NUM_MIX_TIMES);
|
|
||||||
|
|
||||||
int16_t *ip = buffer;
|
|
||||||
float *fp = (float *)buf.mData;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < dataPackets; ++i)
|
|
||||||
{
|
|
||||||
int16_t val = *(++ip);
|
|
||||||
|
|
||||||
*(++fp) = val < 0 ? val / 32768.0 : val / 32767.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return noErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RageSound_CA::FillConverter( void *data, UInt32 frames )
|
void RageSound_CA::FillConverter( void *data, UInt32 frames )
|
||||||
{
|
{
|
||||||
RageTimer tm;
|
RageTimer tm;
|
||||||
|
|
||||||
Mix( (int16_t *)data, frames, mDecodePos, int64_t(mNow->mSampleTime) );
|
Mix( (int16_t *)data, frames, mDecodePos, mNow );
|
||||||
|
|
||||||
g_fLastMixTimes[g_fLastMixTimePos] = tm.GetDeltaTime();
|
g_fLastMixTimes[g_fLastMixTimePos] = tm.GetDeltaTime();
|
||||||
++g_fLastMixTimePos;
|
++g_fLastMixTimePos;
|
||||||
wrap( g_fLastMixTimePos, NUM_MIX_TIMES );
|
wrap( g_fLastMixTimePos, NUM_MIX_TIMES );
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus RageSound_CA::GetDataOther(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,
|
||||||
@@ -359,15 +274,50 @@ OSStatus RageSound_CA::GetDataOther(AudioDeviceID inDevice,
|
|||||||
void *inClientData)
|
void *inClientData)
|
||||||
{
|
{
|
||||||
RageTimer tm;
|
RageTimer tm;
|
||||||
|
|
||||||
RageSound_CA *This = (RageSound_CA *)inClientData;
|
RageSound_CA *This = (RageSound_CA *)inClientData;
|
||||||
UInt32 dataPackets = outOutputData->mBuffers[0].mDataByteSize;
|
AudioBuffer& buf = outOutputData->mBuffers[0];
|
||||||
|
UInt32 dataPackets = buf.mDataByteSize;
|
||||||
|
int64_t decodePos = int64_t(inOutputTime->mSampleTime);
|
||||||
|
int64_t now = int64_t(inNow->mSampleTime);
|
||||||
|
|
||||||
|
if (This->mFormat == OTHER)
|
||||||
|
{
|
||||||
dataPackets /= gConverter->GetOutputFormat().mBytesPerPacket;
|
dataPackets /= gConverter->GetOutputFormat().mBytesPerPacket;
|
||||||
|
This->mDecodePos = decodePos;
|
||||||
This->mDecodePos = int64_t(inOutputTime->mSampleTime);
|
This->mNow = now;
|
||||||
This->mNow = inNow;
|
|
||||||
gConverter->FillComplexBuffer(dataPackets, *outOutputData, NULL);
|
gConverter->FillComplexBuffer(dataPackets, *outOutputData, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RageTimer mixTM;
|
||||||
|
|
||||||
|
if (This->mFormat == EXACT)
|
||||||
|
{
|
||||||
|
dataPackets /= kBytesPerPacket;
|
||||||
|
This->Mix((int16_t *)buf.mData, dataPackets, decodePos, now);
|
||||||
|
}
|
||||||
|
else // This->mFormat == CANONICAL
|
||||||
|
{
|
||||||
|
int16_t buffer[dataPackets * kBytesPerPacket];
|
||||||
|
int16_t *ip = buffer;
|
||||||
|
float *fp = (float *)buf.mData;
|
||||||
|
|
||||||
|
dataPackets >>= 3;
|
||||||
|
This->Mix(buffer, dataPackets, decodePos, now);
|
||||||
|
|
||||||
|
// Convert from signed 16 bit int to signed 32 bit float
|
||||||
|
for (unsigned i = 0; i < dataPackets; ++i)
|
||||||
|
{
|
||||||
|
int16_t val = *(++ip);
|
||||||
|
|
||||||
|
*(++fp) = val / (val < 0 ? 32768.0f : 32767.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g_fLastMixTimes[g_fLastMixTimePos] = tm.GetDeltaTime();
|
||||||
|
++g_fLastMixTimePos;
|
||||||
|
wrap(g_fLastMixTimePos, NUM_MIX_TIMES);
|
||||||
|
}
|
||||||
|
|
||||||
g_fLastIOProcTime = tm.GetDeltaTime();
|
g_fLastIOProcTime = tm.GetDeltaTime();
|
||||||
++g_iNumIOProcCalls;
|
++g_iNumIOProcCalls;
|
||||||
@@ -375,6 +325,7 @@ OSStatus RageSound_CA::GetDataOther(AudioDeviceID inDevice,
|
|||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OSStatus RageSound_CA::OverloadListener(AudioDeviceID inDevice,
|
OSStatus RageSound_CA::OverloadListener(AudioDeviceID inDevice,
|
||||||
UInt32 inChannel,
|
UInt32 inChannel,
|
||||||
Boolean isInput,
|
Boolean isInput,
|
||||||
@@ -388,7 +339,6 @@ OSStatus RageSound_CA::OverloadListener(AudioDeviceID inDevice,
|
|||||||
Output += ssprintf( "%.3f ", g_fLastMixTimes[pos] );
|
Output += ssprintf( "%.3f ", g_fLastMixTimes[pos] );
|
||||||
}
|
}
|
||||||
|
|
||||||
//if( g_iNumIOProcCalls >= 100 )
|
|
||||||
LOG->Warn( "Audio overload. Last IOProc time: %f IOProc calls: %i (%s)",
|
LOG->Warn( "Audio overload. Last IOProc time: %f IOProc calls: %i (%s)",
|
||||||
g_fLastIOProcTime, g_iNumIOProcCalls, Output.c_str() );
|
g_fLastIOProcTime, g_iNumIOProcCalls, Output.c_str() );
|
||||||
g_iNumIOProcCalls = 0;
|
g_iNumIOProcCalls = 0;
|
||||||
|
|||||||
@@ -27,30 +27,17 @@ private:
|
|||||||
int64_t mDecodePos;
|
int64_t mDecodePos;
|
||||||
float mLatency;
|
float mLatency;
|
||||||
CAAudioHardwareDevice *mOutputDevice;
|
CAAudioHardwareDevice *mOutputDevice;
|
||||||
const AudioTimeStamp *mNow;
|
int64_t mNow;
|
||||||
format mFormat;
|
format mFormat;
|
||||||
|
|
||||||
static OSStatus GetDataExact(AudioDeviceID inDevice,
|
static OSStatus GetData(AudioDeviceID inDevice,
|
||||||
const AudioTimeStamp *inNow,
|
|
||||||
const AudioBufferList *inInputData,
|
|
||||||
const AudioTimeStamp *inInputTime,
|
|
||||||
AudioBufferList *outOutputData,
|
|
||||||
const AudioTimeStamp *inOutputTime,
|
|
||||||
void *inClientData);
|
|
||||||
static OSStatus GetDataCanonical(AudioDeviceID inDevice,
|
|
||||||
const AudioTimeStamp *inNow,
|
|
||||||
const AudioBufferList *inInputData,
|
|
||||||
const AudioTimeStamp *inInputTime,
|
|
||||||
AudioBufferList *outOutputData,
|
|
||||||
const AudioTimeStamp *inOutputTime,
|
|
||||||
void *inClientData);
|
|
||||||
static OSStatus GetDataOther(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,
|
||||||
|
|||||||
Reference in New Issue
Block a user