Audio: fix GME not reporting song length most of the time

Now add the intro time and looping time together to get
the length of the song, if the length field itself is not
specified (it's usually not).
This commit is contained in:
James R 2023-03-30 23:18:17 -07:00
parent 535fc17875
commit fccdefb840
2 changed files with 6 additions and 3 deletions

View file

@ -72,7 +72,7 @@ void Gme::seek(int sample)
gme_seek_samples(instance_, sample); gme_seek_samples(instance_, sample);
} }
std::optional<float> Gme::duration_seconds() const float Gme::duration_seconds() const
{ {
SRB2_ASSERT(instance_ != nullptr); SRB2_ASSERT(instance_ != nullptr);
@ -83,7 +83,10 @@ std::optional<float> Gme::duration_seconds() const
auto info_finally = srb2::finally([&info] { gme_free_info(info); }); auto info_finally = srb2::finally([&info] { gme_free_info(info); });
if (info->length == -1) if (info->length == -1)
return std::nullopt; {
// these two fields added together also make the length of the song
return static_cast<float>(info->intro_length + info->loop_length) / 1000.f;
}
// info lengths are in ms // info lengths are in ms
return static_cast<float>(info->length) / 1000.f; return static_cast<float>(info->length) / 1000.f;

View file

@ -56,7 +56,7 @@ public:
std::size_t get_samples(tcb::span<short> buffer); std::size_t get_samples(tcb::span<short> buffer);
void seek(int sample); void seek(int sample);
std::optional<float> duration_seconds() const; float duration_seconds() const;
std::optional<float> loop_point_seconds() const; std::optional<float> loop_point_seconds() const;
float position_seconds() const; float position_seconds() const;