Skip to content

Commit 6790bb5

Browse files
committed
codal_port: Don't call microbit_pin_audio_free when audio/music is done.
Instead leave any connected pin (pin0 by default) in "music" mode. This simplifies the behaviour and can help to avoid clicks going from one sound to another. See related issue #50. Signed-off-by: Damien George <[email protected]>
1 parent ab59d87 commit 6790bb5

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

src/codal_port/modaudio.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ microbit_audio_frame_obj_t *microbit_audio_frame_make_new(void);
5050
void microbit_audio_stop(void) {
5151
audio_source_iter = NULL;
5252
audio_running = false;
53-
microbit_pin_audio_free();
5453
}
5554

5655
STATIC void audio_buffer_ready(void) {

src/codal_port/modmusic.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ void microbit_music_tick(void) {
105105
music_data->async_notes_index = 0;
106106
} else {
107107
music_data->async_state = ASYNC_MUSIC_STATE_IDLE;
108-
microbit_pin_audio_free();
109108
return;
110109
}
111110
}
@@ -289,9 +288,8 @@ STATIC mp_obj_t microbit_music_stop(mp_uint_t n_args, const mp_obj_t *args) {
289288
// Stop any ongoing background music
290289
music_data->async_state = ASYNC_MUSIC_STATE_IDLE;
291290

292-
// Turn off the output and free the audio pin
291+
// Turn off the output
293292
music_output_amplitude(MUSIC_OUTPUT_AMPLITUDE_OFF);
294-
microbit_pin_audio_free();
295293

296294
return mp_const_none;
297295
}
@@ -326,9 +324,6 @@ STATIC mp_obj_t microbit_music_play(mp_uint_t n_args, const mp_obj_t *pos_args,
326324
// Stop any ongoing background music
327325
music_data->async_state = ASYNC_MUSIC_STATE_IDLE;
328326

329-
// Release the previous pin
330-
microbit_pin_audio_free();
331-
332327
// get the pin to play on
333328
microbit_pin_audio_select(args[1].u_obj);
334329

@@ -376,15 +371,11 @@ STATIC mp_obj_t microbit_music_pitch(mp_uint_t n_args, const mp_obj_t *pos_args,
376371
music_data->async_state = ASYNC_MUSIC_STATE_IDLE;
377372

378373
// Update pin modes
379-
microbit_pin_audio_free();
380374
microbit_pin_audio_select(args[2].u_obj);
381375

382376
bool wait = args[3].u_bool;
383377
music_output_amplitude(MUSIC_OUTPUT_AMPLITUDE_ON);
384-
if (frequency == 0) {
385-
microbit_pin_audio_free();
386-
} else if (music_output_period_us(1000000 / frequency) == -1) {
387-
microbit_pin_audio_free();
378+
if (frequency != 0 && music_output_period_us(1000000 / frequency) == -1) {
388379
mp_raise_ValueError(MP_ERROR_TEXT("invalid pitch"));
389380
}
390381
if (duration >= 0) {

0 commit comments

Comments
 (0)