diff --git a/src/sound/mididevices/music_timiditypp_mididevice.cpp b/src/sound/mididevices/music_timiditypp_mididevice.cpp index 3770b9428..c299dddae 100644 --- a/src/sound/mididevices/music_timiditypp_mididevice.cpp +++ b/src/sound/mididevices/music_timiditypp_mididevice.cpp @@ -115,6 +115,8 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args) delete instruments; instruments = nullptr; } + TimidityPlus::set_playback_rate(timidity_frequency); + SampleRate = timidity_frequency; if (instruments == nullptr) { instruments = new TimidityPlus::Instruments; @@ -126,7 +128,7 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args) } if (instruments != nullptr) { - Renderer = new TimidityPlus::Player(timidity_frequency, instruments); + Renderer = new TimidityPlus::Player(instruments); } else { @@ -158,7 +160,6 @@ TimidityPPMIDIDevice::~TimidityPPMIDIDevice () int TimidityPPMIDIDevice::Open(MidiCallback callback, void *userdata) { - int ret = OpenStream(2, 0, callback, userdata); if (ret == 0 && Renderer != nullptr) { diff --git a/src/sound/timiditypp/playmidi.cpp b/src/sound/timiditypp/playmidi.cpp index c68b3e9ae..981e553cc 100644 --- a/src/sound/timiditypp/playmidi.cpp +++ b/src/sound/timiditypp/playmidi.cpp @@ -181,8 +181,8 @@ namespace TimidityPlus { // These two variables need to remain global or things will get messy because they get accessed from non-class code. -int32_t control_ratio = 44; -int32_t playback_rate = 44100; +int32_t control_ratio = 22; +int32_t playback_rate = 22050; #define PLAY_INTERLEAVE_SEC 1.0 #define PORTAMENTO_TIME_TUNING (1.0 / 5000.0) @@ -195,20 +195,24 @@ int32_t playback_rate = 44100; #define DEFAULT_AMPLIFICATION 70 #define VIBRATO_DEPTH_MAX 384 /* 600 cent */ -Player::Player(int freq, Instruments *instr) +void set_playback_rate(int freq) { const int CONTROLS_PER_SECOND = 1000; const int MAX_CONTROL_RATIO = 255; - last_reverb_setting = timidity_reverb; - memset(this, 0, sizeof(*this)); - playback_rate = freq; control_ratio = playback_rate / CONTROLS_PER_SECOND; if (control_ratio < 1) control_ratio = 1; else if (control_ratio > MAX_CONTROL_RATIO) control_ratio = MAX_CONTROL_RATIO; +} + + +Player::Player(Instruments *instr) +{ + last_reverb_setting = timidity_reverb; + memset(this, 0, sizeof(*this)); // init one-time global stuff - this should go to the device class once it exists. instruments = instr; diff --git a/src/sound/timiditypp/playmidi.h b/src/sound/timiditypp/playmidi.h index cc42c826c..797284bf6 100644 --- a/src/sound/timiditypp/playmidi.h +++ b/src/sound/timiditypp/playmidi.h @@ -519,8 +519,6 @@ public: ChannelBitMask drumchannel_mask; ChannelBitMask drumchannels; double *vol_table; - int playback_rate; - int control_ratio; // make this private later Instruments *instruments; @@ -696,7 +694,7 @@ private: public: - Player(int freq, Instruments *); + Player(Instruments *); ~Player(); bool ISDRUMCHANNEL(int c) @@ -741,6 +739,7 @@ public: }; void free_gauss_table(void); +void set_playback_rate(int freq); }