DM: in progress mixer voice
This commit is contained in:
parent
dd05aafb9b
commit
feef177858
|
@ -434,6 +434,7 @@ ifneq ($(CHIP_VARIANT),SAMR21G18A)
|
|||
SRC_SHARED_MODULE += \
|
||||
audioio/__init__.c \
|
||||
audioio/Mixer.c \
|
||||
audioio/MixerVoice.c \
|
||||
audioio/RawSample.c \
|
||||
audioio/WaveFile.c
|
||||
endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
#include "shared-bindings/audioio/Mixer.h"
|
||||
#include "shared-module/audioio/MixerVoice.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -110,6 +111,11 @@ STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
self->base.type = &audioio_mixer_type;
|
||||
common_hal_audioio_mixer_construct(self, voice_count, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate);
|
||||
|
||||
for(int v=0; v<voice_count; v++){
|
||||
self->voice[v] = audioio_mixervoice_type.make_new(&audioio_mixervoice_type, 0, 0, NULL);
|
||||
}
|
||||
self->voice_tuple = mp_obj_new_tuple(self->voice_count, self->voice);
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
|
@ -233,7 +239,7 @@ const mp_obj_property_t audioio_mixer_sample_rate_obj = {
|
|||
STATIC mp_obj_t audioio_mixer_obj_get_voice(mp_obj_t self_in) {
|
||||
audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
raise_error_if_deinited(common_hal_audioio_mixer_deinited(self));
|
||||
return mp_obj_new_tuple(self->voice_count, self->voice);
|
||||
return self->voice_tuple;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_voice_obj, audioio_mixer_obj_get_voice);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Author: dean
|
||||
*/
|
||||
#include "shared-bindings/audioio/Mixer.h"
|
||||
#include "shared-bindings/audioio/MixerVoice.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -125,7 +126,7 @@ STATIC mp_obj_t audioio_mixervoice_obj_set_gain(size_t n_args, const mp_obj_t *p
|
|||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_gain, MP_ARG_OBJ | MP_ARG_REQUIRED },
|
||||
};
|
||||
audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
audioio_mixervoice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||
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);
|
||||
|
||||
|
|
|
@ -8,22 +8,10 @@
|
|||
#ifndef SHARED_BINDINGS_AUDIOIO_MIXERVOICE_H_
|
||||
#define SHARED_BINDINGS_AUDIOIO_MIXERVOICE_H_
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
#include "shared-module/audioio/__init__.h"
|
||||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "shared-module/audioio/Mixer.h"
|
||||
#include "shared-bindings/audioio/RawSample.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_t sample;
|
||||
bool loop;
|
||||
bool more_data;
|
||||
uint32_t* remaining_buffer;
|
||||
uint32_t buffer_length;
|
||||
int16_t gain;
|
||||
} audioio_mixervoice_obj_t;
|
||||
#include "shared-module/audioio/MixerVoice.h"
|
||||
|
||||
extern const mp_obj_type_t audioio_mixer_type;
|
||||
extern const mp_obj_type_t audioio_mixervoice_type;
|
||||
|
|
|
@ -59,10 +59,12 @@ void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self,
|
|||
self->sample_rate = sample_rate;
|
||||
self->voice_count = voice_count;
|
||||
|
||||
#if 0
|
||||
for (uint8_t i = 0; i < self->voice_count; i++) {
|
||||
self->voice[i].sample = NULL;
|
||||
self->voice[i].gain = ((1<<15)-1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void common_hal_audioio_mixer_deinit(audioio_mixer_obj_t* self) {
|
||||
|
@ -100,6 +102,7 @@ void common_hal_audioio_mixer_play(audioio_mixer_obj_t* self, mp_obj_t sample, u
|
|||
if (samples_signed != self->samples_signed) {
|
||||
mp_raise_ValueError(translate("The sample's signedness does not match the mixer's"));
|
||||
}
|
||||
#if 0
|
||||
audioio_mixervoice_obj_t* voice = &self->voice[v];
|
||||
voice->sample = sample;
|
||||
voice->loop = loop;
|
||||
|
@ -109,27 +112,35 @@ void common_hal_audioio_mixer_play(audioio_mixer_obj_t* self, mp_obj_t sample, u
|
|||
// Track length in terms of words.
|
||||
voice->buffer_length /= sizeof(uint32_t);
|
||||
voice->more_data = result == GET_BUFFER_MORE_DATA;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void common_hal_audioio_mixer_stop_voice(audioio_mixer_obj_t* self, uint8_t voice) {
|
||||
#if 0
|
||||
self->voice[voice].sample = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool common_hal_audioio_mixer_get_playing(audioio_mixer_obj_t* self) {
|
||||
#if 0
|
||||
for (int32_t v = 0; v < self->voice_count; v++) {
|
||||
if (self->voice[v].sample != NULL) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void audioio_mixer_reset_buffer(audioio_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;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t add8signed(uint32_t a, uint32_t b) {
|
||||
|
@ -283,6 +294,7 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self,
|
|||
uint8_t channel,
|
||||
uint8_t** buffer,
|
||||
uint32_t* buffer_length) {
|
||||
#if 0
|
||||
if (!single_channel) {
|
||||
channel = 0;
|
||||
}
|
||||
|
@ -403,6 +415,7 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self,
|
|||
self->right_read_count += 1;
|
||||
*buffer = *buffer + self->bits_per_sample / 8;
|
||||
}
|
||||
#endif
|
||||
return GET_BUFFER_MORE_DATA;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
#include "shared-module/audioio/__init__.h"
|
||||
#include "shared-bindings/audioio/MixerVoice.h"
|
||||
|
@ -48,6 +49,7 @@ typedef struct {
|
|||
uint32_t right_read_count;
|
||||
|
||||
uint8_t voice_count;
|
||||
mp_obj_tuple_t *voice_tuple;
|
||||
mp_obj_t voice[];
|
||||
} audioio_mixer_obj_t;
|
||||
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
#include "shared-module/audioio/__init__.h"
|
||||
#include "shared-module/audioio/RawSample.h"
|
||||
|
||||
void common_hal_audioio_mixervoice_set_gain(audioio_mixer_obj_t* self, float gain) {
|
||||
void common_hal_audioio_mixervoice_set_gain(audioio_mixervoice_obj_t* self, float gain) {
|
||||
self->gain = gain * ((1 << 15)-1);
|
||||
}
|
||||
|
|
|
@ -8,5 +8,19 @@
|
|||
#ifndef SHARED_MODULE_AUDIOIO_MIXERVOICE_H_
|
||||
#define SHARED_MODULE_AUDIOIO_MIXERVOICE_H_
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
#include "shared-module/audioio/__init__.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
mp_obj_t sample;
|
||||
bool loop;
|
||||
bool more_data;
|
||||
uint32_t* remaining_buffer;
|
||||
uint32_t buffer_length;
|
||||
int16_t gain;
|
||||
} audioio_mixervoice_obj_t;
|
||||
|
||||
|
||||
#endif /* SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ */
|
||||
|
|
Loading…
Reference in New Issue