From f7cdd163767354fdc40ecd6019829acb7f0d9e47 Mon Sep 17 00:00:00 2001 From: Martmists Date: Wed, 28 Jul 2021 00:54:15 +0200 Subject: [PATCH] Reverberation --- CMakeLists.txt | 1 + src/effects/Reverberation.cpp | 70 +++++++++++++++++++++++++++++++++++ src/effects/Reverberation.h | 35 ++++++++++++++++++ src/utils/CRevModel.cpp | 14 ++++++- src/utils/CRevModel.h | 1 + 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/effects/Reverberation.cpp create mode 100644 src/effects/Reverberation.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 37b7739..52ab6a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ set(FILES # Effects src/effects/Cure.cpp + src/effects/Reverberation.cpp src/effects/TubeSimulator.cpp # Utils diff --git a/src/effects/Reverberation.cpp b/src/effects/Reverberation.cpp new file mode 100644 index 0000000..7fb6739 --- /dev/null +++ b/src/effects/Reverberation.cpp @@ -0,0 +1,70 @@ +// +// Created by mart on 7/28/21. +// + +#include "Reverberation.h" +#include "../constants.h" + +Reverberation::Reverberation() { + this->roomsize = 0.f; + this->width = 0.f; + this->damp = 0.f; + this->wet = 0.f; + this->dry = 0.5f; + + this->model.SetRoomSize(0.f); + this->model.SetWidth(0.f); + this->model.SetDamp(0.f); + this->model.SetWet(0.f); + this->model.SetDry(0.5f); + + this->samplerate = DEFAULT_SAMPLERATE; + this->enabled = false; +} + +void Reverberation::Reset() { + this->model.Reset(); +} + +void Reverberation::Process(float *buffer, uint32_t size) { + if (this->enabled) { + this->model.ProcessReplace(buffer, &buffer[1], size); + } +} + +void Reverberation::SetEnable(bool enable) { + if (!this->enabled && enable) { + Reset(); + } + this->enabled = enable; +} + +void Reverberation::SetRoomSize(float value) { + this->roomsize = value; + this->model.SetRoomSize(value); +} + +void Reverberation::SetDamp(float value) { + this->damp = value; + this->model.SetDamp(value); +} + +void Reverberation::SetWet(float value) { + this->wet = value; + this->model.SetWet(value); +} + +void Reverberation::SetDry(float value) { + this->dry = value; + this->model.SetDry(value); +} + +void Reverberation::SetWidth(float value) { + this->width = value; + this->model.SetWidth(value); +} + +void Reverberation::SetSamplingRate(uint32_t value) { + this->samplerate = value; + this->model.Reset(); +} diff --git a/src/effects/Reverberation.h b/src/effects/Reverberation.h new file mode 100644 index 0000000..3dfc903 --- /dev/null +++ b/src/effects/Reverberation.h @@ -0,0 +1,35 @@ +// +// Created by mart on 7/28/21. +// + +#pragma once + +#include "../utils/CRevModel.h" + +class Reverberation { +public: + Reverberation(); + + void Reset(); + void Process(float* buffer, uint32_t size); + + void SetEnable(bool enable); + void SetRoomSize(float value); + void SetDamp(float value); + void SetWet(float value); + void SetDry(float value); + void SetWidth(float value); + void SetSamplingRate(uint32_t value); + + float roomsize; + float width; + float damp; + float wet; + float dry; + CRevModel model; + uint32_t samplerate; + bool enabled; +}; + + + diff --git a/src/utils/CRevModel.cpp b/src/utils/CRevModel.cpp index a3993e6..8418aea 100644 --- a/src/utils/CRevModel.cpp +++ b/src/utils/CRevModel.cpp @@ -144,6 +144,18 @@ void CRevModel::UpdateCoeffs() { } } +void CRevModel::Reset() { + for (int i=0; i<8; i++) { + combL[i].Mute(); + combR[i].Mute(); + } + + for(int i=0; i<4; i++) { + allpassL[i].Mute(); + allpassR[i].Mute(); + } +} + void CRevModel::SetRoomSize(float value) { roomsize = (value*0.28f) + 0.7f; UpdateCoeffs(); @@ -193,7 +205,7 @@ float CRevModel::GetWidth() { return width; } -float CRevModel::GetMode() { +int CRevModel::GetMode() { if (mode == 1) { return 1.f; } else { diff --git a/src/utils/CRevModel.h b/src/utils/CRevModel.h index 30b3209..7c98cc6 100644 --- a/src/utils/CRevModel.h +++ b/src/utils/CRevModel.h @@ -15,6 +15,7 @@ public: void Mute(); void ProcessReplace(float *bufL, float *bufR, uint32_t size); void UpdateCoeffs(); + void Reset(); void SetRoomSize(float value); void SetDamp(float value);