added missing DMA buffer flush, see issue #270 for details (#271)

This commit is contained in:
Felix Eckhardt authored and GitHub committed 2020-05-21 13:16:34 -07:00
1 parent e0d413622c
commit e59319f605
3 files changed
+17

No files matched your search

+1
View File
@@ -45,6 +45,7 @@ class AudioOutput
return count;
}
virtual bool stop() { return false; }
virtual void flush() { return; }
virtual bool loop() { return true; }
public:
+14
View File
@@ -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<buffersize; i++) {
while (!ConsumeSample(samples)) {
delay(10);
}
}
#endif
}
bool AudioOutputI2S::stop()
{
#ifdef ESP32
+2
View File
@@ -34,6 +34,7 @@ class AudioOutputI2S : public AudioOutput
virtual bool SetChannels(int channels) override;
virtual bool begin() override;
virtual bool ConsumeSample(int16_t sample[2]) override;
virtual void flush() override;
virtual bool stop() override;
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
@@ -47,6 +48,7 @@ class AudioOutputI2S : public AudioOutput
int output_mode;
bool mono;
bool i2sOn;
int dma_buf_count;
// We can restore the old values and free up these pins when in NoDAC mode
uint32_t orig_bck;
uint32_t orig_ws;