aboutsummaryrefslogtreecommitdiff
path: root/audio/softsynth
diff options
context:
space:
mode:
Diffstat (limited to 'audio/softsynth')
-rw-r--r--audio/softsynth/emumidi.h43
-rw-r--r--audio/softsynth/fluidsynth.cpp5
-rw-r--r--audio/softsynth/mt32.cpp5
3 files changed, 29 insertions, 24 deletions
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;