summaryrefslogtreecommitdiff
path: root/servers/audio/effects/reverb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/audio/effects/reverb.cpp')
-rw-r--r--servers/audio/effects/reverb.cpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/servers/audio/effects/reverb.cpp b/servers/audio/effects/reverb.cpp
index 99f60557e1..7c35d88ced 100644
--- a/servers/audio/effects/reverb.cpp
+++ b/servers/audio/effects/reverb.cpp
@@ -57,22 +57,27 @@ const float Reverb::allpass_tunings[MAX_ALLPASS] = {
};
void Reverb::process(float *p_src, float *p_dst, int p_frames) {
- if (p_frames > INPUT_BUFFER_MAX_SIZE)
+ if (p_frames > INPUT_BUFFER_MAX_SIZE) {
p_frames = INPUT_BUFFER_MAX_SIZE;
+ }
int predelay_frames = lrint((params.predelay / 1000.0) * params.mix_rate);
- if (predelay_frames < 10)
+ if (predelay_frames < 10) {
predelay_frames = 10;
- if (predelay_frames >= echo_buffer_size)
+ }
+ if (predelay_frames >= echo_buffer_size) {
predelay_frames = echo_buffer_size - 1;
+ }
for (int i = 0; i < p_frames; i++) {
- if (echo_buffer_pos >= echo_buffer_size)
+ if (echo_buffer_pos >= echo_buffer_size) {
echo_buffer_pos = 0;
+ }
int read_pos = echo_buffer_pos - predelay_frames;
- while (read_pos < 0)
+ while (read_pos < 0) {
read_pos += echo_buffer_size;
+ }
float in = undenormalise(echo_buffer[read_pos] * params.predelay_fb + p_src[i]);
@@ -104,8 +109,9 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) {
int size_limit = c.size - lrintf((float)c.extra_spread_frames * (1.0 - params.extra_spread));
for (int j = 0; j < p_frames; j++) {
- if (c.pos >= size_limit) //reset this now just in case
+ if (c.pos >= size_limit) { //reset this now just in case
c.pos = 0;
+ }
float out = undenormalise(c.buffer[c.pos] * c.feedback);
out = out * (1.0 - c.damp) + c.damp_h * c.damp; //lowpass
@@ -156,8 +162,9 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) {
int size_limit = a.size - lrintf((float)a.extra_spread_frames * (1.0 - params.extra_spread));
for (int j = 0; j < p_frames; j++) {
- if (a.pos >= size_limit)
+ if (a.pos >= size_limit) {
a.pos = 0;
+ }
float aux = a.buffer[a.pos];
a.buffer[a.pos] = undenormalise(allpass_feedback * aux + p_dst[j]);
@@ -200,10 +207,12 @@ void Reverb::set_predelay_feedback(float p_predelay_fb) {
}
void Reverb::set_highpass(float p_frq) {
- if (p_frq > 1)
+ if (p_frq > 1) {
p_frq = 1;
- if (p_frq < 0)
+ }
+ if (p_frq < 0) {
p_frq = 0;
+ }
params.hpf = p_frq;
}
@@ -230,13 +239,15 @@ void Reverb::configure_buffers() {
c.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate);
int len = lrint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames;
- if (len < 5)
+ if (len < 5) {
len = 5; //may this happen?
+ }
c.buffer = memnew_arr(float, len);
c.pos = 0;
- for (int j = 0; j < len; j++)
+ for (int j = 0; j < len; j++) {
c.buffer[j] = 0;
+ }
c.size = len;
}
@@ -246,13 +257,15 @@ void Reverb::configure_buffers() {
a.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate);
int len = lrint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames;
- if (len < 5)
+ if (len < 5) {
len = 5; //may this happen?
+ }
a.buffer = memnew_arr(float, len);
a.pos = 0;
- for (int j = 0; j < len; j++)
+ for (int j = 0; j < len; j++) {
a.buffer[j] = 0;
+ }
a.size = len;
}
@@ -273,10 +286,11 @@ void Reverb::update_parameters() {
for (int i = 0; i < MAX_COMBS; i++) {
Comb &c = comb[i];
c.feedback = room_offset + params.room_size * room_scale;
- if (c.feedback < room_offset)
+ if (c.feedback < room_offset) {
c.feedback = room_offset;
- else if (c.feedback > (room_offset + room_scale))
+ } else if (c.feedback > (room_offset + room_scale)) {
c.feedback = (room_offset + room_scale);
+ }
float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough)
auxdmp *= auxdmp;
@@ -286,19 +300,22 @@ void Reverb::update_parameters() {
}
void Reverb::clear_buffers() {
- if (echo_buffer)
+ if (echo_buffer) {
memdelete_arr(echo_buffer);
+ }
for (int i = 0; i < MAX_COMBS; i++) {
- if (comb[i].buffer)
+ if (comb[i].buffer) {
memdelete_arr(comb[i].buffer);
+ }
comb[i].buffer = nullptr;
}
for (int i = 0; i < MAX_ALLPASS; i++) {
- if (allpass[i].buffer)
+ if (allpass[i].buffer) {
memdelete_arr(allpass[i].buffer);
+ }
allpass[i].buffer = nullptr;
}