diff options
author | Chris Xiong <chirs241097@gmail.com> | 2021-01-07 14:09:38 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2021-01-07 14:09:38 +0800 |
commit | ea68a817c1947b2001775d42755d260d66f4d37f (patch) | |
tree | 3ad0650984c5f442f94fd573a7c74616f193048f /core/qmpmidioutfluid.cpp | |
parent | 327526848c930c5cca7fafbde36d60ea45b786db (diff) | |
download | QMidiPlayer-ea68a817c1947b2001775d42755d260d66f4d37f.tar.xz |
Wait voice now checks for output level instead of polyphony.
Fluidsynth sometimes screw up the number of currently sounding voices.
Diffstat (limited to 'core/qmpmidioutfluid.cpp')
-rw-r--r-- | core/qmpmidioutfluid.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/core/qmpmidioutfluid.cpp b/core/qmpmidioutfluid.cpp index bfa6016..22f4aa2 100644 --- a/core/qmpmidioutfluid.cpp +++ b/core/qmpmidioutfluid.cpp @@ -1,3 +1,4 @@ +#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> @@ -66,7 +67,22 @@ void qmpMidiOutFluid::deviceInit() fluid_set_log_function(FLUID_WARN, nullptr, nullptr); fluid_set_log_function(FLUID_ERR, fluid_default_log_function, nullptr); fluid_set_log_function(FLUID_PANIC, fluid_default_log_function, nullptr); - adriver = new_fluid_audio_driver(settings, synth); + adriver = new_fluid_audio_driver2(settings, + [](void *t, int l, int nfx, float *fx[], int nout, float *out[])->int + { + qmpMidiOutFluid *self = static_cast<qmpMidiOutFluid*>(t); + fluid_synth_process(self->synth, l, nfx, fx, nout, out); + double s = 0; + for (int i = 0; i < nout; ++i) + { + for (int j = 0; j < l; ++j) + { + s += out[i][j] * out[i][j] / l; + } + } + self->output_level = 20 * log10(sqrt(s)); + } + , this); if (!adriver) { fputs("Error creating fluidsynth audio driver!", stderr); @@ -301,6 +317,11 @@ int qmpMidiOutFluid::getMaxPolyphone() { return synth ? fluid_synth_get_polyphony(synth) : 0; } + +double qmpMidiOutFluid::getOutputLevel() +{ + return output_level; +} void qmpMidiOutFluid::setGain(double gain) { if (settings) |