mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
Fixed mp3 playback on linux and added support for mono mp3s
This commit is contained in:
@@ -34,7 +34,7 @@ namespace lullaby
|
||||
bool Mpg123Decoder::inited = false;
|
||||
|
||||
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();
|
||||
@@ -57,9 +57,6 @@ namespace lullaby
|
||||
ret = mpg123_open_feed(handle);
|
||||
if (ret != MPG123_OK)
|
||||
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);
|
||||
|
||||
@@ -113,6 +110,20 @@ namespace lullaby
|
||||
switch(r)
|
||||
{
|
||||
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;
|
||||
case MPG123_NEED_MORE:
|
||||
{
|
||||
@@ -186,7 +197,7 @@ namespace lullaby
|
||||
|
||||
int Mpg123Decoder::getChannels() const
|
||||
{
|
||||
return 2;
|
||||
return channels;
|
||||
}
|
||||
|
||||
int Mpg123Decoder::getBits() const
|
||||
|
||||
@@ -48,6 +48,8 @@ namespace lullaby
|
||||
int data_offset;
|
||||
int data_size;
|
||||
|
||||
int channels;
|
||||
|
||||
public:
|
||||
|
||||
Mpg123Decoder(Data * data, const std::string & ext, int bufferSize, int sampleRate);
|
||||
|
||||
Reference in New Issue
Block a user