Fixed mp3 playback on linux and added support for mono mp3s

This commit is contained in:
bart@bartbes.ath.cx
2010-02-24 21:35:19 +01:00
parent 6aa103c72c
commit 0f54088d06
2 changed files with 28 additions and 15 deletions
+16 -5
View File
@@ -34,7 +34,7 @@ namespace lullaby
bool Mpg123Decoder::inited = false; bool Mpg123Decoder::inited = false;
Mpg123Decoder::Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate) Mpg123Decoder::Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate)
: Decoder(data, ext, bufferSize, sampleRate), handle(0) : Decoder(data, ext, bufferSize, sampleRate), channels(MPG123_STEREO), handle(0)
{ {
data_size = data->getSize(); data_size = data->getSize();
@@ -57,9 +57,6 @@ namespace lullaby
ret = mpg123_open_feed(handle); ret = mpg123_open_feed(handle);
if (ret != MPG123_OK) if (ret != MPG123_OK)
throw love::Exception("Could not open feed."); throw love::Exception("Could not open feed.");
ret = mpg123_format(handle, sampleRate, MPG123_STEREO, MPG123_ENC_SIGNED_16);
if (ret != MPG123_OK)
throw love::Exception("Could not set output format.");
ret = feed(16384); ret = feed(16384);
@@ -113,6 +110,20 @@ namespace lullaby
switch(r) switch(r)
{ {
case MPG123_NEW_FORMAT: case MPG123_NEW_FORMAT:
{
long rate = 0;
int encoding = 0;
int ret = mpg123_getformat(handle, &rate, &channels, &encoding);
if (rate == 0)
rate = sampleRate;
if (channels == 0)
channels = MPG123_STEREO;
if (encoding == 0)
encoding = MPG123_ENC_SIGNED_16;
ret = mpg123_format(handle, rate, channels, encoding);
if (ret != MPG123_OK)
throw love::Exception("Could not set output format.");
}
continue; continue;
case MPG123_NEED_MORE: case MPG123_NEED_MORE:
{ {
@@ -186,7 +197,7 @@ namespace lullaby
int Mpg123Decoder::getChannels() const int Mpg123Decoder::getChannels() const
{ {
return 2; return channels;
} }
int Mpg123Decoder::getBits() const int Mpg123Decoder::getBits() const
@@ -48,6 +48,8 @@ namespace lullaby
int data_offset; int data_offset;
int data_size; int data_size;
int channels;
public: public:
Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate); Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);