Skip to content

Commit 42d56a2

Browse files
committed
codal_port/modaudio: Separate default AudioFrame and output buffer size.
Signed-off-by: Damien George <[email protected]>
1 parent 022f440 commit 42d56a2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/codal_port/modaudio.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#define audio_source_frame MP_STATE_PORT(audio_source_frame_state)
3636
#define audio_source_iter MP_STATE_PORT(audio_source_iter_state)
3737

38-
#define LOG_AUDIO_CHUNK_SIZE (5)
39-
#define AUDIO_CHUNK_SIZE (1 << LOG_AUDIO_CHUNK_SIZE)
38+
#define AUDIO_OUTPUT_BUFFER_SIZE (32)
39+
#define DEFAULT_AUDIO_FRAME_SIZE (32)
4040
#define DEFAULT_SAMPLE_RATE (7812)
4141

4242
typedef enum {
@@ -45,7 +45,7 @@ typedef enum {
4545
AUDIO_OUTPUT_STATE_DATA_WRITTEN,
4646
} audio_output_state_t;
4747

48-
static uint8_t audio_output_buffer[AUDIO_CHUNK_SIZE];
48+
static uint8_t audio_output_buffer[AUDIO_OUTPUT_BUFFER_SIZE];
4949
static volatile audio_output_state_t audio_output_state;
5050
static size_t audio_raw_offset;
5151
static uint32_t audio_current_sound_level;
@@ -123,7 +123,7 @@ static void audio_data_fetcher(mp_sched_node_t *node) {
123123
}
124124

125125
const uint8_t *src = &audio_source_frame->data[audio_raw_offset];
126-
size_t src_len = MIN(audio_source_frame->used_size - audio_raw_offset, AUDIO_CHUNK_SIZE);
126+
size_t src_len = MIN(audio_source_frame->used_size - audio_raw_offset, AUDIO_OUTPUT_BUFFER_SIZE);
127127
audio_raw_offset += src_len;
128128

129129
uint8_t *dest = &audio_output_buffer[0];
@@ -137,17 +137,17 @@ static void audio_data_fetcher(mp_sched_node_t *node) {
137137
}
138138

139139
// Fill any remaining audio_output_buffer bytes with silence.
140-
memset(dest, 128, AUDIO_CHUNK_SIZE - src_len);
140+
memset(dest, 128, AUDIO_OUTPUT_BUFFER_SIZE - src_len);
141141

142-
audio_current_sound_level = sound_level / AUDIO_CHUNK_SIZE;
142+
audio_current_sound_level = sound_level / AUDIO_OUTPUT_BUFFER_SIZE;
143143

144144
audio_buffer_ready();
145145
}
146146

147147
void microbit_hal_audio_raw_ready_callback(void) {
148148
if (audio_output_state == AUDIO_OUTPUT_STATE_DATA_READY) {
149149
// there is data ready to send out to the audio pipeline, so send it
150-
microbit_hal_audio_raw_write_data(&audio_output_buffer[0], AUDIO_CHUNK_SIZE);
150+
microbit_hal_audio_raw_write_data(&audio_output_buffer[0], AUDIO_OUTPUT_BUFFER_SIZE);
151151
audio_output_state = AUDIO_OUTPUT_STATE_DATA_WRITTEN;
152152
} else {
153153
// no data ready, need to call this function later when data is ready
@@ -320,7 +320,7 @@ static mp_obj_t microbit_audio_frame_new(const mp_obj_type_t *type_in, size_t n_
320320

321321
size_t size;
322322
if (args[ARG_duration].u_obj == mp_const_none) {
323-
size = AUDIO_CHUNK_SIZE;
323+
size = DEFAULT_AUDIO_FRAME_SIZE;
324324
} else {
325325
mp_float_t duration = mp_obj_get_float(args[ARG_duration].u_obj);
326326
if (duration <= 0) {

0 commit comments

Comments
 (0)