21
21
//| class Echo:
22
22
//| """An Echo effect"""
23
23
//|
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
+ //| ...
24
69
static 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 ) {
25
70
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 , };
26
71
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 } },
28
73
{ MP_QSTR_delay_ms , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
29
74
{ MP_QSTR_decay , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = MP_OBJ_NULL } },
30
75
{ 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
54
99
}
55
100
56
101
//| def deinit(self) -> None:
57
- //| """Deinitialises the Echo and releases any hardware resources for reuse ."""
102
+ //| """Deinitialises the Echo."""
58
103
//| ...
59
104
static mp_obj_t audiodelays_echo_deinit (mp_obj_t self_in ) {
60
105
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) {
75
120
// Provided by context manager helper.
76
121
77
122
//| def __exit__(self) -> None:
78
- //| """Automatically deinitializes the hardware when exiting a context. See
123
+ //| """Automatically deinitializes when exiting a context. See
79
124
//| :ref:`lifetime-and-contextmanagers` for more info."""
80
125
//| ...
81
126
static 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,
117
162
(mp_obj_t )& audiodelays_echo_set_delay_ms_obj );
118
163
119
164
//| 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 ."""
121
166
static mp_obj_t audiodelays_echo_obj_get_decay (mp_obj_t self_in ) {
122
167
return common_hal_audiodelays_echo_get_decay (self_in );
123
168
}
@@ -143,7 +188,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj,
143
188
(mp_obj_t )& audiodelays_echo_set_decay_obj );
144
189
145
190
//| 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 ."""
147
192
static mp_obj_t audiodelays_echo_obj_get_mix (mp_obj_t self_in ) {
148
193
return common_hal_audiodelays_echo_get_mix (self_in );
149
194
}
@@ -168,10 +213,8 @@ MP_PROPERTY_GETSET(audiodelays_echo_mix_obj,
168
213
(mp_obj_t )& audiodelays_echo_get_mix_obj ,
169
214
(mp_obj_t )& audiodelays_echo_set_mix_obj );
170
215
171
-
172
-
173
216
//| playing: bool
174
- //| """True when any voice is being output . (read-only)"""
217
+ //| """True when the effect is playing a sample . (read-only)"""
175
218
static mp_obj_t audiodelays_echo_obj_get_playing (mp_obj_t self_in ) {
176
219
audiodelays_echo_obj_t * self = MP_OBJ_TO_PTR (self_in );
177
220
check_for_deinit (self );
@@ -188,9 +231,7 @@ MP_PROPERTY_GETTER(audiodelays_echo_playing_obj,
188
231
//| """Plays the sample once when loop=False and continuously when loop=True.
189
232
//| Does not block. Use `playing` to block.
190
233
//|
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."""
194
235
//| ...
195
236
static mp_obj_t audiodelays_echo_obj_play (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
196
237
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
212
253
MP_DEFINE_CONST_FUN_OBJ_KW (audiodelays_echo_play_obj , 1 , audiodelays_echo_obj_play );
213
254
214
255
//| def stop(self) -> None:
215
- //| """Stops playback of the sample."""
256
+ //| """Stops playback of the sample. The echo continues playing. """
216
257
//| ...
217
258
//|
218
259
static 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) {
223
264
}
224
265
MP_DEFINE_CONST_FUN_OBJ_1 (audiodelays_echo_stop_obj , audiodelays_echo_obj_stop );
225
266
226
-
227
-
228
267
static const mp_rom_map_elem_t audiodelays_echo_locals_dict_table [] = {
229
268
// Methods
230
269
{ MP_ROM_QSTR (MP_QSTR_deinit ), MP_ROM_PTR (& audiodelays_echo_deinit_obj ) },
0 commit comments