Skip to content

Commit b796f0d

Browse files
committed
Only calculate lofi bit mask when necessary.
1 parent cef94d7 commit b796f0d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

shared-module/audiofilters/Distortion.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ audioio_get_buffer_result_t audiofilters_distortion_get_buffer(audiofilters_dist
268268
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)));
269269
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
270270

271-
// LOFI mode bit mask
272-
uint32_t word_mask = 0xFFFFFFFF ^ ((1 << (uint32_t)MICROPY_FLOAT_C_FUN(round)(drive * MICROPY_FLOAT_CONST(14.0))) - 1);
273-
274271
// Modify drive value depending on mode
272+
uint32_t word_mask = 0;
275273
if (self->mode == DISTORTION_MODE_CLIP) {
276274
drive = MICROPY_FLOAT_CONST(1.0001) - drive;
277275
} else if (self->mode == DISTORTION_MODE_WAVESHAPE) {
278276
drive = MICROPY_FLOAT_CONST(2.0) * drive / (MICROPY_FLOAT_CONST(1.0001) - drive);
277+
} else if (self->mode == DISTORTION_MODE_LOFI) {
278+
word_mask = 0xFFFFFFFF ^ ((1 << (uint32_t)MICROPY_FLOAT_C_FUN(round)(drive * MICROPY_FLOAT_CONST(14.0))) - 1);
279279
}
280280

281281
if (mix <= MICROPY_FLOAT_CONST(0.01)) { // if mix is zero pure sample only

0 commit comments

Comments
 (0)