21
21
//| """A band-pass filter"""
22
22
//| NOTCH: FilterMode
23
23
//| """A notch filter"""
24
+ //| LOW_SHELF: FilterMode
25
+ //| """A low shelf filter"""
26
+ //| HIGH_SHELF: FilterMode
27
+ //| """A high shelf filter"""
28
+ //| PEAKING_EQ: FilterMode
29
+ //| """A peaking equalizer filter"""
24
30
//|
25
31
//|
26
32
27
33
MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , LOW_PASS , SYNTHIO_LOW_PASS );
28
34
MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , HIGH_PASS , SYNTHIO_HIGH_PASS );
29
35
MAKE_ENUM_VALUE (synthio_filter_mode_type , mode , BAND_PASS , SYNTHIO_BAND_PASS );
30
36
MAKE_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 );
31
40
32
41
MAKE_ENUM_MAP (synthio_filter_mode ) {
33
42
MAKE_ENUM_MAP_ENTRY (mode , LOW_PASS ),
34
43
MAKE_ENUM_MAP_ENTRY (mode , HIGH_PASS ),
35
44
MAKE_ENUM_MAP_ENTRY (mode , BAND_PASS ),
36
45
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 ),
37
49
};
38
50
39
51
static 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
52
64
//| mode: FilterMode,
53
65
//| frequency: BlockInput,
54
66
//| Q: BlockInput = 0.7071067811865475,
67
+ //| A: BlockInput = None,
55
68
//| ) -> 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.
57
78
//|
58
79
//| Since ``frequency`` and ``Q`` are `BlockInput` objects, they can
59
80
//| be varied dynamically. Internally, this is evaluated as "direct form 1"
@@ -70,6 +91,7 @@ static const mp_arg_t block_biquad_properties[] = {
70
91
{ MP_QSTR_mode , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
71
92
{ MP_QSTR_frequency , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
72
93
{ MP_QSTR_Q , MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
94
+ { MP_QSTR_A , MP_ARG_OBJ , {.u_obj = MP_ROM_NONE } },
73
95
};
74
96
75
97
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 ) {
@@ -83,7 +105,9 @@ static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size
83
105
}
84
106
85
107
synthio_filter_mode mode = validate_synthio_filter_mode (args [ARG_mode ].u_obj , MP_QSTR_mode );
86
- return common_hal_synthio_block_biquad_new (mode , args [ARG_frequency ].u_obj , args [ARG_Q ].u_obj );
108
+ mp_obj_t result = common_hal_synthio_block_biquad_new (mode );
109
+ properties_construct_helper (result , block_biquad_properties + 1 , args + 1 , MP_ARRAY_SIZE (block_biquad_properties ) - 1 );
110
+ return result ;
87
111
}
88
112
89
113
//|
@@ -122,7 +146,6 @@ MP_PROPERTY_GETSET(synthio_block_biquad_frequency_obj,
122
146
//| Q: BlockInput
123
147
//| """The sharpness (Q) of the filter"""
124
148
//|
125
- //|
126
149
static mp_obj_t synthio_block_biquad_get_Q (mp_obj_t self_in ) {
127
150
synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
128
151
return common_hal_synthio_block_biquad_get_Q (self );
@@ -139,10 +162,36 @@ MP_PROPERTY_GETSET(synthio_block_biquad_Q_obj,
139
162
(mp_obj_t )& synthio_block_biquad_get_Q_obj ,
140
163
(mp_obj_t )& synthio_block_biquad_set_Q_obj );
141
164
165
+ //|
166
+ //| A: BlockInput
167
+ //| """The gain (A) of the filter
168
+ //|
169
+ //| This setting only has an effect for peaking and shelving EQ filters. It is related
170
+ //| to the filter gain according to the formula ``A = 10^(dBgain/40)``.
171
+ //| """
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
+
142
190
static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table [] = {
143
191
{ MP_ROM_QSTR (MP_QSTR_mode ), MP_ROM_PTR (& synthio_block_biquad_mode_obj ) },
144
192
{ MP_ROM_QSTR (MP_QSTR_frequency ), MP_ROM_PTR (& synthio_block_biquad_frequency_obj ) },
145
193
{ 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 ) },
146
195
};
147
196
static MP_DEFINE_CONST_DICT (synthio_block_biquad_locals_dict , synthio_block_biquad_locals_dict_table ) ;
148
197
0 commit comments