2018-10-02 21:06:52 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the Micro Python project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-08-25 00:36:18 -04:00
|
|
|
#include "shared-bindings/audiomixer/Mixer.h"
|
|
|
|
#include "shared-bindings/audiomixer/MixerVoice.h"
|
|
|
|
#include "shared-module/audiomixer/MixerVoice.h"
|
2018-10-02 21:06:52 -04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "lib/utils/context_manager_helpers.h"
|
|
|
|
#include "py/binary.h"
|
|
|
|
#include "py/objproperty.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "shared-bindings/microcontroller/Pin.h"
|
2019-07-24 21:57:32 -04:00
|
|
|
#include "shared-bindings/audiocore/RawSample.h"
|
2018-10-02 21:06:52 -04:00
|
|
|
#include "shared-bindings/util.h"
|
|
|
|
#include "supervisor/shared/translate.h"
|
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
//| .. currentmodule:: audiomixer
|
2018-10-02 21:06:52 -04:00
|
|
|
//|
|
|
|
|
//| :class:`Mixer` -- Mixes one or more audio samples together
|
|
|
|
//| ===========================================================
|
|
|
|
//|
|
|
|
|
//| Mixer mixes multiple samples into one sample.
|
|
|
|
//|
|
2019-08-03 12:20:06 -04:00
|
|
|
//| .. class:: Mixer(voice_count=2, buffer_size=1024, channel_count=2, bits_per_sample=16, samples_signed=True, sample_rate=8000)
|
2018-10-02 21:06:52 -04:00
|
|
|
//|
|
|
|
|
//| Create a Mixer object that can mix multiple channels with the same sample rate.
|
2019-08-25 15:57:29 -04:00
|
|
|
//| Samples are accessed and controlled with the mixer's `audiomixer.MixerVoice` objects.
|
2018-10-02 21:06:52 -04:00
|
|
|
//|
|
2019-08-03 12:20:06 -04:00
|
|
|
//| :param int voice_count: The maximum number of voices to mix
|
2018-10-02 21:06:52 -04:00
|
|
|
//| :param int buffer_size: The total size in bytes of the buffers to mix into
|
2019-09-03 23:44:43 -04:00
|
|
|
//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
|
2019-08-03 12:20:06 -04:00
|
|
|
//| :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
|
2018-10-02 21:06:52 -04:00
|
|
|
//|
|
|
|
|
//| Playing a wave file from flash::
|
|
|
|
//|
|
|
|
|
//| import board
|
|
|
|
//| import audioio
|
2019-08-03 12:20:06 -04:00
|
|
|
//| import audiocore
|
2019-08-25 00:36:18 -04:00
|
|
|
//| import audiomixer
|
2018-10-02 21:06:52 -04:00
|
|
|
//| import digitalio
|
|
|
|
//|
|
2019-09-03 23:44:43 -04:00
|
|
|
//| a = audioio.AudioOut(board.A0)
|
2019-08-03 12:20:06 -04:00
|
|
|
//| music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
|
|
|
|
//| drum = audiocore.WaveFile(open("drum.wav", "rb"))
|
2019-08-25 00:36:18 -04:00
|
|
|
//| mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1,
|
|
|
|
//| bits_per_sample=16, samples_signed=True)
|
2018-10-02 21:06:52 -04:00
|
|
|
//|
|
|
|
|
//| print("playing")
|
2019-08-03 12:20:06 -04:00
|
|
|
//| # Have AudioOut play our Mixer source
|
2018-10-02 21:06:52 -04:00
|
|
|
//| a.play(mixer)
|
2019-08-03 12:20:06 -04:00
|
|
|
//| # Play the first sample voice
|
|
|
|
//| mixer.voice[0].play(music)
|
2018-10-02 21:06:52 -04:00
|
|
|
//| while mixer.playing:
|
2019-08-03 12:20:06 -04:00
|
|
|
//| # Play the second sample voice
|
|
|
|
//| mixer.voice[1].play(drum)
|
2018-10-02 21:06:52 -04:00
|
|
|
//| time.sleep(1)
|
|
|
|
//| print("stopped")
|
|
|
|
//|
|
2019-08-25 00:36:18 -04:00
|
|
|
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) {
|
2018-10-02 21:06:52 -04:00
|
|
|
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[] = {
|
|
|
|
{ MP_QSTR_voice_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} },
|
|
|
|
{ MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1024} },
|
|
|
|
{ MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} },
|
|
|
|
{ MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} },
|
|
|
|
{ MP_QSTR_samples_signed, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
|
|
|
|
{ MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} },
|
|
|
|
};
|
|
|
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
2019-01-14 20:26:36 -05:00
|
|
|
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
|
|
|
mp_int_t voice_count = args[ARG_voice_count].u_int;
|
|
|
|
if (voice_count < 1 || voice_count > 255) {
|
|
|
|
mp_raise_ValueError(translate("Invalid voice count"));
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_int_t channel_count = args[ARG_channel_count].u_int;
|
|
|
|
if (channel_count < 1 || channel_count > 2) {
|
|
|
|
mp_raise_ValueError(translate("Invalid channel count"));
|
|
|
|
}
|
|
|
|
mp_int_t sample_rate = args[ARG_sample_rate].u_int;
|
|
|
|
if (sample_rate < 1) {
|
|
|
|
mp_raise_ValueError(translate("Sample rate must be positive"));
|
|
|
|
}
|
|
|
|
mp_int_t bits_per_sample = args[ARG_bits_per_sample].u_int;
|
|
|
|
if (bits_per_sample != 8 && bits_per_sample != 16) {
|
|
|
|
mp_raise_ValueError(translate("bits_per_sample must be 8 or 16"));
|
|
|
|
}
|
2019-08-25 00:36:18 -04:00
|
|
|
audiomixer_mixer_obj_t *self = m_new_obj_var(audiomixer_mixer_obj_t, mp_obj_t, voice_count);
|
|
|
|
self->base.type = &audiomixer_mixer_type;
|
|
|
|
common_hal_audiomixer_mixer_construct(self, voice_count, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
2018-11-15 15:04:11 -05:00
|
|
|
for(int v=0; v<voice_count; v++){
|
2019-08-25 00:36:18 -04:00
|
|
|
self->voice[v] = audiomixer_mixervoice_type.make_new(&audiomixer_mixervoice_type, 0, 0, NULL);
|
|
|
|
common_hal_audiomixer_mixervoice_set_parent(self->voice[v], self);
|
2018-11-15 15:04:11 -05:00
|
|
|
}
|
|
|
|
self->voice_tuple = mp_obj_new_tuple(self->voice_count, self->voice);
|
|
|
|
|
2018-10-02 21:06:52 -04:00
|
|
|
return MP_OBJ_FROM_PTR(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
//| .. method:: deinit()
|
|
|
|
//|
|
|
|
|
//| Deinitialises the Mixer and releases any hardware resources for reuse.
|
|
|
|
//|
|
2019-08-25 00:36:18 -04:00
|
|
|
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);
|
2018-10-02 21:06:52 -04:00
|
|
|
return mp_const_none;
|
|
|
|
}
|
2019-08-25 00:36:18 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixer_deinit_obj, audiomixer_mixer_deinit);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
STATIC void check_for_deinit(audiomixer_mixer_obj_t *self) {
|
|
|
|
if (common_hal_audiomixer_mixer_deinited(self)) {
|
2019-06-12 04:00:59 -04:00
|
|
|
raise_deinited_error();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 21:06:52 -04:00
|
|
|
//| .. method:: __enter__()
|
|
|
|
//|
|
|
|
|
//| 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.
|
|
|
|
//|
|
2019-08-25 00:36:18 -04:00
|
|
|
STATIC mp_obj_t audiomixer_mixer_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
2018-10-02 21:06:52 -04:00
|
|
|
(void)n_args;
|
2019-08-25 00:36:18 -04:00
|
|
|
common_hal_audiomixer_mixer_deinit(args[0]);
|
2018-10-02 21:06:52 -04:00
|
|
|
return mp_const_none;
|
|
|
|
}
|
2019-08-25 00:36:18 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomixer_mixer___exit___obj, 4, 4, audiomixer_mixer_obj___exit__);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
|
|
|
//| .. attribute:: playing
|
|
|
|
//|
|
2018-10-05 16:03:28 -04:00
|
|
|
//| True when any voice is being output. (read-only)
|
2018-10-02 21:06:52 -04:00
|
|
|
//|
|
2019-08-25 00:36:18 -04:00
|
|
|
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);
|
2019-06-12 04:00:59 -04:00
|
|
|
check_for_deinit(self);
|
2019-08-25 00:36:18 -04:00
|
|
|
return mp_obj_new_bool(common_hal_audiomixer_mixer_get_playing(self));
|
2018-10-02 21:06:52 -04:00
|
|
|
}
|
2019-08-25 00:36:18 -04:00
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixer_get_playing_obj, audiomixer_mixer_obj_get_playing);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
const mp_obj_property_t audiomixer_mixer_playing_obj = {
|
2018-10-02 21:06:52 -04:00
|
|
|
.base.type = &mp_type_property,
|
2019-08-25 00:36:18 -04:00
|
|
|
.proxy = {(mp_obj_t)&audiomixer_mixer_get_playing_obj,
|
2018-10-02 21:06:52 -04:00
|
|
|
(mp_obj_t)&mp_const_none_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).
|
|
|
|
//|
|
2019-08-25 00:36:18 -04:00
|
|
|
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);
|
2019-06-12 04:00:59 -04:00
|
|
|
check_for_deinit(self);
|
2019-08-25 00:36:18 -04:00
|
|
|
return MP_OBJ_NEW_SMALL_INT(common_hal_audiomixer_mixer_get_sample_rate(self));
|
2018-10-02 21:06:52 -04:00
|
|
|
}
|
2019-08-25 00:36:18 -04:00
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixer_get_sample_rate_obj, audiomixer_mixer_obj_get_sample_rate);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
const mp_obj_property_t audiomixer_mixer_sample_rate_obj = {
|
2018-10-02 21:06:52 -04:00
|
|
|
.base.type = &mp_type_property,
|
2019-08-25 00:36:18 -04:00
|
|
|
.proxy = {(mp_obj_t)&audiomixer_mixer_get_sample_rate_obj,
|
2018-10-02 21:06:52 -04:00
|
|
|
(mp_obj_t)&mp_const_none_obj,
|
|
|
|
(mp_obj_t)&mp_const_none_obj},
|
|
|
|
};
|
|
|
|
|
2018-11-15 14:11:45 -05:00
|
|
|
//| .. attribute:: voice
|
2018-11-14 18:05:29 -05:00
|
|
|
//|
|
2019-08-25 00:36:18 -04:00
|
|
|
//| A tuple of the mixer's `audiomixer.MixerVoice` object(s).
|
2019-08-03 12:20:06 -04:00
|
|
|
//|
|
|
|
|
//| .. code-block:: python
|
2018-10-31 18:27:08 -04:00
|
|
|
//|
|
2019-08-03 12:20:06 -04:00
|
|
|
//| >>> mixer.voice
|
|
|
|
//| (<MixerVoice>,)
|
2019-08-25 00:36:18 -04:00
|
|
|
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);
|
2019-08-03 12:20:06 -04:00
|
|
|
check_for_deinit(self);
|
2018-11-15 15:04:11 -05:00
|
|
|
return self->voice_tuple;
|
2018-10-02 21:06:52 -04:00
|
|
|
}
|
2019-08-25 00:36:18 -04:00
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(audiomixer_mixer_get_voice_obj, audiomixer_mixer_obj_get_voice);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
const mp_obj_property_t audiomixer_mixer_voice_obj = {
|
2018-10-02 21:06:52 -04:00
|
|
|
.base.type = &mp_type_property,
|
2019-08-25 00:36:18 -04:00
|
|
|
.proxy = {(mp_obj_t)&audiomixer_mixer_get_voice_obj,
|
2018-10-02 21:06:52 -04:00
|
|
|
(mp_obj_t)&mp_const_none_obj,
|
|
|
|
(mp_obj_t)&mp_const_none_obj},
|
|
|
|
};
|
|
|
|
|
2019-08-29 23:12:12 -04:00
|
|
|
//| .. method:: play(sample, *, voice=0, loop=False)
|
|
|
|
//|
|
|
|
|
//| 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.
|
|
|
|
//|
|
|
|
|
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[] = {
|
|
|
|
{ MP_QSTR_sample, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
|
|
|
{ MP_QSTR_voice, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
|
|
|
|
{ MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
|
|
|
|
};
|
|
|
|
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
|
|
|
check_for_deinit(self);
|
|
|
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
|
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
|
|
|
|
|
|
uint8_t v = args[ARG_voice].u_int;
|
|
|
|
if (v > (self->voice_count - 1)) {
|
|
|
|
mp_raise_ValueError(translate("Invalid voice"));
|
|
|
|
}
|
|
|
|
audiomixer_mixervoice_obj_t *voice = MP_OBJ_TO_PTR(self->voice[v]);
|
|
|
|
mp_obj_t sample = args[ARG_sample].u_obj;
|
|
|
|
common_hal_audiomixer_mixervoice_play(voice, sample, args[ARG_loop].u_bool);
|
|
|
|
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
//|
|
|
|
|
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[] = {
|
|
|
|
{ MP_QSTR_voice, MP_ARG_INT, {.u_int = 0} },
|
|
|
|
};
|
|
|
|
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
|
|
|
check_for_deinit(self);
|
|
|
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
|
|
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
|
|
|
|
|
|
|
uint8_t v = args[ARG_voice].u_int;
|
|
|
|
if (v > (self->voice_count - 1)) {
|
|
|
|
mp_raise_ValueError(translate("Invalid voice"));
|
|
|
|
}
|
|
|
|
audiomixer_mixervoice_obj_t *voice = MP_OBJ_TO_PTR(self->voice[v]);
|
|
|
|
common_hal_audiomixer_mixervoice_stop(voice);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixer_stop_voice_obj, 1, audiomixer_mixer_obj_stop_voice);
|
|
|
|
|
2018-11-15 14:11:45 -05:00
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
STATIC const mp_rom_map_elem_t audiomixer_mixer_locals_dict_table[] = {
|
2018-10-02 21:06:52 -04:00
|
|
|
// Methods
|
2019-08-25 00:36:18 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiomixer_mixer_deinit_obj) },
|
2018-10-02 21:06:52 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
|
2019-08-25 00:36:18 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiomixer_mixer___exit___obj) },
|
2019-08-29 23:12:12 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audiomixer_mixer_play_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_stop_voice), MP_ROM_PTR(&audiomixer_mixer_stop_voice_obj) },
|
2018-10-02 21:06:52 -04:00
|
|
|
|
|
|
|
// Properties
|
2019-08-25 00:36:18 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiomixer_mixer_playing_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&audiomixer_mixer_sample_rate_obj) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_voice), MP_ROM_PTR(&audiomixer_mixer_voice_obj) }
|
2018-10-02 21:06:52 -04:00
|
|
|
};
|
2019-08-25 00:36:18 -04:00
|
|
|
STATIC MP_DEFINE_CONST_DICT(audiomixer_mixer_locals_dict, audiomixer_mixer_locals_dict_table);
|
2018-10-02 21:06:52 -04:00
|
|
|
|
2019-12-04 10:31:52 -05:00
|
|
|
STATIC const audiosample_p_t audiomixer_mixer_proto = {
|
|
|
|
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample)
|
|
|
|
.sample_rate = (audiosample_sample_rate_fun)common_hal_audiomixer_mixer_get_sample_rate,
|
|
|
|
.bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audiomixer_mixer_get_bits_per_sample,
|
|
|
|
.channel_count = (audiosample_channel_count_fun)common_hal_audiomixer_mixer_get_channel_count,
|
|
|
|
.reset_buffer = (audiosample_reset_buffer_fun)audiomixer_mixer_reset_buffer,
|
|
|
|
.get_buffer = (audiosample_get_buffer_fun)audiomixer_mixer_get_buffer,
|
|
|
|
.get_buffer_structure = (audiosample_get_buffer_structure_fun)audiomixer_mixer_get_buffer_structure,
|
|
|
|
};
|
|
|
|
|
2019-08-25 00:36:18 -04:00
|
|
|
const mp_obj_type_t audiomixer_mixer_type = {
|
2018-10-02 21:06:52 -04:00
|
|
|
{ &mp_type_type },
|
|
|
|
.name = MP_QSTR_Mixer,
|
2019-08-25 00:36:18 -04:00
|
|
|
.make_new = audiomixer_mixer_make_new,
|
|
|
|
.locals_dict = (mp_obj_dict_t*)&audiomixer_mixer_locals_dict,
|
2019-12-04 10:31:52 -05:00
|
|
|
.protocol = &audiomixer_mixer_proto,
|
2018-10-02 21:06:52 -04:00
|
|
|
};
|