2121//| class Echo:
2222//| """An Echo effect"""
2323//|
24+ //| def __init__(
25+ //| self,
26+ //| max_delay_ms: int = 500,
27+ //| delay_ms: BlockInput = 250.0,
28+ //| decay: BlockInput = 0.7,
29+ //| mix: BlockInput = 0.5,
30+ //| buffer_size: int = 512,
31+ //| sample_rate: int = 8000,
32+ //| bits_per_sample: int = 16,
33+ //| samples_signed: bool = True,
34+ //| channel_count: int = 1,
35+ //| ) -> None:
36+ //| """Create a Echo effect that echos an audio sample every set number of microseconds.
37+ //|
38+ //| :param int max_delay_ms: The maximum delay the echo can be
39+ //| :param BlockInput delay_ms: The current echo delay
40+ //| :param BlockInput decay: The rate the echo fades. 0.0 = instant; 1.0 = never.
41+ //| :param BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0).
42+ //| :param int buffer_size: The total size in bytes of the buffers to use
43+ //| :param int sample_rate: The sample rate to be used
44+ //| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
45+ //| :param int bits_per_sample: The bits per sample of the effect
46+ //| :param bool samples_signed: Effect is signed (True) or unsigned (False)
47+ //|
48+ //| Playing adding an echo to a synth::
49+ //|
50+ //| import time
51+ //| import board
52+ //| import audiobusio
53+ //| import synthio
54+ //| import audiodelays
55+ //|
56+ //| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
57+ //| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
58+ //| echo = audiodelays.Echo(max_delay_ms=1000, delay_ms=850, decay=0.65, buffer_size=1024, channel_count=1, sample_rate=44100, mix=0.7)
59+ //| echo.play(synth)
60+ //| audio.play(echo)
61+ //|
62+ //| note = synthio.Note(261)
63+ //| while True:
64+ //| synth.press(note)
65+ //| time.sleep(0.25)
66+ //| synth.release(note)
67+ //| time.sleep(5)"""
68+ //| ...
2469static mp_obj_t audiodelays_echo_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
2570 enum { ARG_max_delay_ms , ARG_delay_ms , ARG_decay , ARG_mix , ARG_buffer_size , ARG_sample_rate , ARG_bits_per_sample , ARG_samples_signed , ARG_channel_count , };
2671 static const mp_arg_t allowed_args [] = {
27- { MP_QSTR_max_delay_ms , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 50 } },
72+ { MP_QSTR_max_delay_ms , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 500 } },
2873 { MP_QSTR_delay_ms , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
2974 { MP_QSTR_decay , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
3075 { MP_QSTR_mix , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
@@ -54,7 +99,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar
5499}
55100
56101//| def deinit(self) -> None:
57- //| """Deinitialises the Echo and releases any hardware resources for reuse ."""
102+ //| """Deinitialises the Echo."""
58103//| ...
59104static mp_obj_t audiodelays_echo_deinit (mp_obj_t self_in ) {
60105 audiodelays_echo_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -75,7 +120,7 @@ static void check_for_deinit(audiodelays_echo_obj_t *self) {
75120// Provided by context manager helper.
76121
77122//| def __exit__(self) -> None:
78- //| """Automatically deinitializes the hardware when exiting a context. See
123+ //| """Automatically deinitializes when exiting a context. See
79124//| :ref:`lifetime-and-contextmanagers` for more info."""
80125//| ...
81126static mp_obj_t audiodelays_echo_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
@@ -117,7 +162,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_delay_ms_obj,
117162 (mp_obj_t )& audiodelays_echo_set_delay_ms_obj );
118163
119164//| decay: BlockInput
120- //| """The rate the echo decays between 0 and 1."""
165+ //| """The rate the echo decays between 0 and 1 where 1 is forever and 0 is no echo ."""
121166static mp_obj_t audiodelays_echo_obj_get_decay (mp_obj_t self_in ) {
122167 return common_hal_audiodelays_echo_get_decay (self_in );
123168}
@@ -143,7 +188,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj,
143188 (mp_obj_t )& audiodelays_echo_set_decay_obj );
144189
145190//| mix: BlockInput
146- //| """The rate the echo mix between 0 and 1."""
191+ //| """The rate the echo mix between 0 and 1 where 0 is only sample and 1 is all effect ."""
147192static mp_obj_t audiodelays_echo_obj_get_mix (mp_obj_t self_in ) {
148193 return common_hal_audiodelays_echo_get_mix (self_in );
149194}
@@ -168,10 +213,8 @@ MP_PROPERTY_GETSET(audiodelays_echo_mix_obj,
168213 (mp_obj_t )& audiodelays_echo_get_mix_obj ,
169214 (mp_obj_t )& audiodelays_echo_set_mix_obj );
170215
171-
172-
173216//| playing: bool
174- //| """True when any voice is being output . (read-only)"""
217+ //| """True when the effect is playing a sample . (read-only)"""
175218static mp_obj_t audiodelays_echo_obj_get_playing (mp_obj_t self_in ) {
176219 audiodelays_echo_obj_t * self = MP_OBJ_TO_PTR (self_in );
177220 check_for_deinit (self );
@@ -188,9 +231,7 @@ MP_PROPERTY_GETTER(audiodelays_echo_playing_obj,
188231//| """Plays the sample once when loop=False and continuously when loop=True.
189232//| Does not block. Use `playing` to block.
190233//|
191- //| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, `audiomixer.Mixer` or `audiomp3.MP3Decoder`.
192- //|
193- //| The sample must match the Effect's encoding settings given in the constructor."""
234+ //| The sample must match the encoding settings given in the constructor."""
194235//| ...
195236static mp_obj_t audiodelays_echo_obj_play (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
196237 enum { ARG_sample , ARG_loop };
@@ -212,7 +253,7 @@ static mp_obj_t audiodelays_echo_obj_play(size_t n_args, const mp_obj_t *pos_arg
212253MP_DEFINE_CONST_FUN_OBJ_KW (audiodelays_echo_play_obj , 1 , audiodelays_echo_obj_play );
213254
214255//| def stop(self) -> None:
215- //| """Stops playback of the sample."""
256+ //| """Stops playback of the sample. The echo continues playing. """
216257//| ...
217258//|
218259static mp_obj_t audiodelays_echo_obj_stop (mp_obj_t self_in ) {
@@ -223,8 +264,6 @@ static mp_obj_t audiodelays_echo_obj_stop(mp_obj_t self_in) {
223264}
224265MP_DEFINE_CONST_FUN_OBJ_1 (audiodelays_echo_stop_obj , audiodelays_echo_obj_stop );
225266
226-
227-
228267static const mp_rom_map_elem_t audiodelays_echo_locals_dict_table [] = {
229268 // Methods
230269 { MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& audiodelays_echo_deinit_obj ) },
0 commit comments