2121//| """A band-pass filter"""
2222//| NOTCH: FilterMode
2323//| """A notch filter"""
24+ //| LOW_SHELF: FilterMode
25+ //| """A notch filter"""
26+ //| HIGH_SHELF: FilterMode
27+ //| """A notch filter"""
28+ //| PEAKING_EQ: FilterMode
29+ //| """A notch filter"""
2430//|
2531//|
2632
2733MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , LOW_PASS , SYNTHIO_LOW_PASS );
2834MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , HIGH_PASS , SYNTHIO_HIGH_PASS );
2935MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , BAND_PASS , SYNTHIO_BAND_PASS );
3036MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , NOTCH , SYNTHIO_NOTCH );
37+ MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , LOW_SHELF , SYNTHIO_LOW_SHELF );
38+ MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , HIGH_SHELF , SYNTHIO_HIGH_SHELF );
39+ MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , PEAKING_EQ , SYNTHIO_PEAKING_EQ );
3140
3241MAKE_ENUM_MAP (synthio_filter_mode ) {
3342 MAKE_ENUM_MAP_ENTRY (mode , LOW_PASS ),
3443 MAKE_ENUM_MAP_ENTRY (mode , HIGH_PASS ),
3544 MAKE_ENUM_MAP_ENTRY (mode , BAND_PASS ),
3645 MAKE_ENUM_MAP_ENTRY (mode , NOTCH ),
46+ MAKE_ENUM_MAP_ENTRY (mode , LOW_SHELF ),
47+ MAKE_ENUM_MAP_ENTRY (mode , HIGH_SHELF ),
48+ MAKE_ENUM_MAP_ENTRY (mode , PEAKING_EQ ),
3749};
3850
3951static MP_DEFINE_CONST_DICT (synthio_filter_mode_locals_dict , synthio_filter_mode_locals_table );
@@ -52,8 +64,17 @@ static synthio_filter_mode validate_synthio_filter_mode(mp_obj_t obj, qstr arg_n
5264//| mode: FilterMode,
5365//| frequency: BlockInput,
5466//| Q: BlockInput = 0.7071067811865475,
67+ //| A: BlockInput = None,
5568//| ) -> None:
56- //| """Construct a biquad filter object with dynamic center frequency & q factor
69+ //| """Construct a biquad filter object with given settings.
70+ //|
71+ //| ``frequency`` gives the center frequency or corner frequency of the filter,
72+ //| depending on the mode.
73+ //|
74+ //| ``Q`` gives the gain or sharpness of the filter.
75+ //|
76+ //| ``A`` controls the gain of peaking and shelving filters according to the
77+ //| formula ``A = 10^(dBgain/40)``. For other filter types it is ignored.
5778//|
5879//| Since ``frequency`` and ``Q`` are `BlockInput` objects, they can
5980//| be varied dynamically. Internally, this is evaluated as "direct form 1"
@@ -70,6 +91,7 @@ static const mp_arg_t block_biquad_properties[] = {
7091 { MP_QSTR_mode , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
7192 { MP_QSTR_frequency , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
7293 { MP_QSTR_Q , MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
94+ { MP_QSTR_A , MP_ARG_OBJ , {.u_obj = MP_ROM_NONE } },
7395};
7496
7597static 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 ) {
@@ -141,10 +163,35 @@ MP_PROPERTY_GETSET(synthio_block_biquad_Q_obj,
141163 (mp_obj_t )& synthio_block_biquad_get_Q_obj ,
142164 (mp_obj_t )& synthio_block_biquad_set_Q_obj );
143165
166+ //|
167+ //| A: BlockInput
168+ //| """The gain (A) of the filter
169+ //|
170+ //| This setting only has an effect for peaking and shelving EQ filters. It is related
171+ //| to the filter gain according to the formula ``A = 10^(dBgain/40)``.
172+ //| """
173+ //|
174+ static mp_obj_t synthio_block_biquad_get_A (mp_obj_t self_in ) {
175+ synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
176+ return common_hal_synthio_block_biquad_get_A (self );
177+ }
178+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_block_biquad_get_A_obj , synthio_block_biquad_get_A );
179+
180+ static mp_obj_t synthio_block_biquad_set_A (mp_obj_t self_in , mp_obj_t arg ) {
181+ synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
182+ common_hal_synthio_block_biquad_set_A (self , arg );
183+ return mp_const_none ;
184+ }
185+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_block_biquad_set_A_obj , synthio_block_biquad_set_A );
186+ MP_PROPERTY_GETSET (synthio_block_biquad_A_obj ,
187+ (mp_obj_t )& synthio_block_biquad_get_A_obj ,
188+ (mp_obj_t )& synthio_block_biquad_set_A_obj );
189+
144190static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table [] = {
145191 { MP_ROM_QSTR (MP_QSTR_mode ), MP_ROM_PTR (& synthio_block_biquad_mode_obj ) },
146192 { MP_ROM_QSTR (MP_QSTR_frequency ), MP_ROM_PTR (& synthio_block_biquad_frequency_obj ) },
147193 { MP_ROM_QSTR (MP_QSTR_Q ), MP_ROM_PTR (& synthio_block_biquad_Q_obj ) },
194+ { MP_ROM_QSTR (MP_QSTR_A ), MP_ROM_PTR (& synthio_block_biquad_A_obj ) },
148195};
149196static MP_DEFINE_CONST_DICT (synthio_block_biquad_locals_dict , synthio_block_biquad_locals_dict_table ) ;
150197
0 commit comments