11
11
#include "shared-bindings/util.h"
12
12
13
13
//| class FilterType:
14
+ //| """The type of filter"""
15
+ //|
14
16
//| LOW_PASS: FilterType
17
+ //| """A low-pass filter"""
15
18
//| HIGH_PASS: FilterType
19
+ //| """A high-pass filter"""
16
20
//| BAND_PASS: FilterType
21
+ //| """A band-pass filter"""
17
22
//|
18
23
19
24
MAKE_ENUM_VALUE (synthio_filter_type , kind , LOW_PASS , SYNTHIO_LOW_PASS );
@@ -37,16 +42,28 @@ static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) {
37
42
}
38
43
39
44
//| class BlockBiquad:
40
- //| def _init__(kind: FilterKind, f0: BlockInput, Q: BlockInput = 0.7071067811865475): ...
45
+ //| def __init__(
46
+ //| kind: FilterKind, frequency: BlockInput, q_factor: BlockInput = 0.7071067811865475
47
+ //| ):
48
+ //| """Construct a biquad filter object with dynamic center frequency & q factor
49
+ //|
50
+ //| Since ``frequency`` and ``q_factor`` are `BlockInput`s, they can be varied dynamically.
51
+ //| Internally, this is evaluated as "direct form 1" biquad filter.
52
+ //|
53
+ //| The internal filter state x[] and y[] is not updated when the filter
54
+ //| coefficients change, and there is no theoretical justification for why
55
+ //| this should result in a stable filter output. However, in practice,
56
+ //| slowly varying the filter's characteristic frequency and sharpness
57
+ //| appears to work as you'd expect."""
41
58
42
59
static const mp_arg_t block_biquad_properties [] = {
43
60
{ MP_QSTR_kind , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
44
- { MP_QSTR_f0 , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
61
+ { MP_QSTR_frequency , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_obj = MP_OBJ_NULL } },
45
62
{ MP_QSTR_Q , MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
46
63
};
47
64
48
65
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 ) {
49
- enum { ARG_kind , ARG_f0 , ARG_Q };
66
+ enum { ARG_kind , ARG_frequency , ARG_Q };
50
67
51
68
mp_arg_val_t args [MP_ARRAY_SIZE (block_biquad_properties )];
52
69
mp_arg_parse_all_kw_array (n_args , n_kw , all_args , MP_ARRAY_SIZE (block_biquad_properties ), block_biquad_properties , args );
@@ -56,7 +73,7 @@ static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size
56
73
}
57
74
58
75
synthio_filter_e kind = validate_synthio_filter (args [ARG_kind ].u_obj , MP_QSTR_kind );
59
- return common_hal_synthio_block_biquad_new (kind , args [ARG_f0 ].u_obj , args [ARG_Q ].u_obj );
76
+ return common_hal_synthio_block_biquad_new (kind , args [ARG_frequency ].u_obj , args [ARG_Q ].u_obj );
60
77
}
61
78
62
79
//|
@@ -72,49 +89,49 @@ MP_PROPERTY_GETTER(synthio_block_biquad_kind_obj,
72
89
(mp_obj_t )& synthio_block_biquad_get_kind_obj );
73
90
74
91
//|
75
- //| f0 : BlockInput
92
+ //| frequency : BlockInput
76
93
//| """The central frequency (in Hz) of the filter"""
77
- static mp_obj_t synthio_block_biquad_get_f0 (mp_obj_t self_in ) {
94
+ static mp_obj_t synthio_block_biquad_get_frequency (mp_obj_t self_in ) {
78
95
synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
79
- return common_hal_synthio_block_biquad_get_f0 (self );
96
+ return common_hal_synthio_block_biquad_get_frequency (self );
80
97
}
81
- MP_DEFINE_CONST_FUN_OBJ_1 (synthio_block_biquad_get_f0_obj , synthio_block_biquad_get_f0 );
98
+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_block_biquad_get_frequency_obj , synthio_block_biquad_get_frequency );
82
99
83
- static mp_obj_t synthio_block_biquad_set_f0 (mp_obj_t
67F4
span> self_in , mp_obj_t arg ) {
100
+ static mp_obj_t synthio_block_biquad_set_frequency (mp_obj_t self_in , mp_obj_t arg ) {
84
101
synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
85
- common_hal_synthio_block_biquad_set_f0 (self , arg );
102
+ common_hal_synthio_block_biquad_set_frequency (self , arg );
86
103
return mp_const_none ;
87
104
}
88
- MP_DEFINE_CONST_FUN_OBJ_2 (synthio_block_biquad_set_f0_obj , synthio_block_biquad_set_f0 );
89
- MP_PROPERTY_GETSET (synthio_block_biquad_f0_obj ,
90
- (mp_obj_t )& synthio_block_biquad_get_f0_obj ,
91
- (mp_obj_t )& synthio_block_biquad_set_f0_obj );
105
+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_block_biquad_set_frequency_obj , synthio_block_biquad_set_frequency );
106
+ MP_PROPERTY_GETSET (synthio_block_biquad_frequency_obj ,
107
+ (mp_obj_t )& synthio_block_biquad_get_frequency_obj ,
108
+ (mp_obj_t )& synthio_block_biquad_set_frequency_obj );
92
109
93
110
94
111
//|
95
- //| Q : BlockInput
96
- //| """The sharpness (Q ) of the filter"""
112
+ //| q_factor : BlockInput
113
+ //| """The sharpness (q_factor ) of the filter"""
97
114
//|
98
- static mp_obj_t synthio_block_biquad_get_Q (mp_obj_t self_in ) {
115
+ static mp_obj_t synthio_block_biquad_get_q_factor (mp_obj_t self_in ) {
99
116
synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
100
- return common_hal_synthio_block_biquad_get_Q (self );
117
+ return common_hal_synthio_block_biquad_get_q_factor (self );
101
118
}
102
- MP_DEFINE_CONST_FUN_OBJ_1 (synthio_block_biquad_get_Q_obj , synthio_block_biquad_get_Q );
119
+ MP_DEFINE_CONST_FUN_OBJ_1 (synthio_block_biquad_get_q_factor_obj , synthio_block_biquad_get_q_factor );
103
120
104
- static mp_obj_t synthio_block_biquad_set_Q (mp_obj_t self_in , mp_obj_t arg ) {
121
+ static mp_obj_t synthio_block_biquad_set_q_factor (mp_obj_t self_in , mp_obj_t arg ) {
105
122
synthio_block_biquad_t * self = MP_OBJ_TO_PTR (self_in );
106
- common_hal_synthio_block_biquad_set_Q (self , arg );
123
+ common_hal_synthio_block_biquad_set_q_factor (self , arg );
107
124
return mp_const_none ;
108
125
}
109
- MP_DEFINE_CONST_FUN_OBJ_2 (synthio_block_biquad_set_Q_obj , synthio_block_biquad_set_Q );
110
- MP_PROPERTY_GETSET (synthio_block_biquad_Q_obj ,
111
- (mp_obj_t )& synthio_block_biquad_get_Q_obj ,
112
- (mp_obj_t )& synthio_block_biquad_set_Q_obj );
126
+ MP_DEFINE_CONST_FUN_OBJ_2 (synthio_block_biquad_set_q_factor_obj , synthio_block_biquad_set_q_factor );
127
+ MP_PROPERTY_GETSET (synthio_block_biquad_q_factor_obj ,
128
+ (mp_obj_t )& synthio_block_biquad_get_q_factor_obj ,
129
+ (mp_obj_t )& synthio_block_biquad_set_q_factor_obj );
113
130
114
131
static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table [] = {
115
132
{ MP_ROM_QSTR (MP_QSTR_kind ), MP_ROM_PTR (& synthio_block_biquad_kind_obj ) },
116
- { MP_ROM_QSTR (MP_QSTR_f0 ), MP_ROM_PTR (& synthio_block_biquad_f0_obj ) },
117
- { MP_ROM_QSTR (MP_QSTR_Q ), MP_ROM_PTR (& synthio_block_biquad_Q_obj ) },
133
+ { MP_ROM_QSTR (MP_QSTR_frequency ), MP_ROM_PTR (& synthio_block_biquad_frequency_obj ) },
134
+ { MP_ROM_QSTR (MP_QSTR_q_factor ), MP_ROM_PTR (& synthio_block_biquad_q_factor_obj ) },
118
135
};
119
136
static MP_DEFINE_CONST_DICT (synthio_block_biquad_locals_dict , synthio_block_biquad_locals_dict_table ) ;
120
137
0 commit comments