Skip to content

Commit 77bc1ba

Browse files
committed
nrf: PWMAudioOut: Remove the need to wait in "pause"
The original formulation was because I saw the need to avoid a transition from playing to stopped exactly when a resume was taking place. However, @tannewt was concerned about this pause causing trouble, because it could be relatively lengthy (several ms even in a typical case). After reflection, I've convinced myself that updating the registers in this order in resume avoids a window where a "stopped" event can be missed as long as the shortcut is updated first. Testing re-performed: pause/resume testing of looped RawSample and WaveFile audio sources.
1 parent 76f65ac commit 77bc1ba

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ports/nrf/common-hal/audiopwmio/PWMAudioOut.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,20 @@ bool common_hal_audiopwmio_pwmaudioout_get_playing(audiopwmio_pwmaudioout_obj_t*
295295
* Perhaps the way forward is to divide even "single buffer" samples into tasks of
296296
* only a few ms long, so that they can be stopped/restarted quickly enough that it
297297
* feels instant. (This also saves on memory, for long in-memory "single buffer"
298-
* samples!)
298+
* samples, since we have to locally take a resampled copy!)
299299
*/
300300
void common_hal_audiopwmio_pwmaudioout_pause(audiopwmio_pwmaudioout_obj_t* self) {
301301
self->paused = true;
302302
self->pwm->SHORTS = NRF_PWM_SHORT_SEQEND1_STOP_MASK;
303-
while(!self->pwm->EVENTS_STOPPED) { /* NOTHING */ }
304303
}
305304

306305
void common_hal_audiopwmio_pwmaudioout_resume(audiopwmio_pwmaudioout_obj_t* self) {
307306
self->paused = false;
308307
self->pwm->SHORTS = NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK;
309-
self->pwm->EVENTS_STOPPED = 0;
310-
self->pwm->TASKS_SEQSTART[0] = 1;
308+
if (self->pwm->EVENTS_STOPPED) {
309+
self->pwm->EVENTS_STOPPED = 0;
310+
self->pwm->TASKS_SEQSTART[0] = 1;
311+
}
311312
}
312313

313314
bool common_hal_audiopwmio_pwmaudioout_get_paused(audiopwmio_pwmaudioout_obj_t* self) {

0 commit comments

Comments
 (0)