diff options
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/audiocore/__init__.c | 35 | ||||
| -rw-r--r-- | shared-module/audiomixer/Mixer.c (renamed from shared-module/audiocore/Mixer.c) | 52 | ||||
| -rw-r--r-- | shared-module/audiomixer/Mixer.h (renamed from shared-module/audiocore/Mixer.h) | 14 | ||||
| -rw-r--r-- | shared-module/audiomixer/MixerVoice.c (renamed from shared-module/audiocore/MixerVoice.c) | 20 | ||||
| -rw-r--r-- | shared-module/audiomixer/MixerVoice.h (renamed from shared-module/audiocore/MixerVoice.h) | 14 | ||||
| -rw-r--r-- | shared-module/audiomixer/__init__.c | 0 | ||||
| -rw-r--r-- | shared-module/audiomixer/__init__.h | 32 |
7 files changed, 100 insertions, 67 deletions
diff --git a/shared-module/audiocore/__init__.c b/shared-module/audiocore/__init__.c index 067cae5dd..8433a1770 100644 --- a/shared-module/audiocore/__init__.c +++ b/shared-module/audiocore/__init__.c @@ -27,13 +27,14 @@ #include "shared-module/audioio/__init__.h" #include "py/obj.h" -#include "shared-bindings/audiocore/Mixer.h" #include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/audiocore/WaveFile.h" -#include "shared-module/audiocore/Mixer.h" #include "shared-module/audiocore/RawSample.h" #include "shared-module/audiocore/WaveFile.h" +#include "shared-bindings/audiomixer/Mixer.h" +#include "shared-module/audiomixer/Mixer.h" + uint32_t audiosample_sample_rate(mp_obj_t sample_obj) { if (MP_OBJ_IS_TYPE(sample_obj, &audioio_rawsample_type)) { audioio_rawsample_obj_t* sample = MP_OBJ_TO_PTR(sample_obj); @@ -41,8 +42,8 @@ uint32_t audiosample_sample_rate(mp_obj_t sample_obj) { } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); return file->sample_rate; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) { + audiomixer_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); return mixer->sample_rate; } return 16000; @@ -55,8 +56,8 @@ uint8_t audiosample_bits_per_sample(mp_obj_t sample_obj) { } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); return file->bits_per_sample; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) { + audiomixer_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); return mixer->bits_per_sample; } return 8; @@ -69,8 +70,8 @@ uint8_t audiosample_channel_count(mp_obj_t sample_obj) { } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); return file->channel_count; - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) { + audiomixer_mixer_obj_t* mixer = MP_OBJ_TO_PTR(sample_obj); return mixer->channel_count; } return 1; @@ -83,9 +84,9 @@ void audiosample_reset_buffer(mp_obj_t sample_obj, bool single_channel, uint8_t } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); audioio_wavefile_reset_buffer(file, single_channel, audio_channel); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - audioio_mixer_reset_buffer(file, single_channel, audio_channel); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) { + audiomixer_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + audiomixer_mixer_reset_buffer(file, single_channel, audio_channel); } } @@ -99,9 +100,9 @@ audioio_get_buffer_result_t audiosample_get_buffer(mp_obj_t sample_obj, } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_wavefile_type)) { audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); return audioio_wavefile_get_buffer(file, single_channel, channel, buffer, buffer_length); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - return audioio_mixer_get_buffer(file, single_channel, channel, buffer, buffer_length); + } else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) { + audiomixer_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + return audiomixer_mixer_get_buffer(file, single_channel, channel, buffer, buffer_length); } return GET_BUFFER_DONE; } @@ -117,9 +118,9 @@ void audiosample_get_buffer_structure(mp_obj_t sample_obj, bool single_channel, audioio_wavefile_obj_t* file = MP_OBJ_TO_PTR(sample_obj); audioio_wavefile_get_buffer_structure(file, single_channel, single_buffer, samples_signed, max_buffer_length, spacing); - } else if (MP_OBJ_IS_TYPE(sample_obj, &audioio_mixer_type)) { - audioio_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); - audioio_mixer_get_buffer_structure(file, single_channel, single_buffer, samples_signed, + } else if (MP_OBJ_IS_TYPE(sample_obj, &audiomixer_mixer_type)) { + audiomixer_mixer_obj_t* file = MP_OBJ_TO_PTR(sample_obj); + audiomixer_mixer_get_buffer_structure(file, single_channel, single_buffer, samples_signed, max_buffer_length, spacing); } } diff --git a/shared-module/audiocore/Mixer.c b/shared-module/audiomixer/Mixer.c index c372d68d0..0ae7c7b09 100644 --- a/shared-module/audiocore/Mixer.c +++ b/shared-module/audiomixer/Mixer.c @@ -26,8 +26,8 @@ * THE SOFTWARE. */ -#include "shared-bindings/audiocore/Mixer.h" -#include "shared-bindings/audiocore/MixerVoice.h" +#include "shared-bindings/audiomixer/Mixer.h" +#include "shared-bindings/audiomixer/MixerVoice.h" #include <stdint.h> @@ -35,24 +35,24 @@ #include "shared-module/audiocore/__init__.h" #include "shared-module/audiocore/RawSample.h" -void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self, - uint8_t voice_count, - uint32_t buffer_size, - uint8_t bits_per_sample, - bool samples_signed, - uint8_t channel_count, - uint32_t sample_rate) { +void common_hal_audiomixer_mixer_construct(audiomixer_mixer_obj_t* self, + uint8_t voice_count, + uint32_t buffer_size, + uint8_t bits_per_sample, + bool samples_signed, + uint8_t channel_count, + uint32_t sample_rate) { self->len = buffer_size / 2 / sizeof(uint32_t) * sizeof(uint32_t); self->first_buffer = m_malloc(self->len, false); if (self->first_buffer == NULL) { - common_hal_audioio_mixer_deinit(self); + common_hal_audiomixer_mixer_deinit(self); mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate first buffer")); } self->second_buffer = m_malloc(self->len, false); if (self->second_buffer == NULL) { - common_hal_audioio_mixer_deinit(self); + common_hal_audiomixer_mixer_deinit(self); mp_raise_msg(&mp_type_MemoryError, translate("Couldn't allocate second buffer")); } @@ -63,31 +63,31 @@ void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self, self->voice_count = voice_count; } -void common_hal_audioio_mixer_deinit(audioio_mixer_obj_t* self) { +void common_hal_audiomixer_mixer_deinit(audiomixer_mixer_obj_t* self) { self->first_buffer = NULL; self->second_buffer = NULL; } -bool common_hal_audioio_mixer_deinited(audioio_mixer_obj_t* self) { +bool common_hal_audiomixer_mixer_deinited(audiomixer_mixer_obj_t* self) { return self->first_buffer == NULL; } -uint32_t common_hal_audioio_mixer_get_sample_rate(audioio_mixer_obj_t* self) { +uint32_t common_hal_audiomixer_mixer_get_sample_rate(audiomixer_mixer_obj_t* self) { return self->sample_rate; } -bool common_hal_audioio_mixer_get_playing(audioio_mixer_obj_t* self) { +bool common_hal_audiomixer_mixer_get_playing(audiomixer_mixer_obj_t* self) { for (int32_t v = 0; v < self->voice_count; v++) { - if (common_hal_audioio_mixervoice_get_playing(MP_OBJ_TO_PTR(self->voice[v]))) { + if (common_hal_audiomixer_mixervoice_get_playing(MP_OBJ_TO_PTR(self->voice[v]))) { return true; } } return false; } -void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self, - bool single_channel, - uint8_t channel) { +void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t* self, + bool single_channel, + uint8_t channel) { #if 0 for (int32_t i = 0; i < self->voice_count; i++) { self->voice[i].sample = NULL; @@ -289,11 +289,11 @@ static inline uint32_t mult16signed(uint32_t val, int32_t mul) { #endif } -audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, - bool single_channel, - uint8_t channel, - uint8_t** buffer, - uint32_t* buffer_length) { +audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t* self, + bool single_channel, + uint8_t channel, + uint8_t** buffer, + uint32_t* buffer_length) { if (!single_channel) { channel = 0; } @@ -317,7 +317,7 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, self->use_first_buffer = !self->use_first_buffer; bool voices_active = false; for (int32_t v = 0; v < self->voice_count; v++) { - audioio_mixervoice_obj_t* voice = MP_OBJ_TO_PTR(self->voice[v]); + audiomixer_mixervoice_obj_t* voice = MP_OBJ_TO_PTR(self->voice[v]); uint32_t j = 0; bool voice_done = voice->sample == NULL; @@ -416,7 +416,7 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, return GET_BUFFER_MORE_DATA; } -void audioio_mixer_get_buffer_structure(audioio_mixer_obj_t* self, bool single_channel, +void audiomixer_mixer_get_buffer_structure(audiomixer_mixer_obj_t* self, bool single_channel, bool* single_buffer, bool* samples_signed, uint32_t* max_buffer_length, uint8_t* spacing) { *single_buffer = false; diff --git a/shared-module/audiocore/Mixer.h b/shared-module/audiomixer/Mixer.h index aaab60e84..ab4780efc 100644 --- a/shared-module/audiocore/Mixer.h +++ b/shared-module/audiomixer/Mixer.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H -#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H +#ifndef MICROPY_INCLUDED_SHARED_MODULE_AUDIOMIXER_MIXER_H +#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOMIXER_MIXER_H #include "py/obj.h" #include "py/objtuple.h" @@ -50,20 +50,20 @@ typedef struct { uint8_t voice_count; mp_obj_tuple_t *voice_tuple; mp_obj_t voice[]; -} audioio_mixer_obj_t; +} audiomixer_mixer_obj_t; // These are not available from Python because it may be called in an interrupt. -void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self, +void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t* self, bool single_channel, uint8_t channel); -audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self, +audioio_get_buffer_result_t audiomixer_mixer_get_buffer(audiomixer_mixer_obj_t* self, bool single_channel, uint8_t channel, uint8_t** buffer, uint32_t* buffer_length); // length in bytes -void audioio_mixer_get_buffer_structure(audioio_mixer_obj_t* self, bool single_channel, +void audiomixer_mixer_get_buffer_structure(audiomixer_mixer_obj_t* self, bool single_channel, bool* single_buffer, bool* samples_signed, uint32_t* max_buffer_length, uint8_t* spacing); -#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H +#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOMIXER_MIXER_H diff --git a/shared-module/audiocore/MixerVoice.c b/shared-module/audiomixer/MixerVoice.c index 80c07511e..ff05dc93e 100644 --- a/shared-module/audiocore/MixerVoice.c +++ b/shared-module/audiomixer/MixerVoice.c @@ -23,33 +23,33 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "shared-bindings/audiocore/Mixer.h" +#include "shared-bindings/audiomixer/Mixer.h" +#include "shared-module/audiomixer/MixerVoice.h" #include <stdint.h> #include "py/runtime.h" -#include "shared-module/audioio/__init__.h" +#include "shared-module/audiomixer/__init__.h" #include "shared-module/audiocore/RawSample.h" -#include "shared-module/audiocore/MixerVoice.h" -void common_hal_audioio_mixervoice_construct(audioio_mixervoice_obj_t *self) { +void common_hal_audiomixer_mixervoice_construct(audiomixer_mixervoice_obj_t *self) { self->sample = NULL; self->level = ((1 << 15) - 1); } -void common_hal_audioio_mixervoice_set_parent(audioio_mixervoice_obj_t* self, audioio_mixer_obj_t *parent) { +void common_hal_audiomixer_mixervoice_set_parent(audiomixer_mixervoice_obj_t* self, audiomixer_mixer_obj_t *parent) { self->parent = parent; } -float common_hal_audioio_mixervoice_get_level(audioio_mixervoice_obj_t* self) { +float common_hal_audiomixer_mixervoice_get_level(audiomixer_mixervoice_obj_t* self) { return ((float) self->level / ((1 << 15) - 1)); } -void common_hal_audioio_mixervoice_set_level(audioio_mixervoice_obj_t* self, float level) { +void common_hal_audiomixer_mixervoice_set_level(audiomixer_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) { +void common_hal_audiomixer_mixervoice_play(audiomixer_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")); } @@ -78,10 +78,10 @@ void common_hal_audioio_mixervoice_play(audioio_mixervoice_obj_t* self, mp_obj_t self->more_data = result == GET_BUFFER_MORE_DATA; } -bool common_hal_audioio_mixervoice_get_playing(audioio_mixervoice_obj_t* self) { +bool common_hal_audiomixer_mixervoice_get_playing(audiomixer_mixervoice_obj_t* self) { return self->sample != NULL; } -void common_hal_audioio_mixervoice_stop(audioio_mixervoice_obj_t* self) { +void common_hal_audiomixer_mixervoice_stop(audiomixer_mixervoice_obj_t* self) { self->sample = NULL; } diff --git a/shared-module/audiocore/MixerVoice.h b/shared-module/audiomixer/MixerVoice.h index 6010313bf..efac19156 100644 --- a/shared-module/audiocore/MixerVoice.h +++ b/shared-module/audiomixer/MixerVoice.h @@ -23,24 +23,24 @@ * 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_ +#ifndef SHARED_MODULE_AUDIOMIXER_MIXERVOICE_H_ +#define SHARED_MODULE_AUDIOMIXER_MIXERVOICE_H_ #include "py/obj.h" -#include "shared-module/audiocore/__init__.h" -#include "shared-module/audiocore/Mixer.h" +#include "shared-module/audiomixer/__init__.h" +#include "shared-module/audiomixer/Mixer.h" typedef struct { mp_obj_base_t base; - audioio_mixer_obj_t *parent; + audiomixer_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; +} audiomixer_mixervoice_obj_t; -#endif /* SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ */ +#endif /* SHARED_MODULE_AUDIOMIXER_MIXERVOICE_H_ */ diff --git a/shared-module/audiomixer/__init__.c b/shared-module/audiomixer/__init__.c new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/shared-module/audiomixer/__init__.c diff --git a/shared-module/audiomixer/__init__.h b/shared-module/audiomixer/__init__.h new file mode 100644 index 000000000..35b731558 --- /dev/null +++ b/shared-module/audiomixer/__init__.h @@ -0,0 +1,32 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Dan Halbert 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 MICROPY_INCLUDED_SHARED_MODULE_AUDIOMIXER__INIT__H +#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOMIXER__INIT__H + +#include "shared-module/audiocore/__init__.h" + +#endif // MICROPY_INCLUDED_SHARED_MODULE_AUDIOMIXER__INIT__H |
