Skip to content

Commit

Permalink
Fix about incorrectly recalculating delay
Browse files Browse the repository at this point in the history
  • Loading branch information
gamblor21 committed Oct 7, 2024
1 parent 0fa3cd8 commit 48e1327
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion shared-module/audiodelays/Echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o
void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) {
// Calculate the current echo buffer length in bytes

uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * sizeof(uint16_t);
uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t));

// Check if our new echo is too long for our maximum buffer
if (new_echo_buffer_len > self->max_echo_buffer_len) {
Expand All @@ -134,6 +134,11 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) {
return;
}

// If the echo buffer is larger then our audio buffer weird things happen
if (new_echo_buffer_len < self->buffer_len) {
return;
}

self->echo_buffer_len = new_echo_buffer_len;
self->current_delay_ms = f_delay_ms;
}
Expand Down

0 comments on commit 48e1327

Please sign in to comment.