38
38
#include "shared-bindings/util.h"
39
39
#include "supervisor/shared/translate.h"
40
40
41
- //| .. currentmodule:: audiomixer
41
+ //|class Mixer:
42
+ //| """.. currentmodule:: audiomixer
42
43
//|
43
- //| :class:`Mixer` -- Mixes one or more audio samples together
44
- //| ===========================================================
44
+ //| :class:`Mixer` -- Mixes one or more audio samples together
45
+ //| ===========================================================
45
46
//|
46
- //| Mixer mixes multiple samples into one sample.
47
+ //| Mixer mixes multiple samples into one sample."""
47
48
//|
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.
49
52
//|
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
52
59
//|
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::
59
61
//|
60
- //| Playing a wave file from flash::
62
+ //| import board
63
+ //| import audioio
64
+ //| import audiocore
65
+ //| import audiomixer
66
+ //| import digitalio
61
67
//|
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)
84
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")"""
84
+ //| ...
85
85
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 ) {
86
86
enum { ARG_voice_count , ARG_buffer_size , ARG_channel_count , ARG_bits_per_sample , ARG_samples_signed , ARG_sample_rate };
87
87
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
125
125
return MP_OBJ_FROM_PTR (self );
126
126
}
127
127
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
+ //| ...
132
131
STATIC mp_obj_t audiomixer_mixer_deinit (mp_obj_t self_in ) {
133
132
audiomixer_mixer_obj_t * self = MP_OBJ_TO_PTR (self_in );
134
133
common_hal_audiomixer_mixer_deinit (self );
@@ -142,28 +141,25 @@ STATIC void check_for_deinit(audiomixer_mixer_obj_t *self) {
142
141
}
143
142
}
144
143
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
+ //| ...
149
147
// Provided by context manager helper.
150
148
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
+ //| ...
156
153
STATIC mp_obj_t audiomixer_mixer_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
157
154
(void )n_args ;
158
155
common_hal_audiomixer_mixer_deinit (args [0 ]);
159
156
return mp_const_none ;
160
157
}
161
158
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audiomixer_mixer___exit___obj , 4 , 4 , audiomixer_mixer_obj___exit__ );
162
159
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
+ //| ...
167
163
STATIC mp_obj_t audiomixer_mixer_obj_get_playing (mp_obj_t self_in ) {
168
164
audiomixer_mixer_obj_t * self = MP_OBJ_TO_PTR (self_in );
169
165
check_for_deinit (self );
@@ -178,10 +174,9 @@ const mp_obj_property_t audiomixer_mixer_playing_obj = {
178
174
(mp_obj_t )& mp_const_none_obj },
179
175
};
180
176
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
+ //| ...
185
180
STATIC mp_obj_t audiomixer_mixer_obj_get_sample_rate (mp_obj_t self_in ) {
186
181
audiomixer_mixer_obj_t * self = MP_OBJ_TO_PTR (self_in );
187
182
check_for_deinit (self );
@@ -196,14 +191,14 @@ const mp_obj_property_t audiomixer_mixer_sample_rate_obj = {
196
191
(mp_obj_t )& mp_const_none_obj },
197
192
};
198
193
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).
202
196
//|
203
- //| .. code-block:: python
197
+ //| .. code-block:: python
204
198
//|
205
- //| >>> mixer.voice
206
- //| (<MixerVoice>,)
199
+ //| >>> mixer.voice
200
+ //| (<MixerVoice>,)"""
201
+ //| ...
207
202
STATIC mp_obj_t audiomixer_mixer_obj_get_voice (mp_obj_t self_in ) {
208
203
audiomixer_mixer_obj_t * self = MP_OBJ_TO_PTR (self_in );
209
204
check_for_deinit (self );
@@ -218,15 +213,14 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
218
213
(mp_obj_t )& mp_const_none_obj },
219
214
};
220
215
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.
222
219
//|
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`.
229
221
//|
222
+ //| The sample must match the Mixer's encoding settings given in the constructor."""
223
+ //| ...
230
224
STATIC mp_obj_t audiomixer_mixer_obj_play (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
231
225
enum { ARG_sample , ARG_voice , ARG_loop };
232
226
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
251
245
}
252
246
MP_DEFINE_CONST_FUN_OBJ_KW (audiomixer_mixer_play_obj , 1 , audiomixer_mixer_obj_play );
253
247
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
+ //| ...
258
251
STATIC mp_obj_t audiomixer_mixer_obj_stop_voice (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
259
252
enum { ARG_voice };
260
253
static const mp_arg_t allowed_args [] = {
0 commit comments