34
34
#include "shared-bindings/util.h"
35
35
#include "supervisor/shared/translate.h"
36
36
37
- //| .. currentmodule:: audiomp3
37
+ //|class MP3:
38
+ //| """.. currentmodule:: audiomp3
38
39
//|
39
- //| :class:`MP3Decoder` -- Load a mp3 file for audio playback
40
- //| =========================================================
40
+ //| :class:`MP3Decoder` -- Load a mp3 file for audio playback
41
+ //| =========================================================
41
42
//|
42
- //| An object that decodes MP3 files for playback on an audio device.
43
+ //| An object that decodes MP3 files for playback on an audio device."""
43
44
//|
44
- //| .. class:: MP3(file[, buffer])
45
+ //| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
46
+ //| """Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
45
47
//|
46
- //| Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
48
+ //| :param typing.BinaryIO file: Already opened mp3 file
49
+ //| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two buffers are allocated internally. The specific buffer size required depends on the mp3 file.
47
50
//|
48
- //| :param typing.BinaryIO file: Already opened mp3 file
49
- //| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two buffers are allocated internally. The specific buffer size required depends on the mp3 file.
50
51
//|
52
+ //| Playing a mp3 file from flash::
51
53
//|
52
- //| Playing a mp3 file from flash::
54
+ //| import board
55
+ //| import audiomp3
56
+ //| import audioio
57
+ //| import digitalio
53
58
//|
54
- //| import board
55
- //| import audiomp3
56
- //| import audioio
57
- //| import digitalio
59
+ //| # Required for CircuitPlayground Express
60
+ //| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
61
+ //| speaker_enable.switch_to_output(value=True)
58
62
//|
59
- //| # Required for CircuitPlayground Express
60
- //| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
61
- //| speaker_enable.switch_to_output(value=True)
62
- //|
63
- //| data = open("cplay-16bit-16khz-64kbps.mp3", "rb")
64
- //| mp3 = audiomp3.MP3Decoder(data)
65
- //| a = audioio.AudioOut(board.A0)
66
- //|
67
- //| print("playing")
68
- //| a.play(mp3)
69
- //| while a.playing:
70
- //| pass
71
- //| print("stopped")
63
+ //| data = open("cplay-16bit-16khz-64kbps.mp3", "rb")
64
+ //| mp3 = audiomp3.MP3Decoder(data)
65
+ //| a = audioio.AudioOut(board.A0)
72
66
//|
67
+ //| print("playing")
68
+ //| a.play(mp3)
69
+ //| while a.playing:
70
+ //| pass
71
+ //| print("stopped")"""
72
+ //| ...
73
73
STATIC mp_obj_t audiomp3_mp3file_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * args , mp_map_t * kw_args ) {
74
74
mp_arg_check_num (n_args , kw_args , 1 , 2 , false);
75
75
@@ -92,10 +92,9 @@ STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
92
92
return MP_OBJ_FROM_PTR (self );
93
93
}
94
94
95
- //| .. method:: deinit()
96
- //|
97
- //| Deinitialises the MP3 and releases all memory resources for reuse.
98
- //|
95
+ //| def deinit(self, ) -> Any:
96
+ //| """Deinitialises the MP3 and releases all memory resources for reuse."""
97
+ //| ...
99
98
STATIC mp_obj_t audiomp3_mp3file_deinit (mp_obj_t self_in ) {
100
99
audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
101
100
common_hal_audiomp3_mp3file_deinit (self );
@@ -109,28 +108,26 @@ STATIC void check_for_deinit(audiomp3_mp3file_obj_t *self) {
109
108
}
110
109
}
111
110
112
- //| .. method:: __enter__()
113
- //|
114
- //| No-op used by Context Managers.
115
- //|
111
+ //| def __enter__(self, ) -> Any:
112
+ //| """No-op used by Context Managers."""
113
+ //| ...
116
114
// Provided by context manager helper.
117
115
118
- //| .. method:: __exit__()
119
- //|
120
- //| Automatically deinitializes the hardware when exiting a context. See
121
- //| :ref:`lifetime-and-contextmanagers` for more info.
116
+ //| def __exit__(self, ) -> Any:
122
117
//|
118
+ //| """Automatically deinitializes the hardware when exiting a context. See
119
+ //| :ref:`lifetime-and-contextmanagers` for more info."""
120
+ //| ...
123
121
STATIC mp_obj_t audiomp3_mp3file_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
124
122
(void )n_args ;
125
123
common_hal_audiomp3_mp3file_deinit (args [0 ]);
126
124
return mp_const_none ;
127
125
}
128
126
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audiomp3_mp3file___exit___obj , 4 , 4 , audiomp3_mp3file_obj___exit__ );
129
127
130
- //| .. attribute:: file
131
- //|
132
- //| File to play back.
133
- //|
128
+ //| file: Any =
129
+ //| """File to play back."""
130
+ //| ...
134
131
STATIC mp_obj_t audiomp3_mp3file_obj_get_file (mp_obj_t self_in ) {
135
132
audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
136
133
check_for_deinit (self );
@@ -158,12 +155,11 @@ const mp_obj_property_t audiomp3_mp3file_file_obj = {
158
155
159
156
160
157
161
- //| .. attribute:: sample_rate
162
- //|
163
- //| 32 bit value that dictates how quickly samples are loaded into the DAC
164
- //| in Hertz (cycles per second). When the sample is looped, this can change
165
- //| the pitch output without changing the underlying sample.
166
- //|
158
+ //| sample_rate: Any =
159
+ //| """32 bit value that dictates how quickly samples are loaded into the DAC
160
+ //| in Hertz (cycles per second). When the sample is looped, this can change
161
+ //| the pitch output without changing the underlying sample."""
162
+ //| ...
167
163
STATIC mp_obj_t audiomp3_mp3file_obj_get_sample_rate (mp_obj_t self_in ) {
168
164
audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
169
165
check_for_deinit (self );
@@ -186,10 +182,9 @@ const mp_obj_property_t audiomp3_mp3file_sample_rate_obj = {
186
182
(mp_obj_t )& mp_const_none_obj },
187
183
};
188
184
189
- //| .. attribute:: bits_per_sample
190
- //|
191
- //| Bits per sample. (read only)
192
- //|
185
+ //| bits_per_sample: Any =
186
+ //| """Bits per sample. (read only)"""
187
+ //| ...
193
188
STATIC mp_obj_t audiomp3_mp3file_obj_get_bits_per_sample (mp_obj_t self_in ) {
194
189
audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
195
190
check_for_deinit (self );
@@ -204,10 +199,9 @@ const mp_obj_property_t audiomp3_mp3file_bits_per_sample_obj = {
204
199
(mp_obj_t )& mp_const_none_obj },
205
200
};
206
201
207
- //| .. attribute:: channel_count
208
- //|
209
- //| Number of audio channels. (read only)
210
- //|
202
+ //| channel_count: Any =
203
+ //| """Number of audio channels. (read only)"""
204
+ //| ...
211
205
STATIC mp_obj_t audiomp3_mp3file_obj_get_channel_count (mp_obj_t self_in ) {
212
206
audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
213
207
check_for_deinit (self );
@@ -222,10 +216,9 @@ const mp_obj_property_t audiomp3_mp3file_channel_count_obj = {
222
216
(mp_obj_t )& mp_const_none_obj },
223
217
};
224
218
225
- //| .. attribute:: rms_level
226
- //|
227
- //| The RMS audio level of a recently played moment of audio. (read only)
228
- //|
219
+ //| rms_level: Any =
220
+ //| """The RMS audio level of a recently played moment of audio. (read only)"""
221
+ //| ...
229
222
STATIC mp_obj_t audiomp3_mp3file_obj_get_rms_level (mp_obj_t self_in ) {
230
223
audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
231
224
check_for_deinit (self );
0 commit comments