diff options
-rw-r--r-- | sky/music/adlibmusic.cpp | 7 | ||||
-rw-r--r-- | sky/music/adlibmusic.h | 14 | ||||
-rw-r--r-- | sword1/music.cpp | 8 | ||||
-rw-r--r-- | sword1/music.h | 15 |
4 files changed, 30 insertions, 14 deletions
diff --git a/sky/music/adlibmusic.cpp b/sky/music/adlibmusic.cpp index 9e9a4860f9..9fe05fec97 100644 --- a/sky/music/adlibmusic.cpp +++ b/sky/music/adlibmusic.cpp @@ -26,11 +26,6 @@ namespace Sky { -void AdlibMusic::passMixerFunc(void *param, int16 *buf, uint len) { - - ((AdlibMusic*)param)->premixerCall(buf, len); -} - AdlibMusic::AdlibMusic(SoundMixer *pMixer, Disk *pDisk, OSystem *system) : MusicBase(pDisk, system) { @@ -40,7 +35,7 @@ AdlibMusic::AdlibMusic(SoundMixer *pMixer, Disk *pDisk, OSystem *system) _opl = makeAdlibOPL(_sampleRate); - _mixer->setupPremix(passMixerFunc, this); + _mixer->setupPremix(this); } AdlibMusic::~AdlibMusic(void) { diff --git a/sky/music/adlibmusic.h b/sky/music/adlibmusic.h index d05f0fc5ac..64af432c1c 100644 --- a/sky/music/adlibmusic.h +++ b/sky/music/adlibmusic.h @@ -23,17 +23,28 @@ #define ADLIBMUSIC_H #include "sky/music/musicbase.h" +#include "sound/audiostream.h" #include "sound/fmopl.h" class SoundMixer; namespace Sky { -class AdlibMusic : public MusicBase { +class AdlibMusic : public AudioStream, public MusicBase { public: AdlibMusic(SoundMixer *pMixer, Disk *pDisk, OSystem *system); ~AdlibMusic(void); virtual void setVolume(uint8 volume); + + // AudioStream API + int readBuffer(int16 *buffer, const int numSamples) { + premixerCall(buffer, numSamples / 2); + return numSamples; + } + bool isStereo() const { return true; } + bool endOfData() const { return false; } + int getRate() const { return _sampleRate; } + private: FM_OPL *_opl; SoundMixer *_mixer; @@ -44,7 +55,6 @@ private: virtual void startDriver(void); void premixerCall(int16 *buf, uint len); - static void passMixerFunc(void *param, int16 *buf, uint len); }; } // End of namespace Sky diff --git a/sword1/music.cpp b/sword1/music.cpp index c0b7a67142..cf01b50b5a 100644 --- a/sword1/music.cpp +++ b/sword1/music.cpp @@ -233,7 +233,8 @@ void MusicHandle::stop() { Music::Music(OSystem *system, SoundMixer *pMixer) { _system = system; _mixer = pMixer; - _mixer->setupPremix(passMixerFunc, this); + _sampleRate = pMixer->getOutputRate(); + _mixer->setupPremix(this); _mutex = _system->createMutex(); _converter[0] = NULL; _converter[1] = NULL; @@ -248,12 +249,9 @@ Music::~Music() { _system->deleteMutex(_mutex); } -void Music::passMixerFunc(void *param, int16 *buf, uint len) { - ((Music*)param)->mixer(buf, len); -} - void Music::mixer(int16 *buf, uint32 len) { Common::StackLock lock(_mutex); + memset(buf, 0, 2 * len * sizeof(int16)); for (int i = 0; i < ARRAYSIZE(_handles); i++) if (_handles[i].streaming() && _converter[i]) _converter[i]->flow(_handles[i], buf, len, _volumeL, _volumeR); diff --git a/sword1/music.h b/sword1/music.h index bb922b24a2..564a478803 100644 --- a/sword1/music.h +++ b/sword1/music.h @@ -83,7 +83,7 @@ public: int getRate() const; }; -class Music { +class Music : public AudioStream { public: Music(OSystem *system, SoundMixer *pMixer); ~Music(); @@ -91,15 +91,28 @@ public: void fadeDown(); void setVolume(uint8 volL, uint8 volR); void giveVolume(uint8 *volL, uint8 *volR); + + // AudioStream API + int readBuffer(int16 *buffer, const int numSamples) { + mixer(buffer, numSamples / 2); + return numSamples; + } + bool isStereo() const { return true; } + bool endOfData() const { return false; } + int getRate() const { return _sampleRate; } + private: st_volume_t _volumeL, _volumeR; MusicHandle _handles[2]; RateConverter *_converter[2]; OSystem *_system; SoundMixer *_mixer; + uint32 _sampleRate; OSystem::MutexRef _mutex; + static void passMixerFunc(void *param, int16 *buf, uint len); void mixer(int16 *buf, uint32 len); + static const char _tuneList[TOTAL_TUNES][8]; // in staticres.cpp }; |