From 5dc6f88dfcac4b27ce15c42f107fb20b726454af Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sat, 29 Jun 2019 18:29:20 +1000 Subject: ZaMultiCompX2: Fix averaging --- plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp | 17 +++++++++++------ plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp index 3c9b447..d752e46 100644 --- a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp +++ b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp @@ -894,15 +894,20 @@ void ZaMultiCompX2Plugin::run_comp(int k, float inL, float inR, float *outL, flo void ZaMultiCompX2Plugin::pushsample(float samples[], float sample, int k) { - float l1norm = 0.f; + int idx0, idx1, idx2; - l1norm += fabsf(sample); + idx1 = pos[k]; ++pos[k]; - if (pos[k] >= MAX_SAMPLES) + if (pos[k] >= MAX_SAMPLES) { pos[k] = 0; - l1norm -= fabsf(samples[pos[k]]); - samples[pos[k]] = sample; - average[k] += l1norm / (float) MAX_SAMPLES; + } + idx2 = pos[k]; + idx0 = pos[k] + 1; + if (idx0 >= MAX_SAMPLES) { + idx0 = 0; + } + samples[idx2] = samples[idx1] + fabsf(sample); + average[k] = ( samples[idx2] - samples[idx0] ) / (float) MAX_SAMPLES; } void ZaMultiCompX2Plugin::run(const float** inputs, float** outputs, uint32_t frames) diff --git a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp index 059180a..58b323d 100644 --- a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp +++ b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.hpp @@ -23,7 +23,7 @@ START_NAMESPACE_DISTRHO #define MAX_FILT 4 #define MAX_COMP 3 -#define MAX_SAMPLES 240 +#define MAX_SAMPLES 480 #define STEREOLINK_MAX 1 #define STEREOLINK_AVERAGE 0 #define DANGER 100000.f -- cgit v1.2.3