diff options
author | Torbjörn Andersson | 2006-03-12 17:50:36 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2006-03-12 17:50:36 +0000 |
commit | 63245b8eba5121a2880f6d40d4aaf77d52e1c37f (patch) | |
tree | e87cc0bca81ea203438d17f30a258bbe382d5fcd /engines/kyra | |
parent | 9d3136fb71858a73a9f4aef8e33e0e444610cb5e (diff) | |
download | scummvm-rg350-63245b8eba5121a2880f6d40d4aaf77d52e1c37f.tar.gz scummvm-rg350-63245b8eba5121a2880f6d40d4aaf77d52e1c37f.tar.bz2 scummvm-rg350-63245b8eba5121a2880f6d40d4aaf77d52e1c37f.zip |
Compensate for rounding errors in _samplesPerCallback by having readBuffer()
generate "leap samples". I doubt this will make any noticeable difference, but
at least now we can probably rule out timer inaccuracies from the list of
possible suspects for the remaining bugs.
Also removed unnecessary mutex locking/unlocking from readBuffer(), spotted by
LordHoto.
svn-id: r21239
Diffstat (limited to 'engines/kyra')
-rw-r--r-- | engines/kyra/sound_adlib.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/engines/kyra/sound_adlib.cpp b/engines/kyra/sound_adlib.cpp index b15a8514a0..fdefaabede 100644 --- a/engines/kyra/sound_adlib.cpp +++ b/engines/kyra/sound_adlib.cpp @@ -34,6 +34,8 @@ // Basic Adlib Programming: // http://www.gamedev.net/reference/articles/article446.asp +#define CALLBACKS_PER_SECOND 72 + namespace Kyra { class AdlibDriver : public AudioStream { @@ -48,11 +50,15 @@ public: int readBuffer(int16 *buffer, const int numSamples) { int samplesLeft = numSamples; memset(buffer, 0, sizeof(int16) * numSamples); - lock(); while (samplesLeft) { if (!_samplesTillCallback) { callback(); _samplesTillCallback = _samplesPerCallback; + _samplesTillCallbackRemainder += _samplesPerCallbackRemainder; + if (_samplesTillCallbackRemainder >= CALLBACKS_PER_SECOND) { + _samplesTillCallback++; + _samplesTillCallbackRemainder -= CALLBACKS_PER_SECOND; + } } int32 render = MIN(samplesLeft, _samplesTillCallback); @@ -61,7 +67,6 @@ public: YM3812UpdateOne(_adlib, buffer, render); buffer += render; } - unlock(); return numSamples; } @@ -312,7 +317,9 @@ private: // _unkTable2_3[] - One of the tables in _unkTable2[] int32 _samplesPerCallback; + int32 _samplesPerCallbackRemainder; int32 _samplesTillCallback; + int32 _samplesTillCallbackRemainder; int _lastProcessed; int8 _flagTrigger; @@ -403,9 +410,10 @@ AdlibDriver::AdlibDriver(Audio::Mixer *mixer) { _mixer->setupPremix(this); - // FIXME: Handle the rounding error? - _samplesPerCallback = getRate() / 72; + _samplesPerCallback = getRate() / CALLBACKS_PER_SECOND; + _samplesPerCallbackRemainder = getRate() % CALLBACKS_PER_SECOND; _samplesTillCallback = 0; + _samplesTillCallbackRemainder = 0; } AdlibDriver::~AdlibDriver() { |