aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra
diff options
context:
space:
mode:
authorTorbjörn Andersson2006-03-12 17:05:59 +0000
committerTorbjörn Andersson2006-03-12 17:05:59 +0000
commit72d2ef72218e419fe8b0b175e7ea7cef9ecbc525 (patch)
treeb8009b55c7d126685fafb7e6e8eb33b60e07ea16 /engines/kyra
parentcb085df0f554354e9fb811a8490a954b0820e83a (diff)
downloadscummvm-rg350-72d2ef72218e419fe8b0b175e7ea7cef9ecbc525.tar.gz
scummvm-rg350-72d2ef72218e419fe8b0b175e7ea7cef9ecbc525.tar.bz2
scummvm-rg350-72d2ef72218e419fe8b0b175e7ea7cef9ecbc525.zip
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
Diffstat (limited to 'engines/kyra')
-rw-r--r--engines/kyra/sound_adlib.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/engines/kyra/sound_adlib.cpp b/engines/kyra/sound_adlib.cpp
index 0c8f53957b..c74d9a0f1a 100644
--- a/engines/kyra/sound_adlib.cpp
+++ b/engines/kyra/sound_adlib.cpp
@@ -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;