#pragma once #include "config.h" #include "SDL_mixer.h" #include #include #include #include #include #include #include #include #include #include #include using namespace soundtouch; using std::span; using std::optional; using std::vector; using std::queue; class Playback { private: std::string filePath; std::atomic_bool running; std::atomic_bool file_changed; std::atomic_bool seeking; std::atomic_bool update; std::atomic_bool restart; std::atomic_bool playback_ready; std::mutex flag_mutex; std::mutex error_mutex; std::thread thread; double position; double length; bool paused; Uint8* buf; size_t bufsize; Mix_CommonMixer_t general_mixer; SDL_AudioDeviceID device; SoundTouch *st; SDL_AudioSpec spec; /// @brief A fake SDL_AudioSpec used to trick SDL Mixer X into allocating a bigger buffer. SDL_AudioSpec fakespec; void SDLCallbackInner(Uint8 *stream, int len); static void SDLCallback(void *userdata, Uint8 *stream, int len); Mix_Music *Load(const char* file); void Unload(Mix_Music* music); void ThreadFunc(); void UpdateST(); double GetMaxSeconds(); queue errors; public: Playback(); ~Playback(); double GetPosition(); double GetLength(); void Seek(double position); void Start(std::string filePath); bool IsPaused(); void Pause(); void Stop(); void Update(); bool IsStopped(); float volume; float speed; float tempo; float pitch; float MaxSeconds = 100.0; float MaxSpeed = 4.0; float MaxPitch = 4.0; float MaxTempo = 4.0; float MinSpeed = 0.25; float MinPitch = 0.25; float MinTempo = 0.25; optional GetError(); bool ErrorExists(); };