Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better synthio #7825

Merged
merged 22 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ msgid "%q in %q must be of type %q, not %q"
msgstr ""

#: ports/espressif/common-hal/espulp/ULP.c
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/microcontroller/Pin.c
Expand Down Expand Up @@ -192,6 +193,10 @@ msgstr ""
msgid "%q must be array of type 'H'"
msgstr ""

#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c
msgid "%q must be array of type 'h'"
msgstr ""

#: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c
#: shared-bindings/canio/CAN.c shared-bindings/digitalio/Pull.c
msgid "%q must be of type %q or %q, not %q"
Expand Down Expand Up @@ -1217,13 +1222,15 @@ msgstr ""
msgid "Interrupt error."
msgstr ""

#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/displayio/EPaperDisplay.c
msgid "Invalid %q"
msgstr ""

#: ports/atmel-samd/common-hal/microcontroller/Pin.c
#: ports/mimxrt10xx/common-hal/microcontroller/Pin.c
#: shared-bindings/microcontroller/Pin.c
msgid "Invalid %q pin"
msgstr ""
Expand Down Expand Up @@ -3827,11 +3834,7 @@ msgstr ""
msgid "out must be a float dense array"
msgstr ""

#: shared-bindings/displayio/Bitmap.c
msgid "out of range of source"
msgstr ""

#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/bitmaptools/__init__.c
msgid "out of range of target"
msgstr ""

Expand All @@ -3856,14 +3859,10 @@ msgstr ""
msgid "parameters must be registers in sequence r0 to r3"
msgstr ""

#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/bitmaptools/__init__.c
msgid "pixel coordinates out of bounds"
msgstr ""

#: shared-bindings/displayio/Bitmap.c
msgid "pixel value requires too many bits"
msgstr ""

#: shared-bindings/displayio/TileGrid.c shared-bindings/vectorio/VectorShape.c
msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter"
msgstr ""
Expand Down Expand Up @@ -4276,10 +4275,6 @@ msgstr ""
msgid "value out of range of target"
msgstr ""

#: shared-bindings/displayio/Bitmap.c
msgid "value_count must be > 0"
msgstr ""

#: ports/espressif/common-hal/watchdog/WatchDogTimer.c
msgid "watchdog not initialized"
msgstr ""
Expand Down
2 changes: 2 additions & 0 deletions ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ CIRCUITPY_AUDIOIO = 1
CIRCUITPY_AUDIOMIXER = 1
CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_KEYPAD = 1
CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS = 0
CIRCUITPY_KEYPAD_KEYMATRIX = 0
CIRCUITPY_MATH = 1
CIRCUITPY_STAGE = 1
CIRCUITPY_SYNTHIO = 1
Expand Down
1 change: 0 additions & 1 deletion ports/mimxrt10xx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ INC += \
-Iboards/$(BOARD) \
-Iperipherals/ \
-Iperipherals/mimxrt10xx/ \
-Isdk/CMSIS/Include \
-Isdk/devices/$(CHIP_FAMILY) \
-Isdk/devices/$(CHIP_FAMILY)/drivers \
-Isdk/drivers/common
Expand Down
1 change: 1 addition & 0 deletions ports/mimxrt10xx/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CIRCUITPY_AUDIOIO = 0
CIRCUITPY_AUDIOMIXER = 1
CIRCUITPY_AUDIOMP3 = 1
CIRCUITPY_AUDIOPWMIO = 1
CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12
CIRCUITPY_BUSDEVICE = 1
CIRCUITPY_COUNTIO = 0
CIRCUITPY_FREQUENCYIO = 0
Expand Down
1 change: 1 addition & 0 deletions ports/raspberrypi/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CIRCUITPY_PWMIO ?= 1
CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_DISPLAYIO)
CIRCUITPY_ROTARYIO ?= 1
CIRCUITPY_ROTARYIO_SOFTENCODER = 1
CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12

