diff options
author | Torbjörn Andersson | 2004-01-08 13:05:32 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2004-01-08 13:05:32 +0000 |
commit | 150805b18c33ad91e087522515e763b547b3d38b (patch) | |
tree | cf41e10c86fea58fcda0193538503b9709994bb2 | |
parent | 12cd552cab94537735aa6d89ce1ec1fd5dfa899e (diff) | |
download | scummvm-rg350-150805b18c33ad91e087522515e763b547b3d38b.tar.gz scummvm-rg350-150805b18c33ad91e087522515e763b547b3d38b.tar.bz2 scummvm-rg350-150805b18c33ad91e087522515e763b547b3d38b.zip |
Merged read() and readBuffer(), like in BS2.
svn-id: r12248
-rw-r--r-- | sword1/music.cpp | 50 | ||||
-rw-r--r-- | sword1/music.h | 1 |
2 files changed, 22 insertions, 29 deletions
diff --git a/sword1/music.cpp b/sword1/music.cpp index 3895cc95a5..082583afdf 100644 --- a/sword1/music.cpp +++ b/sword1/music.cpp @@ -52,38 +52,32 @@ bool SwordMusicHandle::endOfData() const { } int SwordMusicHandle::readBuffer(int16 *buffer, const int numSamples) { - // TODO: merge the read() code into readBuffer(), for higher efficency; - // we then can remove read() (as it isn't needed for anything anymore). int samples; - for (samples = 0; samples < numSamples && !endOfData(); samples++) - *buffer++ = read(); - return samples; -} - -int16 SwordMusicHandle::read() { - if (!streaming()) - return 0; - int16 sample = _file.readUint16LE(); - if (_file.ioFailed()) { - if (!_looping) { - stop(); - return 0; + for (samples = 0; samples < numSamples && !endOfData(); samples++) { + int16 sample = _file.readUint16LE(); + if (_file.ioFailed()) { + if (!_looping) { + stop(); + sample = 0; + } else { + _file.clearIOFailed(); + _file.seek(WAVEHEADERSIZE); + sample = _file.readUint16LE(); + } } - _file.clearIOFailed(); - _file.seek(WAVEHEADERSIZE); - sample = _file.readUint16LE(); - } - if (_fading > 0) { - if (--_fading == 0) { - _looping = false; - _file.close(); + if (_fading > 0) { + if (--_fading == 0) { + _looping = false; + _file.close(); + } + sample = (sample * _fading) / _fadeSamples; + } else if (_fading < 0) { + _fading++; + sample = (sample * (_fadeSamples + _fading)) / _fadeSamples; } - sample = (sample * _fading) / _fadeSamples; - } else if (_fading < 0) { - _fading++; - sample = (sample * (_fadeSamples + _fading)) / _fadeSamples; + *buffer++ = sample; } - return sample; + return samples; } bool SwordMusicHandle::play(const char *filename, bool loop) { diff --git a/sword1/music.h b/sword1/music.h index c30c7cfce7..c7a4fe2e30 100644 --- a/sword1/music.h +++ b/sword1/music.h @@ -45,7 +45,6 @@ private: public: SwordMusicHandle() : _looping(false), _fading(0) {} virtual int readBuffer(int16 *buffer, const int numSamples); - int16 read(); bool play(const char *filename, bool loop); void stop(); void fadeUp(); |