Skip to content

Commit

Permalink
Add Mixer::loop() to allow just sending I2S data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
earlephilhower committed Feb 26, 2018
1 parent e9aec04 commit db411fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/AudioOutputMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/AudioOutputMixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand Down

0 comments on commit db411fa

Please sign in to comment.