mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-31 15:19:53 +02:00
Refactor getNextPlayerChunk
This commit is contained in:
parent
71ed07a1d0
commit
4d4270dad5
1 changed files with 48 additions and 9 deletions
|
@ -53,7 +53,7 @@ void Stream::setRealSampleRate(double sampleRate)
|
||||||
correctAfterXFrames_ = 0;
|
correctAfterXFrames_ = 0;
|
||||||
else
|
else
|
||||||
correctAfterXFrames_ = round((format_.rate / sampleRate) / (format_.rate / sampleRate - 1.));
|
correctAfterXFrames_ = round((format_.rate / sampleRate) / (format_.rate / sampleRate - 1.));
|
||||||
// LOG(DEBUG) << "Correct after X: " << correctAfterXFrames_ << " (Real rate: " << sampleRate << ", rate: " << format_.rate << ")\n";
|
// LOG(DEBUG) << "Correct after X: " << correctAfterXFrames_ << " (Real rate: " << sampleRate << ", rate: " << format_.rate << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,16 +163,55 @@ cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, const cs::usec
|
||||||
char* buffer = (char*)malloc(toRead * format_.frameSize);
|
char* buffer = (char*)malloc(toRead * format_.frameSize);
|
||||||
cs::time_point_clk tp = getNextPlayerChunk(buffer, timeout, toRead);
|
cs::time_point_clk tp = getNextPlayerChunk(buffer, timeout, toRead);
|
||||||
|
|
||||||
float factor = (float)toRead / framesPerBuffer; //(float)(framesPerBuffer*channels_);
|
// float factor = (float)toRead / framesPerBuffer;
|
||||||
// if (abs(framesCorrection) > 1)
|
// if (abs(framesCorrection) > 1)
|
||||||
// LOG(INFO) << "correction: " << framesCorrection << ", factor: " << factor << "\n";
|
// LOG(INFO) << "correction: " << framesCorrection << ", factor: " << factor << "\n";
|
||||||
float idx = 0;
|
|
||||||
for (size_t n = 0; n < framesPerBuffer; ++n)
|
size_t slices = (abs(framesCorrection) + 1);
|
||||||
|
size_t pos = 0;
|
||||||
|
int idx = 0;
|
||||||
|
if (framesCorrection < 0)
|
||||||
{
|
{
|
||||||
size_t index(floor(idx)); // = (int)(ceil(n*factor));
|
int size = framesPerBuffer / slices;
|
||||||
memcpy((char*)outputBuffer + n * format_.frameSize, buffer + index * format_.frameSize, format_.frameSize);
|
// LOG(TRACE) << "getNextPlayerChunk, frames: " << framesPerBuffer << ", correction: " << framesCorrection << " (" << toRead << "), slices: " << slices
|
||||||
idx += factor;
|
// << "\n";
|
||||||
|
|
||||||
|
for (size_t n = 0; n < slices; ++n)
|
||||||
|
{
|
||||||
|
if (n + 1 == slices)
|
||||||
|
size = framesPerBuffer - pos;
|
||||||
|
|
||||||
|
// LOG(TRACE) << "slice: " << n << ", size: " << size << ", out pos: " << pos << ", source pos: " << pos + idx << "\n";
|
||||||
|
memcpy((char*)outputBuffer + pos * format_.frameSize, buffer + (pos + idx) * format_.frameSize, size * format_.frameSize);
|
||||||
|
pos += size;
|
||||||
|
idx -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int size = toRead / slices;
|
||||||
|
// LOG(TRACE) << "getNextPlayerChunk, frames: " << framesPerBuffer << ", correction: " << framesCorrection << " (" << toRead << "), slices: " << slices
|
||||||
|
// << "\n";
|
||||||
|
|
||||||
|
for (size_t n = 0; n < slices; ++n)
|
||||||
|
{
|
||||||
|
if (n + 1 == slices)
|
||||||
|
size = toRead - pos;
|
||||||
|
|
||||||
|
// LOG(TRACE) << "slice: " << n << ", size: " << size << ", out pos: " << pos + idx << ", source pos: " << pos << "\n";
|
||||||
|
memcpy((char*)outputBuffer + (pos + idx) * format_.frameSize, buffer + pos * format_.frameSize, size * format_.frameSize);
|
||||||
|
pos += size;
|
||||||
|
idx -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// float idx = 0;
|
||||||
|
// for (size_t n = 0; n < framesPerBuffer; ++n)
|
||||||
|
// {
|
||||||
|
// size_t index(floor(idx)); // = (int)(ceil(n*factor));
|
||||||
|
// memcpy((char*)outputBuffer + n * format_.frameSize, buffer + index * format_.frameSize, format_.frameSize);
|
||||||
|
// idx += factor;
|
||||||
|
// }
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
return tp;
|
return tp;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue