diff options
author | Max Horn | 2007-06-28 20:09:58 +0000 |
---|---|---|
committer | Max Horn | 2007-06-28 20:09:58 +0000 |
commit | d35861fc4ae5f23126dd7b1a0e512f79b64ff481 (patch) | |
tree | f4800c0cdc9ab8469d2faddcd0d7c916e3080b2f /engines | |
parent | 675fc8ab719a2600fb9a0487a056e58b2876ff7d (diff) | |
download | scummvm-rg350-d35861fc4ae5f23126dd7b1a0e512f79b64ff481.tar.gz scummvm-rg350-d35861fc4ae5f23126dd7b1a0e512f79b64ff481.tar.bz2 scummvm-rg350-d35861fc4ae5f23126dd7b1a0e512f79b64ff481.zip |
Changed GOB to use common/frac.h
svn-id: r27763
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gob/sound.cpp | 31 | ||||
-rw-r--r-- | engines/gob/sound.h | 7 |
2 files changed, 12 insertions, 26 deletions
diff --git a/engines/gob/sound.cpp b/engines/gob/sound.cpp index e3a4715920..acee317f03 100644 --- a/engines/gob/sound.cpp +++ b/engines/gob/sound.cpp @@ -35,8 +35,6 @@ namespace Gob { -#define FRAC_BITS 16 - void SoundDesc::set(SoundType type, SoundSource src, byte *data, uint32 dSize) { @@ -174,9 +172,7 @@ Snd::Snd(GobEngine *vm) : _vm(vm) { _repCount = 0; _offset = 0; - _offsetFrac = 0; _offsetInc = 0; - _offsetIncFrac = 0; _cur = 0; _last = 0; @@ -324,11 +320,7 @@ void Snd::setSample(SoundDesc &sndDesc, int16 repCount, int16 frequency, _playingSound = 1; _offset = 0; - _offsetFrac = 0; - - uint32 incr = (_freq << FRAC_BITS) / _rate; - _offsetInc = incr >> FRAC_BITS; - _offsetIncFrac = incr & ((1UL << FRAC_BITS) - 1); + _offsetInc = (_freq << FRAC_BITS) / _rate; _last = _cur; _cur = _data[0]; @@ -381,7 +373,6 @@ void Snd::checkEndSample() { nextCompositionPos(); else if ((_repCount == -1) || (--_repCount > 0)) { _offset = 0; - _offsetFrac = 0; _end = false; _playingSound = 1; } else { @@ -393,30 +384,26 @@ void Snd::checkEndSample() { int Snd::readBuffer(int16 *buffer, const int numSamples) { Common::StackLock slock(_mutex); - int16 val; - uint32 tmp, oldOffset; - for (int i = 0; i < numSamples; i++) { if (!_data) return i; - if (_end || (_offset >= _length)) + if (_end || (fracToInt(_offset) >= (int)_length)) checkEndSample(); if (_end) return i; // Linear interpolation. See sound/rate.cpp - val = (_last + (((_cur - _last) * _offsetFrac + - (1UL << (FRAC_BITS - 1))) >> FRAC_BITS)) << 8; - *buffer++ = (((int32) val) * _fadeVol) >> 16; + int32 val = (_last + (((_cur - _last) * (_offset & FRAC_LO_MASK) + + FRAC_HALF) >> FRAC_BITS)) << 8; + *buffer++ = (val * _fadeVol) >> 16; - oldOffset = _offset; + int16 oldOffset = fracToInt(_offset); - tmp = _offsetFrac + _offsetIncFrac; - _offset += _offsetInc + (tmp >> FRAC_BITS); - _offsetFrac = tmp & ((1UL << FRAC_BITS) - 1); + _offset += _offsetInc; - if (oldOffset < _offset) { + // Was there an integral change? + if (oldOffset < fracToInt(_offset)) { _last = _cur; _cur = _data[oldOffset]; } diff --git a/engines/gob/sound.h b/engines/gob/sound.h index 76b9f2b159..4e9a640b6b 100644 --- a/engines/gob/sound.h +++ b/engines/gob/sound.h @@ -27,6 +27,7 @@ #define GOB_SOUND_H #include "common/mutex.h" +#include "common/frac.h" #include "sound/audiostream.h" #include "sound/mixer.h" @@ -174,10 +175,8 @@ protected: int32 _freq; int32 _repCount; - uint32 _offset; - uint32 _offsetFrac; - uint32 _offsetInc; - uint32 _offsetIncFrac; + frac_t _offset; + frac_t _offsetInc; int16 _cur; int16 _last; |