summaryrefslogtreecommitdiff
path: root/shared-bindings/audiomixer
diff options
context:
space:
mode:
authordherrada <dylan.herrada@gmail.com>2020-04-30 13:06:09 -0400
committerdherrada <dylan.herrada@gmail.com>2020-04-30 13:06:09 -0400
commitd65e85104431b354737d11b5ec9a29387d390cfd (patch)
tree8e305c53832cf8df05a3b4fdb7baffdd871e0678 /shared-bindings/audiomixer
parent7ff9b9bc80b3dafd4b263bc8854e4582a21664c2 (diff)
Did audioio, audiomixer, audiomp3
Diffstat (limited to 'shared-bindings/audiomixer')
-rw-r--r--shared-bindings/audiomixer/Mixer.c139
-rw-r--r--shared-bindings/audiomixer/MixerVoice.c48
-rw-r--r--shared-bindings/audiomixer/__init__.c4
3 files changed, 99 insertions, 92 deletions
diff --git a/shared-bindings/audiomixer/Mixer.c b/shared-bindings/audiomixer/Mixer.c
index 93b1d3635..966581d45 100644
--- a/shared-bindings/audiomixer/Mixer.c
+++ b/shared-bindings/audiomixer/Mixer.c
@@ -38,50 +38,51 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
-//|class Mixer:
-//|""".. currentmodule:: audiomixer
+//| class Mixer:
+//| """.. currentmodule:: audiomixer
//|
-//|:class:`Mixer` -- Mixes one or more audio samples together
-//|===========================================================
+//| :class:`Mixer` -- Mixes one or more audio samples together
+//| ===========================================================
//|
-//|Mixer mixes multiple samples into one sample."""
+//| Mixer mixes multiple samples into one sample."""
//|
-//|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.
+//| 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
-//|:param int buffer_size: The total size in bytes of the buffers to mix into
-//|:param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
-//|:param int bits_per_sample: The bits per sample of the samples being played
-//|:param bool samples_signed: Samples are signed (True) or unsigned (False)
-//|:param int sample_rate: The sample rate to be used for all samples
+//| :param int voice_count: The maximum number of voices to mix
+//| :param int buffer_size: The total size in bytes of the buffers to mix into
+//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
+//| :param int bits_per_sample: The bits per sample of the samples being played
+//| :param bool samples_signed: Samples are signed (True) or unsigned (False)
+//| :param int sample_rate: The sample rate to be used for all samples
//|
-//|Playing a wave file from flash::
+//| Playing a wave file from flash::
//|
-//|import board
-//|import audioio
-//|import audiocore
-//|import audiomixer
-//|import digitalio
+//| import board
+//| import audioio
+//| import audiocore
+//| import audiomixer
+//| import digitalio
//|
-//|a = audioio.AudioOut(board.A0)
-//|music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
-//|drum = audiocore.WaveFile(open("drum.wav", "rb"))
-//|mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1,
-//|bits_per_sample=16, samples_signed=True)
+//| a = audioio.AudioOut(board.A0)
+//| music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
+//| drum = audiocore.WaveFile(open("drum.wav", "rb"))
+//| mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1,
+//| bits_per_sample=16, samples_signed=True)
+//|
+//| print("playing")
+//| # Have AudioOut play our Mixer source
+//| a.play(mixer)
+//| # Play the first sample voice
+//| mixer.voice[0].play(music)
+//| while mixer.playing:
+//| # Play the second sample voice
+//| mixer.voice[1].play(drum)
+//| time.sleep(1)
+//| print("stopped")"""
+//| ...
//|
-//|print("playing")
-//|# Have AudioOut play our Mixer source
-//|a.play(mixer)
-//|# Play the first sample voice
-//|mixer.voice[0].play(music)
-//|while mixer.playing:
-//|# Play the second sample voice
-//|mixer.voice[1].play(drum)
-//|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[] = {
@@ -125,9 +126,10 @@ STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar
return MP_OBJ_FROM_PTR(self);
}
-//|def deinit(self, ) -> Any:
-//|"""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);
@@ -141,15 +143,17 @@ STATIC void check_for_deinit(audiomixer_mixer_obj_t *self) {
}
}
-//|def __enter__(self, ) -> Any:
-//|"""No-op used by Context Managers."""
-//|...
+//| 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."""
-//|...
+//| 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 =
-//|"""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);
@@ -174,9 +178,9 @@ const mp_obj_property_t audiomixer_mixer_playing_obj = {
(mp_obj_t)&mp_const_none_obj},
};
-//|sample_rate: Any =
-//|"""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);
@@ -191,14 +195,13 @@ const mp_obj_property_t audiomixer_mixer_sample_rate_obj = {
(mp_obj_t)&mp_const_none_obj},
};
-//|voice: Any =
-//|"""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
+//| .. code-block:: python
//|
-//|>>> mixer.voice
-//|(<MixerVoice>,)"""
-//|...
+//| >>> 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);
@@ -213,14 +216,15 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
(mp_obj_t)&mp_const_none_obj},
};
-//|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.
+//| 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`.
+//| 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[] = {
@@ -245,9 +249,10 @@ 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);
-//|def stop_voice(self, voice: Any = 0) -> Any:
-//|"""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[] = {
diff --git a/shared-bindings/audiomixer/MixerVoice.c b/shared-bindings/audiomixer/MixerVoice.c
index 299600dd1..257d9507b 100644
--- a/shared-bindings/audiomixer/MixerVoice.c
+++ b/shared-bindings/audiomixer/MixerVoice.c
@@ -37,18 +37,18 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
-//|class MixerVoice:
-//|""".. currentmodule:: audiomixer
+//| class MixerVoice:
+//| """.. currentmodule:: audiomixer
//|
-//|:class:`MixerVoice` -- Voice objects used with Mixer
-//|=====================================================
+//| :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`."""
//|
-//|def __init__(self, ):
+//| def __init__(self, ):
+//| """MixerVoice instance object(s) created by `audiomixer.Mixer`."""
+//| ...
//|
-//|"""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);
@@ -59,14 +59,15 @@ STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t
return MP_OBJ_FROM_PTR(self);
}
-//|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.
+//| 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`.
+//| 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,9 +84,10 @@ 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);
-//|def stop(self, ) -> Any:
-//|"""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[] = {
@@ -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 =
-//|"""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));
}
@@ -137,9 +139,9 @@ const mp_obj_property_t audiomixer_mixervoice_level_obj = {
(mp_obj_t)&mp_const_none_obj},
};
-//|playing: Any =
-//|"""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);
diff --git a/shared-bindings/audiomixer/__init__.c b/shared-bindings/audiomixer/__init__.c
index 79bab440e..c90a4a0e6 100644
--- a/shared-bindings/audiomixer/__init__.c
+++ b/shared-bindings/audiomixer/__init__.c
@@ -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[] = {