3434#include "shared-bindings/util.h"
3535#include "supervisor/shared/translate.h"
3636
37- //| .. currentmodule:: audiomp3
37+ //|class MP3:
38+ //| """.. currentmodule:: audiomp3
3839//|
39- //| :class:`MP3Decoder` -- Load a mp3 file for audio playback
40- //| =========================================================
40+ //| :class:`MP3Decoder` -- Load a mp3 file for audio playback
41+ //| =========================================================
4142//|
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."""
4344//|
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`.
4547//|
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.
4750//|
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.
5051//|
52+ //| Playing a mp3 file from flash::
5153//|
52- //| Playing a mp3 file from flash::
54+ //| import board
55+ //| import audiomp3
56+ //| import audioio
57+ //| import digitalio
5358//|
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)
5862//|
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)
7266//|
67+ //| print("playing")
68+ //| a.play(mp3)
69+ //| while a.playing:
70+ //| pass
71+ //| print("stopped")"""
72+ //| ...
7373STATIC 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 ) {
7474 mp_arg_check_num (n_args , kw_args , 1 , 2 , false);
7575
@@ -92,10 +92,9 @@ STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
9292 return MP_OBJ_FROM_PTR (self );
9393}
9494
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+ //| ...
9998STATIC mp_obj_t audiomp3_mp3file_deinit (mp_obj_t self_in ) {
10099 audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
101100 common_hal_audiomp3_mp3file_deinit (self );
@@ -109,28 +108,26 @@ STATIC void check_for_deinit(audiomp3_mp3file_obj_t *self) {
109108 }
110109}
111110
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+ //| ...
116114// Provided by context manager helper.
117115
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:
122117//|
118+ //| """Automatically deinitializes the hardware when exiting a context. See
119+ //| :ref:`lifetime-and-contextmanagers` for more info."""
120+ //| ...
123121STATIC mp_obj_t audiomp3_mp3file_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
124122 (void )n_args ;
125123 common_hal_audiomp3_mp3file_deinit (args [0 ]);
126124 return mp_const_none ;
127125}
128126STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audiomp3_mp3file___exit___obj , 4 , 4 , audiomp3_mp3file_obj___exit__ );
129127
130- //| .. attribute:: file
131- //|
132- //| File to play back.
133- //|
128+ //| file: Any =
129+ //| """File to play back."""
130+ //| ...
134131STATIC mp_obj_t audiomp3_mp3file_obj_get_file (mp_obj_t self_in ) {
135132 audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
136133 check_for_deinit (self );
@@ -158,12 +155,11 @@ const mp_obj_property_t audiomp3_mp3file_file_obj = {
158155
159156
160157
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+ //| ...
167163STATIC mp_obj_t audiomp3_mp3file_obj_get_sample_rate (mp_obj_t self_in ) {
168164 audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
169165 check_for_deinit (self );
@@ -186,10 +182,9 @@ const mp_obj_property_t audiomp3_mp3file_sample_rate_obj = {
186182 (mp_obj_t )& mp_const_none_obj },
187183};
188184
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+ //| ...
193188STATIC mp_obj_t audiomp3_mp3file_obj_get_bits_per_sample (mp_obj_t self_in ) {
194189 audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
195190 check_for_deinit (self );
@@ -204,10 +199,9 @@ const mp_obj_property_t audiomp3_mp3file_bits_per_sample_obj = {
204199 (mp_obj_t )& mp_const_none_obj },
205200};
206201
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+ //| ...
211205STATIC mp_obj_t audiomp3_mp3file_obj_get_channel_count (mp_obj_t self_in ) {
212206 audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
213207 check_for_deinit (self );
@@ -222,10 +216,9 @@ const mp_obj_property_t audiomp3_mp3file_channel_count_obj = {
222216 (mp_obj_t )& mp_const_none_obj },
223217};
224218
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+ //| ...
229222STATIC mp_obj_t audiomp3_mp3file_obj_get_rms_level (mp_obj_t self_in ) {
230223 audiomp3_mp3file_obj_t * self = MP_OBJ_TO_PTR (self_in );
231224 check_for_deinit (self );
0 commit comments