From 24e641a834becd3ef99682c915a6b6936d4584f0 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 25 May 2021 16:06:00 -0500 Subject: [PATCH 1/4] Fix for Issue #4266 --- ports/raspberrypi/audio_dma.c | 1 - ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index 28a80a770c..61c022f446 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -368,7 +368,6 @@ bool audio_dma_get_playing(audio_dma_t *dma) { } if (!dma_channel_is_busy(dma->channel[0]) && !dma_channel_is_busy(dma->channel[1])) { - audio_dma_stop(dma); return false; } diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index 4fef53ff0a..ddf9cc0bd4 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -126,17 +126,14 @@ void common_hal_audiopwmio_pwmaudioout_deinit(audiopwmio_pwmaudioout_obj_t *self } void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, mp_obj_t sample, bool loop) { - if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) { - common_hal_audiopwmio_pwmaudioout_stop(self); - } // TODO: Share pacing timers based on frequency. size_t pacing_timer = NUM_DMA_TIMERS; for (size_t i = 0; i < NUM_DMA_TIMERS; i++) { if (dma_hw->timer[i] == 0) { pacing_timer = i; + break; } - break; } if (pacing_timer == NUM_DMA_TIMERS) { mp_raise_RuntimeError(translate("No DMA pacing timer found")); From 760e8c77bd3e9cc12ffc2852c8a02eb01352a9ec Mon Sep 17 00:00:00 2001 From: root Date: Sat, 29 May 2021 11:55:10 -0500 Subject: [PATCH 2/4] Changes to correct repeat playing on a channel --- ports/raspberrypi/audio_dma.c | 2 ++ ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index 61c022f446..7044c44edf 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -352,6 +352,8 @@ bool audio_dma_get_paused(audio_dma_t *dma) { void audio_dma_init(audio_dma_t *dma) { dma->first_buffer = NULL; dma->second_buffer = NULL; + dma->channel[0] = NUM_DMA_CHANNELS; + dma->channel[1] = NUM_DMA_CHANNELS; } void audio_dma_deinit(audio_dma_t *dma) { diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index ddf9cc0bd4..9f2c877416 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -127,6 +127,12 @@ void common_hal_audiopwmio_pwmaudioout_deinit(audiopwmio_pwmaudioout_obj_t *self void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, mp_obj_t sample, bool loop) { + if (self->dma.channel[0] < NUM_DMA_CHANNELS) { + if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) { + common_hal_audiopwmio_pwmaudioout_stop(self); + } + } + // TODO: Share pacing timers based on frequency. size_t pacing_timer = NUM_DMA_TIMERS; for (size_t i = 0; i < NUM_DMA_TIMERS; i++) { From a2b220370eb6261f207532319cca768266f3730a Mon Sep 17 00:00:00 2001 From: root Date: Sat, 29 May 2021 12:26:41 -0500 Subject: [PATCH 3/4] Fix formatting issue --- ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index 9f2c877416..f5bfd2d0df 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -130,7 +130,7 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, if (self->dma.channel[0] < NUM_DMA_CHANNELS) { if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) { common_hal_audiopwmio_pwmaudioout_stop(self); - } + } } // TODO: Share pacing timers based on frequency. From 8761e4bfd7b7124873c561b1b86e7c597d024489 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 30 May 2021 12:12:38 -0500 Subject: [PATCH 4/4] Initialize pacing timer --- ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index f5bfd2d0df..e191606577 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -102,6 +102,7 @@ void common_hal_audiopwmio_pwmaudioout_construct(audiopwmio_pwmaudioout_obj_t *s } audio_dma_init(&self->dma); + self->pacing_timer = NUM_DMA_TIMERS; self->quiescent_value = quiescent_value; } @@ -127,10 +128,8 @@ void common_hal_audiopwmio_pwmaudioout_deinit(audiopwmio_pwmaudioout_obj_t *self void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, mp_obj_t sample, bool loop) { - if (self->dma.channel[0] < NUM_DMA_CHANNELS) { - if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) { - common_hal_audiopwmio_pwmaudioout_stop(self); - } + if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) { + common_hal_audiopwmio_pwmaudioout_stop(self); } // TODO: Share pacing timers based on frequency.