Well, since this is the only sound driver working atm. Replace the latency with a simple calculation of the time to drain a buffer. Also, use more samples.
This commit is contained in:
@@ -20,12 +20,10 @@ using namespace QT;
|
|||||||
|
|
||||||
const unsigned channels = 2;
|
const unsigned channels = 2;
|
||||||
const unsigned samplesize = channels*16;
|
const unsigned samplesize = channels*16;
|
||||||
const unsigned samples = 512;
|
const unsigned samples = 2048;
|
||||||
const unsigned freq = 44100;
|
const unsigned freq = 44100;
|
||||||
const unsigned buffersize = samples*samplesize/8;
|
const unsigned buffersize = samples*samplesize/8;
|
||||||
|
|
||||||
/* Oh boy! dealing with memory at inturupt time. What fun! */
|
|
||||||
#pragma options align=power
|
|
||||||
static volatile Uint32 fill_me = 0;
|
static volatile Uint32 fill_me = 0;
|
||||||
static UInt8 *buffer[2];
|
static UInt8 *buffer[2];
|
||||||
static CmpSoundHeader header;
|
static CmpSoundHeader header;
|
||||||
@@ -49,13 +47,7 @@ RageSound_QT1::RageSound_QT1() {
|
|||||||
channel->userInfo = reinterpret_cast<long>(this);
|
channel->userInfo = reinterpret_cast<long>(this);
|
||||||
channel->qLength = 2;
|
channel->qLength = 2;
|
||||||
|
|
||||||
soundOutput = OpenDefaultComponent(kSoundOutputDeviceType, NULL);
|
latency = static_cast<float>(samples) / freq; /* double buffer */
|
||||||
ASSERT(soundOutput != NULL);
|
|
||||||
|
|
||||||
TimeRecord record;
|
|
||||||
SoundComponentGetInfo(soundOutput, NULL, siOutputLatency, &record);
|
|
||||||
latency = record.value.lo / record.scale;
|
|
||||||
latency += static_cast<float>(samples) / freq; /* double buffer */
|
|
||||||
LOG->Trace("The output latency is %f", latency);
|
LOG->Trace("The output latency is %f", latency);
|
||||||
|
|
||||||
OSErr err = SndNewChannel(&channel, sampledSynth, initStereo, callback);
|
OSErr err = SndNewChannel(&channel, sampledSynth, initStereo, callback);
|
||||||
@@ -92,8 +84,6 @@ RageSound_QT1::~RageSound_QT1() {
|
|||||||
SAFE_DELETE(channel);
|
SAFE_DELETE(channel);
|
||||||
SAFE_DELETE_ARRAY(buffer[0]);
|
SAFE_DELETE_ARRAY(buffer[0]);
|
||||||
SAFE_DELETE_ARRAY(buffer[1]);
|
SAFE_DELETE_ARRAY(buffer[1]);
|
||||||
if (soundOutput)
|
|
||||||
CloseComponent(soundOutput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageSound_QT1::GetData(SndChannel *chan, SndCommand *cmd_passed) {
|
void RageSound_QT1::GetData(SndChannel *chan, SndCommand *cmd_passed) {
|
||||||
@@ -119,6 +109,7 @@ void RageSound_QT1::GetData(SndChannel *chan, SndCommand *cmd_passed) {
|
|||||||
} else
|
} else
|
||||||
P->last_pos += samples;
|
P->last_pos += samples;
|
||||||
|
|
||||||
|
bool moreThanOneSound;
|
||||||
/* Swap buffers */
|
/* Swap buffers */
|
||||||
header.samplePtr = reinterpret_cast<Ptr>(buffer[play_me]);
|
header.samplePtr = reinterpret_cast<Ptr>(buffer[play_me]);
|
||||||
SndCommand cmd;
|
SndCommand cmd;
|
||||||
@@ -131,12 +122,14 @@ void RageSound_QT1::GetData(SndChannel *chan, SndCommand *cmd_passed) {
|
|||||||
|
|
||||||
/* Clear the fill buffer */
|
/* Clear the fill buffer */
|
||||||
memset(buffer[fill_me], 0, buffersize);
|
memset(buffer[fill_me], 0, buffersize);
|
||||||
|
moreThanOneSound = P->sounds.size() > 1;
|
||||||
|
|
||||||
for (unsigned i=0; i<P->sounds.size(); ++i) {
|
for (unsigned i=0; i<P->sounds.size(); ++i) {
|
||||||
if (P->sounds[i]->stopping)
|
if (P->sounds[i]->stopping)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
unsigned got = P->sounds[i]->snd->GetPCM(reinterpret_cast<char *>(buffer[fill_me]), buffersize, P->last_pos);
|
unsigned got = P->sounds[i]->snd->GetPCM(reinterpret_cast<char *>(buffer[fill_me]), buffersize, P->last_pos);
|
||||||
|
if (moreThanOneSound)
|
||||||
mix.write(reinterpret_cast<SInt16 *>(buffer[fill_me]), got / 2);
|
mix.write(reinterpret_cast<SInt16 *>(buffer[fill_me]), got / 2);
|
||||||
if (got < buffersize) {
|
if (got < buffersize) {
|
||||||
P->sounds[i]->stopping = true;
|
P->sounds[i]->stopping = true;
|
||||||
@@ -144,6 +137,7 @@ void RageSound_QT1::GetData(SndChannel *chan, SndCommand *cmd_passed) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (moreThanOneSound)
|
||||||
mix.read(reinterpret_cast<SInt16 *>(buffer[fill_me]));
|
mix.read(reinterpret_cast<SInt16 *>(buffer[fill_me]));
|
||||||
|
|
||||||
cmd.cmd = callBackCmd;
|
cmd.cmd = callBackCmd;
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ private:
|
|||||||
|
|
||||||
vector<sound *> sounds;
|
vector<sound *> sounds;
|
||||||
QT::ComponentInstance clock;
|
QT::ComponentInstance clock;
|
||||||
QT::ComponentInstance soundOutput;
|
|
||||||
QT::SndChannelPtr channel;
|
QT::SndChannelPtr channel;
|
||||||
int last_pos;
|
int last_pos;
|
||||||
float latency;
|
float latency;
|
||||||
|
|||||||
Reference in New Issue
Block a user