diff options
author | Torbjörn Andersson | 2004-10-12 17:03:07 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2004-10-12 17:03:07 +0000 |
commit | 372eeb54cbc030737afac9bda9ccc7f41b873659 (patch) | |
tree | 17829c17a1a76dd12f63a7dc670a9b48ba672d95 /sword2/driver | |
parent | f5403e079fbfa5348d1e9f084ed215dc40314655 (diff) | |
download | scummvm-rg350-372eeb54cbc030737afac9bda9ccc7f41b873659.tar.gz scummvm-rg350-372eeb54cbc030737afac9bda9ccc7f41b873659.tar.bz2 scummvm-rg350-372eeb54cbc030737afac9bda9ccc7f41b873659.zip |
Migration to the newer form of setupPremix().
svn-id: r15532
Diffstat (limited to 'sword2/driver')
-rw-r--r-- | sword2/driver/d_sound.cpp | 75 | ||||
-rw-r--r-- | sword2/driver/d_sound.h | 19 |
2 files changed, 63 insertions, 31 deletions
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index 6572b43539..e0ca6afbb9 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -25,10 +25,10 @@ #include "common/stdafx.h" #include "common/file.h" -#include "sound/rate.h" #include "sound/mp3.h" #include "sound/vorbis.h" #include "sound/flac.h" +#include "sound/rate.h" #include "sword2/sword2.h" #include "sword2/resman.h" #include "sword2/driver/d_draw.h" @@ -40,10 +40,6 @@ static AudioStream *makeCLUStream(File *fp, int size); static File fpMus; -static void premix_proc(void *param, int16 *data, uint len) { - ((Sound *) param)->streamMusic(data, len); -} - static AudioStream *getAudioStream(File *fp, const char *base, int cd, uint32 id, uint32 *numSamples) { struct { const char *ext; @@ -494,23 +490,24 @@ Sound::Sound(Sword2Engine *vm) { _musicPaused = false; _musicMuted = false; - for (int i = 0; i < MAXMUS; i++) { + _mixBuffer = NULL; + _mixBufferLen = 0; + + for (int i = 0; i < MAXMUS; i++) _music[i] = NULL; - _converter[i] = NULL; - } - _vm->_mixer->setupPremix(premix_proc, this); + _vm->_mixer->setupPremix(this); } Sound::~Sound() { int i; - _vm->_mixer->setupPremix(0, 0); + _vm->_mixer->setupPremix(0); - for (i = 0; i < MAXMUS; i++) { + for (i = 0; i < MAXMUS; i++) delete _music[i]; - delete _converter[i]; - } + + free(_mixBuffer); for (i = 0; i < MAXFX; i++) stopFxHandle(i); @@ -521,34 +518,63 @@ Sound::~Sound() { _vm->_system->deleteMutex(_mutex); } -void Sound::streamMusic(int16 *data, uint len) { +// AudioStream API + +int Sound::readBuffer(int16 *buffer, const int numSamples) { Common::StackLock lock(_mutex); - if (!_soundOn) - return; + if (!_soundOn || _musicPaused) + return 0; for (int i = 0; i < MAXMUS; i++) { if (_music[i] && _music[i]->readyToRemove()) { delete _music[i]; - delete _converter[i]; _music[i] = NULL; - _converter[i] = NULL; } } - if (!_musicPaused) { - for (int i = 0; i < MAXMUS; i++) { - if (_music[i]) { - st_volume_t volume = _musicMuted ? 0 : _musicVolTable[_musicVol]; - _converter[i]->flow(*_music[i], data, len, volume, volume); + memset(buffer, 0, 2 * numSamples); + + if (!_mixBuffer || numSamples > _mixBufferLen) { + if (_mixBuffer) + _mixBuffer = (int16 *) realloc(_mixBuffer, 2 * numSamples); + else + _mixBuffer = (int16 *) malloc(2 * numSamples); + + _mixBufferLen = numSamples; + } + + if (!_mixBuffer) + return 0; + + for (int i = 0; i < MAXMUS; i++) { + if (!_music[i]) + continue; + + int len = _music[i]->readBuffer(_mixBuffer, numSamples); + + if (!_musicMuted) { + for (int j = 0; j < len; j++) { + clampedAdd(buffer[j], (_musicVolTable[_musicVol] * _mixBuffer[j]) / 255); } } } if (!_music[0] && !_music[1] && fpMus.isOpen()) fpMus.close(); + + return numSamples; } +int16 Sound::read() { + error("ProcInputStream::read not supported"); +} + +bool Sound::isStereo() const { return false; } +bool Sound::endOfData() const { return !fpMus.isOpen(); } +int Sound::getRate() const { return 22050; } + + /** * This function creates the pan table. */ @@ -707,9 +733,7 @@ int32 Sound::streamCompMusic(uint32 musicId, bool looping) { } delete _music[primary]; - delete _converter[primary]; _music[primary] = NULL; - _converter[primary] = NULL; } // Pick the available music stream. If no music is playing it doesn't @@ -741,7 +765,6 @@ int32 Sound::streamCompMusic(uint32 musicId, bool looping) { return RDERR_INVALIDFILENAME; } - _converter[primary] = makeRateConverter(_music[primary]->getRate(), _vm->_mixer->getOutputRate(), _music[primary]->isStereo(), false); return RD_OK; } diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h index eeed5ca77a..234abbe08b 100644 --- a/sword2/driver/d_sound.h +++ b/sword2/driver/d_sound.h @@ -24,8 +24,6 @@ #include "sound/audiostream.h" #include "sound/mixer.h" -class RateConverter; - namespace Sword2 { class MusicInputStream; @@ -57,7 +55,7 @@ struct FxHandle { PlayingSoundHandle _handle; }; -class Sound { +class Sound : public AudioStream { private: Sword2Engine *_vm; @@ -68,7 +66,9 @@ private: static int32 _musicVolTable[17]; MusicInputStream *_music[MAXMUS]; - RateConverter *_converter[MAXMUS]; + int16 *_mixBuffer; + int _mixBufferLen; + bool _musicPaused; bool _musicMuted; uint8 _musicVol; @@ -90,7 +90,16 @@ public: Sound(Sword2Engine *vm); ~Sound(); - void streamMusic(int16 *data, uint len); + // AudioStream API + + int readBuffer(int16 *buffer, const int numSamples); + int16 read(); + bool isStereo() const; + bool endOfData() const; + int getRate() const; + + // End of AudioStream API + void buildPanTable(bool reverse); bool getWavInfo(uint8 *data, WavInfo *wavInfo); |