From ed8830fcc807f9620185e143558f90f9b2cb8aea Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 3 Apr 2015 10:59:10 -0400 Subject: AUDIO: Use the built-in OPL timer for MidiDriver_ADLIB --- audio/softsynth/adlib.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'audio/softsynth') diff --git a/audio/softsynth/adlib.cpp b/audio/softsynth/adlib.cpp index 49e69ecd57..c7b5297e2d 100644 --- a/audio/softsynth/adlib.cpp +++ b/audio/softsynth/adlib.cpp @@ -948,9 +948,12 @@ public: // AudioStream API + int readBuffer(int16 *data, const int numSamples); bool isStereo() const { return _opl->isStereo(); } int getRate() const { return _mixer->getOutputRate(); } + virtual void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc); + private: bool _scummSmallHeader; // FIXME: This flag controls a special mode for SCUMM V3 games #ifdef ENABLE_OPL3 @@ -963,6 +966,9 @@ private: byte *_regCacheSecondary; #endif + Common::TimerManager::TimerProc _adlibTimerProc; + void *_adlibTimerParam; + int _timerCounter; uint16 _channelTable2[9]; @@ -1403,6 +1409,8 @@ MidiDriver_ADLIB::MidiDriver_ADLIB(Audio::Mixer *mixer) _timerIncrease = 0xD69; _timerThreshold = 0x411B; _opl = 0; + _adlibTimerProc = 0; + _adlibTimerParam = 0; } int MidiDriver_ADLIB::open() { @@ -1452,6 +1460,7 @@ int MidiDriver_ADLIB::open() { } #endif + _opl->start(new Common::Functor0Mem(this, &MidiDriver_ADLIB::onTimer)); _mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); return 0; @@ -1617,13 +1626,17 @@ void MidiDriver_ADLIB::adlibWriteSecondary(byte reg, byte value) { #endif void MidiDriver_ADLIB::generateSamples(int16 *data, int len) { - if (_opl->isStereo()) { - len *= 2; - } - _opl->readBuffer(data, len); + // Dummy implementation until we no longer inherit from MidiDriver_Emulated +} + +int MidiDriver_ADLIB::readBuffer(int16 *data, const int numSamples) { + return _opl->readBuffer(data, numSamples); } void MidiDriver_ADLIB::onTimer() { + if (_adlibTimerProc) + (*_adlibTimerProc)(_adlibTimerParam); + _timerCounter += _timerIncrease; while (_timerCounter >= _timerThreshold) { _timerCounter -= _timerThreshold; @@ -1655,6 +1668,11 @@ void MidiDriver_ADLIB::onTimer() { } } +void MidiDriver_ADLIB::setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) { + _adlibTimerProc = timerProc; + _adlibTimerParam = timerParam; +} + void MidiDriver_ADLIB::mcOff(AdLibVoice *voice) { AdLibVoice *tmp; -- cgit v1.2.3