Skip to content

Commit 8330471

Browse files
committed
Added inline pyi to audiomixer
1 parent 1363e6e commit 8330471

File tree

2 files changed

+90
-100
lines changed

2 files changed

+90
-100
lines changed

shared-bindings/audiomixer/Mixer.c

Lines changed: 67 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,50 @@
3838
#include "shared-bindings/util.h"
3939
#include "supervisor/shared/translate.h"
4040

41-
//| .. currentmodule:: audiomixer
41+
//|class Mixer:
42+
//| """.. currentmodule:: audiomixer
4243
//|
43-
//| :class:`Mixer` -- Mixes one or more audio samples together
44-
//| ===========================================================
44+
//| :class:`Mixer` -- Mixes one or more audio samples together
45+
//| ===========================================================
4546
//|
46-
//| Mixer mixes multiple samples into one sample.
47+
//| Mixer mixes multiple samples into one sample."""
4748
//|
48-
//| .. class:: Mixer(voice_count=2, buffer_size=1024, channel_count=2, bits_per_sample=16, samples_signed=True, sample_rate=8000)
49+
//| def __init__(self, voice_count: int = 2, buffer_size: int = 1024, channel_count: int = 2, bits_per_sample: int = 16, samples_signed: bool = True, sample_rate: int = 8000):
50+
//| """Create a Mixer object that can mix multiple channels with the same sample rate.
51+
//| Samples are accessed and controlled with the mixer's `audiomixer.MixerVoice` objects.
4952
//|
50-
//| Create a Mixer object that can mix multiple channels with the same sample rate.
51-
//| Samples are accessed and controlled with the mixer's `audiomixer.MixerVoice` objects.
53+
//| :param int voice_count: The maximum number of voices to mix
54+
//| :param int buffer_size: The total size in bytes of the buffers to mix into
55+
//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
56+
//| :param int bits_per_sample: The bits per sample of the samples being played
57+
//| :param bool samples_signed: Samples are signed (True) or unsigned (False)
58+
//| :param int sample_rate: The sample rate to be used for all samples
5259
//|
53-
//| :param int voice_count: The maximum number of voices to mix
54-
//| :param int buffer_size: The total size in bytes of the buffers to mix into
55-
//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
56-
//| :param int bits_per_sample: The bits per sample of the samples being played
57-
//| :param bool samples_signed: Samples are signed (True) or unsigned (False)
58-
//| :param int sample_rate: The sample rate to be used for all samples
60+
//| Playing a wave file from flash::
5961
//|
60-
//| Playing a wave file from flash::
62+
//| import board
63+
//| import audioio
64+
//| import audiocore
65+
//| import audiomixer
66+
//| import digitalio
6167
//|
62-
//| import board
63-
//| import audioio
64-
//| import audiocore
65-
//| import audiomixer
66-
//| import digitalio
67-
//|
68-
//| a = audioio.AudioOut(board.A0)
69-
//| music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
70-
//| drum = audiocore.WaveFile(open("drum.wav", "rb"))
71-
//| mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1,
72-
//| bits_per_sample=16, samples_signed=True)
73-
//|
74-
//| print("playing")
75-
//| # Have AudioOut play our Mixer source
76-
//| a.play(mixer)
77-
//| # Play the first sample voice
78-
//| mixer.voice[0].play(music)
79-
//| while mixer.playing:
80-
//| # Play the second sample voice
81-
//| mixer.voice[1].play(drum)
82-
//| time.sleep(1)
83-
//| print("stopped")
68+
//| a = audioio.AudioOut(board.A0)
69+
//| music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
70+
//| drum = audiocore.WaveFile(open("drum.wav", "rb"))
71+
//| mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1,
72+
//| bits_per_sample=16, samples_signed=True)
8473
//|
74+
//| print("playing")
75+
//| # Have AudioOut play our Mixer source
76+
//| a.play(mixer)
77+
//| # Play the first sample voice
78+
//| mixer.voice[0].play(music)
79+
//| while mixer.playing:
80+
//| # Play the second sample voice
81+
//| mixer.voice[1].play(drum)
82+
//| time.sleep(1)
83+
//| print("stopped")"""
84+
//| ...
8585
STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
8686
enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate };
8787
static const mp_arg_t allowed_args[] = {
@@ -125,10 +125,9 @@ STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar
125125
return MP_OBJ_FROM_PTR(self);
126126
}
127127

