From b9dea05dbfaa9a55a429892b1cf87e1518083866 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 5 Apr 2023 08:51:55 -0500 Subject: [PATCH] Enable audiomixer on unix port, for testing --- ports/unix/variants/coverage/mpconfigvariant.mk | 7 +++++++ shared-bindings/audiomixer/Mixer.c | 2 -- shared-bindings/audiomixer/Mixer.h | 1 - shared-bindings/audiomixer/MixerVoice.c | 4 +--- shared-bindings/audiomixer/MixerVoice.h | 7 ++----- shared-bindings/audiomixer/__init__.c | 1 - shared-module/audiomixer/Mixer.c | 6 +++++- shared-module/audiomixer/MixerVoice.c | 8 ++++---- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ports/unix/variants/coverage/mpconfigvariant.mk b/ports/unix/variants/coverage/mpconfigvariant.mk index 8b25ddb705..854d052c6c 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.mk +++ b/ports/unix/variants/coverage/mpconfigvariant.mk @@ -33,6 +33,9 @@ SRC_BITMAP := \ shared-bindings/audiocore/__init__.c \ shared-bindings/audiocore/RawSample.c \ shared-bindings/audiocore/WaveFile.c \ + shared-bindings/audiomixer/__init__.c \ + shared-bindings/audiomixer/Mixer.c \ + shared-bindings/audiomixer/MixerVoice.c \ shared-bindings/bitmaptools/__init__.c \ shared-bindings/displayio/Bitmap.c \ shared-bindings/rainbowio/__init__.c \ @@ -48,6 +51,9 @@ SRC_BITMAP := \ shared-module/audiocore/__init__.c \ shared-module/audiocore/RawSample.c \ shared-module/audiocore/WaveFile.c \ + shared-module/audiomixer/__init__.c \ + shared-module/audiomixer/Mixer.c \ + shared-module/audiomixer/MixerVoice.c \ shared-module/bitmaptools/__init__.c \ shared-module/displayio/area.c \ shared-module/displayio/Bitmap.c \ @@ -67,6 +73,7 @@ SRC_C += $(SRC_BITMAP) CFLAGS += \ -DCIRCUITPY_AESIO=1 \ -DCIRCUITPY_AUDIOCORE=1 \ + -DCIRCUITPY_AUDIOMIXER=1 \ -DCIRCUITPY_AUDIOCORE_DEBUG=1 \ -DCIRCUITPY_BITMAPTOOLS=1 \ -DCIRCUITPY_DISPLAYIO_UNIX=1 \ diff --git a/shared-bindings/audiomixer/Mixer.c b/shared-bindings/audiomixer/Mixer.c index 58c618fc11..83fcc06712 100644 --- a/shared-bindings/audiomixer/Mixer.c +++ b/shared-bindings/audiomixer/Mixer.c @@ -33,8 +33,6 @@ #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/util.h" #include "supervisor/shared/translate/translate.h" diff --git a/shared-bindings/audiomixer/Mixer.h b/shared-bindings/audiomixer/Mixer.h index fd1154cc43..d04f793dde 100644 --- a/shared-bindings/audiomixer/Mixer.h +++ b/shared-bindings/audiomixer/Mixer.h @@ -28,7 +28,6 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMIXER_MIXER_H #include "shared-module/audiomixer/Mixer.h" -#include "shared-bindings/audiocore/RawSample.h" extern const mp_obj_type_t audiomixer_mixer_type; extern const mp_obj_type_t audiomixer_mixervoice_type; diff --git a/shared-bindings/audiomixer/MixerVoice.c b/shared-bindings/audiomixer/MixerVoice.c index 16a1be520f..1d6cd7f39a 100644 --- a/shared-bindings/audiomixer/MixerVoice.c +++ b/shared-bindings/audiomixer/MixerVoice.c @@ -32,8 +32,6 @@ #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/util.h" #include "supervisor/shared/translate/translate.h" @@ -115,7 +113,7 @@ STATIC mp_obj_t audiomixer_mixervoice_obj_set_level(size_t n_args, const mp_obj_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - float level = mp_obj_get_float(args[ARG_level].u_obj); + mp_float_t level = mp_obj_get_float(args[ARG_level].u_obj); if (level > 1 || level < 0) { mp_raise_ValueError(translate("level must be between 0 and 1")); diff --git a/shared-bindings/audiomixer/MixerVoice.h b/shared-bindings/audiomixer/MixerVoice.h index bce4632760..0ff8accee4 100644 --- a/shared-bindings/audiomixer/MixerVoice.h +++ b/shared-bindings/audiomixer/MixerVoice.h @@ -26,9 +26,6 @@ #ifndef SHARED_BINDINGS_AUDIOMIXER_MIXERVOICE_H_ #define SHARED_BINDINGS_AUDIOMIXER_MIXERVOICE_H_ -#include "common-hal/microcontroller/Pin.h" -#include "shared-bindings/audiocore/RawSample.h" - #include "shared-module/audiomixer/MixerVoice.h" #include "shared-module/audiomixer/Mixer.h" @@ -39,8 +36,8 @@ void common_hal_audiomixer_mixervoice_construct(audiomixer_mixervoice_obj_t *sel void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t *self, audiomixer_mixer_obj_t *parent); void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop); void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t *self); -float common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self); -void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, float gain); +mp_float_t common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self); +void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, mp_float_t gain); bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t *self); diff --git a/shared-bindings/audiomixer/__init__.c b/shared-bindings/audiomixer/__init__.c index 8292be9e95..4c8068172b 100644 --- a/shared-bindings/audiomixer/__init__.c +++ b/shared-bindings/audiomixer/__init__.c @@ -29,7 +29,6 @@ #include "py/obj.h" #include "py/runtime.h" -#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiomixer/Mixer.h" //| """Support for audio mixing""" diff --git a/shared-module/audiomixer/Mixer.c b/shared-module/audiomixer/Mixer.c index 1c5de4d934..ce39f88919 100644 --- a/shared-module/audiomixer/Mixer.c +++ b/shared-module/audiomixer/Mixer.c @@ -35,6 +35,10 @@ #include "shared-module/audiocore/__init__.h" #include "shared-module/audiocore/RawSample.h" +#if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) +#include "periph.h" +#endif + void common_hal_audiomixer_mixer_construct(audiomixer_mixer_obj_t *self, uint8_t voice_count, uint32_t buffer_size, @@ -140,7 +144,7 @@ static inline uint32_t mult16signed(uint32_t val, int32_t mul) { float mod_mul = (float)mul / (float)((1 << 15) - 1); for (int8_t i = 0; i < 2; i++) { int16_t ai = (val >> (sizeof(uint16_t) * 8 * i)); - int32_t intermediate = ai * mod_mul; + int32_t intermediate = (int32_t)(ai * mod_mul); if (intermediate > SHRT_MAX) { intermediate = SHRT_MAX; } else if (intermediate < SHRT_MIN) { diff --git a/shared-module/audiomixer/MixerVoice.c b/shared-module/audiomixer/MixerVoice.c index bb58b0c111..f4d2a6514e 100644 --- a/shared-module/audiomixer/MixerVoice.c +++ b/shared-module/audiomixer/MixerVoice.c @@ -42,12 +42,12 @@ void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t *se self->parent = parent; } -float common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self) { - return (float)self->level / (1 << 15); +mp_float_t common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t *self) { + return (mp_float_t)self->level / (1 << 15); } -void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, float level) { - self->level = level * (1 << 15); +void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *self, mp_float_t level) { + self->level = (uint16_t)(level * (1 << 15)); } void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop) {