8000 Fix sample decimation bug on `audiodelays.Echo` when `freq_shift=True` by relic-se · Pull Request #10017 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Fix sample decimation bug on audiodelays.Echo when freq_shift=True #10017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions shared-module/audiodelays/Echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
echo = echo_buffer[echo_buffer_pos >> 8];
next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate;

word = (int16_t)(echo * decay);
for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) {
word = (int16_t)(echo_buffer[j % echo_buf_len] * decay);
echo_buffer[j % echo_buf_len] = word;
}
} else {
Expand Down Expand Up @@ -421,33 +421,33 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
if (self->freq_shift) {
echo = echo_buffer[echo_buffer_pos >> 8];
next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate;
word = (int32_t)(echo * decay + sample_word);
} else {
echo = echo_buffer[self->echo_buffer_read_pos++];
word = (int32_t)(echo * decay + sample_word);
}

if (MP_LIKELY(self->bits_per_sample == 16)) {
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));
if (self->freq_shift) {
for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) {
word = (int32_t)(echo_buffer[j % echo_buf_len] * decay + sample_word);
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));
echo_buffer[j % echo_buf_len] = (int16_t)word;
}
} else {
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));
echo_buffer[self->echo_buffer_write_pos++] = (int16_t)word;
}
} else {
// Do not have mix_down for 8 bit so just hard cap samples into 1 byte
if (word > 127) {
word = 127;
} else if (word < -128) {
word = -128;
}
if (self->freq_shift) {
for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) {
word = (int32_t)(echo_buffer[j % echo_buf_len] * decay + sample_word);
// Do not have mix_down for 8 bit so just hard cap samples into 1 byte
word = MIN(MAX(word, -128), 127);
echo_buffer[j % echo_buf_len] = (int8_t)word;
}
} else {
// Do not have mix_down for 8 bit so just hard cap samples into 1 byte
word = MIN(MAX(word, -128), 127);
echo_buffer[self->echo_buffer_write_pos++] = (int8_t)word;
}
}
Expand Down
0