23
23
//|
24
24
//| def __init__(
25
25
//| self,
26
- //| filter : Optional[synthio.Biquad] = None,
26
+ //| filters : Optional[List[ synthio.Biquad] ] = None,
27
27
//| mix: synthio.BlockInput = 1.0,
28
28
//| buffer_size: int = 512,
29
29
//| sample_rate: int = 8000,
38
38
//| The mix parameter allows you to change how much of the unchanged sample passes through to
39
39
//| the output to how much of the effect audio you hear as the output.
40
40
//|
41
- //| :param Optional[synthio.Biquad] filter: The normalized biquad filter object used to process the signal.
41
+ //| :param Optional[List[ synthio.Biquad]] filters: A list of normalized biquad filter objects used to process the signal.
42
42
//| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0).
43
43
//| :param int buffer_size: The total size in bytes of each of the two playback buffers to use
44
44
//| :param int sample_rate: The sample rate to be used
56
56
//|
57
57
//| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
58
58
//| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
59
- //| filter = audiofilters.Filter(filter=synth.low_pass_filter(frequency=2000, Q=1.25), buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0)
60
- //| filter.play(synth)
61
- //| audio.play(filter)
59
+ //| effect = audiofilters.Filter(buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0)
60
+ //| effect.filters.append(synth.low_pass_filter(frequency=2000, Q=1.25))
61
+ //| effect.play(synth)
62
+ //| audio.play(effect)
62
63
//|
63
64
//| note = synthio.Note(261)
64
65
//| while True:
68
69
//| time.sleep(5)"""
69
70
//| ...
70
71
static mp_obj_t audiofilters_filter_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
71
- enum { ARG_filter , ARG_mix , ARG_buffer_size , ARG_sample_rate , ARG_bits_per_sample , ARG_samples_signed , ARG_channel_count , };
72
+ enum { ARG_filters , ARG_mix , ARG_buffer_size , ARG_sample_rate , ARG_bits_per_sample , ARG_samples_signed , ARG_channel_count , };
72
73
static const mp_arg_t allowed_args [] = {
73
- { MP_QSTR_filter , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
74
+ { MP_QSTR_filters , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
74
75
{ MP_QSTR_mix , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
75
76
{ MP_QSTR_buffer_size , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 512 } },
76
77
{ MP_QSTR_sample_rate , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 8000 } },
@@ -90,7 +91,7 @@ static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n
90
91
}
91
92
92
93
audiofilters_filter_obj_t * self = mp_obj_malloc (audiofilters_filter_obj_t , & audiofilters_filter_type );
93
- common_hal_audiofilters_filter_construct (self , args [ARG_filter ].u_obj , args [ARG_mix ].u_obj , args [ARG_buffer_size ].u_int , bits_per_sample , args [ARG_samples_signed ].u_bool , channel_count , sample_rate );
94
+ common_hal_audiofilters_filter_construct (self , args [ARG_filters ].u_obj , args [ARG_mix ].u_obj , args [ARG_buffer_size ].u_int , bits_per_sample , args [ARG_samples_signed ].u_bool , channel_count , sample_rate );
94
95
95
96
return MP_OBJ_FROM_PTR (self );
96
97
}
@@ -128,31 +129,34 @@ static mp_obj_t audiofilters_filter_obj___exit__(size_t n_args, const mp_obj_t *
128
129
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audiofilters_filter___exit___obj , 4 , 4 , audiofilters_filter_obj___exit__ ) ;
129
130
130
131
131
- //| filter: Optional[synthio.Biquad]
132
- //| """The normalized biquad filter object used to process the signal."""
133
- static mp_obj_t audiofilters_filter_obj_get_filter (mp_obj_t self_in ) {
134
- return common_hal_audiofilters_filter_get_filter (self_in );
132
+ //| filters: List[synthio.Biquad]
133
+ //| """A list of normalized biquad filter objects used to process the signal."""
134
+ //|
135
+ static mp_obj_t audiofilters_filter_obj_get_filters (mp_obj_t self_in ) {
136
+ audiofilters_filter_obj_t * self = MP_OBJ_TO_PTR (self_in );
137
+ check_for_deinit (self );
138
+ return common_hal_audiofilters_filter_get_filters (self );
135
139
}
136
- MP_DEFINE_CONST_FUN_OBJ_1 (audiofilters_filter_get_filter_obj , audiofilters_filter_obj_get_filter );
140
+ MP_DEFINE_CONST_FUN_OBJ_1 (audiofilters_filter_get_filters_obj , audiofilters_filter_obj_get_filters );
137
141
138
- static mp_obj_t audiofilters_filter_obj_set_filter (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
139
- enum { ARG_filter };
142
+ static mp_obj_t audiofilters_filter_obj_set_filters (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
143
+ enum { ARG_filters };
140
144
static const mp_arg_t allowed_args [] = {
141
- { MP_QSTR_filter , MP_ARG_OBJ | MP_ARG_REQUIRED , {} },
145
+ { MP_QSTR_filters , MP_ARG_OBJ | MP_ARG_REQUIRED , {} },
142
146
};
143
147
audiofilters_filter_obj_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
144
148
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
145
149
mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
146
150
147
- common_hal_audiofilters_filter_set_filter (self , args [ARG_filter ].u_obj );
151
+ common_hal_audiofilters_filter_set_filters (self , args [ARG_filters ].u_obj );
148
152
149
153
return mp_const_none ;
150
154
}
151
- MP_DEFINE_CONST_FUN_OBJ_KW (audiofilters_filter_set_filter_obj , 1 , audiofilters_filter_obj_set_filter );
155
+ MP_DEFINE_CONST_FUN_OBJ_KW (audiofilters_filter_set_filters_obj , 1 , audiofilters_filter_obj_set_filters );
152
156
153
- MP_PROPERTY_GETSET (audiofilters_filter_filter_obj ,
154
- (mp_obj_t )& audiofilters_filter_get_filter_obj ,
155
- (mp_obj_t )& audiofilters_filter_set_filter_obj );
157
+ MP_PROPERTY_GETSET (audiofilters_filter_filters_obj ,
158
+ (mp_obj_t )& audiofilters_filter_get_filters_obj ,
159
+ (mp_obj_t )& audiofilters_filter_set_filters_obj );
156
160
157
161
158
162
//| mix: synthio.BlockInput
@@ -241,7 +245,7 @@ static const mp_rom_map_elem_t audiofilters_filter_locals_dict_table[] = {
241
245
242
246
// Properties
243
247
{ MP_ROM_QSTR (MP_QSTR_playing ), MP_ROM_PTR (& audiofilters_filter_playing_obj ) },
244
- { MP_ROM_QSTR (MP_QSTR_filter ), MP_ROM_PTR (& audiofilters_filter_filter_obj ) },
248
+ { MP_ROM_QSTR (MP_QSTR_filters ), MP_ROM_PTR (& audiofilters_filter_filters_obj ) },
245
249
{ MP_ROM_QSTR (MP_QSTR_mix ), MP_ROM_PTR (& audiofilters_filter_mix_obj ) },
246
250
};
247
251
static MP_DEFINE_CONST_DICT (audiofilters_filter_locals_dict , audiofilters_filter_locals_dict_table ) ;
0 commit comments