From 2e8f9dcec93653f1bd1f115662f9fcf3a5581fd8 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 3 Apr 2015 01:05:03 -0400 Subject: AUDIO: Remove the sample rate configuration from the OPL code --- engines/sherlock/scalpel/drivers/adlib.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'engines/sherlock') diff --git a/engines/sherlock/scalpel/drivers/adlib.cpp b/engines/sherlock/scalpel/drivers/adlib.cpp index 91641fcccd..3c5a6559c4 100644 --- a/engines/sherlock/scalpel/drivers/adlib.cpp +++ b/engines/sherlock/scalpel/drivers/adlib.cpp @@ -285,8 +285,6 @@ private: }; int MidiDriver_SH_AdLib::open() { - int rate = _mixer->getOutputRate(); - debugC(kDebugLevelAdLibDriver, "AdLib: starting driver"); _opl = OPL::Config::create(OPL::Config::kOpl2); @@ -294,7 +292,7 @@ int MidiDriver_SH_AdLib::open() { if (!_opl) return -1; - _opl->init(rate); + _opl->init(); MidiDriver_Emulated::open(); -- cgit v1.2.3 From dcb75fcaf12ebf194e0b68e841c3eee9739e4d1e Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sat, 30 May 2015 01:37:21 -0400 Subject: SHERLOCK: Use the built-in OPL timer --- engines/sherlock/scalpel/drivers/adlib.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'engines/sherlock') diff --git a/engines/sherlock/scalpel/drivers/adlib.cpp b/engines/sherlock/scalpel/drivers/adlib.cpp index 3c5a6559c4..033b4740a7 100644 --- a/engines/sherlock/scalpel/drivers/adlib.cpp +++ b/engines/sherlock/scalpel/drivers/adlib.cpp @@ -219,7 +219,8 @@ uint16 frequencyLookUpTable[SHERLOCK_ADLIB_NOTES_COUNT] = { class MidiDriver_SH_AdLib : public MidiDriver_Emulated { public: MidiDriver_SH_AdLib(Audio::Mixer *mixer) - : MidiDriver_Emulated(mixer), _masterVolume(15), _opl(0) { + : MidiDriver_Emulated(mixer), _masterVolume(15), _opl(0), + _adlibTimerProc(0), _adlibTimerParam(0) { memset(_voiceChannelMapping, 0, sizeof(_voiceChannelMapping)); } virtual ~MidiDriver_SH_AdLib() { } @@ -232,6 +233,7 @@ public: MidiChannel *getPercussionChannel() { return NULL; } // AudioStream + int readBuffer(int16 *data, const int numSamples); bool isStereo() const { return false; } int getRate() const { return _mixer->getOutputRate(); } int getPolyphony() const { return SHERLOCK_ADLIB_VOICES_COUNT; } @@ -240,6 +242,8 @@ public: // MidiDriver_Emulated void generateSamples(int16 *buf, int len); + virtual void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc); + void setVolume(byte volume); virtual uint32 property(int prop, uint32 param); @@ -261,16 +265,17 @@ private: OPL::OPL *_opl; int _masterVolume; + Common::TimerManager::TimerProc _adlibTimerProc; + void *_adlibTimerParam; + // points to a MIDI channel for each of the new voice channels byte _voiceChannelMapping[SHERLOCK_ADLIB_VOICES_COUNT]; // stores information about all FM voice channels adlib_ChannelEntry _channels[SHERLOCK_ADLIB_VOICES_COUNT]; -protected: void onTimer(); -private: void resetAdLib(); void resetAdLibOperatorRegisters(byte baseRegister, byte value); void resetAdLibFMVoiceChannelRegisters(byte baseRegister, byte value); @@ -296,6 +301,7 @@ int MidiDriver_SH_AdLib::open() { MidiDriver_Emulated::open(); + _opl->start(new Common::Functor0Mem(this, &MidiDriver_SH_AdLib::onTimer)); _mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO); return 0; @@ -316,6 +322,12 @@ void MidiDriver_SH_AdLib::setVolume(byte volume) { // original driver did this before MIDI data processing on each tick // we do it atm after MIDI data processing void MidiDriver_SH_AdLib::onTimer() { + if (_adlibTimerProc) + (*_adlibTimerProc)(_adlibTimerParam); + + // this should/must get called per tick + // original driver did this before MIDI data processing on each tick + // we do it atm after MIDI data processing for (byte FMvoiceChannel = 0; FMvoiceChannel < SHERLOCK_ADLIB_VOICES_COUNT; FMvoiceChannel++) { if (_channels[FMvoiceChannel].inUse) { _channels[FMvoiceChannel].inUseTimer++; @@ -416,7 +428,11 @@ void MidiDriver_SH_AdLib::send(uint32 b) { } void MidiDriver_SH_AdLib::generateSamples(int16 *data, int len) { - _opl->readBuffer(data, len); + // Dummy implementation until we no longer inherit from MidiDriver_Emulated +} + +int MidiDriver_SH_AdLib::readBuffer(int16 *data, const int numSamples) { + return _opl->readBuffer(data, numSamples); } void MidiDriver_SH_AdLib::noteOn(byte MIDIchannel, byte note, byte velocity) { @@ -625,6 +641,11 @@ uint32 MidiDriver_SH_AdLib::property(int prop, uint32 param) { return 0; } +void MidiDriver_SH_AdLib::setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc) { + _adlibTimerProc = timerProc; + _adlibTimerParam = timerParam; +} + MidiDriver *MidiDriver_SH_AdLib_create() { return new MidiDriver_SH_AdLib(g_system->getMixer()); } -- cgit v1.2.3 From bed9da8b9dbbaa19d317f71663e42875c1717fda Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 30 Apr 2015 00:01:30 -0400 Subject: AUDIO: Remove all AudioStream access to OPL --- engines/sherlock/scalpel/drivers/adlib.cpp | 31 ++++++++++-------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'engines/sherlock') diff --git a/engines/sherlock/scalpel/drivers/adlib.cpp b/engines/sherlock/scalpel/drivers/adlib.cpp index 033b4740a7..29a39f0c39 100644 --- a/engines/sherlock/scalpel/drivers/adlib.cpp +++ b/engines/sherlock/scalpel/drivers/adlib.cpp @@ -216,11 +216,11 @@ uint16 frequencyLookUpTable[SHERLOCK_ADLIB_NOTES_COUNT] = { 0x1DE6, 0x1E03, 0x1E22, 0x1E42, 0x1E65, 0x1E89 }; -class MidiDriver_SH_AdLib : public MidiDriver_Emulated { +class MidiDriver_SH_AdLib : public MidiDriver { public: MidiDriver_SH_AdLib(Audio::Mixer *mixer) - : MidiDriver_Emulated(mixer), _masterVolume(15), _opl(0), - _adlibTimerProc(0), _adlibTimerParam(0) { + : _masterVolume(15), _opl(0), + _adlibTimerProc(0), _adlibTimerParam(0), _isOpen(false) { memset(_voiceChannelMapping, 0, sizeof(_voiceChannelMapping)); } virtual ~MidiDriver_SH_AdLib() { } @@ -231,17 +231,12 @@ public: void send(uint32 b); MidiChannel *allocateChannel() { return NULL; } MidiChannel *getPercussionChannel() { return NULL; } + bool isOpen() const { return _isOpen; } + uint32 getBaseTempo() { return 1000000 / OPL::OPL::kDefaultCallbackFrequency; } - // AudioStream - int readBuffer(int16 *data, const int numSamples); - bool isStereo() const { return false; } - int getRate() const { return _mixer->getOutputRate(); } int getPolyphony() const { return SHERLOCK_ADLIB_VOICES_COUNT; } bool hasRhythmChannel() const { return false; } - // MidiDriver_Emulated - void generateSamples(int16 *buf, int len); - virtual void setTimerCallback(void *timerParam, Common::TimerManager::TimerProc timerProc); void setVolume(byte volume); @@ -268,6 +263,8 @@ private: Common::TimerManager::TimerProc _adlibTimerProc; void *_adlibTimerParam; + bool _isOpen; + // points to a MIDI channel for each of the new voice channels byte _voiceChannelMapping[SHERLOCK_ADLIB_VOICES_COUNT]; @@ -299,16 +296,16 @@ int MidiDriver_SH_AdLib::open() { _opl->init(); - MidiDriver_Emulated::open(); + _isOpen = true; _opl->start(new Common::Functor0Mem(this, &MidiDriver_SH_AdLib::onTimer)); - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO); return 0; } void MidiDriver_SH_AdLib::close() { - _mixer->stopHandle(_mixerSoundHandle); + // Stop the OPL timer + _opl->stop(); delete _opl; } @@ -427,14 +424,6 @@ void MidiDriver_SH_AdLib::send(uint32 b) { } } -void MidiDriver_SH_AdLib::generateSamples(int16 *data, int len) { - // Dummy implementation until we no longer inherit from MidiDriver_Emulated -} - -int MidiDriver_SH_AdLib::readBuffer(int16 *data, const int numSamples) { - return _opl->readBuffer(data, numSamples); -} - void MidiDriver_SH_AdLib::noteOn(byte MIDIchannel, byte note, byte velocity) { int16 oldestInUseChannel = -1; uint16 oldestInUseTimer = 0; -- cgit v1.2.3