Skip to content

Commit feef177

Browse files
committed
DM: in progress mixer voice
1 parent dd05aaf commit feef177

8 files changed

Lines changed: 41 additions & 16 deletions

File tree

ports/atmel-samd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ ifneq ($(CHIP_VARIANT),SAMR21G18A)
434434
SRC_SHARED_MODULE += \
435435
audioio/__init__.c \
436436
audioio/Mixer.c \
437+
audioio/MixerVoice.c \
437438
audioio/RawSample.c \
438439
audioio/WaveFile.c
439440
endif

shared-bindings/audioio/Mixer.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626
#include "shared-bindings/audioio/Mixer.h"
27+
#include "shared-module/audioio/MixerVoice.h"
2728

2829
#include <stdint.h>
2930

@@ -110,6 +111,11 @@ STATIC mp_obj_t audioio_mixer_make_new(const mp_obj_type_t *type, size_t n_args,
110111
self->base.type = &audioio_mixer_type;
111112
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);
112113

114+
for(int v=0; v<voice_count; v++){
115+
self->voice[v] = audioio_mixervoice_type.make_new(&audioio_mixervoice_type, 0, 0, NULL);
116+
}
117+
self->voice_tuple = mp_obj_new_tuple(self->voice_count, self->voice);
118+
113119
return MP_OBJ_FROM_PTR(self);
114120
}
115121

@@ -233,7 +239,7 @@ const mp_obj_property_t audioio_mixer_sample_rate_obj = {
233239
STATIC mp_obj_t audioio_mixer_obj_get_voice(mp_obj_t self_in) {
234240
audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
235241
raise_error_if_deinited(common_hal_audioio_mixer_deinited(self));
236-
return mp_obj_new_tuple(self->voice_count, self->voice);
242+
return self->voice_tuple;
237243
}
238244
MP_DEFINE_CONST_FUN_OBJ_1(audioio_mixer_get_voice_obj, audioio_mixer_obj_get_voice);
239245

shared-bindings/audioio/MixerVoice.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Author: dean
66
*/
77
#include "shared-bindings/audioio/Mixer.h"
8+
#include "shared-bindings/audioio/MixerVoice.h"
89

910
#include <stdint.h>
1011

@@ -125,7 +126,7 @@ STATIC mp_obj_t audioio_mixervoice_obj_set_gain(size_t n_args, const mp_obj_t *p
125126
static const mp_arg_t allowed_args[] = {
126127
{ MP_QSTR_gain, MP_ARG_OBJ | MP_ARG_REQUIRED },
127128
};
128-
audioio_mixer_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
129+
audioio_mixervoice_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
129130
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
130131
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
131132

shared-bindings/audioio/MixerVoice.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,10 @@
88
#ifndef SHARED_BINDINGS_AUDIOIO_MIXERVOICE_H_
99
#define SHARED_BINDINGS_AUDIOIO_MIXERVOICE_H_
1010

11-
#include "py/obj.h"
12-
13-
#include "shared-module/audioio/__init__.h"
14-
1511
#include "common-hal/microcontroller/Pin.h"
1612
#include "shared-module/audioio/Mixer.h"
1713
#include "shared-bindings/audioio/RawSample.h"
18-
19-
typedef struct {
20-
mp_obj_t sample;
21-
bool loop;
22-
bool more_data;
23-
uint32_t* remaining_buffer;
24-
uint32_t buffer_length;
25-
int16_t gain;
26-
} audioio_mixervoice_obj_t;
14+
#include "shared-module/audioio/MixerVoice.h"
2715

2816
extern const mp_obj_type_t audioio_mixer_type;
2917
extern const mp_obj_type_t audioio_mixervoice_type;

shared-module/audioio/Mixer.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ void common_hal_audioio_mixer_construct(audioio_mixer_obj_t* self,
5959
self->sample_rate = sample_rate;
6060
self->voice_count = voice_count;
6161

62+
#if 0
6263
for (uint8_t i = 0; i < self->voice_count; i++) {
6364
self->voice[i].sample = NULL;
6465
self->voice[i].gain = ((1<<15)-1);
6566
}
67+
#endif
6668
}
6769

6870
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
100102
if (samples_signed != self->samples_signed) {
101103
mp_raise_ValueError(translate("The sample's signedness does not match the mixer's"));
102104
}
105+
#if 0
103106
audioio_mixervoice_obj_t* voice = &self->voice[v];
104107
voice->sample = sample;
105108
voice->loop = loop;
@@ -109,27 +112,35 @@ void common_hal_audioio_mixer_play(audioio_mixer_obj_t* self, mp_obj_t sample, u
109112
// Track length in terms of words.
110113
voice->buffer_length /= sizeof(uint32_t);
111114
voice->more_data = result == GET_BUFFER_MORE_DATA;
115+
116+
#endif
112117
}
113118

114119
void common_hal_audioio_mixer_stop_voice(audioio_mixer_obj_t* self, uint8_t voice) {
120+
#if 0
115121
self->voice[voice].sample = NULL;
122+
#endif
116123
}
117124

118125
bool common_hal_audioio_mixer_get_playing(audioio_mixer_obj_t* self) {
126+
#if 0
119127
for (int32_t v = 0; v < self->voice_count; v++) {
120128
if (self->voice[v].sample != NULL) {
121129
return true;
122130
}
123131
}
132+
#endif
124133
return false;
125134
}
126135

127136
void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self,
128137
bool single_channel,
129138
uint8_t channel) {
139+
#if 0
130140
for (int32_t i = 0; i < self->voice_count; i++) {
131141
self->voice[i].sample = NULL;
132142
}
143+
#endif
133144
}
134145

135146
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,
283294
uint8_t channel,
284295
uint8_t** buffer,
285296
uint32_t* buffer_length) {
297+
#if 0
286298
if (!single_channel) {
287299
channel = 0;
288300
}
@@ -403,6 +415,7 @@ audioio_get_buffer_result_t audioio_mixer_get_buffer(audioio_mixer_obj_t* self,
403415
self->right_read_count += 1;
404416
*buffer = *buffer + self->bits_per_sample / 8;
405417
}
418+
#endif
406419
return GET_BUFFER_MORE_DATA;
407420
}
408421

