Add loop method to all input and outputs
Adds a virtual loop() method to the file input and audio output objects. By default does nothing, but it can be used to prefill buffers/etc. in the case of a buffered input, or to update a volume meter on an output, etc. The AudioGenerators all now call it as part of their own loop()s, so there is no user intervention required to make it work. Thanks to @armSeb for the idea with his SPI RAM code.
This commit is contained in:
1 parent
df4588197f
commit
fece88a9be
10 files changed
+72
-23
No files matched your search
@@ -73,10 +73,10 @@ bool AudioGeneratorWAV::GetBufferedData(int bytes, void *dest)
|
||||
|
||||
bool AudioGeneratorWAV::loop()
|
||||
{
|
||||
if (!running) return true; // Nothing to do here!
|
||||
if (!running) goto done; // Nothing to do here!
|
||||
|
||||
// First, try and push in the stored sample. If we can't, then punt and try later
|
||||
if (!output->ConsumeSample(lastSample)) return true; // Can't send, but no error detected
|
||||
if (!output->ConsumeSample(lastSample)) goto done; // Can't send, but no error detected
|
||||
|
||||
// Try and stuff the buffer one sample at a time
|
||||
do
|
||||
@@ -101,6 +101,10 @@ bool AudioGeneratorWAV::loop()
|
||||
}
|
||||
} while (running && output->ConsumeSample(lastSample));
|
||||
|
||||
done:
|
||||
file->loop();
|
||||
output->loop();
|
||||
|
||||
return running;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user