Added inline pyi to audiomixer
This commit is contained in:
parent
1363e6e724
commit
8330471068
|
@ -38,16 +38,16 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiomixer
|
||||
//|class Mixer:
|
||||
//| """.. currentmodule:: audiomixer
|
||||
//|
|
||||
//| :class:`Mixer` -- Mixes one or more audio samples together
|
||||
//| ===========================================================
|
||||
//|
|
||||
//| Mixer mixes multiple samples into one sample.
|
||||
//| Mixer mixes multiple samples into one sample."""
|
||||
//|
|
||||
//| .. class:: Mixer(voice_count=2, buffer_size=1024, channel_count=2, bits_per_sample=16, samples_signed=True, sample_rate=8000)
|
||||
//|
|
||||
//| Create a Mixer object that can mix multiple channels with the same sample rate.
|
||||
//| def __init__(self, voice_count: int = 2, buffer_size: int = 1024, channel_count: int = 2, bits_per_sample: int = 16, samples_signed: bool = True, sample_rate: int = 8000):
|
||||
//| """Create a Mixer object that can mix multiple channels with the same sample rate.
|
||||
//| Samples are accessed and controlled with the mixer's `audiomixer.MixerVoice` objects.
|
||||
//|
|
||||
//| :param int voice_count: The maximum number of voices to mix
|
||||
|
@ -80,8 +80,8 @@
|
|||
//| # Play the second sample voice
|
||||
//| mixer.voice[1].play(drum)
|
||||
//| time.sleep(1)
|
||||
//| print("stopped")
|
||||
//|
|
||||
//| 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[] = {
|
||||
|
@ -125,10 +125,9 @@ STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the Mixer and releases any hardware resources for reuse.
|
||||
//|
|
||||
//| 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);
|
||||
|
@ -142,17 +141,15 @@ STATIC void check_for_deinit(audiomixer_mixer_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//|
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//|
|
||||
//| 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]);
|
||||
|
@ -160,10 +157,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__);
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when any voice is being output. (read-only)
|
||||
//|
|
||||
//| 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);
|
||||
|
@ -178,10 +174,9 @@ const mp_obj_property_t audiomixer_mixer_playing_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: sample_rate
|
||||
//|
|
||||
//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second).
|
||||
//|
|
||||
//| 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);
|
||||
|
@ -196,14 +191,14 @@ const mp_obj_property_t audiomixer_mixer_sample_rate_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: voice
|
||||
//|
|
||||
//| A tuple of the mixer's `audiomixer.MixerVoice` object(s).
|
||||
//| voice: Any =
|
||||
//| """A tuple of the mixer's `audiomixer.MixerVoice` object(s).
|
||||
//|
|
||||
//| .. code-block:: python
|
||||
//|
|
||||
//| >>> mixer.voice
|
||||
//| (<MixerVoice>,)
|
||||
//| (<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);
|
||||
|
@ -218,15 +213,14 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: play(sample, *, voice=0, loop=False)
|
||||
//|
|
||||
//| Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| def play(self, sample: Any, *, voice: Any = 0, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| The sample must match the Mixer's encoding settings given in the constructor.
|
||||
//|
|
||||
//| 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[] = {
|
||||
|
@ -251,10 +245,9 @@ STATIC mp_obj_t audiomixer_mixer_obj_play(size_t n_args, const mp_obj_t *pos_arg
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixer_play_obj, 1, audiomixer_mixer_obj_play);
|
||||
|
||||
//| .. method:: stop_voice(voice=0)
|
||||
//|
|
||||
//| Stops playback of the sample on the given voice.
|
||||
//|
|
||||
//| 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[] = {
|
||||
|
|
|
@ -37,17 +37,18 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiomixer
|
||||
//|class MixerVoice:
|
||||
//| """.. currentmodule:: audiomixer
|
||||
//|
|
||||
//| :class:`MixerVoice` -- Voice objects used with Mixer
|
||||
//| =====================================================
|
||||
//|
|
||||
//| Used to access and control samples with `audiomixer.Mixer`.
|
||||
//| Used to access and control samples with `audiomixer.Mixer`."""
|
||||
//|
|
||||
//| .. class:: MixerVoice()
|
||||
//|
|
||||
//| MixerVoice instance object(s) created by `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);
|
||||
|
@ -58,15 +59,14 @@ STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: play(sample, *, loop=False)
|
||||
//|
|
||||
//| Plays the sample once when ``loop=False``, and continuously when ``loop=True``.
|
||||
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when ``loop=False``, and continuously when ``loop=True``.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiomixer.Mixer` or `audiocore.RawSample`.
|
||||
//|
|
||||
//| The sample must match the `audiomixer.Mixer`'s encoding settings given in the constructor.
|
||||
//|
|
||||
//| 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[] = {
|
||||
|
@ -83,10 +83,9 @@ STATIC mp_obj_t audiomixer_mixervoice_obj_play(size_t n_args, const mp_obj_t *po
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_play_obj, 1, audiomixer_mixervoice_obj_play);
|
||||
|
||||
//| .. method:: stop()
|
||||
//|
|
||||
//| Stops playback of the sample on this voice.
|
||||
//|
|
||||
//| 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[] = {
|
||||
|
@ -102,10 +101,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);
|
||||
|
||||
//| .. attribute:: level()
|
||||
//|
|
||||
//| The volume level of a voice, as a floating point number between 0 and 1.
|
||||
//|
|
||||
//| 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));
|
||||
}
|
||||
|
@ -139,10 +137,9 @@ const mp_obj_property_t audiomixer_mixervoice_level_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when this voice is being output. (read-only)
|
||||
//|
|
||||
//| 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);
|
||||
|
|
Loading…
Reference in New Issue