35
35
#define audio_source_frame MP_STATE_PORT(audio_source_frame_state)
36
36
#define audio_source_iter MP_STATE_PORT(audio_source_iter_state)
37
37
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 )
40
40
#define DEFAULT_SAMPLE_RATE (7812)
41
41
42
42
typedef enum {
@@ -45,7 +45,7 @@ typedef enum {
45
45
AUDIO_OUTPUT_STATE_DATA_WRITTEN ,
46
46
} audio_output_state_t ;
47
47
48
- static uint8_t audio_output_buffer [AUDIO_CHUNK_SIZE ];
48
+ static uint8_t audio_output_buffer [AUDIO_OUTPUT_BUFFER_SIZE ];
49
49
static volatile audio_output_state_t audio_output_state ;
50
50
static size_t audio_raw_offset ;
51
51
static uint32_t audio_current_sound_level ;
@@ -123,7 +123,7 @@ static void audio_data_fetcher(mp_sched_node_t *node) {
123
123
}
124
124
125
125
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 );
127
127
audio_raw_offset += src_len ;
128
128
129
129
uint8_t * dest = & audio_output_buffer [0 ];
@@ -137,17 +137,17 @@ static void audio_data_fetcher(mp_sched_node_t *node) {
137
137
}
138
138
139
139
// 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 );
141
141
142
- audio_current_sound_level = sound_level / AUDIO_CHUNK_SIZE ;
142
+ audio_current_sound_level = sound_level / AUDIO_OUTPUT_BUFFER_SIZE ;
143
143
144
144
audio_buffer_ready ();
145
145
}
146
146
147
147
void microbit_hal_audio_raw_ready_callback (void ) {
148
148
if (audio_output_state == AUDIO_OUTPUT_STATE_DATA_READY ) {
149
149
// 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 );
151
151
audio_output_state = AUDIO_OUTPUT_STATE_DATA_WRITTEN ;
152
152
} else {
153
153
// 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_
320
320
321
321
size_t size ;
322
322
if (args [ARG_duration ].u_obj == mp_const_none ) {
323
- size = AUDIO_CHUNK_SIZE ;
323
+ size = DEFAULT_AUDIO_FRAME_SIZE ;
324
324
} else {
325
325
mp_float_t duration = mp_obj_get_float (args [ARG_duration ].u_obj );
326
326
if (duration <= 0 ) {
0 commit comments