From 80f29047bd89706b9157bbf89e59ac63193d5664 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Tue, 14 Jan 2025 15:32:18 -0800 Subject: [PATCH] Fix issues related to sample-based time codes --- backends/playback/sdl_mixer_x/sdl_mixer_x.hpp | 7 +++++++ playback_backend.hpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backends/playback/sdl_mixer_x/sdl_mixer_x.hpp b/backends/playback/sdl_mixer_x/sdl_mixer_x.hpp index fa41e37..c7a71a5 100644 --- a/backends/playback/sdl_mixer_x/sdl_mixer_x.hpp +++ b/backends/playback/sdl_mixer_x/sdl_mixer_x.hpp @@ -7,6 +7,7 @@ class SDLMixerXBackend : public PlaybackBackend { Mix_CommonMixer_t mixer; File *file; bool initial = false; + double length; public: inline std::string get_id() override { return "sdl_mixer_x"; @@ -15,6 +16,12 @@ class SDLMixerXBackend : public PlaybackBackend { return "SDL Mixer X"; } std::optional get_max_samples() override; + inline double get_length() override { + return length; + } + inline uint64_t get_length_samples() override { + return time_to_samples(get_length()); + } void seek(double position) override; inline void seek_samples(uint64_t position) override { seek(samples_to_time(position)); diff --git a/playback_backend.hpp b/playback_backend.hpp index 769190b..994ff83 100644 --- a/playback_backend.hpp +++ b/playback_backend.hpp @@ -72,7 +72,7 @@ class PlaybackBackend { inline virtual void seek(double position) { seek_samples(time_to_samples(position)); } inline virtual void seek_samples(uint64_t position) { } inline virtual double get_position_time() { - return ((double)position) / ((double)spec.freq); + return ((double)get_position_samples()) / ((double)spec.freq); } inline virtual uint64_t get_position_samples() { return position;