summaryrefslogtreecommitdiff
path: root/shared-bindings/audiocore
diff options
context:
space:
mode:
Diffstat (limited to 'shared-bindings/audiocore')
-rw-r--r--shared-bindings/audiocore/RawSample.c114
-rw-r--r--shared-bindings/audiocore/WaveFile.c105
2 files changed, 104 insertions, 115 deletions
diff --git a/shared-bindings/audiocore/RawSample.c b/shared-bindings/audiocore/RawSample.c
index 96af58a4f..b879b1b97 100644
--- a/shared-bindings/audiocore/RawSample.c
+++ b/shared-bindings/audiocore/RawSample.c
@@ -35,45 +35,45 @@
#include "shared-bindings/audiocore/RawSample.h"
#include "supervisor/shared/translate.h"
-//| .. currentmodule:: audiocore
-//|
-//| :class:`RawSample` -- A raw audio sample buffer
-//| ========================================================
-//|
-//| An in-memory sound sample
-//|
-//| .. class:: RawSample(buffer, *, channel_count=1, sample_rate=8000)
-//|
-//| 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
-//| first sample will be for channel 1, the second sample will be for channel two, the third for
-//| channel 1 and so on.
-//|
-//| :param array.array buffer: An `array.array` with samples
-//| :param int channel_count: The number of channels in the buffer
-//| :param int sample_rate: The desired playback sample rate
-//|
-//| Simple 8ksps 440 Hz sin wave::
-//|
-//| import audiocore
-//| import audioio
-//| import board
-//| import array
-//| import time
-//| import math
-//|
-//| # Generate one period of sine wav.
-//| length = 8000 // 440
-//| sine_wave = array.array("h", [0] * length)
-//| for i in range(length):
-//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15))
-//|
-//| dac = audioio.AudioOut(board.SPEAKER)
-//| sine_wave = audiocore.RawSample(sine_wave)
-//| dac.play(sine_wave, loop=True)
-//| time.sleep(1)
-//| dac.stop()
-//|
+//|class RawSample:
+//| """.. currentmodule:: audiocore
+//|
+//| :class:`RawSample` -- A raw audio sample buffer
+//| ========================================================
+//|
+//| An in-memory sound sample"""
+//|
+//| 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
+//| 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
+//| channel 1 and so on.
+//|
+//| :param array.array buffer: An `array.array` with samples
+//| :param int channel_count: The number of channels in the buffer
+//| :param int sample_rate: The desired playback sample rate
+//|
+//| Simple 8ksps 440 Hz sin wave::
+//|
+//| import audiocore
+//| import audioio
+//| import board
+//| import array
+//| import time
+//| import math
+//|
+//| # Generate one period of sine wav.
+//| length = 8000 // 440
+//| sine_wave = array.array("h", [0] * length)
+//| for i in range(length):
+//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15))
+//|
+//| dac = audioio.AudioOut(board.SPEAKER)
+//| sine_wave = audiocore.RawSample(sine_wave)
+//| dac.play(sine_wave, loop=True)
+//| time.sleep(1)
+//| 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) {
enum { ARG_buffer, ARG_channel_count, ARG_sample_rate };
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);
}
-//| .. method:: deinit()
-//|
-//| Deinitialises the AudioOut and releases any hardware resources for reuse.
-//|
+//| def deinit(self, ) -> Any:
+//| """Deinitialises the AudioOut and releases any hardware resources for reuse."""
+//| ...
STATIC mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) {
audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audioio_rawsample_deinit(self);
@@ -122,17 +121,15 @@ STATIC void check_for_deinit(audioio_rawsample_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 audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
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__);
-//| .. attribute:: sample_rate
-//|
-//| 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
-//| sample. This will not change the sample rate of any active playback. Call ``play`` again to
-//| change it.
-//|
+//| sample_rate: Any =
+//| """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
+//| sample. This will not change the sample rate of any active playback. Call ``play`` again to
+//| change it."""
+//| ...
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);
check_for_deinit(self);
diff --git a/shared-bindings/audiocore/WaveFile.c b/shared-bindings/audiocore/WaveFile.c
index 178d2a139..f57e1f877 100644
--- a/shared-bindings/audiocore/WaveFile.c
+++ b/shared-bindings/audiocore/WaveFile.c
@@ -33,44 +33,43 @@
#include "shared-bindings/util.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
-//| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
-//| an internal buffer.
+//| 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
+//| an internal buffer."""
+//| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
+//| """Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//|
-//| .. class:: WaveFile(file[, buffer])
+//| :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.
//|
-//| Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
//|
-//| :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.
+//| Playing a wave file from flash::
//|
+//| import board
+//| import audiocore
+//| import audioio
+//| import digitalio
//|
-//| Playing a wave file from flash::
+//| # Required for CircuitPlayground Express
+//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
+//| speaker_enable.switch_to_output(value=True)
//|
-//| import board
-//| import audiocore
-//| import audioio
-//| import digitalio
-//|
-//| # Required for CircuitPlayground Express
-//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
-//| speaker_enable.switch_to_output(value=True)
-//|
-//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
-//| wav = audiocore.WaveFile(data)
-//| a = audioio.AudioOut(board.A0)
-//|
-//| print("playing")
-//| a.play(wav)
-//| while a.playing:
-//| pass
-//| print("stopped")
+//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
+//| wav = audiocore.WaveFile(data)
+//| a = audioio.AudioOut(board.A0)
//|
+//| print("playing")
+//| a.play(wav)
+//| while a.playing:
+//| pass
+//| 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) {
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);
}
-//| .. method:: deinit()
-//|
-//| Deinitialises the WaveFile and releases all memory resources for reuse.
-//|
+//| def deinit(self, ) -> Any:
+//| """Deinitialises the WaveFile and releases all memory resources for reuse."""
+//| ...
STATIC mp_obj_t audioio_wavefile_deinit(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audioio_wavefile_deinit(self);
@@ -110,17 +108,15 @@ STATIC void check_for_deinit(audioio_wavefile_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 audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
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__);
-//| .. attribute:: sample_rate
-//|
-//| 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.
-//|
+//| 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 audioio_wavefile_obj_get_sample_rate(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
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},
};
-//| .. attribute:: bits_per_sample
-//|
-//| Bits per sample. (read only)
-//|
+//| bits_per_sample: Any =
+//| """Bits per sample. (read only)"""
+//| ...
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);
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},
};
-//| .. attribute:: channel_count
-//|
-//| Number of audio channels. (read only)
-//|
+//| channel_count: Any =
+//| """Number of audio channels. (read only)"""
+//| ...
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);
check_for_deinit(self);