From 59352af48621fc3c65919a62d5c9a3908447a840 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 21 Feb 2018 19:05:14 +0100 Subject: [PATCH] - Volume tweaking. --- src/sound/mididevices/music_timiditypp_mididevice.cpp | 11 +++++++++++ src/sound/timiditypp/playmidi.cpp | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sound/mididevices/music_timiditypp_mididevice.cpp b/src/sound/mididevices/music_timiditypp_mididevice.cpp index b90959c99..458152bfa 100644 --- a/src/sound/mididevices/music_timiditypp_mididevice.cpp +++ b/src/sound/mididevices/music_timiditypp_mididevice.cpp @@ -70,6 +70,8 @@ public: instruments = nullptr; } + double test[3] = { 0, 0, 0 }; + protected: TimidityPlus::Player *Renderer; @@ -161,6 +163,7 @@ int TimidityPPMIDIDevice::Open(MidiCallback callback, void *userdata) } // No instruments loaded means we cannot play... if (instruments == nullptr) return 0; + TimidityVolumeChanged(); return ret; } @@ -216,6 +219,14 @@ void TimidityPPMIDIDevice::ComputeOutput(float *buffer, int len) if (Renderer != nullptr) Renderer->compute_data(buffer, len); sampletime += len; + + for (int i = 0; i < len * 2; i++) + { + if (buffer[i] < test[0]) test[0] = buffer[i]; + if (buffer[i] > test[1]) test[1] = buffer[i]; + test[2] += fabs(buffer[i]); + } + Printf("Min = %f, Max = %f, Avg = %f\n", test[0], test[1], test[2] / sampletime); } //========================================================================== diff --git a/src/sound/timiditypp/playmidi.cpp b/src/sound/timiditypp/playmidi.cpp index fe03b6a61..cc55003ac 100644 --- a/src/sound/timiditypp/playmidi.cpp +++ b/src/sound/timiditypp/playmidi.cpp @@ -230,7 +230,7 @@ double Player::cnv_Hz_to_vib_ratio(double freq) void Player::adjust_amplification(void) { - static const double compensation_ratio = 1.0; + static const double compensation_ratio = 5.0; /* compensate master volume */ master_volume = (double)(amplification) / 100.0 * ((double)master_volume_ratio * (compensation_ratio/0xFFFF)); @@ -5033,7 +5033,7 @@ int Player::compute_data(float *buffer, int32_t count) // pass to caller for (int i = 0; i < process*2; i++) { - *buffer++ = (common_buffer[i])*(5.f / 0x80000000u); + *buffer++ = (common_buffer[i])*(1.f / 0x80000000u); } } return RC_OK;