Rename FilterType -> FilterMode
This commit is contained in:
parent
b03d396cfa
commit
e891bce129
6 changed files with 43 additions and 43 deletions
|
|
@ -10,41 +10,41 @@
|
|||
#include "shared-bindings/synthio/BlockBiquad.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| class FilterType:
|
||||
//| class FilterMode:
|
||||
//| """The type of filter"""
|
||||
//|
|
||||
//| LOW_PASS: FilterType
|
||||
//| LOW_PASS: FilterMode
|
||||
//| """A low-pass filter"""
|
||||
//| HIGH_PASS: FilterType
|
||||
//| HIGH_PASS: FilterMode
|
||||
//| """A high-pass filter"""
|
||||
//| BAND_PASS: FilterType
|
||||
//| BAND_PASS: FilterMode
|
||||
//| """A band-pass filter"""
|
||||
//|
|
||||
|
||||
MAKE_ENUM_VALUE(synthio_filter_type, kind, LOW_PASS, SYNTHIO_LOW_PASS);
|
||||
MAKE_ENUM_VALUE(synthio_filter_type, kind, HIGH_PASS, SYNTHIO_HIGH_PASS);
|
||||
MAKE_ENUM_VALUE(synthio_filter_type, kind, BAND_PASS, SYNTHIO_BAND_PASS);
|
||||
MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, LOW_PASS, SYNTHIO_LOW_PASS);
|
||||
MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, HIGH_PASS, SYNTHIO_HIGH_PASS);
|
||||
MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, BAND_PASS, SYNTHIO_BAND_PASS);
|
||||
|
||||
MAKE_ENUM_MAP(synthio_filter) {
|
||||
MAKE_ENUM_MAP_ENTRY(kind, LOW_PASS),
|
||||
MAKE_ENUM_MAP_ENTRY(kind, HIGH_PASS),
|
||||
MAKE_ENUM_MAP_ENTRY(kind, BAND_PASS),
|
||||
MAKE_ENUM_MAP(synthio_filter_mode) {
|
||||
MAKE_ENUM_MAP_ENTRY(mode, LOW_PASS),
|
||||
MAKE_ENUM_MAP_ENTRY(mode, HIGH_PASS),
|
||||
MAKE_ENUM_MAP_ENTRY(mode, BAND_PASS),
|
||||
};
|
||||
|
||||
static MP_DEFINE_CONST_DICT(synthio_filter_locals_dict, synthio_filter_locals_table);
|
||||
static MP_DEFINE_CONST_DICT(synthio_filter_mode_locals_dict, synthio_filter_mode_locals_table);
|
||||
|
||||
MAKE_PRINTER(synthio, synthio_filter);
|
||||
MAKE_PRINTER(synthio, synthio_filter_mode);
|
||||
|
||||
MAKE_ENUM_TYPE(synthio, FilterType, synthio_filter);
|
||||
MAKE_ENUM_TYPE(synthio, FilterMode, synthio_filter_mode);
|
||||
|
||||
static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) {
|
||||
return cp_enum_value(&synthio_filter_type, obj, arg_name);
|
||||
static synthio_filter_mode validate_synthio_filter_mode(mp_obj_t obj, qstr arg_name) {
|
||||
return cp_enum_value(&synthio_filter_mode_type, obj, arg_name);
|
||||
}
|
||||
|
||||
//| class BlockBiquad:
|
||||
//| def __init__(
|
||||
//| self,
|
||||
//| kind: FilterType,
|
||||
//| mode: FilterMode,
|
||||
//| frequency: BlockInput,
|
||||
//| q_factor: BlockInput = 0.7071067811865475,
|
||||
//| ) -> None:
|
||||
|
|
@ -61,13 +61,13 @@ static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) {
|
|||
//| appears to work as you'd expect."""
|
||||
|
||||
static const mp_arg_t block_biquad_properties[] = {
|
||||
{ MP_QSTR_kind, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } },
|
||||
{ MP_QSTR_mode, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } },
|
||||
{ MP_QSTR_frequency, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } },
|
||||
{ MP_QSTR_Q, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL } },
|
||||
};
|
||||
|
||||
static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
enum { ARG_kind, ARG_frequency, ARG_Q };
|
||||
enum { ARG_mode, ARG_frequency, ARG_Q };
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(block_biquad_properties)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(block_biquad_properties), block_biquad_properties, args);
|
||||
|
|
@ -76,21 +76,21 @@ static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size
|
|||
args[ARG_Q].u_obj = mp_obj_new_float(MICROPY_FLOAT_CONST(0.7071067811865475));
|
||||
}
|
||||
|
||||
synthio_filter_e kind = validate_synthio_filter(args[ARG_kind].u_obj, MP_QSTR_kind);
|
||||
return common_hal_synthio_block_biquad_new(kind, args[ARG_frequency].u_obj, args[ARG_Q].u_obj);
|
||||
synthio_filter_mode mode = validate_synthio_filter_mode(args[ARG_mode].u_obj, MP_QSTR_mode);
|
||||
return common_hal_synthio_block_biquad_new(mode, args[ARG_frequency].u_obj, args[ARG_Q].u_obj);
|
||||
}
|
||||
|
||||
//|
|
||||
//| kind: FilterType
|
||||
//| """The kind of filter (read-only)"""
|
||||
static mp_obj_t synthio_block_biquad_get_kind(mp_obj_t self_in) {
|
||||
//| mode: FilterMode
|
||||
//| """The mode of filter (read-only)"""
|
||||
static mp_obj_t synthio_block_biquad_get_mode(mp_obj_t self_in) {
|
||||
synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
return cp_enum_find(&synthio_filter_type, common_hal_synthio_block_biquad_get_kind(self));
|
||||
return cp_enum_find(&synthio_filter_mode_type, common_hal_synthio_block_biquad_get_mode(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_kind_obj, synthio_block_biquad_get_kind);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_mode_obj, synthio_block_biquad_get_mode);
|
||||
|
||||
MP_PROPERTY_GETTER(synthio_block_biquad_kind_obj,
|
||||
(mp_obj_t)&synthio_block_biquad_get_kind_obj);
|
||||
MP_PROPERTY_GETTER(synthio_block_biquad_mode_obj,
|
||||
(mp_obj_t)&synthio_block_biquad_get_mode_obj);
|
||||
|
||||
//|
|
||||
//| frequency: BlockInput
|
||||
|
|
@ -133,7 +133,7 @@ MP_PROPERTY_GETSET(synthio_block_biquad_q_factor_obj,
|
|||
(mp_obj_t)&synthio_block_biquad_set_q_factor_obj);
|
||||
|
||||
static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_kind), MP_ROM_PTR(&synthio_block_biquad_kind_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&synthio_block_biquad_mode_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&synthio_block_biquad_frequency_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_q_factor), MP_ROM_PTR(&synthio_block_biquad_q_factor_obj) },
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
#include "py/obj.h"
|
||||
|
||||
extern const mp_obj_type_t synthio_block_biquad_type_obj;
|
||||
extern const mp_obj_type_t synthio_filter_type;
|
||||
extern const mp_obj_type_t synthio_filter_mode_type;
|
||||
typedef struct synthio_block_biquad synthio_block_biquad_t;
|
||||
|
||||
typedef enum {
|
||||
SYNTHIO_LOW_PASS, SYNTHIO_HIGH_PASS, SYNTHIO_BAND_PASS
|
||||
} synthio_filter_e;
|
||||
} synthio_filter_mode;
|
||||
|
||||
|
||||
mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self);
|
||||
|
|
@ -23,6 +23,6 @@ void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self,
|
|||
mp_obj_t common_hal_synthio_block_biquad_get_frequency(synthio_block_biquad_t *self);
|
||||
void common_hal_synthio_block_biquad_set_frequency(synthio_block_biquad_t *self, mp_obj_t frequency);
|
||||
|
||||
synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t *self);
|
||||
synthio_filter_mode common_hal_synthio_block_biquad_get_mode(synthio_block_biquad_t *self);
|
||||
|
||||
mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t frequency, mp_obj_t Q);
|
||||
mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_mode mode, mp_obj_t frequency, mp_obj_t Q);
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ static const mp_rom_map_elem_t synthio_module_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_synthio) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Biquad), MP_ROM_PTR(&synthio_biquad_type_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BlockBiquad), MP_ROM_PTR(&synthio_block_biquad_type_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_FilterType), MP_ROM_PTR(&synthio_filter_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_FilterMode), MP_ROM_PTR(&synthio_filter_mode_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Math), MP_ROM_PTR(&synthio_math_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MathOperation), MP_ROM_PTR(&synthio_math_operation_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MidiTrack), MP_ROM_PTR(&synthio_miditrack_type) },
|
||||
|
|
|
|||
|
|
@ -30,16 +30,16 @@ static void fast_sincos(mp_float_t theta, sincos_result_t *result) {
|
|||
result->s = evens - odds;
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t f0, mp_obj_t Q) {
|
||||
mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_mode mode, mp_obj_t f0, mp_obj_t Q) {
|
||||
synthio_block_biquad_t *self = mp_obj_malloc(synthio_block_biquad_t, &synthio_block_biquad_type_obj);
|
||||
self->kind = kind;
|
||||
self->mode = mode;
|
||||
synthio_block_assign_slot(f0, &self->f0, MP_QSTR_frequency);
|
||||
synthio_block_assign_slot(Q, &self->Q, MP_QSTR_q_factor);
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t *self) {
|
||||
return self->kind;
|
||||
synthio_filter_mode common_hal_synthio_block_biquad_get_mode(synthio_block_biquad_t *self) {
|
||||
return self->mode;
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self) {
|
||||
|
|
@ -79,7 +79,7 @@ void common_hal_synthio_block_biquad_tick(mp_obj_t self_in, biquad_filter_state
|
|||
a1 = -2 * sc.c;
|
||||
a2 = 1 - alpha;
|
||||
|
||||
switch (self->kind) {
|
||||
switch (self->mode) {
|
||||
default:
|
||||
case SYNTHIO_LOW_PASS:
|
||||
b2 = b0 = (1 - sc.c) * .5;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
typedef struct synthio_block_biquad {
|
||||
mp_obj_base_t base;
|
||||
synthio_filter_e kind;
|
||||
synthio_filter_mode mode;
|
||||
synthio_block_slot_t f0, Q;
|
||||
} synthio_block_biquad_t;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ def synthesize(synth):
|
|||
|
||||
for biquad in (
|
||||
None,
|
||||
synthio.BlockBiquad(synthio.FilterType.LOW_PASS, freq_sweep),
|
||||
synthio.BlockBiquad(synthio.FilterType.HIGH_PASS, freq_sweep),
|
||||
synthio.BlockBiquad(synthio.FilterType.BAND_PASS, freq_sweep, Q=8),
|
||||
synthio.BlockBiquad(synthio.FilterMode.LOW_PASS, freq_sweep),
|
||||
synthio.BlockBiquad(synthio.FilterMode.HIGH_PASS, freq_sweep),
|
||||
synthio.BlockBiquad(synthio.FilterMode.BAND_PASS, freq_sweep, Q=8),
|
||||
):
|
||||
n = synthio.Note(
|
||||
frequency=synthio.midi_to_hz(72),
|
||||
|
|
|
|||
Loading…
Reference in a new issue