Did audioio, audiomixer, audiomp3
This commit is contained in:
parent
7ff9b9bc80
commit
d65e851044
@ -94,6 +94,7 @@
|
||||
//| pass
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_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_left_channel, ARG_right_channel, ARG_quiescent_value };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -118,6 +119,7 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialises the AudioOut and releases any hardware resources for reuse."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_deinit(mp_obj_t self_in) {
|
||||
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_audioio_audioout_deinit(self);
|
||||
@ -133,12 +135,14 @@ STATIC void check_for_deinit(audioio_audioout_obj_t *self) {
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
common_hal_audioio_audioout_deinit(args[0]);
|
||||
@ -157,6 +161,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_audioout___exit___obj, 4, 4,
|
||||
//| resolution will use the highest order bits to output. For example, the SAMD21 has a 10 bit
|
||||
//| DAC that ignores the lowest 6 bits when playing 16 bit samples."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_sample, ARG_loop };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -178,6 +183,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audioio_audioout_play_obj, 1, audioio_audioout_obj_pl
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """Stops playback and resets to the start of the sample."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
|
||||
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -186,9 +192,9 @@ STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_stop_obj, audioio_audioout_obj_stop);
|
||||
|
||||
//|playing: Any =
|
||||
//| playing: Any = ...
|
||||
//| """True when an audio sample is being output even if `paused`. (read-only)"""
|
||||
//|...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_obj_get_playing(mp_obj_t self_in) {
|
||||
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -206,6 +212,7 @@ const mp_obj_property_t audioio_audioout_playing_obj = {
|
||||
//| def pause(self, ) -> Any:
|
||||
//| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
|
||||
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -221,6 +228,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_pause_obj, audioio_audioout_obj_pause
|
||||
//| def resume(self, ) -> Any:
|
||||
//| """Resumes sample playback after :py:func:`pause`."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
|
||||
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -233,9 +241,9 @@ STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_resume_obj, audioio_audioout_obj_resume);
|
||||
|
||||
//|paused: Any =
|
||||
//| paused: Any = ...
|
||||
//| """True when playback is paused. (read-only)"""
|
||||
//|...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_obj_get_paused(mp_obj_t self_in) {
|
||||
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "shared-bindings/audiomixer/Mixer.h"
|
||||
#endif
|
||||
|
||||
//| :mod:`audioio` --- Support for audio input and output
|
||||
//| """:mod:`audioio` --- Support for audio input and output
|
||||
//| ======================================================
|
||||
//|
|
||||
//| .. module:: audioio
|
||||
@ -68,7 +68,7 @@
|
||||
//|
|
||||
//| For compatibility with CircuitPython 4.x, some builds allow the items in
|
||||
//| `audiocore` to be imported from `audioio`. This will be removed for all
|
||||
//| boards in a future build of CircuitPython.
|
||||
//| boards in a future build of CircuitPython."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audioio_module_globals_table[] = {
|
||||
|
@ -82,6 +82,7 @@
|
||||
//| time.sleep(1)
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
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) {
|
||||
enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -128,6 +129,7 @@ STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialises the Mixer and releases any hardware resources for reuse."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_deinit(mp_obj_t self_in) {
|
||||
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_audiomixer_mixer_deinit(self);
|
||||
@ -144,12 +146,14 @@ STATIC void check_for_deinit(audiomixer_mixer_obj_t *self) {
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
common_hal_audiomixer_mixer_deinit(args[0]);
|
||||
@ -157,9 +161,9 @@ STATIC mp_obj_t audiomixer_mixer_obj___exit__(size_t n_args, const mp_obj_t *arg
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomixer_mixer___exit___obj, 4, 4, audiomixer_mixer_obj___exit__);
|
||||
|
||||
//|playing: Any =
|
||||
//| playing: Any = ...
|
||||
//| """True when any voice is being output. (read-only)"""
|
||||
//|...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_obj_get_playing(mp_obj_t self_in) {
|
||||
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -174,9 +178,9 @@ const mp_obj_property_t audiomixer_mixer_playing_obj = {
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//|sample_rate: Any =
|
||||
//| sample_rate: Any = ...
|
||||
//| """32 bit value that dictates how quickly samples are played in Hertz (cycles per second)."""
|
||||
//|...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_obj_get_sample_rate(mp_obj_t self_in) {
|
||||
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -191,14 +195,13 @@ const mp_obj_property_t audiomixer_mixer_sample_rate_obj = {
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//|voice: Any =
|
||||
//| voice: Any = ...
|
||||
//| """A tuple of the mixer's `audiomixer.MixerVoice` object(s).
|
||||
//|
|
||||
//| .. code-block:: python
|
||||
//|
|
||||
//| >>> mixer.voice
|
||||
//| (<MixerVoice>,)"""
|
||||
//|...
|
||||
STATIC mp_obj_t audiomixer_mixer_obj_get_voice(mp_obj_t self_in) {
|
||||
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -221,6 +224,7 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
|
||||
//|
|
||||
//| The sample must match the Mixer's encoding settings given in the constructor."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_sample, ARG_voice, ARG_loop };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -248,6 +252,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixer_play_obj, 1, audiomixer_mixer_obj_pl
|
||||
//| def stop_voice(self, voice: Any = 0) -> Any:
|
||||
//| """Stops playback of the sample on the given voice."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_obj_stop_voice(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_voice };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
@ -46,9 +46,9 @@
|
||||
//| Used to access and control samples with `audiomixer.Mixer`."""
|
||||
//|
|
||||
//| def __init__(self, ):
|
||||
//|
|
||||
//| """MixerVoice instance object(s) created by `audiomixer.Mixer`."""
|
||||
//| ...
|
||||
//|
|
||||
// TODO: support mono or stereo voices
|
||||
STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
audiomixer_mixervoice_obj_t *self = m_new_obj(audiomixer_mixervoice_obj_t);
|
||||
@ -67,6 +67,7 @@ STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t
|
||||
//|
|
||||
//| The sample must match the `audiomixer.Mixer`'s encoding settings given in the constructor."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixervoice_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_sample, ARG_loop };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -86,6 +87,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_play_obj, 1, audiomixer_mixervo
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """Stops playback of the sample on this voice."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_voice };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -101,9 +103,9 @@ STATIC mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *po
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_stop_obj, 1, audiomixer_mixervoice_obj_stop);
|
||||
|
||||
//|level(): Any =
|
||||
//| level: Any = ...
|
||||
//| """The volume level of a voice, as a floating point number between 0 and 1."""
|
||||
//|...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixervoice_obj_get_level(mp_obj_t self_in) {
|
||||
return mp_obj_new_float(common_hal_audiomixer_mixervoice_get_level(self_in));
|
||||
}
|
||||
@ -137,9 +139,9 @@ const mp_obj_property_t audiomixer_mixervoice_level_obj = {
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//|playing: Any =
|
||||
//| playing: Any = ...
|
||||
//| """True when this voice is being output. (read-only)"""
|
||||
//|...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t audiomixer_mixervoice_obj_get_playing(mp_obj_t self_in) {
|
||||
audiomixer_mixervoice_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/audiomixer/Mixer.h"
|
||||
|
||||
//| :mod:`audiomixer` --- Support for audio mixer
|
||||
//| """:mod:`audiomixer` --- Support for audio mixer
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: audiomixer
|
||||
@ -46,7 +46,7 @@
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Mixer
|
||||
//| MixerVoice
|
||||
//| MixerVoice"""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audiomixer_module_globals_table[] = {
|
||||
|
@ -43,6 +43,7 @@
|
||||
//| An object that decodes MP3 files for playback on an audio device."""
|
||||
//|
|
||||
//| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
|
||||
//|
|
||||
//| """Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
|
||||
//|
|
||||
//| :param typing.BinaryIO file: Already opened mp3 file
|
||||
@ -70,6 +71,7 @@
|
||||
//| 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) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 2, false);
|
||||
|
||||
@ -95,6 +97,7 @@ STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialises the MP3 and releases all memory resources for reuse."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomp3_mp3file_deinit(mp_obj_t self_in) {
|
||||
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_audiomp3_mp3file_deinit(self);
|
||||
@ -111,12 +114,14 @@ STATIC void check_for_deinit(audiomp3_mp3file_obj_t *self) {
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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) {
|
||||
(void)n_args;
|
||||
common_hal_audiomp3_mp3file_deinit(args[0]);
|
||||
@ -124,9 +129,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__);
|
||||
|
||||
//|file: Any =
|
||||
//| file: Any = ...
|
||||
//| """File to play back."""
|
||||
//|...
|
||||
//|
|
||||
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);
|
||||
check_for_deinit(self);
|
||||
@ -154,11 +159,11 @@ const mp_obj_property_t audiomp3_mp3file_file_obj = {
|
||||
|
||||
|
||||
|
||||
//|sample_rate: Any =
|
||||
//| sample_rate: Any = ...
|
||||
//| """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
|
||||
//| the pitch output without changing the underlying sample."""
|
||||
//|...
|
||||
//|
|
||||
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);
|
||||
check_for_deinit(self);
|
||||
@ -181,9 +186,9 @@ const mp_obj_property_t audiomp3_mp3file_sample_rate_obj = {
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//|bits_per_sample: Any =
|
||||
//| bits_per_sample: Any = ...
|
||||
//| """Bits per sample. (read only)"""
|
||||
//|...
|
||||
//|
|
||||
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);
|
||||
check_for_deinit(self);
|
||||
@ -198,9 +203,9 @@ const mp_obj_property_t audiomp3_mp3file_bits_per_sample_obj = {
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//|channel_count: Any =
|
||||
//| channel_count: Any = ...
|
||||
//| """Number of audio channels. (read only)"""
|
||||
//|...
|
||||
//|
|
||||
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);
|
||||
check_for_deinit(self);
|
||||
@ -215,9 +220,9 @@ const mp_obj_property_t audiomp3_mp3file_channel_count_obj = {
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//|rms_level: Any =
|
||||
//| rms_level: Any = ...
|
||||
//| """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) {
|
||||
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "shared-bindings/audiomp3/MP3Decoder.h"
|
||||
|
||||
//| :mod:`audiomp3` --- Support for MP3-compressed audio files
|
||||
//| """:mod:`audiomp3` --- Support for MP3-compressed audio files
|
||||
//| ==========================================================
|
||||
//|
|
||||
//| .. module:: audiomp3
|
||||
@ -44,7 +44,7 @@
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| MP3Decoder
|
||||
//| MP3Decoder"""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audiomp3_module_globals_table[] = {
|
||||
|
Loading…
Reference in New Issue
Block a user