After several days, telling LordHoto over and over that "no, I don't think the

timer inaccuracies can cause that kind of problems, or we'd have noticed it in
the other game engines as well", guess what? The other game engines do not
necessary use a timer for their Adlib music. So now Kyra doesn't either.

Fortunately for my dignity, the music is still a bit uneven at times, but the
situation does seem to have improved a bit, and the sound effects sound better
to me now.

svn-id: r21237
This commit is contained in:
Torbjörn Andersson 2006-03-12 17:05:59 +00:00
parent cb085df0f5
commit 72d2ef7221

View File

@ -46,9 +46,21 @@ public:
// AudioStream API
int readBuffer(int16 *buffer, const int numSamples) {
memset(buffer, 0, sizeof(int16)*numSamples);
int samplesLeft = numSamples;
memset(buffer, 0, sizeof(int16) * numSamples);
lock();
YM3812UpdateOne(_adlib, buffer, numSamples);
while (samplesLeft) {
if (!_samplesTillCallback) {
callback();
_samplesTillCallback = _samplesPerCallback;
}
int32 render = MIN(samplesLeft, _samplesTillCallback);
samplesLeft -= render;
_samplesTillCallback -= render;
YM3812UpdateOne(_adlib, buffer, render);
buffer += render;
}
unlock();
return numSamples;
}
@ -299,6 +311,9 @@ private:
// _unkTable2_2[] - One of the tables in _unkTable2[]
// _unkTable2_3[] - One of the tables in _unkTable2[]
int32 _samplesPerCallback;
int32 _samplesTillCallback;
int _lastProcessed;
int8 _flagTrigger;
int _curTable;
@ -360,11 +375,6 @@ private:
void unlock() { _mutex.unlock(); }
};
void AdlibTimerCall(void *refCon) {
AdlibDriver *driver = (AdlibDriver*)refCon;
driver->callback();
}
AdlibDriver::AdlibDriver(Audio::Mixer *mixer) {
_mixer = mixer;
@ -393,11 +403,12 @@ AdlibDriver::AdlibDriver(Audio::Mixer *mixer) {
_mixer->setupPremix(this);
Common::g_timer->installTimerProc(&AdlibTimerCall, 13888, this);
// FIXME: Handle the rounding error?
_samplesPerCallback = getRate() / 72;
_samplesTillCallback = 0;
}
AdlibDriver::~AdlibDriver() {
Common::g_timer->removeTimerProc(&AdlibTimerCall);
_mixer->setupPremix(0);
OPLDestroy(_adlib);
_adlib = 0;