Skip to content

Commit d65e851

Browse files
committed
Did audioio, audiomixer, audiomp3
1 parent 7ff9b9b commit d65e851

File tree

7 files changed

+247
-227
lines changed

7 files changed

+247
-227
lines changed

shared-bindings/audioio/AudioOut.c

Lines changed: 86 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -36,64 +36,65 @@
3636
#include "shared-bindings/util.h"
3737
#include "supervisor/shared/translate.h"
3838

39-
//|class AudioOut:
40-
//|""".. currentmodule:: audioio
39+
//| class AudioOut:
40+
//| """.. currentmodule:: audioio
4141
//|
42-
//|:class:`AudioOut` -- Output an analog audio signal
43-
//|========================================================
42+
//| :class:`AudioOut` -- Output an analog audio signal
43+
//| ========================================================
4444
//|
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."""
4646
//|
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).
5050
//|
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.
5555
//|
56-
//|Simple 8ksps 440 Hz sin wave::
56+
//| Simple 8ksps 440 Hz sin wave::
5757
//|
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
6464
//|
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)
7070
//|
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()
7676
//|
77-
//|Playing a wave file from flash::
77+
//| Playing a wave file from flash::
7878
//|
79-
//|import board
80-
//|import audioio
81-
//|import digitalio
79+
//| import board
80+
//| import audioio
81+
//| import digitalio
8282
//|
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)
8686
//|
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+
//| ...
9097
//|
91-
//|print("playing")
92-
//|a.play(wav)
93-
//|while a.playing:
94-
//|pass
95-
//|print("stopped")"""
96-
//|...
9798
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) {
9899
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
99100
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
115116
return MP_OBJ_FROM_PTR(self);
116117
}
117118

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+
//|
121123
STATIC mp_obj_t audioio_audioout_deinit(mp_obj_t self_in) {
122124
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
123125
common_hal_audioio_audioout_deinit(self);
@@ -130,15 +132,17 @@ STATIC void check_for_deinit(audioio_audioout_obj_t *self) {
130132
raise_deinited_error();
131133
}
132134
}
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+
//|
136139
// Provided by context manager helper.
137140

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+
//|
142146
STATIC mp_obj_t audioio_audioout_obj___exit__(size_t n_args, const mp_obj_t *args) {
143147
(void)n_args;
144148
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
147151
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_audioout___exit___obj, 4, 4, audioio_audioout_obj___exit__);
148152

149153

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`.
153159
//|
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+
//| ...
155164
//|
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-
//|...
160165
STATIC mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
161166
enum { ARG_sample, ARG_loop };
162167
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
175180
}
176181
MP_DEFINE_CONST_FUN_OBJ_KW(audioio_audioout_play_obj, 1, audioio_audioout_obj_play);
177182

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+
//|
181187
STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
182188
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
183189
check_for_deinit(self);
@@ -186,9 +192,9 @@ STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
186192
}
187193
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_stop_obj, audioio_audioout_obj_stop);
188194

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+
//|
192198
STATIC mp_obj_t audioio_audioout_obj_get_playing(mp_obj_t self_in) {
193199
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
194200
check_for_deinit(self);
@@ -203,9 +209,10 @@ const mp_obj_property_t audioio_audioout_playing_obj = {
203209
(mp_obj_t)&mp_const_none_obj},
204210
};
205211

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+
//|
209216
STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
210217
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
211218
check_for_deinit(self);
@@ -218,9 +225,10 @@ STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
218225
}
219226
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_pause_obj, audioio_audioout_obj_pause);
220227

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+
//|
224232
STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
225233
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
226234
check_for_deinit(self);
@@ -233,9 +241,9 @@ STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
233241
}
234242
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_resume_obj, audioio_audioout_obj_resume);
235243

236-
//|paused: Any =
237-
//|"""True when playback is paused. (read-only)"""
238-
//|...
244+
//| paused: Any = ...
245+
//| """True when playback is paused. (read-only)"""
246+
//|
239247
STATIC mp_obj_t audioio_audioout_obj_get_paused(mp_obj_t self_in) {
240248
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
241249
check_for_deinit(self);

shared-bindings/audioio/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "shared-bindings/audiomixer/Mixer.h"
4343
#endif
4444

45-
//| :mod:`audioio` --- Support for audio input and output
45+
//| """:mod:`audioio` --- Support for audio input and output
4646
//| ======================================================
4747
//|
4848
//| .. module:: audioio
@@ -68,7 +68,7 @@
6868
//|
6969
//| For compatibility with CircuitPython 4.x, some builds allow the items in
7070
//| `audiocore` to be imported from `audioio`. This will be removed for all
71-
//| boards in a future build of CircuitPython.
71+
//| boards in a future build of CircuitPython."""
7272
//|
7373

7474
STATIC const mp_rom_map_elem_t audioio_module_globals_table[] = {

0 commit comments

Comments
 (0)