66 lines
No EOL
1.5 KiB
C++
66 lines
No EOL
1.5 KiB
C++
#pragma once
|
|
#include "config.h"
|
|
#include "SDL_mixer.h"
|
|
#include <thread>
|
|
#include <SDL.h>
|
|
#include <SDL_audio.h>
|
|
#include <string>
|
|
#include <atomic>
|
|
#include <mutex>
|
|
#include <SoundTouch.h>
|
|
#include <span>
|
|
#include <optional>
|
|
using namespace soundtouch;
|
|
using std::span;
|
|
using std::optional;
|
|
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::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;
|
|
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();
|
|
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;
|
|
double MaxSeconds = 100.0;
|
|
double MaxSpeed = 4.0;
|
|
double MaxPitch = 4.0;
|
|
double MaxTempo = 4.0;
|
|
double MinSpeed = 0.25;
|
|
double MinPitch = 0.25;
|
|
double MinTempo = 0.25;
|
|
}; |