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.
This commit is contained in:
1 parent
e9aec0449d
commit
db411fadbf
2 files changed
+10
-3
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user