From b638efe0fad55e18513a9c0453100c0d3b9dd8c3 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 3 Apr 2015 17:38:16 -0400 Subject: PARALLACTION: Use the built-in OPL timer --- engines/parallaction/adlib.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'engines/parallaction') diff --git a/engines/parallaction/adlib.cpp b/engines/parallaction/adlib.cpp index a2defa932b..302530bcad 100644 --- a/engines/parallaction/adlib.cpp +++ b/engines/parallaction/adlib.cpp @@ -285,8 +285,13 @@ public: bool isStereo() const { return false; } int getRate() const { return _mixer->getOutputRate(); } + int readBuffer(int16 *data, const int numSamples); - void generateSamples(int16 *buf, int len); + void generateSamples(int16 *buf, int len) {} + virtual void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) { + _adlibTimerProc = timerProc; + _adlibTimerParam = timerParam; + } protected: OPL::OPL *_opl; @@ -320,6 +325,12 @@ protected: void muteMelodicVoice(uint8 voice); void initVoices(); + +private: + void onTimer(); + + Common::TimerManager::TimerProc _adlibTimerProc; + void *_adlibTimerParam; }; MidiDriver *createAdLibDriver() { @@ -364,6 +375,7 @@ int AdLibDriver::open() { initVoices(); + _opl->start(new Common::Functor0Mem(this, &AdLibDriver::onTimer)); _mixer->playStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); return 0; } @@ -777,9 +789,13 @@ MidiChannel *AdLibDriver::allocateChannel() { return NULL; } -void AdLibDriver::generateSamples(int16 *buf, int len) { - memset(buf, 0, sizeof(int16) * len); - _opl->readBuffer(buf, len); +int AdLibDriver::readBuffer(int16 *data, const int numSamples) { + return _opl->readBuffer(data, numSamples); +} + +void AdLibDriver::onTimer() { + if (_adlibTimerProc) + (*_adlibTimerProc)(_adlibTimerParam); } void AdLibDriver::initVoices() { -- cgit v1.2.3