mirror of
https://github.com/jorio/Pomme.git
synced 2024-06-10 06:29:31 +00:00
MP3: Fix incomplete playback at end of stream
This commit is contained in:
parent
543b50c1eb
commit
38d2be66b6
|
@ -24,17 +24,13 @@ SndListHandle Pomme::Sound::LoadMP3AsResource(std::istream& stream)
|
||||||
|
|
||||||
int totalSamples = 0;
|
int totalSamples = 0;
|
||||||
|
|
||||||
while (true)
|
while (!stream.eof() || !fileBuf.empty())
|
||||||
{
|
{
|
||||||
// Refill buffer
|
// Refill the buffer as long as data is available in the input stream.
|
||||||
if (fileBuf.size() < MINIMP3_BUF_SIZE)
|
// Once the stream is depleted, keep feeding the buffer to mp3dec until the buffer is empty.
|
||||||
|
if (fileBuf.size() < MINIMP3_BUF_SIZE
|
||||||
|
&& !stream.eof())
|
||||||
{
|
{
|
||||||
if (stream.eof())
|
|
||||||
{
|
|
||||||
// bail
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto oldSize = fileBuf.size();
|
auto oldSize = fileBuf.size();
|
||||||
auto toRead = MINIMP3_BUF_SIZE - oldSize;
|
auto toRead = MINIMP3_BUF_SIZE - oldSize;
|
||||||
|
|
||||||
|
@ -45,6 +41,11 @@ SndListHandle Pomme::Sound::LoadMP3AsResource(std::istream& stream)
|
||||||
fileBuf.resize(oldSize + didRead);
|
fileBuf.resize(oldSize + didRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileBuf.empty())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
int numDecodedSamples = mp3dec_decode_frame(&context, fileBuf.data(), (int) fileBuf.size(), tempPCM.data(), &frameInfo);
|
int numDecodedSamples = mp3dec_decode_frame(&context, fileBuf.data(), (int) fileBuf.size(), tempPCM.data(), &frameInfo);
|
||||||
|
|
||||||
if (numDecodedSamples > 0)
|
if (numDecodedSamples > 0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user