From 808e8a73383f95523bbc05670b8bda92a816147c Mon Sep 17 00:00:00 2001 From: probonopd Date: Fri, 18 Apr 2025 19:00:21 +0200 Subject: [PATCH 1/3] Normalize reverb time to sample rate For consistent decay across different sample rates Closes #563 --- src/effect_platervbstereo.cpp | 12 +++++++----- src/effect_platervbstereo.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/effect_platervbstereo.cpp b/src/effect_platervbstereo.cpp index ce2af1e..4224503 100644 --- a/src/effect_platervbstereo.cpp +++ b/src/effect_platervbstereo.cpp @@ -85,6 +85,7 @@ const int16_t AudioWaveformSine[257] = { AudioEffectPlateReverb::AudioEffectPlateReverb(float32_t samplerate) { + m_samplerate = samplerate; input_attn = 0.5f; in_allp_k = INP_ALLP_COEFF; @@ -200,7 +201,8 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t } cleanup_done = false; - rv_time = rv_time_k; + rv_time = rv_time_k * (m_samplerate / 44100.0f); + float32_t rv_time_scaler_scaled = rv_time_scaler * (m_samplerate / 44100.0f); for (uint16_t i=0; i < len; i++) { @@ -300,7 +302,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf1 - hpf1; hpf1 += temp1 * lp_hipass_f; acc = lpf1 + temp2*lp_hidamp_k + hpf1*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler; // scale by the reveb time + acc = acc * rv_time * rv_time_scaler_scaled; // scale by the reveb time input = acc + in_allp_out_L; @@ -319,7 +321,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf2 - hpf2; hpf2 += temp1 * lp_hipass_f; acc = lpf2 + temp2*lp_hidamp_k + hpf2*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler; + acc = acc * rv_time * rv_time_scaler_scaled; input = acc + in_allp_out_R; @@ -338,7 +340,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf3 - hpf3; hpf3 += temp1 * lp_hipass_f; acc = lpf3 + temp2*lp_hidamp_k + hpf3*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler; + acc = acc * rv_time * rv_time_scaler_scaled; input = acc + in_allp_out_L; @@ -357,7 +359,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf4 - hpf4; hpf4 += temp1 * lp_hipass_f; acc = lpf4 + temp2*lp_hidamp_k + hpf4*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler; + acc = acc * rv_time * rv_time_scaler_scaled; lp_allp_out = acc; diff --git a/src/effect_platervbstereo.h b/src/effect_platervbstereo.h index 23538c4..05b73b2 100644 --- a/src/effect_platervbstereo.h +++ b/src/effect_platervbstereo.h @@ -113,6 +113,7 @@ private: bool bypass = false; float32_t reverb_level; float32_t input_attn; + float32_t m_samplerate; // store the sample rate float32_t in_allp_k; // input allpass coeff float32_t in_allp1_bufL[224]; // input allpass buffers From 8dbf1607f85c112d1911afbf5b458b6909dd1140 Mon Sep 17 00:00:00 2001 From: probonopd Date: Fri, 18 Apr 2025 19:24:01 +0200 Subject: [PATCH 2/3] Use 48 kHz for the scaling As suggested by @Banana71 --- src/effect_platervbstereo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/effect_platervbstereo.cpp b/src/effect_platervbstereo.cpp index 4224503..45e03b2 100644 --- a/src/effect_platervbstereo.cpp +++ b/src/effect_platervbstereo.cpp @@ -201,8 +201,8 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t } cleanup_done = false; - rv_time = rv_time_k * (m_samplerate / 44100.0f); - float32_t rv_time_scaler_scaled = rv_time_scaler * (m_samplerate / 44100.0f); + rv_time = rv_time_k * (m_samplerate / 48000.0f); + float32_t rv_time_scaler_scaled = rv_time_scaler * (m_samplerate / 48000.0f); for (uint16_t i=0; i < len; i++) { From 827d9cd7d39c47165cae3c5654013024954f1e9b Mon Sep 17 00:00:00 2001 From: probonopd Date: Sun, 20 Apr 2025 15:33:31 +0200 Subject: [PATCH 3/3] rv_time = rv_time_k * (48000.0f / m_samplerate); --- src/effect_platervbstereo.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/effect_platervbstereo.cpp b/src/effect_platervbstereo.cpp index 45e03b2..acf0f47 100644 --- a/src/effect_platervbstereo.cpp +++ b/src/effect_platervbstereo.cpp @@ -201,8 +201,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t } cleanup_done = false; - rv_time = rv_time_k * (m_samplerate / 48000.0f); - float32_t rv_time_scaler_scaled = rv_time_scaler * (m_samplerate / 48000.0f); + rv_time = rv_time_k * (48000.0f / m_samplerate); for (uint16_t i=0; i < len; i++) { @@ -302,7 +301,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf1 - hpf1; hpf1 += temp1 * lp_hipass_f; acc = lpf1 + temp2*lp_hidamp_k + hpf1*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler_scaled; // scale by the reveb time + acc = acc * rv_time * rv_time_scaler; // scale by the reveb time input = acc + in_allp_out_L; @@ -321,7 +320,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf2 - hpf2; hpf2 += temp1 * lp_hipass_f; acc = lpf2 + temp2*lp_hidamp_k + hpf2*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler_scaled; + acc = acc * rv_time * rv_time_scaler; input = acc + in_allp_out_R; @@ -340,7 +339,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf3 - hpf3; hpf3 += temp1 * lp_hipass_f; acc = lpf3 + temp2*lp_hidamp_k + hpf3*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler_scaled; + acc = acc * rv_time * rv_time_scaler; input = acc + in_allp_out_L; @@ -359,7 +358,7 @@ void AudioEffectPlateReverb::doReverb(const float32_t* inblockL, const float32_t temp1 = lpf4 - hpf4; hpf4 += temp1 * lp_hipass_f; acc = lpf4 + temp2*lp_hidamp_k + hpf4*lp_lodamp_k; - acc = acc * rv_time * rv_time_scaler_scaled; + acc = acc * rv_time * rv_time_scaler; lp_allp_out = acc;