Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer pre-fill #122

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/AudioFileSourceBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ void AudioFileSourceBuffer::fill()
}
}

bool AudioFileSourceBuffer::fill(uint32_t len, uint32_t max_delay)
{
if (!src->isOpen()) {
Serial.printf_P(PSTR("Source file not open\n"));
return false;
}
if (!src->loop()) return false;
fill();

uint32_t toFill = (len < buffSize) ? len : buffSize;
uint32_t startTimestamp = millis();
while (length < toFill && millis() - startTimestamp < max_delay) {
delay(100);
if (!src->loop()) return false;
fill();
}
filled = true;
if (length < len) return false;
return true;
}



bool AudioFileSourceBuffer::loop()
Expand Down
1 change: 1 addition & 0 deletions src/AudioFileSourceBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AudioFileSourceBuffer : public AudioFileSource
virtual uint32_t getPos() override;
virtual bool loop() override;

virtual bool fill(uint32_t len, uint32_t max_delay);
virtual uint32_t getFillLevel();

enum { STATUS_FILLING=2, STATUS_UNDERFLOW };
Expand Down