From 150805b18c33ad91e087522515e763b547b3d38b Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Thu, 8 Jan 2004 13:05:32 +0000 Subject: Merged read() and readBuffer(), like in BS2. svn-id: r12248 --- sword1/music.cpp | 50 ++++++++++++++++++++++---------------------------- sword1/music.h | 1 - 2 files changed, 22 insertions(+), 29 deletions(-) (limited to 'sword1') 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(); -- cgit v1.2.3