mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
Playing with some buffering improvements -- try to buffer samples in
chunks, instead of one at a time. Increased the default stream buffer size.
This commit is contained in:
parent
165b5aeb32
commit
9af25a1541
@ -61,6 +61,7 @@ Stream::Stream(int samplesPerChannel, int bufferCount, unsigned int options)
|
||||
, decoderChannels(0)
|
||||
, decoderSamplePosition(0)
|
||||
, done(false)
|
||||
, flags(FlagNone)
|
||||
, remainder(nullptr)
|
||||
, rawBuffer(nullptr) {
|
||||
if ((this->options & NoDSP) == 0) {
|
||||
@ -216,7 +217,23 @@ Buffer* Stream::GetNextProcessedOutputBuffer() {
|
||||
}
|
||||
|
||||
void Stream::RefillInternalBuffers() {
|
||||
int count = this->bufferCount - this->filledBuffers.size();
|
||||
int recycled = this->recycledBuffers.size();
|
||||
int count = 0;
|
||||
|
||||
if (!this->rawBuffer) { /* not initialized */
|
||||
this->flags |= FlagFilling;
|
||||
recycled = this->bufferCount;
|
||||
}
|
||||
else if (recycled > (this->bufferCount * 2) / 3) { /* dwindling */
|
||||
this->flags |= FlagFilling;
|
||||
}
|
||||
|
||||
if ((this->flags & FlagFilling) > 0) {
|
||||
count = std::min(recycled, this->bufferCount / 5);
|
||||
if (count <= 1) {
|
||||
this->flags &= ~FlagFilling; /* full again */
|
||||
}
|
||||
}
|
||||
|
||||
while (!this->done && count > 0) {
|
||||
--count;
|
||||
|
@ -56,7 +56,7 @@ namespace musik { namespace core { namespace audio {
|
||||
memory. if we need more buffers they will be allocated dynamically */
|
||||
static StreamPtr Create(
|
||||
int samplesPerChannel = 2048,
|
||||
int bufferCount = 32,
|
||||
int bufferCount = 128,
|
||||
unsigned int options = 0);
|
||||
|
||||
private:
|
||||
@ -72,6 +72,8 @@ namespace musik { namespace core { namespace audio {
|
||||
virtual bool OpenStream(std::string uri);
|
||||
|
||||
private:
|
||||
enum Flags { FlagNone = 0, FlagFilling = 1 };
|
||||
|
||||
bool GetNextBufferFromDecoder();
|
||||
Buffer* GetEmptyBuffer();
|
||||
void ApplyDsp(Buffer* buffer);
|
||||
@ -96,6 +98,7 @@ namespace musik { namespace core { namespace audio {
|
||||
unsigned int options;
|
||||
int samplesPerChannel;
|
||||
int bufferCount;
|
||||
int flags;
|
||||
bool done;
|
||||
|
||||
float* rawBuffer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user