Skip to content

Commit 0e64e1c

Browse files
committed
Implement block ticking within audio effects.
1 parent 4257c62 commit 0e64e1c

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

shared-module/audiodelays/Echo.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,16 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
284284
channel = 0;
285285
}
286286

287+
// Switch our buffers to the other buffer
288+
self->last_buf_idx = !self->last_buf_idx;
289+
290+
// If we are using 16 bit samples we need a 16 bit pointer, 8 bit needs an 8 bit pointer
291+
int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx];
292+
int8_t *hword_buffer = self->buffer[self->last_buf_idx];
293+
uint32_t length = self->buffer_len / (self->bits_per_sample / 8);
294+
287295
// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
296+
shared_bindings_synthio_lfo_tick(self->sample_rate, length / self->channel_count);
288297
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
289298
mp_float_t decay = synthio_block_slot_get_limited(&self->decay, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
290299

@@ -293,14 +302,6 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *
293302
recalculate_delay(self, delay_ms);
294303
}
295304

296-
// Switch our buffers to the other buffer
297-
self->last_buf_idx = !self->last_buf_idx;
298-
299-
// If we are using 16 bit samples we need a 16 bit pointer, 8 bit needs an 8 bit pointer
300-
int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx];
301-
int8_t *hword_buffer = self->buffer[self->last_buf_idx];
302-
uint32_t length = self->buffer_len / (self->bits_per_sample / 8);
303-
304305
// The echo buffer is always stored as a 16-bit value internally
305306
int16_t *echo_buffer = (int16_t *)self->echo_buffer;
306307
uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t);

shared-module/audiofilters/Distortion.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,16 @@ static mp_float_t db_to_linear(mp_float_t value) {
208208
audioio_get_buffer_result_t audiofilters_distortion_get_buffer(audiofilters_distortion_obj_t *self, bool single_channel_output, uint8_t channel,
209209
uint8_t **buffer, uint32_t *buffer_length) {
210210

211+
// Switch our buffers to the other buffer
212+
self->last_buf_idx = !self->last_buf_idx;
213+
214+
// If we are using 16 bit samples we need a 16 bit pointer, 8 bit needs an 8 bit pointer
215+
int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx];
216+
int8_t *hword_buffer = self->buffer[self->last_buf_idx];
217+
uint32_t length = self->buffer_len / (self->bits_per_sample / 8);
218+
211219
// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
220+
shared_bindings_synthio_lfo_tick(self->sample_rate, length / self->channel_count);
212221
mp_float_t drive = synthio_block_slot_get_limited(&self->drive, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
213222
mp_float_t pre_gain = db_to_linear(synthio_block_slot_get_limited(&self->pre_gain, MICROPY_FLOAT_CONST(-60.0), MICROPY_FLOAT_CONST(60.0)));
214223
mp_float_t post_gain = db_to_linear(synthio_block_slot_get_limited(&self->post_gain, MICROPY_FLOAT_CONST(-80.0), MICROPY_FLOAT_CONST(24.0)));
@@ -224,14 +233,6 @@ audioio_get_buffer_result_t audiofilters_distortion_get_buffer(audiofilters_dist
224233
drive = MICROPY_FLOAT_CONST(2.0) * drive / (MICROPY_FLOAT_CONST(1.0001) - drive);
225234
}
226235

227-
// Switch our buffers to the other buffer
228-
self->last_buf_idx = !self->last_buf_idx;
229-
230-
// If we are using 16 bit samples we need a 16 bit pointer, 8 bit needs an 8 bit pointer
231-
int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx];
232-
int8_t *hword_buffer = self->buffer[self->last_buf_idx];
233-
uint32_t length = self->buffer_len / (self->bits_per_sample / 8);
234-
235236
// Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample
236237
while (length != 0) {
237238
// Check if there is no more sample to play, we will either load more data, reset the sample if loop is on or clear the sample

shared-module/audiofilters/Filter.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,6 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o
246246
channel = 0;
247247
}
248248

249-
// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
250-
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
251-
252249
// Switch our buffers to the other buffer
253250
self->last_buf_idx = !self->last_buf_idx;
254251

@@ -257,6 +254,10 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o
257254
int8_t *hword_buffer = self->buffer[self->last_buf_idx];
258255
uint32_t length = self->buffer_len / (self->bits_per_sample / 8);
259256

257+
// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
258+
shared_bindings_synthio_lfo_tick(self->sample_rate, length / self->channel_count);
259+
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
260+
260261
// Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample
261262
while (length != 0) {
262263
// Check if there is no more sample to play, we will either load more data, reset the sample if loop is on or clear the sample

0 commit comments

Comments
 (0)