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
2632MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , LOW_PASS , SYNTHIO_LOW_PASS );
2733MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , HIGH_PASS , SYNTHIO_HIGH_PASS );
2834MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , BAND_PASS , SYNTHIO_BAND_PASS );
2935MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , NOTCH , SYNTHIO_NOTCH );
36+ MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , LOW_SHELF , SYNTHIO_LOW_SHELF );
37+ MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , HIGH_SHELF , SYNTHIO_HIGH_SHELF );
38+ MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , PEAKING_EQ , SYNTHIO_PEAKING_EQ );
3039
3140MAKE_ENUM_MAP (synthio_filter_mode ) {
3241 MAKE_ENUM_MAP_ENTRY (mode , LOW_PASS ),
3342 MAKE_ENUM_MAP_ENTRY (mode , HIGH_PASS ),
3443 MAKE_ENUM_MAP_ENTRY (mode , BAND_PASS ),
3544 MAKE_ENUM_MAP_ENTRY (mode , NOTCH ),
45+ MAKE_ENUM_MAP_ENTRY (mode , LOW_SHELF ),
46+ MAKE_ENUM_MAP_ENTRY (mode , HIGH_SHELF ),
47+ MAKE_ENUM_MAP_ENTRY (mode , PEAKING_EQ ),
3648};
3749
3850static MP_DEFINE_CONST_DICT (synthio_filter_mode_locals_dict , synthio_filter_mode_locals_table );
@@ -51,8 +63,17 @@ static synthio_filter_mode validate_synthio_filter_mode(mp_obj_t obj, qstr arg_n
5163//| mode: FilterMode,
5264//| frequency: BlockInput,
5365//| Q: BlockInput = 0.7071067811865475,
66+ //| A: BlockInput = None,
5467//| ) -> None:
55- //| """Construct a biquad filter object with dynamic center frequency & q factor
68+ //| """Construct a biquad filter object with given settings.
69+ //|
70+ //| ``frequency`` gives the center frequency or corner frequency of the filter,
71+ //| depending on the mode.
72+ //|
73+ //| ``Q`` gives the gain or sharpness of the filter.
74+ //|
75+ //| ``A`` controls the gain of peaking and shelving filters according to the
76+ //| formula ``A = 10^(dBgain/40)``. For other filter types it is ignored.
5677//|
5778//| Since ``frequency`` and ``Q`` are `BlockInput` objects, they can
5879//| be varied dynamically. Internally, this is evaluated as "direct form 1"
@@ -68,6 +89,7 @@ static const mp_arg_t block_biquad_properties[] = {
6889 { MP_QSTR_mode , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
6990 { MP_QSTR_frequency , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
7091 { MP_QSTR_Q , MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
92+ { MP_QSTR_A , MP_ARG_OBJ , {.u_obj = MP_ROM_NONE } },
7193};
7294
7395static 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 ) {
@@ -138,10 +160,35 @@ MP_PROPERTY_GETSET(synthio_block_biquad_Q_obj,
138160 (mp_obj_t )& synthio_block_biquad_get_Q_obj ,
139161 (mp_obj_t )& synthio_block_biquad_set_Q_obj );
140162
163+ //|
164+ //| A: BlockInput
165+ //| """The gain (A) of the filter
166+ //|
167+ //| This setting only has an effect for peaking and shelving EQ filters. It is related
168+ //| to the filter gain according to the formula ``A = 10^(dBgain/40)``.
169+ //| """
170+ //|
171+ static mp_obj_t synthio_block_biquad_get_A (mp_obj_t self_in ) {
172+ synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
173+ return common_hal_synthio_block_biquad_get_A (self );
174+ }
175+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_block_biquad_get_A_obj , synthio_block_biquad_get_A );
176+
177+ static mp_obj_t synthio_block_biquad_set_A (mp_obj_t self_in , mp_obj_t arg ) {
178+ synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
179+ common_hal_synthio_block_biquad_set_A (self , arg );
180+ return mp_const_none ;
181+ }
182+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_block_biquad_set_A_obj , synthio_block_biquad_set_A );
183+ MP_PROPERTY_GETSET (synthio_block_biquad_A_obj ,
184+ (mp_obj_t )& synthio_block_biquad_get_A_obj ,
185+ (mp_obj_t )& synthio_block_biquad_set_A_obj );
186+
141187static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table [] = {
142188 { MP_ROM_QSTR (MP_QSTR_mode ), MP_ROM_PTR (& synthio_block_biquad_mode_obj ) },
143189 { MP_ROM_QSTR (MP_QSTR_frequency ), MP_ROM_PTR (& synthio_block_biquad_frequency_obj ) },
144190 { MP_ROM_QSTR (MP_QSTR_Q ), MP_ROM_PTR (& synthio_block_biquad_Q_obj ) },
191+ { MP_ROM_QSTR (MP_QSTR_A ), MP_ROM_PTR (& synthio_block_biquad_A_obj ) },
145192};
146193static MP_DEFINE_CONST_DICT (synthio_block_biquad_locals_dict , synthio_block_biquad_locals_dict_table ) ;
147194
0 commit comments