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
@@ -115,9 +115,17 @@ uint32_t AudioFileSourceBuffer::read(void *data, uint32_t len)
|
||||
writePtr = 0;
|
||||
length = 0;
|
||||
filled = false;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
fill();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void AudioFileSourceBuffer::fill()
|
||||
{
|
||||
if (!buffer) return;
|
||||
|
||||
if (length < buffSize) {
|
||||
// Now try and opportunistically fill the buffer
|
||||
if (readPtr > writePtr) {
|
||||
@@ -127,7 +135,7 @@ uint32_t AudioFileSourceBuffer::read(void *data, uint32_t len)
|
||||
length += cnt;
|
||||
writePtr = (writePtr + cnt) % buffSize;
|
||||
}
|
||||
return bytes;
|
||||
return;
|
||||
}
|
||||
|
||||
int bytesAvailEnd = buffSize - writePtr;
|
||||
@@ -135,7 +143,7 @@ uint32_t AudioFileSourceBuffer::read(void *data, uint32_t len)
|
||||
int cnt = src->readNonBlock(&buffer[writePtr], bytesAvailEnd);
|
||||
length += cnt;
|
||||
writePtr = (writePtr + cnt) % buffSize;
|
||||
if (cnt != bytesAvailEnd) return bytes;
|
||||
if (cnt != bytesAvailEnd) return;
|
||||
}
|
||||
int bytesAvailStart = readPtr - 1;
|
||||
if (bytesAvailStart > 0) {
|
||||
@@ -144,7 +152,14 @@ uint32_t AudioFileSourceBuffer::read(void *data, uint32_t len)
|
||||
writePtr = (writePtr + cnt) % buffSize;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AudioFileSourceBuffer::loop()
|
||||
{
|
||||
if (!src->loop()) return false;
|
||||
fill();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user