128-
//| .. method:: deinit()
129-
//|
130-
//| Deinitialises the Mixer and releases any hardware resources for reuse.
131-
//|
128+
//| def deinit(self, ) -> Any:
129+
//| """Deinitialises the Mixer and releases any hardware resources for reuse."""
130+
//| ...
132131
STATIC mp_obj_t audiomixer_mixer_deinit(mp_obj_t self_in) {
133132
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
134133
common_hal_audiomixer_mixer_deinit(self);
@@ -142,28 +141,25 @@ STATIC void check_for_deinit(audiomixer_mixer_obj_t *self) {
142141
}
143142
}
144143

145-
//| .. method:: __enter__()
146-
//|
147-
//| No-op used by Context Managers.
148-
//|
144+
//| def __enter__(self, ) -> Any:
145+
//| """No-op used by Context Managers."""
146+
//| ...
149147
// Provided by context manager helper.
150148

151-
//| .. method:: __exit__()
152-
//|
153-
//| Automatically deinitializes the hardware when exiting a context. See
154-
//| :ref:`lifetime-and-contextmanagers` for more info.
155-
//|
149+
//| def __exit__(self, ) -> Any:
150+
//| """Automatically deinitializes the hardware when exiting a context. See
151+
//| :ref:`lifetime-and-contextmanagers` for more info."""
152+
//| ...
156153
STATIC mp_obj_t audiomixer_mixer_obj___exit__(size_t n_args, const mp_obj_t *args) {
157154
(void)n_args;
158155
common_hal_audiomixer_mixer_deinit(args[0]);
159156
return mp_const_none;
160157
}
161158
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomixer_mixer___exit___obj, 4, 4, audiomixer_mixer_obj___exit__);
162159

163-
//| .. attribute:: playing
164-
//|
165-
//| True when any voice is being output. (read-only)
166-
//|
160+
//| playing: Any =
161+
//| """True when any voice is being output. (read-only)"""
162+
//| ...
167163
STATIC mp_obj_t audiomixer_mixer_obj_get_playing(mp_obj_t self_in) {
168164
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
169165
check_for_deinit(self);
@@ -178,10 +174,9 @@ const mp_obj_property_t audiomixer_mixer_playing_obj = {
178174
(mp_obj_t)&mp_const_none_obj},
179175
};
180176

181-
//| .. attribute:: sample_rate
182-
//|
183-
//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second).
184-
//|
177+
//| sample_rate: Any =
178+
//| """32 bit value that dictates how quickly samples are played in Hertz (cycles per second)."""
179+
//| ...
185180
STATIC mp_obj_t audiomixer_mixer_obj_get_sample_rate(mp_obj_t self_in) {
186181
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
187182
check_for_deinit(self);
@@ -196,14 +191,14 @@ const mp_obj_property_t audiomixer_mixer_sample_rate_obj = {
196191
(mp_obj_t)&mp_const_none_obj},
197192
};
198193

199-
//| .. attribute:: voice
200-
//|
201-
//| A tuple of the mixer's `audiomixer.MixerVoice` object(s).
194+
//| voice: Any =
195+
//| """A tuple of the mixer's `audiomixer.MixerVoice` object(s).
202196
//|
203-
//| .. code-block:: python
197+
//| .. code-block:: python
204198
//|
205-
//| >>> mixer.voice
206-
//| (<MixerVoice>,)
199+
//| >>> mixer.voice
200+
//| (<MixerVoice>,)"""
201+
//| ...
207202
STATIC mp_obj_t audiomixer_mixer_obj_get_voice(mp_obj_t self_in) {
208203
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
209204
check_for_deinit(self);
@@ -218,15 +213,14 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
218213
(mp_obj_t)&mp_const_none_obj},
219214
};
220215

221-
//| .. method:: play(sample, *, voice=0, loop=False)
216+
//| def play(self, sample: Any, *, voice: Any = 0, loop: Any = False) -> Any:
217+
//| """Plays the sample once when loop=False and continuously when loop=True.
218+
//| Does not block. Use `playing` to block.
222219
//|
223-
//| Plays the sample once when loop=False and continuously when loop=True.
224-
//| Does not block. Use `playing` to block.
225-
//|
226-
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
227-
//|
228-
//| The sample must match the Mixer's encoding settings given in the constructor.
220+
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
229221
//|
222+
//| The sample must match the Mixer's encoding settings given in the constructor."""
223+
//| ...
230224
STATIC mp_obj_t audiomixer_mixer_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
231225
enum { ARG_sample, ARG_voice, ARG_loop };
232226
static const mp_arg_t allowed_args[] = {
@@ -251,10 +245,9 @@ STATIC mp_obj_t audiomixer_mixer_obj_play(size_t n_args, const mp_obj_t *pos_arg
251245
}
252246
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixer_play_obj, 1, audiomixer_mixer_obj_play);
253247

