Skip to content

Commit 06446b5

Browse files
committed
Use full buffer for storing delay and remove division of average
1 parent c3085f5 commit 06446b5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

shared-module/audiodelays/Chorus.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ audioio_get_buffer_result_t audiodelays_chorus_get_buffer(audiodelays_chorus_obj
194194
// The chorus buffer is always stored as a 16-bit value internally
195195
int16_t *chorus_buffer = (int16_t *)self->chorus_buffer;
196196
uint32_t chorus_buf_len = self->chorus_buffer_len / sizeof(uint16_t);
197+
uint32_t max_chorus_buf_len = self->max_chorus_buffer_len / sizeof(uint16_t);
197198

198199
// Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample
199200
while (length != 0) {
@@ -227,6 +228,7 @@ audioio_get_buffer_result_t audiodelays_chorus_get_buffer(audiodelays_chorus_obj
227228
shared_bindings_synthio_lfo_tick(self->base.sample_rate, n / self->base.channel_count);
228229

229230
int32_t voices = MAX(synthio_block_slot_get(&self->voices), 1.0);
231+
int32_t mix_down_scale = SYNTHIO_MIX_DOWN_SCALE(voices);
230232

231233
mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms);
232234
if (MICROPY_FLOAT_C_FUN(fabs)(self->current_delay_ms - f_delay_ms) >= self->sample_ms) {
@@ -275,15 +277,18 @@ audioio_get_buffer_result_t audiodelays_chorus_get_buffer(audiodelays_chorus_obj
275277

276278
for (int32_t v = 0; v < voices; v++) {
277279
if (c_pos < 0) {
278-
c_pos += chorus_buf_len;
280+
c_pos += max_chorus_buf_len;
279281
}
280282
word += chorus_buffer[c_pos];
281283

282284
c_pos -= step;
283285
}
284-
word = word / voices;
285286

286-
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));
287+
// Dividing would get an average but does not sound as good
288+
// Leaving this here in case someone wants to try an average instead
289+
// word = word / voices;
290+
291+
word = synthio_mix_down_sample(word, mix_down_scale);
287292
}
288293

289294
if (MP_LIKELY(self->base.bits_per_sample == 16)) {
@@ -300,7 +305,7 @@ audioio_get_buffer_result_t audiodelays_chorus_get_buffer(audiodelays_chorus_obj
300305
}
301306
}
302307

303-
if (self->chorus_buffer_pos >= chorus_buf_len) {
308+
if (self->chorus_buffer_pos >= max_chorus_buf_len) {
304309
self->chorus_buffer_pos = 0;
305310
}
306311
}

0 commit comments

Comments
 (0)