aboutsummaryrefslogtreecommitdiff
path: root/engines/sherlock/scalpel
diff options
context:
space:
mode:
authorMatthew Hoops2015-05-30 01:37:21 -0400
committerMatthew Hoops2015-07-07 20:19:45 -0400
commitdcb75fcaf12ebf194e0b68e841c3eee9739e4d1e (patch)
tree2d27b4caa48c987ab1be0b14827ff79b085835a7 /engines/sherlock/scalpel
parent73e8ac2a9b51fc4d278c87677b815f1f6c308775 (diff)
downloadscummvm-rg350-dcb75fcaf12ebf194e0b68e841c3eee9739e4d1e.tar.gz
scummvm-rg350-dcb75fcaf12ebf194e0b68e841c3eee9739e4d1e.tar.bz2
scummvm-rg350-dcb75fcaf12ebf194e0b68e841c3eee9739e4d1e.zip
SHERLOCK: Use the built-in OPL timer
Diffstat (limited to 'engines/sherlock/scalpel')
-rw-r--r--engines/sherlock/scalpel/drivers/adlib.cpp29
1 files changed, 25 insertions, 4 deletions
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<void, MidiDriver_SH_AdLib>(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());
}