@@ -208,7 +208,16 @@ static mp_float_t db_to_linear(mp_float_t value) {
208208audioio_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
0 commit comments