aboutsummaryrefslogtreecommitdiff
path: root/core/qmpmidioutfluid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/qmpmidioutfluid.cpp')
-rw-r--r--core/qmpmidioutfluid.cpp23
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)