Added inline pyi to audiomp3

This commit is contained in:
dherrada 2020-04-27 17:29:50 -04:00
parent 8330471068
commit 829da5c127
No known key found for this signature in database
GPG Key ID: CE2ADBAB8775CE81
1 changed files with 53 additions and 60 deletions

View File

@ -34,42 +34,42 @@
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
//| .. currentmodule:: audiomp3 //|class MP3:
//| """.. currentmodule:: audiomp3
//| //|
//| :class:`MP3Decoder` -- Load a mp3 file for audio playback //| :class:`MP3Decoder` -- Load a mp3 file for audio playback
//| ========================================================= //| =========================================================
//| //|
//| An object that decodes MP3 files for playback on an audio device. //| An object that decodes MP3 files for playback on an audio device."""
//| //|
//| .. class:: MP3(file[, buffer]) //| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
//| """Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//| //|
//| Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`. //| :param typing.BinaryIO file: Already opened mp3 file
//| //| :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.
//| :param typing.BinaryIO file: Already opened mp3 file
//| :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.
//| //|
//| //|
//| Playing a mp3 file from flash:: //| Playing a mp3 file from flash::
//| //|
//| import board //| import board
//| import audiomp3 //| import audiomp3
//| import audioio //| import audioio
//| import digitalio //| import digitalio
//| //|
//| # Required for CircuitPlayground Express //| # Required for CircuitPlayground Express
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) //| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
//| speaker_enable.switch_to_output(value=True) //| speaker_enable.switch_to_output(value=True)
//| //|
//| data = open("cplay-16bit-16khz-64kbps.mp3", "rb") //| data = open("cplay-16bit-16khz-64kbps.mp3", "rb")
//| mp3 = audiomp3.MP3Decoder(data) //| mp3 = audiomp3.MP3Decoder(data)
//| a = audioio.AudioOut(board.A0) //| a = audioio.AudioOut(board.A0)
//|
//| print("playing")
//| a.play(mp3)
//| while a.playing:
//| pass
//| print("stopped")
//| //|
//| print("playing")
//| a.play(mp3)
//| while a.playing:
//| pass
//| print("stopped")"""
//| ...
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) { 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) {
mp_arg_check_num(n_args, kw_args, 1, 2, false); mp_arg_check_num(n_args, kw_args, 1, 2, false);
@ -92,10 +92,9 @@ STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
return MP_OBJ_FROM_PTR(self); return MP_OBJ_FROM_PTR(self);
} }
//| .. method:: deinit() //| def deinit(self, ) -> Any:
//| //| """Deinitialises the MP3 and releases all memory resources for reuse."""
//| Deinitialises the MP3 and releases all memory resources for reuse. //| ...
//|
STATIC mp_obj_t audiomp3_mp3file_deinit(mp_obj_t self_in) { STATIC mp_obj_t audiomp3_mp3file_deinit(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in); audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiomp3_mp3file_deinit(self); common_hal_audiomp3_mp3file_deinit(self);
@ -109,17 +108,16 @@ STATIC void check_for_deinit(audiomp3_mp3file_obj_t *self) {
} }
} }
//| .. method:: __enter__() //| def __enter__(self, ) -> Any:
//| //| """No-op used by Context Managers."""
//| No-op used by Context Managers. //| ...
//|
// Provided by context manager helper. // Provided by context manager helper.
//| .. method:: __exit__() //| def __exit__(self, ) -> Any:
//|
//| Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info.
//| //|
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
STATIC mp_obj_t audiomp3_mp3file_obj___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t audiomp3_mp3file_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args; (void)n_args;
common_hal_audiomp3_mp3file_deinit(args[0]); common_hal_audiomp3_mp3file_deinit(args[0]);
@ -127,10 +125,9 @@ STATIC mp_obj_t audiomp3_mp3file_obj___exit__(size_t n_args, const mp_obj_t *arg
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomp3_mp3file___exit___obj, 4, 4, audiomp3_mp3file_obj___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomp3_mp3file___exit___obj, 4, 4, audiomp3_mp3file_obj___exit__);
//| .. attribute:: file //| file: Any =
//| //| """File to play back."""
//| File to play back. //| ...
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_file(mp_obj_t self_in) { STATIC mp_obj_t audiomp3_mp3file_obj_get_file(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in); audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);
@ -158,12 +155,11 @@ const mp_obj_property_t audiomp3_mp3file_file_obj = {
//| .. attribute:: sample_rate //| sample_rate: Any =
//| //| """32 bit value that dictates how quickly samples are loaded into the DAC
//| 32 bit value that dictates how quickly samples are loaded into the DAC //| in Hertz (cycles per second). When the sample is looped, this can change
//| in Hertz (cycles per second). When the sample is looped, this can change //| the pitch output without changing the underlying sample."""
//| the pitch output without changing the underlying sample. //| ...
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_sample_rate(mp_obj_t self_in) { STATIC mp_obj_t audiomp3_mp3file_obj_get_sample_rate(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in); audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);
@ -186,10 +182,9 @@ const mp_obj_property_t audiomp3_mp3file_sample_rate_obj = {
(mp_obj_t)&mp_const_none_obj}, (mp_obj_t)&mp_const_none_obj},
}; };
//| .. attribute:: bits_per_sample //| bits_per_sample: Any =
//| //| """Bits per sample. (read only)"""
//| Bits per sample. (read only) //| ...
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_bits_per_sample(mp_obj_t self_in) { STATIC mp_obj_t audiomp3_mp3file_obj_get_bits_per_sample(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in); audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);
@ -204,10 +199,9 @@ const mp_obj_property_t audiomp3_mp3file_bits_per_sample_obj = {
(mp_obj_t)&mp_const_none_obj}, (mp_obj_t)&mp_const_none_obj},
}; };
//| .. attribute:: channel_count //| channel_count: Any =
//| //| """Number of audio channels. (read only)"""
//| Number of audio channels. (read only) //| ...
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_channel_count(mp_obj_t self_in) { STATIC mp_obj_t audiomp3_mp3file_obj_get_channel_count(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in); audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);
@ -222,10 +216,9 @@ const mp_obj_property_t audiomp3_mp3file_channel_count_obj = {
(mp_obj_t)&mp_const_none_obj}, (mp_obj_t)&mp_const_none_obj},
}; };
//| .. attribute:: rms_level //| rms_level: Any =
//| //| """The RMS audio level of a recently played moment of audio. (read only)"""
//| The RMS audio level of a recently played moment of audio. (read only) //| ...
//|
STATIC mp_obj_t audiomp3_mp3file_obj_get_rms_level(mp_obj_t self_in) { STATIC mp_obj_t audiomp3_mp3file_obj_get_rms_level(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in); audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);