Commit befefc2e authored by Stefan Westerfeld's avatar Stefan Westerfeld

Relax mp3 error handling to be able to load more mp3s.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 4bb57c7f
...@@ -88,17 +88,29 @@ mp3_try_load (const string& filename, WavData& wav_data) ...@@ -88,17 +88,29 @@ mp3_try_load (const string& filename, WavData& wav_data)
vector<float> buffer (buffer_bytes / sizeof (float)); vector<float> buffer (buffer_bytes / sizeof (float));
vector<float> samples; vector<float> samples;
size_t done = 0; while (true)
do
{ {
err = mpg123_read (mh, reinterpret_cast<unsigned char *> (&buffer[0]), buffer_bytes, &done); size_t done = 0;
if (err != MPG123_OK && err != MPG123_DONE)
return false;
const size_t n_values = done / sizeof (float); err = mpg123_read (mh, reinterpret_cast<unsigned char *> (&buffer[0]), buffer_bytes, &done);
samples.insert (samples.end(), buffer.begin(), buffer.begin() + n_values); if (err == MPG123_OK)
{
const size_t n_values = done / sizeof (float);
samples.insert (samples.end(), buffer.begin(), buffer.begin() + n_values);
}
else if (err == MPG123_DONE)
{
break;
}
else if (err == MPG123_NEED_MORE)
{
// some mp3s have this error before reaching eof -> harmless
}
else
{
return false;
}
} }
while (done);
wav_data = WavData (samples, channels, rate, 24); wav_data = WavData (samples, channels, rate, 24);
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment