Skip to content

Commit 1363e6e

Browse files
committed
Added inline pyi to audiocore
1 parent 088b5b1 commit 1363e6e

File tree

1 file changed

+91
-100
lines changed

1 file changed

+91
-100
lines changed

shared-bindings/audioio/AudioOut.c

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

39-
//| .. currentmodule:: audioio
40-
//|
41-
//| :class:`AudioOut` -- Output an analog audio signal
42-
//| ========================================================
43-
//|
44-
//| AudioOut can be used to output an analog audio signal on a given pin.
45-
//|
46-
//| .. class:: AudioOut(left_channel, *, right_channel=None, quiescent_value=0x8000)
47-
//|
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-
//|
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-
//|
56-
//| Simple 8ksps 440 Hz sin wave::
57-
//|
58-
//| import audiocore
59-
//| import audioio
60-
//| import board
61-
//| import array
62-
//| import time
63-
//| import math
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)
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()
76-
//|
77-
//| Playing a wave file from flash::
78-
//|
79-
//| import board
80-
//| import audioio
81-
//| import digitalio
82-
//|
83-
//| # Required for CircuitPlayground Express
84-
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
85-
//| speaker_enable.switch_to_output(value=True)
86-
//|
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-
//|
39+
//|class AudioOut:
40+
//| """.. currentmodule:: audioio
41+
//|
42+
//| :class:`AudioOut` -- Output an analog audio signal
43+
//| ========================================================
44+
//|
45+
//| AudioOut can be used to output an analog audio signal on a given pin."""
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).
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.
55+
//|
56+
//| Simple 8ksps 440 Hz sin wave::
57+
//|
58+
//| import audiocore
59+
//| import audioio
60+
//| import board
61+
//| import array
62+
//| import time
63+
//| import math
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)
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()
76+
//|
77+
//| Playing a wave file from flash::
78+
//|
79+
//| import board
80+
//| import audioio
81+
//| import digitalio
82+
//|
83+
//| # Required for CircuitPlayground Express
84+
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
85+
//| speaker_enable.switch_to_output(value=True)
86+
//|
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+
//| ...
9797
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) {
9898
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
9999
static const mp_arg_t allowed_args[] = {
@@ -115,10 +115,9 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
115115
return MP_OBJ_FROM_PTR(self);
116116
}
117117

118-
//| .. method:: deinit()
119-
//|
120-
//| Deinitialises the AudioOut and releases any hardware resources for reuse.
121-
//|
118+
//| def deinit(self, ) -> Any:
119+
//| """Deinitialises the AudioOut and releases any hardware resources for reuse."""
120+
//| ...
122121
STATIC mp_obj_t audioio_audioout_deinit(mp_obj_t self_in) {
123122
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
124123
common_hal_audioio_audioout_deinit(self);
@@ -131,17 +130,15 @@ STATIC void check_for_deinit(audioio_audioout_obj_t *self) {
131130
raise_deinited_error();
132131
}
133132
}
134-
//| .. method:: __enter__()
135-
//|
136-
//| No-op used by Context Managers.
137-
//|
133+
//| def __enter__(self, ) -> Any:
134+
//| """No-op used by Context Managers."""
135+
//| ...
138136
// Provided by context manager helper.
139137

140-
//| .. method:: __exit__()
141-
//|
142-
//| Automatically deinitializes the hardware when exiting a context. See
143-
//| :ref:`lifetime-and-contextmanagers` for more info.
144-
//|
138+
//| def __exit__(self, ) -> Any:
139+
//| """Automatically deinitializes the hardware when exiting a context. See
140+
//| :ref:`lifetime-and-contextmanagers` for more info."""
141+
//| ...
145142
STATIC mp_obj_t audioio_audioout_obj___exit__(size_t n_args, const mp_obj_t *args) {
146143
(void)n_args;
147144
common_hal_audioio_audioout_deinit(args[0]);
@@ -150,17 +147,16 @@ STATIC mp_obj_t audioio_audioout_obj___exit__(size_t n_args, const mp_obj_t *arg
150147
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_audioout___exit___obj, 4, 4, audioio_audioout_obj___exit__);
151148

152149

153-
//| .. method:: play(sample, *, loop=False)
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.
154153
//|
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`.
159-
//|
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.
154+
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
163155
//|
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+
//| ...
164160
STATIC mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
165161
enum { ARG_sample, ARG_loop };
166162
static const mp_arg_t allowed_args[] = {
@@ -179,10 +175,9 @@ STATIC mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_arg
179175
}
180176
MP_DEFINE_CONST_FUN_OBJ_KW(audioio_audioout_play_obj, 1, audioio_audioout_obj_play);
181177

182-
//| .. method:: stop()
183-
//|
184-
//| Stops playback and resets to the start of the sample.
185-
//|
178+
//| def stop(self, ) -> Any:
179+
//| """Stops playback and resets to the start of the sample."""
180+
//| ...
186181
STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
187182
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
188183
check_for_deinit(self);
@@ -191,10 +186,9 @@ STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
191186
}
192187
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_stop_obj, audioio_audioout_obj_stop);
193188

194-
//| .. attribute:: playing
195-
//|
196-
//| True when an audio sample is being output even if `paused`. (read-only)
197-
//|
189+
//| playing: Any =
190+
//| """True when an audio sample is being output even if `paused`. (read-only)"""
191+
//| ...
198192
STATIC mp_obj_t audioio_audioout_obj_get_playing(mp_obj_t self_in) {
199193
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
200194
check_for_deinit(self);
@@ -209,10 +203,9 @@ const mp_obj_property_t audioio_audioout_playing_obj = {
209203
(mp_obj_t)&mp_const_none_obj},
210204
};
211205

212-
//| .. method:: pause()
213-
//|
214-
//| Stops playback temporarily while remembering the position. Use `resume` to resume playback.
215-
//|
206+
//| def pause(self, ) -> Any:
207+
//| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
208+
//| ...
216209
STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
217210
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
218211
check_for_deinit(self);
@@ -225,10 +218,9 @@ STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
225218
}
226219
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_pause_obj, audioio_audioout_obj_pause);
227220

228-
//| .. method:: resume()
229-
//|
230-
//| Resumes sample playback after :py:func:`pause`.
231-
//|
221+
//| def resume(self, ) -> Any:
222+
//| """Resumes sample playback after :py:func:`pause`."""
223+
//| ...
232224
STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
233225
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
234226
check_for_deinit(self);
@@ -241,10 +233,9 @@ STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
241233
}
242234
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_resume_obj, audioio_audioout_obj_resume);
243235

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

0 commit comments

Comments
 (0)