From 58bb5d5d1232f4c71babfe2b2aa3d61d84e959a9 Mon Sep 17 00:00:00 2001 From: pio Date: Wed, 30 Oct 2024 17:39:30 +0100 Subject: [PATCH] Plate reverb - better null block handling --- src/effect_platereverb_F32.cpp | 70 ++++++++++++++++++++++++++-------- src/effect_platereverb_F32.h | 9 ++++- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/effect_platereverb_F32.cpp b/src/effect_platereverb_F32.cpp index 68a8df9..1ebef21 100644 --- a/src/effect_platereverb_F32.cpp +++ b/src/effect_platereverb_F32.cpp @@ -41,9 +41,6 @@ #define RV_MASTER_LOWPASS_F (0.6f) // master lowpass scaled frequency coeff. - -AudioEffectPlateReverb_F32::AudioEffectPlateReverb_F32() : AudioStream_F32(2, inputQueueArray_f32) { begin();} - bool AudioEffectPlateReverb_F32::begin() { inputGainSet = 0.5f; @@ -124,7 +121,7 @@ void AudioEffectPlateReverb_F32::update() { #if defined(__IMXRT1062__) if (!initialised) return; - audio_block_f32_t *blockL, *blockR; + audio_block_f32_t *blockL, *blockR, *blockSilent; int16_t i; float acc; float rv_time; @@ -160,8 +157,35 @@ void AudioEffectPlateReverb_F32::update() blockR = AudioStream_F32::receiveReadOnly_f32(1); if (!blockL || !blockR) { - if (blockL) AudioStream_F32::release(blockL); - if (blockR) AudioStream_F32::release(blockR); + // preapare silent block + blockSilent = AudioStream_F32::allocate_f32(); + if (!blockSilent) // no memory, + { + if (blockL) AudioStream_F32::release(blockL); + if (blockR) AudioStream_F32::release(blockR); + return; + } + memset(&blockSilent->data[0], 0, blockSilent->length*sizeof(float32_t)); + + if (blockL) + { + AudioStream_F32::transmit(blockL, 0); + AudioStream_F32::release(blockL); + } + else + { + AudioStream_F32::transmit(blockSilent, 0); + } + if (blockR) + { + AudioStream_F32::transmit(blockR, 1); + AudioStream_F32::release(blockR); + } + else + { + AudioStream_F32::transmit(blockSilent, 1); + } + AudioStream_F32::release(blockSilent); return; } AudioStream_F32::transmit(blockL, 0); @@ -171,12 +195,12 @@ void AudioEffectPlateReverb_F32::update() return; break; case BYPASS_MODE_OFF: - blockL = AudioStream_F32::allocate_f32(); - if (!blockL) return; - memset(&blockL->data[0], 0, blockL->length*sizeof(float32_t)); - AudioStream_F32::transmit(blockL, 0); - AudioStream_F32::transmit(blockL, 1); - AudioStream_F32::release(blockL); + blockSilent = AudioStream_F32::allocate_f32(); + if (!blockSilent) return; + memset(&blockSilent->data[0], 0, blockSilent->length*sizeof(float32_t)); + AudioStream_F32::transmit(blockSilent, 0); + AudioStream_F32::transmit(blockSilent, 1); + AudioStream_F32::release(blockSilent); return; break; case BYPASS_MODE_TRAILS: @@ -189,10 +213,26 @@ void AudioEffectPlateReverb_F32::update() if (!blockL || !blockR) { - if (blockL) AudioStream_F32::release(blockL); - if (blockR) AudioStream_F32::release(blockR); - return; + // preapare silent block + blockSilent = AudioStream_F32::allocate_f32(); + if (!blockSilent) // no memory, + { + if (blockL) AudioStream_F32::release(blockL); + if (blockR) AudioStream_F32::release(blockR); + return; + } + memset(&blockSilent->data[0], 0, blockSilent->length*sizeof(float32_t)); + if (!blockL) + { + blockL = blockSilent; + } + + if (!blockR) + { + blockR = blockSilent; + } } + flags.cleanup_done = 0; rv_time = rv_time_k; diff --git a/src/effect_platereverb_F32.h b/src/effect_platereverb_F32.h index 91edf28..7f1c9c3 100644 --- a/src/effect_platereverb_F32.h +++ b/src/effect_platereverb_F32.h @@ -44,7 +44,12 @@ class AudioEffectPlateReverb_F32 : public AudioStream_F32 { public: - AudioEffectPlateReverb_F32(); + AudioEffectPlateReverb_F32() : AudioStream_F32(2, inputQueueArray_f32) { begin();} + AudioEffectPlateReverb_F32(const AudioSettings_F32 &settings) : AudioStream_F32(2, inputQueueArray_f32) + { + block_size = settings.audio_block_samples; + begin(); + } ~AudioEffectPlateReverb_F32(){}; virtual void update(); @@ -510,6 +515,8 @@ private: const float freeze_hidamp_k = 1.0f; bool initialised = false; + uint16_t block_size = AUDIO_BLOCK_SAMPLES; + }; #endif // _EFFECT_PLATERVBSTEREO_20COPY_H_