shared-module/audioio/Mixer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define MICROPY_INCLUDED_SHARED_MODULE_AUDIOIO_MIXER_H
2929

3030
#include "py/obj.h"
31+
#include "py/objtuple.h"
3132

3233
#include "shared-module/audioio/__init__.h"
3334
#include "shared-bindings/audioio/MixerVoice.h"
@@ -48,6 +49,7 @@ typedef struct {
4849
uint32_t right_read_count;
4950

5051
uint8_t voice_count;
52+
mp_obj_tuple_t *voice_tuple;
5153
mp_obj_t voice[];
5254
} audioio_mixer_obj_t;
5355

shared-module/audioio/MixerVoice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
#include "shared-module/audioio/__init__.h"
1414
#include "shared-module/audioio/RawSample.h"
1515

16-
void common_hal_audioio_mixervoice_set_gain(audioio_mixer_obj_t* self, float gain) {
16+
void common_hal_audioio_mixervoice_set_gain(audioio_mixervoice_obj_t* self, float gain) {
1717
self->gain = gain * ((1 << 15)-1);
1818
}

shared-module/audioio/MixerVoice.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,19 @@
88
#ifndef SHARED_MODULE_AUDIOIO_MIXERVOICE_H_
99
#define SHARED_MODULE_AUDIOIO_MIXERVOICE_H_
1010

11+
#include "py/obj.h"
12+
13+
#include "shared-module/audioio/__init__.h"
14+
15+
typedef struct {
16+
mp_obj_base_t base;
17+
mp_obj_t sample;
18+
bool loop;
19+
bool more_data;
20+
uint32_t* remaining_buffer;
21+
uint32_t buffer_length;
22+
int16_t gain;
23+
} audioio_mixervoice_obj_t;
24+
1125

1226
#endif /* SHARED_MODULE_AUDIOIO_MIXERVOICE_H_ */

0 commit comments

Comments
 (0)