diff options
author | Max Horn | 2004-01-03 19:12:23 +0000 |
---|---|---|
committer | Max Horn | 2004-01-03 19:12:23 +0000 |
commit | cf6a5c0a04a23ac4b8044710f94dc224a1538a45 (patch) | |
tree | 4a9db3abbf83fa84dbea2772decf06a6a58f0cbb /sword2/driver | |
parent | ee3558b748cfe205110bf8cb5090999916a2780b (diff) | |
download | scummvm-rg350-cf6a5c0a04a23ac4b8044710f94dc224a1538a45.tar.gz scummvm-rg350-cf6a5c0a04a23ac4b8044710f94dc224a1538a45.tar.bz2 scummvm-rg350-cf6a5c0a04a23ac4b8044710f94dc224a1538a45.zip |
cleanup
svn-id: r12116
Diffstat (limited to 'sword2/driver')
-rw-r--r-- | sword2/driver/d_sound.cpp | 94 | ||||
-rw-r--r-- | sword2/driver/d_sound.h | 3 |
2 files changed, 45 insertions, 52 deletions
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index b061db823d..2ee80a0724 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -175,64 +175,58 @@ void MusicHandle::stop(void) { } int MusicHandle::readBuffer(int16 *buffer, const int numSamples) { + assert(numSamples > 0); int samples; - for (samples = 0; samples < numSamples && !endOfData(); samples++) - *buffer++ = read(); - return samples; -} - -int16 MusicHandle::read(void) { - uint8 in; - uint16 delta; - int16 out; - - if (!_streaming) - return 0; - - if (_firstTime) { - _lastSample = fpMus.readUint16LE(); - _filePos += 2; - _firstTime = false; - return _lastSample; - } // Assume the file handle has been correctly positioned already. - in = fpMus.readByte(); - delta = GetCompressedAmplitude(in) << GetCompressedShift(in); - - if (GetCompressedSign(in)) - out = _lastSample - delta; - else - out = _lastSample + delta; - - _filePos++; - _lastSample = out; - - if (_looping) { - if (_filePos >= _fileEnd) { - _firstTime = true; - _filePos = _fileStart; - fpMus.seek(_filePos, SEEK_SET); + for (samples = 0; samples < numSamples && !endOfData(); samples++) { + int16 out; + if (_firstTime) { + _lastSample = fpMus.readUint16LE(); + _filePos += 2; + _firstTime = false; + out = _lastSample; + } else { + uint8 in = fpMus.readByte(); + uint16 delta = GetCompressedAmplitude(in) << GetCompressedShift(in); + + if (GetCompressedSign(in)) + out = _lastSample - delta; + else + out = _lastSample + delta; + + _filePos++; + _lastSample = out; + + if (_looping) { + if (_filePos >= _fileEnd) { + _firstTime = true; + _filePos = _fileStart; + fpMus.seek(_filePos, SEEK_SET); + } + } else { + // Fade out at the end of the music, unless it already is. + if (_fileEnd - _filePos <= FADE_SAMPLES && _fading <= 0) + fadeDown(); + } + + if (_fading > 0) { + if (--_fading == 0) { + _streaming = false; + _looping = false; + } + out = (out * _fading) / FADE_SAMPLES; + } else if (_fading < 0) { + _fading++; + out = (out * (FADE_SAMPLES + _fading)) / FADE_SAMPLES; + } } - } else { - // Fade out at the end of the music, unless it already is. - if (_fileEnd - _filePos <= FADE_SAMPLES && _fading <= 0) - fadeDown(); - } - if (_fading > 0) { - if (--_fading == 0) { - _streaming = false; - _looping = false; - } - out = (out * _fading) / FADE_SAMPLES; - } else if (_fading < 0) { - _fading++; - out = (out * (FADE_SAMPLES + _fading)) / FADE_SAMPLES; + *buffer++ = out; } - return out; + return samples; } bool MusicHandle::endOfData(void) const { diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h index 705d3f2baf..d333305dbd 100644 --- a/sword2/driver/d_sound.h +++ b/sword2/driver/d_sound.h @@ -63,8 +63,7 @@ public: void fadeUp(void); int32 play(const char *filename, uint32 musicId, bool looping); void stop(void); - virtual int readBuffer(int16 *buffer, const int numSamples); - int16 read(void); + int readBuffer(int16 *buffer, const int numSamples); bool endOfData(void) const; // This stream never 'ends' bool endOfStream(void) const { return false; } |