Skip to content

Commit

Permalink
Fixing bug when loading ogg loop (fix #1295)
Browse files Browse the repository at this point in the history
The ogg loop layers was empty because the samples are being appended to
the end of the buffer. The first samples are always zero and we see just
silence in the layers.

Now the samples are copied to the correct place in the buffer.
  • Loading branch information
elieserdejesus committed Jun 27, 2020
1 parent c7ad3ad commit b66f33b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Common/file/OggFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ bool OggFileReader::read(const QString &filePath, SamplesBuffer &outBuffer, quin
// decode and append decoded data in 'outBuffer'
int decodedFrames = 0;
const int MAX_SAMPLES_PER_DECODE = 1024;
bool append = outBuffer.getFrameLenght() == 0;
auto remaining = outBuffer.getFrameLenght();
do
{
const auto &decodedBuffer = decoder.decode(MAX_SAMPLES_PER_DECODE);
decodedFrames = decodedBuffer.getFrameLenght();
if (!decodedBuffer.isEmpty()) {
outBuffer.append(decodedBuffer);
if (append) {
outBuffer.append(decodedBuffer);
}
else {
auto samplesToCopy = std::min(decodedBuffer.getFrameLenght(), remaining);
auto outBufferOffset = outBuffer.getFrameLenght() - remaining;
outBuffer.set(decodedBuffer, 0, samplesToCopy, outBufferOffset);
remaining -= samplesToCopy;
}
}
}
while(decodedFrames > 0);
Expand Down

0 comments on commit b66f33b

Please sign in to comment.