From 065efb05b75e35f7e161b6828742b01d26ce5379 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 3 Aug 2019 11:20:06 -0500 Subject: bring MixerVoice back to building state; update documentation --- shared-module/audiocore/Mixer.c | 1 + shared-module/audiocore/MixerVoice.c | 82 ++++++++++++++++++++++++++++++++++++ shared-module/audiocore/MixerVoice.h | 46 ++++++++++++++++++++ shared-module/audioio/MixerVoice.c | 64 ---------------------------- shared-module/audioio/MixerVoice.h | 28 ------------ 5 files changed, 129 insertions(+), 92 deletions(-) create mode 100644 shared-module/audiocore/MixerVoice.c create mode 100644 shared-module/audiocore/MixerVoice.h delete mode 100644 shared-module/audioio/MixerVoice.c delete mode 100644 shared-module/audioio/MixerVoice.h (limited to 'shared-module') diff --git a/shared-module/audiocore/Mixer.c b/shared-module/audiocore/Mixer.c index 8c083f419..40ed63dc4 100644 --- a/shared-module/audiocore/Mixer.c +++ b/shared-module/audiocore/Mixer.c @@ -25,6 +25,7 @@ */ #include "shared-bindings/audiocore/Mixer.h" +#include "shared-bindings/audiocore/MixerVoice.h" #include diff --git a/shared-module/audiocore/MixerVoice.c b/shared-module/audiocore/MixerVoice.c new file mode 100644 index 000000000..c16dfccb0 --- /dev/null +++ b/shared-module/audiocore/MixerVoice.c @@ -0,0 +1,82 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 DeanM 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. + */ +#include "shared-bindings/audiocore/Mixer.h" + +#include + +#include "py/runtime.h" +#include "shared-module/audioio/__init__.h" +#include "shared-module/audiocore/RawSample.h" +#include "shared-module/audiocore/MixerVoice.h" + +void common_hal_audioio_mixervoice_set_parent(audioio_mixervoice_obj_t* self, audioio_mixer_obj_t *parent) { + self->parent = parent; +} + +float common_hal_audioio_mixervoice_get_level(audioio_mixervoice_obj_t* self) { + return self->level; +} + +void common_hal_audioio_mixervoice_set_level(audioio_mixervoice_obj_t* self, float level) { + self->level = level * ((1 << 15)-1); +} + +void common_hal_audioio_mixervoice_play(audioio_mixervoice_obj_t* self, mp_obj_t sample, bool loop) { + if (audiosample_sample_rate(sample) != self->parent->sample_rate) { + mp_raise_ValueError(translate("The sample's sample rate does not match the mixer's")); + } + if (audiosample_channel_count(sample) != self->parent->channel_count) { + mp_raise_ValueError(translate("The sample's channel count does not match the mixer's")); + } + if (audiosample_bits_per_sample(sample) != self->parent->bits_per_sample) { + mp_raise_ValueError(translate("The sample's bits_per_sample does not match the mixer's")); + } + bool single_buffer; + bool samples_signed; + uint32_t max_buffer_length; + uint8_t spacing; + audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, + &max_buffer_length, &spacing); + if (samples_signed != self->parent->samples_signed) { + mp_raise_ValueError(translate("The sample's signedness does not match the mixer's")); + } + self->sample = sample; + self->loop = loop; + + audiosample_reset_buffer(sample, false, 0); + audioio_get_buffer_result_t result = audiosample_get_buffer(sample, false, 0, (uint8_t**) &self->remaining_buffer, &self->buffer_length); + // Track length in terms of words. + self->buffer_length /= sizeof(uint32_t); + self->more_data = result == GET_BUFFER_MORE_DATA; +} + +bool common_hal_audioio_mixervoice_get_playing(audioio_mixervoice_obj_t* self) { + return self->sample != NULL; +} + +void common_hal_audioio_mixervoice_stop(audioio_mixervoice_obj_t* self) { + self->sample = NULL; +} diff --git a/shared-module/audiocore/MixerVoice.h b/shared-module/audiocore/MixerVoice.h new file mode 100644 index 000000000..6010313bf --- /dev/null +++ b/shared-module/audiocore/MixerVoice.h @@ -0,0 +1,46 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 DeanM 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. + */ +#ifndef SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ +#define SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ + +#include "py/obj.h" + +#include "shared-module/audiocore/__init__.h" +#include "shared-module/audiocore/Mixer.h" + +typedef struct { + mp_obj_base_t base; + audioio_mixer_obj_t *parent; + mp_obj_t sample; + bool loop; + bool more_data; + uint32_t* remaining_buffer; + uint32_t buffer_length; + int16_t level; +} audioio_mixervoice_obj_t; + + +#endif /* SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ */ diff --git a/shared-module/audioio/MixerVoice.c b/shared-module/audioio/MixerVoice.c deleted file mode 100644 index 3e8aaff89..000000000 --- a/shared-module/audioio/MixerVoice.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * MixerVoice.c - * - * Created on: Nov 15, 2018 - * Author: dean - */ - -#include "shared-bindings/audioio/Mixer.h" - -#include - -#include "py/runtime.h" -#include "shared-module/audioio/__init__.h" -#include "shared-module/audioio/RawSample.h" -#include "shared-module/audioio/MixerVoice.h" - -void common_hal_audioio_mixervoice_set_parent(audioio_mixervoice_obj_t* self, audioio_mixer_obj_t *parent) { - self->parent = parent; -} - -float common_hal_audioio_mixervoice_get_level(audioio_mixervoice_obj_t* self) { - return self->level; -} - -void common_hal_audioio_mixervoice_set_level(audioio_mixervoice_obj_t* self, float level) { - self->level = level * ((1 << 15)-1); -} - -void common_hal_audioio_mixervoice_play(audioio_mixervoice_obj_t* self, mp_obj_t sample, bool loop) { - if (audiosample_sample_rate(sample) != self->parent->sample_rate) { - mp_raise_ValueError(translate("The sample's sample rate does not match the mixer's")); - } - if (audiosample_channel_count(sample) != self->parent->channel_count) { - mp_raise_ValueError(translate("The sample's channel count does not match the mixer's")); - } - if (audiosample_bits_per_sample(sample) != self->parent->bits_per_sample) { - mp_raise_ValueError(translate("The sample's bits_per_sample does not match the mixer's")); - } - bool single_buffer; - bool samples_signed; - uint32_t max_buffer_length; - uint8_t spacing; - audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, - &max_buffer_length, &spacing); - if (samples_signed != self->parent->samples_signed) { - mp_raise_ValueError(translate("The sample's signedness does not match the mixer's")); - } - self->sample = sample; - self->loop = loop; - - audiosample_reset_buffer(sample, false, 0); - audioio_get_buffer_result_t result = audiosample_get_buffer(sample, false, 0, (uint8_t**) &self->remaining_buffer, &self->buffer_length); - // Track length in terms of words. - self->buffer_length /= sizeof(uint32_t); - self->more_data = result == GET_BUFFER_MORE_DATA; -} - -bool common_hal_audioio_mixervoice_get_playing(audioio_mixervoice_obj_t* self) { - return self->sample != NULL; -} - -void common_hal_audioio_mixervoice_stop(audioio_mixervoice_obj_t* self) { - self->sample = NULL; -} diff --git a/shared-module/audioio/MixerVoice.h b/shared-module/audioio/MixerVoice.h deleted file mode 100644 index 2811a741a..000000000 --- a/shared-module/audioio/MixerVoice.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * MixerVoice.h - * - * Created on: Nov 15, 2018 - * Author: dean - */ - -#ifndef SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ -#define SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ - -#include "py/obj.h" - -#include "shared-module/audioio/__init__.h" -#include "shared-module/audioio/Mixer.h" - -typedef struct { - mp_obj_base_t base; - audioio_mixer_obj_t *parent; - mp_obj_t sample; - bool loop; - bool more_data; - uint32_t* remaining_buffer; - uint32_t buffer_length; - int16_t level; -} audioio_mixervoice_obj_t; - - -#endif /* SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ */ -- cgit v1.2.3