From db411fadbfaf7de6988635829629715bf091e906 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 26 Feb 2018 13:11:23 -0800 Subject: [PATCH] Add Mixer::loop() to allow just sending I2S data Allow users to call the ::loop() method to pump out any possible data to the I2S interface, without requiring any Stubs to pump the queue. --- src/AudioOutputMixer.cpp | 10 ++++++++-- src/AudioOutputMixer.h | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/AudioOutputMixer.cpp b/src/AudioOutputMixer.cpp index d9354be..57a1c06 100644 --- a/src/AudioOutputMixer.cpp +++ b/src/AudioOutputMixer.cpp @@ -177,7 +177,7 @@ void AudioOutputMixer::RemoveInput(int id) stubRunning[id] = false; } -bool AudioOutputMixer::ConsumeSample(int16_t sample[2], int id) +bool AudioOutputMixer::loop() { // First, try and fill I2S... // This is not optimal, but algorithmically should work fine @@ -216,7 +216,13 @@ bool AudioOutputMixer::ConsumeSample(int16_t sample[2], int id) readPtr = (readPtr + 1) % buffSize; } } while (avail); - + return true; +} + +bool AudioOutputMixer::ConsumeSample(int16_t sample[2], int id) +{ + loop(); // Send any pre-existing, completed I2S data we can fit + // Now, do we have space for a new sample? int nextWritePtr = (writePtr[id] + 1) % buffSize; if (nextWritePtr == readPtr) { diff --git a/src/AudioOutputMixer.h b/src/AudioOutputMixer.h index 1a0bb09..2d2d1ec 100644 --- a/src/AudioOutputMixer.h +++ b/src/AudioOutputMixer.h @@ -38,7 +38,7 @@ class AudioOutputMixerStub : public AudioOutput virtual bool begin() override; virtual bool ConsumeSample(int16_t sample[2]) override; virtual bool stop() override; - + protected: AudioOutputMixer *parent; int id; @@ -56,6 +56,7 @@ class AudioOutputMixer : public AudioOutput virtual bool begin() override; virtual bool ConsumeSample(int16_t sample[2]) override; virtual bool stop() override; + virtual bool loop() override; // Send all existing samples we can to I2S AudioOutputMixerStub *NewInput(); // Get a new stub to pass to a generator