# Things that need to be implemented.
# Use PWM internally
Expand Down
25 changes: 24 additions & 1 deletion ports/unix/variants/coverage/mpconfigvariant.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,30 @@ SRC_BITMAP := \
displayio_min.c \
shared-bindings/aesio/aes.c \
shared-bindings/aesio/__init__.c \
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 \
shared-bindings/struct/__init__.c \
shared-bindings/synthio/__init__.c \
shared-bindings/synthio/MidiTrack.c \
shared-bindings/synthio/Synthesizer.c \
shared-bindings/traceback/__init__.c \
shared-bindings/util.c \
shared-bindings/zlib/__init__.c \
shared-module/aesio/aes.c \
shared-module/aesio/__init__.c \
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 \
Expand All @@ -47,19 +62,27 @@ SRC_BITMAP := \
shared-module/os/getenv.c \
shared-module/rainbowio/__init__.c \
shared-module/struct/__init__.c \
shared-module/synthio/__init__.c \
shared-module/synthio/MidiTrack.c \
shared-module/synthio/Synthesizer.c \
shared-module/traceback/__init__.c \
shared-module/zlib/__init__.c \

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 \
-DCIRCUITPY_OS_GETENV=1 \
-DCIRCUITPY_GIFIO=1 \
-DCIRCUITPY_OS_GETENV=1 \
-DCIRCUITPY_RAINBOWIO=1 \
-DCIRCUITPY_STRUCT=1 \
-DCIRCUITPY_SYNTHIO=1 \
-DCIRCUITPY_SYNTHIO_MAX_CHANNELS=14 \
-DCIRCUITPY_TRACEBACK=1 \
-DCIRCUITPY_ZLIB=1

Expand Down
1 change: 1 addition & 0 deletions py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ SRC_SHARED_MODULE_ALL = \
supervisor/__init__.c \
supervisor/StatusBar.c \
synthio/MidiTrack.c \
synthio/Synthesizer.c \
synthio/__init__.c \
terminalio/Terminal.c \
terminalio/__init__.c \
Expand Down
18 changes: 18 additions & 0 deletions py/circuitpy_mpconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ CFLAGS += -DCIRCUITPY_AUDIOCORE=$(CIRCUITPY_AUDIOCORE)
CIRCUITPY_AUDIOMIXER ?= $(CIRCUITPY_AUDIOIO)
CFLAGS += -DCIRCUITPY_AUDIOMIXER=$(CIRCUITPY_AUDIOMIXER)

ifndef CIRCUITPY_AUDIOCORE_DEBUG
CIRCUITPY_AUDIOCORE_DEBUG ?= 0
endif
CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG)

ifndef CIRCUITPY_AUDIOMP3
ifeq ($(CIRCUITPY_FULL_BUILD),1)
CIRCUITPY_AUDIOMP3 = $(CIRCUITPY_AUDIOCORE)
Expand Down Expand Up @@ -286,6 +291,15 @@ CFLAGS += -DCIRCUITPY_JSON=$(CIRCUITPY_JSON)
CIRCUITPY_KEYPAD ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_KEYPAD=$(CIRCUITPY_KEYPAD)

CIRCUITPY_KEYPAD_KEYS ?= $(CIRCUITPY_KEYPAD)
CFLAGS += -DCIRCUITPY_KEYPAD_KEYS=$(CIRCUITPY_KEYPAD_KEYS)

CIRCUITPY_KEYPAD_KEYMATRIX ?= $(CIRCUITPY_KEYPAD)
CFLAGS += -DCIRCUITPY_KEYPAD_KEYMATRIX=$(CIRCUITPY_KEYPAD_KEYMATRIX)

CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS ?= $(CIRCUITPY_KEYPAD)
CFLAGS += -DCIRCUITPY_KEYPAD_SHIFTREGISTERKEYS=$(CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS)

CIRCUITPY_MATH ?= 1
CFLAGS += -DCIRCUITPY_MATH=$(CIRCUITPY_MATH)

Expand Down Expand Up @@ -437,6 +451,10 @@ CFLAGS += -DCIRCUITPY_SUPERVISOR=$(CIRCUITPY_SUPERVISOR)
CIRCUITPY_SYNTHIO ?= $(CIRCUITPY_AUDIOCORE)
CFLAGS += -DCIRCUITPY_SYNTHIO=$(CIRCUITPY_SYNTHIO)

CIRCUITPY_SYNTHIO_MAX_CHANNELS ?= 2
CFLAGS += -DCIRCUITPY_SYNTHIO_MAX_CHANNELS=$(CIRCUITPY_SYNTHIO_MAX_CHANNELS)


