@@ -149,8 +149,13 @@ STATIC mp_obj_t microbit_microphone_get_events(mp_obj_t self_in) {
149149STATIC MP_DEFINE_CONST_FUN_OBJ_1 (microbit_microphone_get_events_obj , microbit_microphone_get_events );
150150
151151static 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+
152157 // 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 );
154159
155160 if (wait ) {
156161 // 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
176181 size_t size = args [ARG_duration ].u_int * args [ARG_rate ].u_int / 1000 ;
177182 microbit_audio_frame_obj_t * audio_frame = microbit_audio_frame_make_new (size , args [ARG_rate ].u_int );
178183
184+ // Start recording and wait.
179185 microbit_microphone_record_helper (audio_frame , args [ARG_rate ].u_int , true);
180186
181187 // 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
201207 }
202208 microbit_audio_frame_obj_t * audio_frame = MP_OBJ_TO_PTR (args [ARG_buffer ].u_obj );
203209
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 );
211212
212213 return mp_const_none ;
213214}
0 commit comments