From e59319f605d45d06ae0c6a7f983872c0366dd11c Mon Sep 17 00:00:00 2001 From: Felix Eckhardt Date: Thu, 21 May 2020 22:16:34 +0200 Subject: [PATCH] added missing DMA buffer flush, see issue #270 for details (#271) --- src/AudioOutput.h | 1 + src/AudioOutputI2S.cpp | 14 ++++++++++++++ src/AudioOutputI2S.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/AudioOutput.h b/src/AudioOutput.h index 558fe92..dc15742 100644 --- a/src/AudioOutput.h +++ b/src/AudioOutput.h @@ -45,6 +45,7 @@ class AudioOutput return count; } virtual bool stop() { return false; } + virtual void flush() { return; } virtual bool loop() { return true; } public: diff --git a/src/AudioOutputI2S.cpp b/src/AudioOutputI2S.cpp index ad3087b..f7e194e 100644 --- a/src/AudioOutputI2S.cpp +++ b/src/AudioOutputI2S.cpp @@ -30,6 +30,7 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int { this->portNo = port; this->i2sOn = false; + this->dma_buf_count = dma_buf_count; if (output_mode != EXTERNAL_I2S && output_mode != INTERNAL_DAC && output_mode != INTERNAL_PDM) { output_mode = EXTERNAL_I2S; } @@ -198,6 +199,19 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2]) #endif } +void AudioOutputI2S::flush() { +#ifdef ESP32 + // makes sure that all stored DMA samples are consumed / played + int buffersize = 64 * this->dma_buf_count; + int16_t samples[2] = {0x0,0x0}; + for (int i=0;i