Added inline pyi to audiocore

This commit is contained in:
dherrada 2020-04-27 16:49:12 -04:00
parent e96235d0cf
commit 088b5b1785
No known key found for this signature in database
GPG Key ID: CE2ADBAB8775CE81
2 changed files with 96 additions and 107 deletions

View File

@ -35,16 +35,16 @@
#include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/audiocore/RawSample.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
//| .. currentmodule:: audiocore //|class RawSample:
//| """.. currentmodule:: audiocore
//| //|
//| :class:`RawSample` -- A raw audio sample buffer //| :class:`RawSample` -- A raw audio sample buffer
//| ======================================================== //| ========================================================
//| //|
//| An in-memory sound sample //| An in-memory sound sample"""
//| //|
//| .. class:: RawSample(buffer, *, channel_count=1, sample_rate=8000) //| def __init__(self, buffer: array.array, *, channel_count: int = 1, sample_rate: int = 8000):
//| //| """Create a RawSample based on the given buffer of signed values. If channel_count is more than
//| Create a RawSample based on the given buffer of signed values. If channel_count is more than
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the //| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
//| first sample will be for channel 1, the second sample will be for channel two, the third for //| first sample will be for channel 1, the second sample will be for channel two, the third for
//| channel 1 and so on. //| channel 1 and so on.
@ -72,8 +72,8 @@
//| sine_wave = audiocore.RawSample(sine_wave) //| sine_wave = audiocore.RawSample(sine_wave)
//| dac.play(sine_wave, loop=True) //| dac.play(sine_wave, loop=True)
//| time.sleep(1) //| time.sleep(1)
//| dac.stop() //| dac.stop()"""
//| //| ...
STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_channel_count, ARG_sample_rate }; enum { ARG_buffer, ARG_channel_count, ARG_sample_rate };
static const mp_arg_t allowed_args[] = { static const mp_arg_t allowed_args[] = {
@ -105,10 +105,9 @@ STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a
return MP_OBJ_FROM_PTR(self); return MP_OBJ_FROM_PTR(self);
} }
//| .. method:: deinit() //| def deinit(self, ) -> Any:
//| //| """Deinitialises the AudioOut and releases any hardware resources for reuse."""
//| Deinitialises the AudioOut and releases any hardware resources for reuse. //| ...
//|
STATIC mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) { STATIC mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) {
audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audioio_rawsample_deinit(self); common_hal_audioio_rawsample_deinit(self);
@ -122,17 +121,15 @@ STATIC void check_for_deinit(audioio_rawsample_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
//| Automatically deinitializes the hardware when exiting a context. See //| :ref:`lifetime-and-contextmanagers` for more info."""
//| :ref:`lifetime-and-contextmanagers` for more info. //| ...
//|
STATIC mp_obj_t audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args; (void)n_args;
common_hal_audioio_rawsample_deinit(args[0]); common_hal_audioio_rawsample_deinit(args[0]);
@ -140,13 +137,12 @@ STATIC mp_obj_t audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *ar
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_rawsample___exit___obj, 4, 4, audioio_rawsample_obj___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_rawsample___exit___obj, 4, 4, audioio_rawsample_obj___exit__);
//| .. attribute:: sample_rate //| sample_rate: Any =
//| //| """32 bit value that dictates how quickly samples are played in Hertz (cycles per second).
//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second).
//| When the sample is looped, this can change the pitch output without changing the underlying //| When the sample is looped, this can change the pitch output without changing the underlying
//| sample. This will not change the sample rate of any active playback. Call ``play`` again to //| sample. This will not change the sample rate of any active playback. Call ``play`` again to
//| change it. //| change it."""
//| //| ...
STATIC mp_obj_t audioio_rawsample_obj_get_sample_rate(mp_obj_t self_in) { STATIC mp_obj_t audioio_rawsample_obj_get_sample_rate(mp_obj_t self_in) {
audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in); audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);

View File

@ -33,18 +33,17 @@
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
//| .. currentmodule:: audiocore //|class WaveFile:
//| """.. currentmodule:: audiocore
//| //|
//| :class:`WaveFile` -- Load a wave file for audio playback //| :class:`WaveFile` -- Load a wave file for audio playback
//| ======================================================== //| ========================================================
//| //|
//| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must //| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must
//| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating //| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
//| an internal buffer. //| an internal buffer."""
//| //| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
//| .. class:: WaveFile(file[, buffer]) //| """Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//|
//| Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//| //|
//| :param typing.BinaryIO file: Already opened wave file //| :param typing.BinaryIO file: Already opened wave 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 512 byte buffers are allocated internally. //| :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 512 byte buffers are allocated internally.
@ -69,8 +68,8 @@
//| a.play(wav) //| a.play(wav)
//| while a.playing: //| while a.playing:
//| pass //| pass
//| print("stopped") //| print("stopped")"""
//| //| ...
STATIC mp_obj_t audioio_wavefile_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 audioio_wavefile_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);
@ -93,10 +92,9 @@ STATIC mp_obj_t audioio_wavefile_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 WaveFile and releases all memory resources for reuse."""
//| Deinitialises the WaveFile and releases all memory resources for reuse. //| ...
//|
STATIC mp_obj_t audioio_wavefile_deinit(mp_obj_t self_in) { STATIC mp_obj_t audioio_wavefile_deinit(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audioio_wavefile_deinit(self); common_hal_audioio_wavefile_deinit(self);
@ -110,17 +108,15 @@ STATIC void check_for_deinit(audioio_wavefile_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
//| Automatically deinitializes the hardware when exiting a context. See //| :ref:`lifetime-and-contextmanagers` for more info."""
//| :ref:`lifetime-and-contextmanagers` for more info. //| ...
//|
STATIC mp_obj_t audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *args) { STATIC mp_obj_t audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args; (void)n_args;
common_hal_audioio_wavefile_deinit(args[0]); common_hal_audioio_wavefile_deinit(args[0]);
@ -128,12 +124,11 @@ STATIC mp_obj_t audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *arg
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_wavefile___exit___obj, 4, 4, audioio_wavefile_obj___exit__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_wavefile___exit___obj, 4, 4, audioio_wavefile_obj___exit__);
//| .. 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 audioio_wavefile_obj_get_sample_rate(mp_obj_t self_in) { STATIC mp_obj_t audioio_wavefile_obj_get_sample_rate(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);
@ -156,10 +151,9 @@ const mp_obj_property_t audioio_wavefile_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 audioio_wavefile_obj_get_bits_per_sample(mp_obj_t self_in) { STATIC mp_obj_t audioio_wavefile_obj_get_bits_per_sample(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);
@ -174,10 +168,9 @@ const mp_obj_property_t audioio_wavefile_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 audioio_wavefile_obj_get_channel_count(mp_obj_t self_in) { STATIC mp_obj_t audioio_wavefile_obj_get_channel_count(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in); audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self); check_for_deinit(self);