diff options
-rw-r--r-- | audio/mpu401.cpp | 3 | ||||
-rw-r--r-- | audio/mpu401.h | 29 | ||||
-rw-r--r-- | audio/softsynth/emumidi.h | 43 | ||||
-rw-r--r-- | audio/softsynth/fluidsynth.cpp | 5 | ||||
-rw-r--r-- | audio/softsynth/mt32.cpp | 5 |
5 files changed, 47 insertions, 38 deletions
diff --git a/audio/mpu401.cpp b/audio/mpu401.cpp index 4f62de930c..8d1e5b6047 100644 --- a/audio/mpu401.cpp +++ b/audio/mpu401.cpp @@ -101,6 +101,9 @@ MidiDriver_MPU401::MidiDriver_MPU401() : } } +MidiDriver_MPU401::~MidiDriver_MPU401() { +} + void MidiDriver_MPU401::close() { if (_timer_proc) g_system->getTimerManager()->removeTimerProc(_timer_proc); diff --git a/audio/mpu401.h b/audio/mpu401.h index 070eaf636a..07e2817381 100644 --- a/audio/mpu401.h +++ b/audio/mpu401.h @@ -46,22 +46,22 @@ private: public: MidiDriver *device(); byte getNumber() { return _channel; } - void release() { _allocated = false; } + virtual void release() { _allocated = false; } - void send(uint32 b); + virtual void send(uint32 b); // Regular messages - void noteOff(byte note); - void noteOn(byte note, byte velocity); - void programChange(byte program); - void pitchBend(int16 bend); + virtual void noteOff(byte note); + virtual void noteOn(byte note, byte velocity); + virtual void programChange(byte program); + virtual void pitchBend(int16 bend); // Control Change messages - void controlChange(byte control, byte value); - void pitchBendFactor(byte value); + virtual void controlChange(byte control, byte value); + virtual void pitchBendFactor(byte value); // SysEx messages - void sysEx_customInstrument(uint32 type, const byte *instr); + virtual void sysEx_customInstrument(uint32 type, const byte *instr); // Only to be called by the owner void init(MidiDriver *owner, byte channel); @@ -78,14 +78,15 @@ private: public: MidiDriver_MPU401(); + virtual ~MidiDriver_MPU401(); virtual void close(); - void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc); - uint32 getBaseTempo(void) { return 10000; } - uint32 property(int prop, uint32 param); + virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc); + virtual uint32 getBaseTempo(void) { return 10000; } + virtual uint32 property(int prop, uint32 param); - MidiChannel *allocateChannel(); - MidiChannel *getPercussionChannel() { return &_midi_channels[9]; } + virtual MidiChannel *allocateChannel(); + virtual MidiChannel *getPercussionChannel() { return &_midi_channels[9]; } }; diff --git a/audio/softsynth/emumidi.h b/audio/softsynth/emumidi.h index 35c81490e4..815c020982 100644 --- a/audio/softsynth/emumidi.h +++ b/audio/softsynth/emumidi.h @@ -45,25 +45,24 @@ private: int _samplesPerTick; protected: + int _baseFreq; + virtual void generateSamples(int16 *buf, int len) = 0; virtual void onTimer() {} - int _baseFreq; - public: - MidiDriver_Emulated(Audio::Mixer *mixer) : _mixer(mixer) { - _isOpen = false; - - _timerProc = 0; - _timerParam = 0; - - _nextTick = 0; - _samplesPerTick = 0; - - _baseFreq = 250; + MidiDriver_Emulated(Audio::Mixer *mixer) : + _mixer(mixer), + _isOpen(false), + _timerProc(0), + _timerParam(0), + _nextTick(0), + _samplesPerTick(0), + _baseFreq(250) { } - int open() { + // MidiDriver API + virtual int open() { _isOpen = true; int d = getRate() / _baseFreq; @@ -73,19 +72,21 @@ public: // but less prone to arithmetic overflow. _samplesPerTick = (d << FIXP_SHIFT) + (r << FIXP_SHIFT) / _baseFreq; + return 0; } - void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { + virtual void setTimerCallback(void *timer_param, Common::TimerManager::TimerProc timer_proc) { _timerProc = timer_proc; _timerParam = timer_param; } - uint32 getBaseTempo() { return 1000000 / _baseFreq; } - + virtual uint32 getBaseTempo() { + return 1000000 / _baseFreq; + } // AudioStream API - int readBuffer(int16 *data, const int numSamples) { + virtual int readBuffer(int16 *data, const int numSamples) { const int stereoFactor = isStereo() ? 2 : 1; int len = numSamples / stereoFactor; int step; @@ -101,16 +102,22 @@ public: if (!(_nextTick >> FIXP_SHIFT)) { if (_timerProc) (*_timerProc)(_timerParam); + onTimer(); + _nextTick += _samplesPerTick; } + data += step * stereoFactor; len -= step; } while (len); return numSamples; } - bool endOfData() const { return false; } + + virtual bool endOfData() const { + return false; + } }; #endif diff --git a/audio/softsynth/fluidsynth.cpp b/audio/softsynth/fluidsynth.cpp index bd016548ec..f6f66ce5e8 100644 --- a/audio/softsynth/fluidsynth.cpp +++ b/audio/softsynth/fluidsynth.cpp @@ -40,7 +40,6 @@ private: fluid_synth_t *_synth; int _soundFont; int _outputRate; - Audio::SoundHandle _handle; protected: // Because GCC complains about casting from const to non-const... @@ -144,7 +143,7 @@ int MidiDriver_FluidSynth::open() { MidiDriver_Emulated::open(); // The MT-32 emulator uses kSFXSoundType here. I don't know why. - _mixer->playStream(Audio::Mixer::kMusicSoundType, &_handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); + _mixer->playStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); return 0; } @@ -153,7 +152,7 @@ void MidiDriver_FluidSynth::close() { return; _isOpen = false; - _mixer->stopHandle(_handle); + _mixer->stopHandle(_mixerSoundHandle); if (_soundFont != -1) fluid_synth_sfunload(_synth, _soundFont, 1); diff --git a/audio/softsynth/mt32.cpp b/audio/softsynth/mt32.cpp index a980b564fc..dd2c7e2121 100644 --- a/audio/softsynth/mt32.cpp +++ b/audio/softsynth/mt32.cpp @@ -51,7 +51,6 @@ class MidiChannel_MT32 : public MidiChannel_MPU401 { class MidiDriver_MT32 : public MidiDriver_Emulated { private: - Audio::SoundHandle _handle; MidiChannel_MT32 _midiChannels[16]; uint16 _channelMask; MT32Emu::Synth *_synth; @@ -336,7 +335,7 @@ int MidiDriver_MT32::open() { g_system->updateScreen(); - _mixer->playStream(Audio::Mixer::kSFXSoundType, &_handle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); + _mixer->playStream(Audio::Mixer::kSFXSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); return 0; } @@ -378,7 +377,7 @@ void MidiDriver_MT32::close() { // Detach the player callback handler setTimerCallback(NULL, NULL); // Detach the mixer callback handler - _mixer->stopHandle(_handle); + _mixer->stopHandle(_mixerSoundHandle); _synth->close(); delete _synth; |