From fccdefb840708cc39aa0d0f5d80e38a7f99674cf Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 30 Mar 2023 23:18:17 -0700 Subject: [PATCH] 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). --- src/audio/gme.cpp | 7 +++++-- src/audio/gme.hpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/audio/gme.cpp b/src/audio/gme.cpp index 154889e37..bdde47faa 100644 --- a/src/audio/gme.cpp +++ b/src/audio/gme.cpp @@ -72,7 +72,7 @@ void Gme::seek(int sample) gme_seek_samples(instance_, sample); } -std::optional Gme::duration_seconds() const +float Gme::duration_seconds() const { SRB2_ASSERT(instance_ != nullptr); @@ -83,7 +83,10 @@ std::optional Gme::duration_seconds() const auto info_finally = srb2::finally([&info] { gme_free_info(info); }); if (info->length == -1) - return std::nullopt; + { + // these two fields added together also make the length of the song + return static_cast(info->intro_length + info->loop_length) / 1000.f; + } // info lengths are in ms return static_cast(info->length) / 1000.f; diff --git a/src/audio/gme.hpp b/src/audio/gme.hpp index 453f5cdda..945f2a775 100644 --- a/src/audio/gme.hpp +++ b/src/audio/gme.hpp @@ -56,7 +56,7 @@ public: std::size_t get_samples(tcb::span buffer); void seek(int sample); - std::optional duration_seconds() const; + float duration_seconds() const; std::optional loop_point_seconds() const; float position_seconds() const;