mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Fixed file not closing after require(). Changed seek() to use seconds.
This commit is contained in:
@@ -73,9 +73,9 @@ namespace lullaby
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
bool FLACDecoder::seek(int ms)
|
||||
bool FLACDecoder::seek(float s)
|
||||
{
|
||||
return seek_absolute(ms);
|
||||
return seek_absolute((int)(s*1000.0f));
|
||||
}
|
||||
|
||||
bool FLACDecoder::rewind()
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace lullaby
|
||||
static bool accepts(const std::string &ext);
|
||||
love::sound::Decoder *clone();
|
||||
int decode();
|
||||
bool seek(int ms);
|
||||
bool seek(float s);
|
||||
bool rewind();
|
||||
bool isSeekable();
|
||||
int getChannels() const;
|
||||
|
||||
@@ -85,9 +85,9 @@ namespace lullaby
|
||||
return r;
|
||||
}
|
||||
|
||||
bool ModPlugDecoder::seek(int ms)
|
||||
bool ModPlugDecoder::seek(float s)
|
||||
{
|
||||
ModPlug_Seek(plug, ms);
|
||||
ModPlug_Seek(plug, (int)(s*1000.0f));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace lullaby
|
||||
|
||||
love::sound::Decoder * clone();
|
||||
int decode();
|
||||
bool seek(int ms);
|
||||
bool seek(float s);
|
||||
bool rewind();
|
||||
bool isSeekable();
|
||||
int getChannels() const;
|
||||
|
||||
@@ -58,9 +58,20 @@ namespace lullaby
|
||||
if (ret != MPG123_OK)
|
||||
throw love::Exception("Could not set output format.");
|
||||
size_t numbytes = 0;
|
||||
ret = mpg123_decode(handle, (unsigned char*) data->getData(), data->getSize(), NULL, 0, &numbytes);
|
||||
if (ret != MPG123_DONE && ret != MPG123_NEW_FORMAT)
|
||||
throw love::Exception("Could not decode feed.");
|
||||
ret = mpg123_feed(handle, (unsigned char*)data->getData(), data->getSize());
|
||||
|
||||
if(ret == MPG123_NEW_FORMAT)
|
||||
{
|
||||
long rate;
|
||||
int channels;
|
||||
int encoding;
|
||||
mpg123_getformat(handle, &rate, &channels, &encoding);
|
||||
}
|
||||
else if(ret != 0)
|
||||
{
|
||||
throw love::Exception(mpg123_strerror(handle));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Mpg123Decoder::~Mpg123Decoder()
|
||||
@@ -98,9 +109,26 @@ namespace lullaby
|
||||
int Mpg123Decoder::decode()
|
||||
{
|
||||
size_t numbytes;
|
||||
int r = mpg123_read(handle, (unsigned char*) buffer, bufferSize, &numbytes);
|
||||
|
||||
for(int i = 0; i < 2; ++i)
|
||||
{
|
||||
int r = mpg123_read(handle, (unsigned char*) buffer, bufferSize, &numbytes);
|
||||
|
||||
switch(r)
|
||||
{
|
||||
case MPG123_NEW_FORMAT:
|
||||
continue;
|
||||
case MPG123_DONE:
|
||||
eof = false;
|
||||
case MPG123_OK:
|
||||
default:
|
||||
return numbytes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If we're done, then EOF. If some error occurred, pretend we EOF'd.
|
||||
/*
|
||||
if (r == MPG123_DONE || r != MPG123_OK)
|
||||
{
|
||||
if ( r == MPG123_NEED_MORE )
|
||||
@@ -114,19 +142,21 @@ namespace lullaby
|
||||
numbytes = 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return numbytes;
|
||||
}
|
||||
|
||||
bool Mpg123Decoder::seek(int ms)
|
||||
bool Mpg123Decoder::seek(float s)
|
||||
{
|
||||
mpg123_seek(handle, ms, SEEK_SET);
|
||||
return true;
|
||||
off_t r = mpg123_seek(handle, (off_t)(s*1000.0f), SEEK_SET);
|
||||
|
||||
return (r >= 0);
|
||||
}
|
||||
|
||||
bool Mpg123Decoder::rewind()
|
||||
{
|
||||
if(mpg123_seek(handle, 0, SEEK_SET) < 0)
|
||||
if(mpg123_seek(handle, 0, SEEK_SET) >= 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace lullaby
|
||||
|
||||
love::sound::Decoder * clone();
|
||||
int decode();
|
||||
bool seek(int ms);
|
||||
bool seek(float s);
|
||||
bool rewind();
|
||||
bool isSeekable();
|
||||
int getChannels() const;
|
||||
|
||||
@@ -218,10 +218,10 @@ namespace lullaby
|
||||
return size;
|
||||
}
|
||||
|
||||
bool VorbisDecoder::seek(int ms)
|
||||
bool VorbisDecoder::seek(float s)
|
||||
{
|
||||
eof = false;
|
||||
int result = ov_time_seek(&handle, ms / 100);
|
||||
int result = ov_time_seek(&handle, (int)(s*1000.0f) / 100);
|
||||
|
||||
if(result == 0)
|
||||
return true;
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace lullaby
|
||||
|
||||
love::sound::Decoder * clone();
|
||||
int decode();
|
||||
bool seek(int ms);
|
||||
bool seek(float s);
|
||||
bool rewind();
|
||||
bool isSeekable();
|
||||
int getChannels() const;
|
||||
|
||||
Reference in New Issue
Block a user