Skip to content

Commit 48ca21d

Browse files
committed
Add Distortion to unix port and make type conversions explicit.
1 parent 57022f9 commit 48ca21d

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

ports/unix/variants/coverage/mpconfigvariant.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ SRC_BITMAP := \
3535
shared-bindings/audiocore/WaveFile.c \
3636
shared-bindings/audiodelays/Echo.c \
3737
shared-bindings/audiodelays/__init__.c \
38+
shared-bindings/audiofilters/Distortion.c \
3839
shared-bindings/audiofilters/Filter.c \
3940
shared-bindings/audiofilters/__init__.c \
4041
shared-bindings/audiomixer/__init__.c \
@@ -77,6 +78,7 @@ SRC_BITMAP := \
7778
shared-module/audiocore/WaveFile.c \
7879
shared-module/audiodelays/Echo.c \
7980
shared-module/audiodelays/__init__.c \
81+
shared-module/audiofilters/Distortion.c \
8082
shared-module/audiofilters/Filter.c \
8183
shared-module/audiofilters/__init__.c \
8284
shared-module/audiomixer/__init__.c \

py/circuitpy_defns.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ SRC_SHARED_MODULE_ALL = \
625625
audiocore/__init__.c \
626626
audiodelays/Echo.c \
627627
audiodelays/__init__.c \
628-
audiofilters/Filter.c \
629628
audiofilters/Distortion.c \
629+
audiofilters/Filter.c \
630630
audiofilters/__init__.c \
631631
audioio/__init__.c \
632632
audiomixer/Mixer.c \

shared-module/audiofilters/Distortion.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ 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-
if (!single_channel_output) {
212-
channel = 0;
213-
}
214-
215211
// get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required
216212
mp_float_t drive = synthio_block_slot_get_limited(&self->drive, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
217213
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)));
@@ -300,7 +296,7 @@ audioio_get_buffer_result_t audiofilters_distortion_get_buffer(audiofilters_dist
300296
}
301297

302298
// Apply pre-gain
303-
int32_t word = sample_word * pre_gain;
299+
int32_t word = (int32_t)(sample_word * pre_gain);
304300

305301
// Apply bit mask before converting to float
306302
if (self->mode == DISTORTION_MODE_LOFI) {
@@ -345,10 +341,10 @@ audioio_get_buffer_result_t audiofilters_distortion_get_buffer(audiofilters_dist
345341
}
346342

347343
// Convert sample back to signed integer
348-
word = wordf * MICROPY_FLOAT_CONST(32767.0);
344+
word = (int32_t)(wordf * MICROPY_FLOAT_CONST(32767.0));
349345
} else {
350346
// Apply post-gain
351-
word = word * post_gain;
347+
word = (int32_t)(word * post_gain);
352348
}
353349

354350
// Hard clip
@@ -357,12 +353,12 @@ audioio_get_buffer_result_t audiofilters_distortion_get_buffer(audiofilters_dist
357353
}
358354

359355
if (MP_LIKELY(self->bits_per_sample == 16)) {
360-
word_buffer[i] = (sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix);
356+
word_buffer[i] = (int16_t)((sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix));
361357
if (!self->samples_signed) {
362358
word_buffer[i] ^= 0x8000;
363359
}
364360
} else {
365-
int8_t mixed = (sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix);
361+
int8_t mixed = (int8_t)((sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix));
366362
if (self->samples_signed) {
367363
hword_buffer[i] = mixed;
368364
} else {

0 commit comments

Comments
 (0)