@@ -149,8 +149,13 @@ STATIC mp_obj_t microbit_microphone_get_events(mp_obj_t self_in) {
149
149
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (microbit_microphone_get_events_obj , microbit_microphone_get_events );
150
150
151
151
static void microbit_microphone_record_helper (microbit_audio_frame_obj_t * audio_frame , int rate , bool wait ) {
152
+ // Set the rate of the AudioFrame, if specified.
153
+ if (rate > 0 ) {
154
+ audio_frame -> rate = rate ;
155
+ }
156
+
152
157
// Start the recording.
153
- microbit_hal_microphone_start_recording (audio_frame -> data , audio_frame -> alloc_size , & audio_frame -> used_size , rate );
158
+ microbit_hal_microphone_start_recording (audio_frame -> data , audio_frame -> alloc_size , & audio_frame -> used_size , audio_frame -> rate );
154
159
155
160
if (wait ) {
156
161
// Wait for the recording to finish.
@@ -176,6 +181,7 @@ static mp_obj_t microbit_microphone_record(mp_uint_t n_args, const mp_obj_t *pos
176
181
size_t size = args [ARG_duration ].u_int * args [ARG_rate ].u_int / 1000 ;
177
182
microbit_audio_frame_obj_t * audio_frame = microbit_audio_frame_make_new (size , args [ARG_rate ].u_int );
178
183
184
+ // Start recording and wait.
179
185
microbit_microphone_record_helper (audio_frame , args [ARG_rate ].u_int , true);
180
186
181
187
// Return the new AudioFrame.
@@ -201,13 +207,8 @@ static mp_obj_t microbit_microphone_record_into(mp_uint_t n_args, const mp_obj_t
201
207
}
202
208
microbit_audio_frame_obj_t * audio_frame = MP_OBJ_TO_PTR (args [ARG_buffer ].u_obj );
203
209
204
- // Set the rate of the AudioFrame, if specified.
205
- if (args [ARG_rate ].u_int > 0 ) {
206
- audio_frame -> rate = args [ARG_rate ].u_int ;
207
- }
208
-
209
- // Start the recording.
210
- microbit_hal_microphone_start_recording (audio_frame -> data , audio_frame -> alloc_size , & audio_frame -> used_size , audio_frame -> rate );
210
+ // Start recording and wait if requested.
211
+ microbit_microphone_record_helper (audio_frame , args [ARG_rate ].u_int , args [ARG_wait ].u_bool );
211
212
212
213
return mp_const_none ;
213
214
}
0 commit comments