Commit 5f718b61 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Use mp3 loader in WavData.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent a7ae7b8b
......@@ -36,6 +36,8 @@ mp3_try_load (const string& filename, WavData& wav_data)
err = mpg123_open (mh, filename.c_str());
assert (err == 0);
err = mpg123_getformat (mh, &rate, &channels, &encoding);
if (err != 0)
return false;
assert (err == 0);
printf ("# %d\n", err);
printf ("# %ld %d %d\n", rate, channels, encoding);
......@@ -54,7 +56,6 @@ mp3_try_load (const string& filename, WavData& wav_data)
{
err = mpg123_read( mh, &buffer[0], buffer.size(), &done );
assert (err == 0 || err == MPG123_DONE);
printf ("# done=%zd err=%d\n", done, err);
float *f = reinterpret_cast<float *> (&buffer[0]);
for (int i = 0; i < buffer.size() / 4; i++)
......
......@@ -4,15 +4,22 @@ int
main (int argc, char **argv)
{
WavData wd;
if (argc >= 2 && mp3_try_load (argv[1], wd))
if (argc >= 2)
{
int sec = wd.n_values() / wd.sample_rate();
if (mp3_try_load (argv[1], wd))
{
int sec = wd.n_values() / wd.sample_rate();
printf ("loaded mp3 %s: %d:%02d\n", argv[1], sec / 60, sec % 60);
if (argc == 3)
printf ("loaded mp3 %s: %d:%02d\n", argv[1], sec / 60, sec % 60);
if (argc == 3)
{
wd.save (argv[2]);
printf ("saved wav: %s\n", argv[2]);
}
}
else
{
wd.save (argv[2]);
printf ("saved wav: %s\n", argv[2]);
printf ("mp3 try load %s failed\n", argv[1]);
}
}
}
#include "wavdata.hh"
#include "mp3.hh"
#include <math.h>
#include <sndfile.h>
......@@ -35,11 +36,19 @@ WavData::load (const string& filename)
int error = sf_error (sndfile);
if (error)
{
m_error_blurb = sf_strerror (sndfile);
if (sndfile)
sf_close (sndfile);
return false;
if (mp3_try_load (filename, *this))
{
// ok, if its an mp3, take it
return true;
}
else
{
m_error_blurb = sf_strerror (sndfile);
if (sndfile)
sf_close (sndfile);
return false;
}
}
vector<int> isamples (sfinfo.frames * sfinfo.channels);
......
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