Skip to content

Commit

Permalink
BlockBiquad: Use Q as argument name
Browse files Browse the repository at this point in the history
Synthesizer.lpf takes `Q` as the argument name, use the same convention
here.
  • Loading branch information
jepler committed Nov 7, 2024
1 parent 6ff3860 commit c06e6ee
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ CHIP_FAMILY = rp2
EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ"

CIRCUITPY__EVE = 1
CIRCUITPY_SSL = 1
28 changes: 14 additions & 14 deletions shared-bindings/synthio/BlockBiquad.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ static synthio_filter_mode validate_synthio_filter_mode(mp_obj_t obj, qstr arg_n
//| self,
//| mode: FilterMode,
//| frequency: BlockInput,
//| q_factor: BlockInput = 0.7071067811865475,
//| Q: BlockInput = 0.7071067811865475,
//| ) -> None:
//| """Construct a biquad filter object with dynamic center frequency & q factor
//|
//| Since ``frequency`` and ``q_factor`` are `BlockInput` objects, they can
//| Since ``frequency`` and ``Q`` are `BlockInput` objects, they can
//| be varied dynamically. Internally, this is evaluated as "direct form 1"
//| biquad filter.
//|
Expand Down Expand Up @@ -115,29 +115,29 @@ MP_PROPERTY_GETSET(synthio_block_biquad_frequency_obj,


//|
//| q_factor: BlockInput
//| """The sharpness (q_factor) of the filter"""
//| Q: BlockInput
//| """The sharpness (Q) of the filter"""
//|
static mp_obj_t synthio_block_biquad_get_q_factor(mp_obj_t self_in) {
static mp_obj_t synthio_block_biquad_get_Q(mp_obj_t self_in) {
synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in);
return common_hal_synthio_block_biquad_get_q_factor(self);
return common_hal_synthio_block_biquad_get_Q(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_q_factor_obj, synthio_block_biquad_get_q_factor);
MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_Q_obj, synthio_block_biquad_get_Q);

static mp_obj_t synthio_block_biquad_set_q_factor(mp_obj_t self_in, mp_obj_t arg) {
static mp_obj_t synthio_block_biquad_set_Q(mp_obj_t self_in, mp_obj_t arg) {
synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_synthio_block_biquad_set_q_factor(self, arg);
common_hal_synthio_block_biquad_set_Q(self, arg);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_q_factor_obj, synthio_block_biquad_set_q_factor);
MP_PROPERTY_GETSET(synthio_block_biquad_q_factor_obj,
(mp_obj_t)&synthio_block_biquad_get_q_factor_obj,
(mp_obj_t)&synthio_block_biquad_set_q_factor_obj);
MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_Q_obj, synthio_block_biquad_set_Q);
MP_PROPERTY_GETSET(synthio_block_biquad_Q_obj,
(mp_obj_t)&synthio_block_biquad_get_Q_obj,
(mp_obj_t)&synthio_block_biquad_set_Q_obj);

static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table[] = {
{ 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) },
{ MP_ROM_QSTR(MP_QSTR_Q), MP_ROM_PTR(&synthio_block_biquad_Q_obj) },
};
static MP_DEFINE_CONST_DICT(synthio_block_biquad_locals_dict, synthio_block_biquad_locals_dict_table);

Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/synthio/BlockBiquad.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ typedef enum {
} synthio_filter_mode;


mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self);
void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self, mp_obj_t Q);
mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self);
void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q);

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);
Expand Down
8 changes: 4 additions & 4 deletions shared-module/synthio/BlockBiquad.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_mode mode, mp_obj_t
synthio_block_biquad_t *self = mp_obj_malloc(synthio_block_biquad_t, &synthio_block_biquad_type_obj);
self->mode = mode;
synthio_block_assign_slot(f0, &self->f0, MP_QSTR_frequency);
synthio_block_assign_slot(Q, &self->Q, MP_QSTR_q_factor);
synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q);
return MP_OBJ_FROM_PTR(self);
}

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) {
mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self) {
return self->Q.obj;
}

void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self, mp_obj_t q_factor) {
synthio_block_assign_slot(q_factor, &self->Q, MP_QSTR_q_factor);
void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q) {
synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q);
}

mp_obj_t common_hal_synthio_block_biquad_get_frequency(synthio_block_biquad_t *self) {
Expand Down
2 changes: 1 addition & 1 deletion tests/circuitpython/synthio_block_biquad.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def gen(synth):
l = LFO(sweep, offset=1440, scale=2880, rate=.025, once=True)
yield [l]
b = BlockBiquad(FilterMode.LOW_PASS, l)
b = BlockBiquad(FilterMode.LOW_PASS, l, Q=.5**.5)
n = Note(100, filter=b, waveform=white_noise)
synth.press(n)
yield 20

0 comments on commit c06e6ee

Please sign in to comment.