254-
//| .. method:: stop_voice(voice=0)
255-
//|
256-
//| Stops playback of the sample on the given voice.
257-
//|
248+
//| def stop_voice(self, voice: Any = 0) -> Any:
249+
//| """Stops playback of the sample on the given voice."""
250+
//| ...
258251
STATIC mp_obj_t audiomixer_mixer_obj_stop_voice(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
259252
enum { ARG_voice };
260253
static const mp_arg_t allowed_args[] = {

shared-bindings/audiomixer/MixerVoice.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@
3737
#include "shared-bindings/util.h"
3838
#include "supervisor/shared/translate.h"
3939

40-
//| .. currentmodule:: audiomixer
40+
//|class MixerVoice:
41+
//| """.. currentmodule:: audiomixer
4142
//|
42-
//| :class:`MixerVoice` -- Voice objects used with Mixer
43-
//| =====================================================
43+
//| :class:`MixerVoice` -- Voice objects used with Mixer
44+
//| =====================================================
4445
//|
45-
//| Used to access and control samples with `audiomixer.Mixer`.
46+
//| Used to access and control samples with `audiomixer.Mixer`."""
4647
//|
47-
//| .. class:: MixerVoice()
48-
//|
49-
//| MixerVoice instance object(s) created by `audiomixer.Mixer`.
48+
//| def __init__(self, ):
5049
//|
50+
//| """MixerVoice instance object(s) created by `audiomixer.Mixer`."""
51+
//| ...
5152
// TODO: support mono or stereo voices
5253
STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
5354
audiomixer_mixervoice_obj_t *self = m_new_obj(audiomixer_mixervoice_obj_t);
@@ -58,15 +59,14 @@ STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t
5859
return MP_OBJ_FROM_PTR(self);
5960
}
6061

61-
//| .. method:: play(sample, *, loop=False)
62-
//|
63-
//| Plays the sample once when ``loop=False``, and continuously when ``loop=True``.
64-
//| Does not block. Use `playing` to block.
65-
//|
66-
//| Sample must be an `audiocore.WaveFile`, `audiomixer.Mixer` or `audiocore.RawSample`.
62+
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
63+
//| """Plays the sample once when ``loop=False``, and continuously when ``loop=True``.
64+
//| Does not block. Use `playing` to block.
6765
//|
68-
//| The sample must match the `audiomixer.Mixer`'s encoding settings given in the constructor.
66+
//| Sample must be an `audiocore.WaveFile`, `audiomixer.Mixer` or `audiocore.RawSample`.
6967
//|
68+
//| The sample must match the `audiomixer.Mixer`'s encoding settings given in the constructor."""
69+
//| ...
7070
STATIC mp_obj_t audiomixer_mixervoice_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
7171
enum { ARG_sample, ARG_loop };
7272
static const mp_arg_t allowed_args[] = {
@@ -83,10 +83,9 @@ STATIC mp_obj_t audiomixer_mixervoice_obj_play(size_t n_args, const mp_obj_t *po
8383
}
8484
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_play_obj, 1, audiomixer_mixervoice_obj_play);
8585

86-
//| .. method:: stop()
87-
//|
88-
//| Stops playback of the sample on this voice.
89-
//|
86+
//| def stop(self, ) -> Any:
87+
//| """Stops playback of the sample on this voice."""
88+
//| ...
9089
STATIC mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
9190
enum { ARG_voice };
9291
static const mp_arg_t allowed_args[] = {
@@ -102,10 +101,9 @@ STATIC mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *po
102101
}
103102
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_stop_obj, 1, audiomixer_mixervoice_obj_stop);
104103

105-
//| .. attribute:: level()
106-
//|
107-
//| The volume level of a voice, as a floating point number between 0 and 1.
108-
//|
104+
//| level(): Any =
105+
//| """The volume level of a voice, as a floating point number between 0 and 1."""
106+
//| ...
109107
STATIC mp_obj_t audiomixer_mixervoice_obj_get_level(mp_obj_t self_in) {
110108
return mp_obj_new_float(common_hal_audiomixer_mixervoice_get_level(self_in));
111109
}
@@ -139,10 +137,9 @@ const mp_obj_property_t audiomixer_mixervoice_level_obj = {
139137
(mp_obj_t)&mp_const_none_obj},
140138
};
141139

142-
//| .. attribute:: playing
143-
//|
144-
//| True when this voice is being output. (read-only)
145-
//|
140+
//| playing: Any =
141+
//| """True when this voice is being output. (read-only)"""
142+
//| ...
146143

147144
STATIC mp_obj_t audiomixer_mixervoice_obj_get_playing(mp_obj_t self_in) {
148145
audiomixer_mixervoice_obj_t *self = MP_OBJ_TO_PTR(self_in);

0 commit comments

Comments
 (0)