mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +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;
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user