CIRCUITPY_SYS ?= 1
CFLAGS += -DCIRCUITPY_SYS=$(CIRCUITPY_SYS)

Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/audiobusio/I2SOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
//| ...
STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if !CIRCUITPY_AUDIOBUSIO_I2SOUT
mp_raise_NotImplementedError(translate("I2SOut not available"));
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_I2SOut);
return NULL; // Not reachable.
#else
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/audiobusio/PDMIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
//| ...
STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if !CIRCUITPY_AUDIOBUSIO_PDMIN
mp_raise_NotImplementedError(translate("PDMIn not available"));
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_PDMIn);
#else
enum { ARG_clock_pin, ARG_data_pin, ARG_sample_rate, ARG_bit_depth, ARG_mono, ARG_oversample, ARG_startup_delay };
static const mp_arg_t allowed_args[] = {
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/audiocore/RawSample.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//| def __init__(
//| self, buffer: ReadableBuffer, *, channel_count: int = 1, sample_rate: int = 8000
//| ) -> None:
//| """Create a RawSample based on the given buffer of signed values. If channel_count is more than
//| """Create a RawSample based on the given buffer of values. If channel_count is more than
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
//| first sample will be for channel 1, the second sample will be for channel two, the third for
//| channel 1 and so on.
Expand Down
1 change: 1 addition & 0 deletions shared-bindings/audiocore/WaveFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "shared-bindings/audiocore/WaveFile.h"
#include "shared-bindings/util.h"
#include "supervisor/shared/translate/translate.h"
#include "extmod/vfs_posix.h"

//| class WaveFile:
//| """Load a wave file for audio playback
Expand Down
48 changes: 47 additions & 1 deletion shared-bindings/audiocore/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,64 @@
#include "py/obj.h"
#include "py/runtime.h"

#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/audiocore/__init__.h"
#include "shared-bindings/audiocore/RawSample.h"
#include "shared-bindings/audiocore/WaveFile.h"
// #include "shared-bindings/audiomixer/Mixer.h"

//| """Support for audio samples"""

#if CIRCUITPY_AUDIOCORE_DEBUG
// (no docstrings so that the debug functions are not shown on docs.circuitpython.org)
STATIC mp_obj_t audiocore_get_buffer(mp_obj_t sample_in) {
uint8_t *buffer = NULL;
uint32_t buffer_length = 0;
audioio_get_buffer_result_t gbr = audiosample_get_buffer(sample_in, false, 0, &buffer, &buffer_length);

mp_obj_t result[2] = {mp_obj_new_int_from_uint(gbr), mp_const_none};

if (gbr != GET_BUFFER_ERROR) {
// copies the data because the gc semantics of get_buffer are unclear
result[1] = mp_obj_new_bytes(buffer, buffer_length);
}

return mp_obj_new_tuple(2, result);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_get_buffer_obj, audiocore_get_buffer);

STATIC mp_obj_t audiocore_get_structure(mp_obj_t sample_in) {
bool single_buffer, samples_signed;
uint32_t max_buffer_length;
uint8_t spacing;

audiosample_get_buffer_structure(sample_in, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing);
mp_obj_t result[4] = {
mp_obj_new_int_from_uint(single_buffer),
mp_obj_new_int_from_uint(samples_signed),
mp_obj_new_int_from_uint(max_buffer_length),
mp_obj_new_int_from_uint(spacing),
};
return mp_obj_new_tuple(4, result);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_get_structure_obj, audiocore_get_structure);

STATIC mp_obj_t audiocore_reset_buffer(mp_obj_t sample_in) {
audiosample_reset_buffer(sample_in, false, 0);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_reset_buffer_obj, audiocore_reset_buffer);

#endif

STATIC const mp_rom_map_elem_t audiocore_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiocore) },
{ MP_ROM_QSTR(MP_QSTR_RawSample), MP_ROM_PTR(&audioio_rawsample_type) },
{ MP_ROM_QSTR(MP_QSTR_WaveFile), MP_ROM_PTR(&audioio_wavefile_type) },
#if CIRCUITPY_AUDIOCORE_DEBUG
{ MP_ROM_QSTR(MP_QSTR_get_buffer), MP_ROM_PTR(&audiocore_get_buffer_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_buffer), MP_ROM_PTR(&audiocore_reset_buffer_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_structure), MP_ROM_PTR(&audiocore_get_structure_obj) },
#endif
};

STATIC MP_DEFINE_CONST_DICT(audiocore_module_globals, audiocore_module_globals_table);
Expand Down
2 changes: 0 additions & 2 deletions shared-bindings/audiomixer/Mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 0 additions & 2 deletions shared-bindings/audiomixer/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMIXER_MIXER_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMIXER_MIXER_H

#include "common-hal/microcontroller/Pin.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;
Expand Down
4 changes: 1 addition & 3 deletions shared-bindings/audiomixer/MixerVoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"));
Expand Down
7 changes: 2 additions & 5 deletions shared-bindings/audiomixer/MixerVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion shared-bindings/audiomixer/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/keypad/Event.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ STATIC mp_obj_t keypad_event_unary_op(mp_unary_op_t op, mp_obj_t self_in) {

STATIC void keypad_event_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
keypad_event_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<Event: key_number %d %s>",
mp_printf(print, "<Event: key_number %d %q>",
common_hal_keypad_event_get_key_number(self),
common_hal_keypad_event_get_pressed(self) ? "pressed" : "released");
common_hal_keypad_event_get_pressed(self) ? MP_QSTR_pressed : MP_QSTR_released);
}

STATIC const mp_rom_map_elem_t keypad_event_locals_dict_table[] = {
Expand Down
Loading