@@ -63,6 +63,7 @@ static audiofilters_distortion_mode validate_distortion_mode(mp_obj_t obj, qstr
6363//| pre_gain: synthio.BlockInput = 0.0,
6464//| post_gain: synthio.BlockInput = 0.0,
6565//| mode: DistortionMode = DistortionMode.CLIP,
66+ //| soft_clip: bool = False,
6667//| mix: synthio.BlockInput = 1.0,
6768//| buffer_size: int = 512,
6869//| sample_rate: int = 8000,
@@ -81,6 +82,7 @@ static audiofilters_distortion_mode validate_distortion_mode(mp_obj_t obj, qstr
8182//| :param synthio.BlockInput pre_gain: Increases or decreases the volume before the effect, in decibels. Value can range from -60 to 60.
8283//| :param synthio.BlockInput post_gain: Increases or decreases the volume after the effect, in decibels. Value can range from -80 to 24.
8384//| :param DistortionMode mode: Distortion type.
85+ //| :param bool soft_clip: Whether or not to soft clip (True) or hard clip (False) the output.
8486//| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0).
8587//| :param int buffer_size: The total size in bytes of each of the two playback buffers to use
8688//| :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
111113//| ...
112114
113115static 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 , };
115117 static const mp_arg_t allowed_args [] = {
116118 { MP_QSTR_drive , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 )} },
117119 { MP_QSTR_pre_gain , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 )} },
118120 { MP_QSTR_post_gain , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (0 )} },
119121 { 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} },
120123 { MP_QSTR_mix , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_ROM_INT (1 )} },
121124 { MP_QSTR_buffer_size , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 512 } },
122125 { 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
141144 }
142145
143146 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 );
145148 return MP_OBJ_FROM_PTR (self );
146149}
147150
@@ -257,6 +260,25 @@ MP_PROPERTY_GETSET(audiofilters_distortion_mode_obj,
257260 (mp_obj_t )& audiofilters_distortion_set_mode_obj );
258261
259262
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+
260282//| mix: synthio.BlockInput
261283//| """The rate the filtered signal mix between 0 and 1 where 0 is only sample and 1 is all effect."""
262284static 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[] = {
339361 { MP_ROM_QSTR (MP_QSTR_pre_gain ), MP_ROM_PTR (& audiofilters_distortion_pre_gain_obj ) },
340362 { MP_ROM_QSTR (MP_QSTR_post_gain ), MP_ROM_PTR (& audiofilters_distortion_post_gain_obj ) },
341363 { 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 ) },
342365 { MP_ROM_QSTR (MP_QSTR_mix ), MP_ROM_PTR (& audiofilters_distortion_mix_obj ) },
343366};
344367static MP_DEFINE_CONST_DICT (audiofilters_distortion_locals_dict , audiofilters_distortion_locals_dict_table ) ;
0 commit comments