From ea68a817c1947b2001775d42755d260d66f4d37f Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Thu, 7 Jan 2021 14:09:38 +0800 Subject: Wait voice now checks for output level instead of polyphony. Fluidsynth sometimes screw up the number of currently sounding voices. --- core/qmpmidioutfluid.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'core/qmpmidioutfluid.cpp') 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 #include #include #include @@ -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(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) -- cgit v1.2.3