mirror of
https://github.com/love2d/love.git
synced 2026-08-13 09:00:54 +02:00
Added Source:getDuration (thanks Boolsheet!)
For streaming sources, the duration may not always be sample-accurate and may return -1 if it cannot be determined at all.
This commit is contained in:
@@ -34,6 +34,7 @@ namespace lullaby
|
||||
ModPlugDecoder::ModPlugDecoder(Data *data, const std::string &ext, int bufferSize)
|
||||
: Decoder(data, ext, bufferSize)
|
||||
, plug(0)
|
||||
, duration(-2.0)
|
||||
{
|
||||
|
||||
// Set some ModPlug settings.
|
||||
@@ -141,6 +142,22 @@ int ModPlugDecoder::getBitDepth() const
|
||||
return 16;
|
||||
}
|
||||
|
||||
double ModPlugDecoder::getDuration()
|
||||
{
|
||||
// Only calculate the duration if we haven't done so already.
|
||||
if (duration == -2.0)
|
||||
{
|
||||
int lengthms = ModPlug_GetLength(plug);
|
||||
|
||||
if (lengthms < 0)
|
||||
duration = -1.0;
|
||||
else
|
||||
duration = (double) lengthms / 1000.0;
|
||||
}
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
} // lullaby
|
||||
} // sound
|
||||
} // love
|
||||
|
||||
Reference in New Issue
Block a user