@@ -63,6 +63,7 @@ static audiofilters_distortion_mode validate_distortion_mode(mp_obj_t obj, qstr
63
63
//| pre_gain: synthio.BlockInput = 0.0,
64
64
//| post_gain: synthio.BlockInput = 0.0,
65
65
//| mode: DistortionMode = DistortionMode.CLIP,
66
+ //| soft_clip: bool = False,
66
67
//| mix: synthio.BlockInput = 1.0,
67
68
//| buffer_size: int = 512,
68
69
//| sample_rate: int = 8000,
@@ -81,6 +82,7 @@ static audiofilters_distortion_mode validate_distortion_mode(mp_obj_t obj, qstr
81
82
//| :param synthio.BlockInput pre_gain: Increases or decreases the volume before the effect, in decibels. Value can range from -60 to 60.
82
83
//| :param synthio.BlockInput post_gain: Increases or decreases the volume after the effect, in decibels. Value can range from -80 to 24.
83
84
//| :param DistortionMode mode: Distortion type.
85
+ //| :param bool soft_clip: Whether or not to soft clip (True) or hard clip (False) the output.
84
86
//| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0).
85
87
//| :param int buffer_size: The total size in bytes of each of the two playback buffers to use
86
88
//| :param int sample_rate: The sample rate to be used
@@ -111,12 +113,13 @@ static audiofilters_distortion_mode validate_distortion_mode(mp_obj_t obj, qstr
111
113
//| ...
112
114
113
115
static mp_obj_t audiofilters_distortion_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
114
- enum { ARG_drive , ARG_pre_gain , ARG_post_gain , ARG_mode , ARG_mix , ARG_buffer_size , ARG_sample_rate , ARG_bits_per_sample , ARG_samples_signed , ARG_channel_count , };
116
+ enum { ARG_drive , ARG_pre_gain , ARG_post_gain , ARG_mode , ARG_soft_clip , ARG_mix , ARG_buffer_size , ARG_sample_rate , ARG_bits_per_sample , ARG_samples_signed , ARG_channel_count , };
115
117
static const mp_arg_t allowed_args [] = {
116
118
{ MP_QSTR_drive , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 )} },
117
119
{ MP_QSTR_pre_gain , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 )} },
118
120
{ MP_QSTR_post_gain , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 )} },
119
121
{ MP_QSTR_mode , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
122
+ { MP_QSTR_soft_clip , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = false} },
120
123
{ MP_QSTR_mix , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 )} },
121
124
{ MP_QSTR_buffer_size , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 512 } },
122
125
{ MP_QSTR_sample_rate , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 8000 } },
@@ -141,7 +144,7 @@ static mp_obj_t audiofilters_distortion_make_new(const mp_obj_type_t *type, size
141
144
}
142
145
143
146
audiofilters_distortion_obj_t * self = mp_obj_malloc (audiofilters_distortion_obj_t , & audiofilters_distortion_type );
144
- common_hal_audiofilters_distortion_construct (self , args [ARG_drive ].u_obj , args [ARG_pre_gain ].u_obj , args [ARG_post_gain ].u_obj , mode , args [ARG_mix ].u_obj , args [ARG_buffer_size ].u_int , bits_per_sample , args [ARG_samples_signed ].u_bool , channel_count , sample_rate );
147
+ common_hal_audiofilters_distortion_construct (self , args [ARG_drive ].u_obj , args [ARG_pre_gain ].u_obj , args [ARG_post_gain ].u_obj , mode , args [ARG_soft_clip ]. 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 );
145
148
return MP_OBJ_FROM_PTR (self );
146
149
}
147
150
@@ -257,6 +260,25 @@ MP_PROPERTY_GETSET(audiofilters_distortion_mode_obj,
257
260
(mp_obj_t )& audiofilters_distortion_set_mode_obj );
258
261
259
262
263
+ //| soft_clip: bool
264
+ //| """Whether or not to soft clip (True) or hard clip (False) the output."""
265
+ static mp_obj_t audiofilters_distortion_obj_get_soft_clip (mp_obj_t self_in ) {
266
+ return mp_obj_new_bool (common_hal_audiofilters_distortion_get_soft_clip (self_in ));
267
+ }
268
+ MP_DEFINE_CONST_FUN_OBJ_1 (audiofilters_distortion_get_soft_clip_obj , audiofilters_distortion_obj_get_soft_clip );
269
+
270
+ static mp_obj_t audiofilters_distortion_obj_set_soft_clip (mp_obj_t self_in , mp_obj_t soft_clip_in ) {
271
+ audiofilters_distortion_obj_t * self = MP_OBJ_TO_PTR (self_in );
272
+ common_hal_audiofilters_distortion_set_soft_clip (self , mp_obj_is_true (soft_clip_in ));
273
+ return mp_const_none ;
274
+ }
275
+ MP_DEFINE_CONST_FUN_OBJ_2 (audiofilters_distortion_set_soft_clip_obj , audiofilters_distortion_obj_set_soft_clip );
276
+
277
+ MP_PROPERTY_GETSET (audiofilters_distortion_soft_clip_obj ,
278
+ (mp_obj_t )& audiofilters_distortion_get_soft_clip_obj ,
279
+ (mp_obj_t )& audiofilters_distortion_set_soft_clip_obj );
280
+
281
+
260
282
//| mix: synthio.BlockInput
261
283
//| """The rate the filtered signal mix between 0 and 1 where 0 is only sample and 1 is all effect."""
262
284
static mp_obj_t audiofilters_distortion_obj_get_mix (mp_obj_t self_in ) {
@@ -339,6 +361,7 @@ static const mp_rom_map_elem_t audiofilters_distortion_locals_dict_table[] = {
339
361
{ MP_ROM_QSTR (MP_QSTR_pre_gain ), MP_ROM_PTR (& audiofilters_distortion_pre_gain_obj ) },
340
362
{ MP_ROM_QSTR (MP_QSTR_post_gain ), MP_ROM_PTR (& audiofilters_distortion_post_gain_obj ) },
341
363
{ MP_ROM_QSTR (MP_QSTR_mode ), MP_ROM_PTR (& audiofilters_distortion_mode_obj ) },
364
+ { MP_ROM_QSTR (MP_QSTR_soft_clip ), MP_ROM_PTR (& audiofilters_distortion_soft_clip_obj ) },
342
365
{ MP_ROM_QSTR (MP_QSTR_mix ), MP_ROM_PTR (& audiofilters_distortion_mix_obj ) },
343
366
};
344
367
static MP_DEFINE_CONST_DICT (audiofilters_distortion_locals_dict , audiofilters_distortion_locals_dict_table ) ;
0 commit comments