36
36
#include "shared-bindings/util.h"
37
37
#include "supervisor/shared/translate.h"
38
38
39
- //|class AudioOut:
40
- //|""".. currentmodule:: audioio
39
+ //| class AudioOut:
40
+ //| """.. currentmodule:: audioio
41
41
//|
42
- //|:class:`AudioOut` -- Output an analog audio signal
43
- //|========================================================
42
+ //| :class:`AudioOut` -- Output an analog audio signal
43
+ //| ========================================================
44
44
//|
45
- //|AudioOut can be used to output an analog audio signal on a given pin."""
45
+ //| AudioOut can be used to output an analog audio signal on a given pin."""
46
46
//|
47
- //|def __init__(self, left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 0x8000):
48
- //|"""Create a AudioOut object associated with the given pin(s). This allows you to
49
- //|play audio signals out on the given pin(s).
47
+ //| def __init__(self, left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 0x8000):
48
+ //| """Create a AudioOut object associated with the given pin(s). This allows you to
49
+ //| play audio signals out on the given pin(s).
50
50
//|
51
- //|:param ~microcontroller.Pin left_channel: The pin to output the left channel to
52
- //|:param ~microcontroller.Pin right_channel: The pin to output the right channel to
53
- //|:param int quiescent_value: The output value when no signal is present. Samples should start
54
- //|and end with this value to prevent audible popping.
51
+ //| :param ~microcontroller.Pin left_channel: The pin to output the left channel to
52
+ //| :param ~microcontroller.Pin right_channel: The pin to output the right channel to
53
+ //| :param int quiescent_value: The output value when no signal is present. Samples should start
54
+ //| and end with this value to prevent audible popping.
55
55
//|
56
- //|Simple 8ksps 440 Hz sin wave::
56
+ //| Simple 8ksps 440 Hz sin wave::
57
57
//|
58
- //|import audiocore
59
- //|import audioio
60
- //|import board
61
- //|import array
62
- //|import time
63
- //|import math
58
+ //| import audiocore
59
+ //| import audioio
60
+ //| import board
61
+ //| import array
62
+ //| import time
63
+ //| import math
64
64
//|
65
- //|# Generate one period of sine wav.
66
- //|length = 8000 // 440
67
- //|sine_wave = array.array("H", [0] * length)
68
- //|for i in range(length):
69
- //|sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
65
+ //| # Generate one period of sine wav.
66
+ //| length = 8000 // 440
67
+ //| sine_wave = array.array("H", [0] * length)
68
+ //| for i in range(length):
69
+ //| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
70
70
//|
71
- //|dac = audioio.AudioOut(board.SPEAKER)
72
- //|sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
73
- //|dac.play(sine_wave, loop=True)
74
- //|time.sleep(1)
75
- //|dac.stop()
71
+ //| dac = audioio.AudioOut(board.SPEAKER)
72
+ //| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
73
+ //| dac.play(sine_wave, loop=True)
74
+ //| time.sleep(1)
75
+ //| dac.stop()
76
76
//|
77
- //|Playing a wave file from flash::
77
+ //| Playing a wave file from flash::
78
78
//|
79
- //|import board
80
- //|import audioio
81
- //|import digitalio
79
+ //| import board
80
+ //| import audioio
81
+ //| import digitalio
82
82
//|
83
- //|# Required for CircuitPlayground Express
84
- //|speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
85
- //|speaker_enable.switch_to_output(value=True)
83
+ //| # Required for CircuitPlayground Express
84
+ //| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
85
+ //| speaker_enable.switch_to_output(value=True)
86
86
//|
87
- //|data = open("cplay-5.1-16bit-16khz.wav", "rb")
88
- //|wav = audiocore.WaveFile(data)
89
- //|a = audioio.AudioOut(board.A0)
87
+ //| data = open("cplay-5.1-16bit-16khz.wav", "rb")
88
+ //| wav = audiocore.WaveFile(data)
89
+ //| a = audioio.AudioOut(board.A0)
90
+ //|
91
+ //| print("playing")
92
+ //| a.play(wav)
93
+ //| while a.playing:
94
+ //| pass
95
+ //| print("stopped")"""
96
+ //| ...
90
97
//|
91
- //|print("playing")
92
- //|a.play(wav)
93
- //|while a.playing:
94
- //|pass
95
- //|print("stopped")"""
96
- //|...
97
98
STATIC mp_obj_t audioio_audioout_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
98
99
enum { ARG_left_channel , ARG_right_channel , ARG_quiescent_value };
99
100
static const mp_arg_t allowed_args [] = {
@@ -115,9 +116,10 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
115
116
return MP_OBJ_FROM_PTR (self );
116
117
}
117
118
118
- //|def deinit(self, ) -> Any:
119
- //|"""Deinitialises the AudioOut and releases any hardware resources for reuse."""
120
- //|...
119
+ //| def deinit(self, ) -> Any:
120
+ //| """Deinitialises the AudioOut and releases any hardware resources for reuse."""
121
+ //| ...
122
+ //|
121
123
STATIC mp_obj_t audioio_audioout_deinit (mp_obj_t self_in ) {
122
124
audioio_audioout_obj_t * self = MP_OBJ_TO_PTR (self_in );
123
125
common_hal_audioio_audioout_deinit (self );
@@ -130,15 +132,17 @@ STATIC void check_for_deinit(audioio_audioout_obj_t *self) {
130
132
raise_deinited_error ();
131
133
}
132
134
}
133
- //|def __enter__(self, ) -> Any:
134
- //|"""No-op used by Context Managers."""
135
- //|...
135
+ //| def __enter__(self, ) -> Any:
136
+ //| """No-op used by Context Managers."""
137
+ //| ...
138
+ //|
136
139
// Provided by context manager helper.
137
140
138
- //|def __exit__(self, ) -> Any:
139
- //|"""Automatically deinitializes the hardware when exiting a context. See
140
- //|:ref:`lifetime-and-contextmanagers` for more info."""
141
- //|...
141
+ //| def __exit__(self, ) -> Any:
142
+ //| """Automatically deinitializes the hardware when exiting a context. See
143
+ //| :ref:`lifetime-and-contextmanagers` for more info."""
144
+ //| ...
145
+ //|
142
146
STATIC mp_obj_t audioio_audioout_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
143
147
(void )n_args ;
144
148
common_hal_audioio_audioout_deinit (args [0 ]);
@@ -147,16 +151,17 @@ STATIC mp_obj_t audioio_audioout_obj___exit__(size_t n_args, const mp_obj_t *arg
147
151
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audioio_audioout___exit___obj , 4 , 4 , audioio_audioout_obj___exit__ );
148
152
149
153
150
- //|def play(self, sample: Any, *, loop: Any = False) -> Any:
151
- //|"""Plays the sample once when loop=False and continuously when loop=True.
152
- //|Does not block. Use `playing` to block.
154
+ //| def play(self, sample: Any, *, loop: Any = False) -> Any:
155
+ //| """Plays the sample once when loop=False and continuously when loop=True.
156
+ //| Does not block. Use `playing` to block.
157
+ //|
158
+ //| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
153
159
//|
154
- //|Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
160
+ //| The sample itself should consist of 16 bit samples. Microcontrollers with a lower output
161
+ //| resolution will use the highest order bits to output. For example, the SAMD21 has a 10 bit
162
+ //| DAC that ignores the lowest 6 bits when playing 16 bit samples."""
163
+ //| ...
155
164
//|
156
- //|The sample itself should consist of 16 bit samples. Microcontrollers with a lower output
157
- //|resolution will use the highest order bits to output. For example, the SAMD21 has a 10 bit
158
- //|DAC that ignores the lowest 6 bits when playing 16 bit samples."""
159
- //|...
160
165
STATIC mp_obj_t audioio_audioout_obj_play (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
161
166
enum { ARG_sample , ARG_loop };
162
167
static const mp_arg_t allowed_args [] = {
@@ -175,9 +180,10 @@ STATIC mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_arg
175
180
}
176
181
MP_DEFINE_CONST_FUN_OBJ_KW (audioio_audioout_play_obj , 1 , audioio_audioout_obj_play );
177
182
178
- //|def stop(self, ) -> Any:
179
- //|"""Stops playback and resets to the start of the sample."""
180
- //|...
183
+ //| def stop(self, ) -> Any:
184
+ //| """Stops playback and resets to the start of the sample."""
185
+ //| ...
186
+ //|
181
187
STATIC mp_obj_t audioio_audioout_obj_stop (mp_obj_t self_in ) {
182
188
audioio_audioout_obj_t * self = MP_OBJ_TO_PTR (self_in );
183
189
check_for_deinit (self );
@@ -186,9 +192,9 @@ STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
186
192
}
187
193
MP_DEFINE_CONST_FUN_OBJ_1 (audioio_audioout_stop_obj , audioio_audioout_obj_stop );
188
194
189
- //|playing: Any =
190
- //|"""True when an audio sample is being output even if `paused`. (read-only)"""
191
- //|...
195
+ //| playing: Any = ...
196
+ //| """True when an audio sample is being output even if `paused`. (read-only)"""
197
+ //|
192
198
STATIC mp_obj_t audioio_audioout_obj_get_playing (mp_obj_t self_in ) {
193
199
audioio_audioout_obj_t * self = MP_OBJ_TO_PTR (self_in );
194
200
check_for_deinit (self );
@@ -203,9 +209,10 @@ const mp_obj_property_t audioio_audioout_playing_obj = {
203
209
(mp_obj_t )& mp_const_none_obj },
204
210
};
205
211
206
- //|def pause(self, ) -> Any:
207
- //|"""Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
208
- //|...
212
+ //| def pause(self, ) -> Any:
213
+ //| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
214
+ //| ...
215
+ //|
209
216
STATIC mp_obj_t audioio_audioout_obj_pause (mp_obj_t self_in ) {
210
217
audioio_audioout_obj_t * self = MP_OBJ_TO_PTR (self_in );
211
218
check_for_deinit (self );
@@ -218,9 +225,10 @@ STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
218
225
}
219
226
MP_DEFINE_CONST_FUN_OBJ_1 (audioio_audioout_pause_obj , audioio_audioout_obj_pause );
220
227
221
- //|def resume(self, ) -> Any:
222
- //|"""Resumes sample playback after :py:func:`pause`."""
223
- //|...
228
+ //| def resume(self, ) -> Any:
229
+ //| """Resumes sample playback after :py:func:`pause`."""
230
+ //| ...
231
+ //|
224
232
STATIC mp_obj_t audioio_audioout_obj_resume (mp_obj_t self_in ) {
225
233
audioio_audioout_obj_t * self = MP_OBJ_TO_PTR (self_in );
226
234
check_for_deinit (self );
@@ -233,9 +241,9 @@ STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
233
241
}
234
242
MP_DEFINE_CONST_FUN_OBJ_1 (audioio_audioout_resume_obj , audioio_audioout_obj_resume );
235
243
236
- //|paused: Any =
237
- //|"""True when playback is paused. (read-only)"""
238
- //|...
244
+ //| paused: Any = ...
245
+ //| """True when playback is paused. (read-only)"""
246
+ //|
239
247
STATIC mp_obj_t audioio_audioout_obj_get_paused (mp_obj_t self_in ) {
240
248
audioio_audioout_obj_t * self = MP_OBJ_TO_PTR (self_in );
241
249
check_for_deinit (self );
0 commit comments