2014-06-22 15:02:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2020-08-02 17:56:57 +00:00
|
|
|
#include <mutex>
|
2020-08-02 19:55:46 +00:00
|
|
|
#include <vector>
|
2014-06-22 15:02:04 +00:00
|
|
|
|
2020-08-02 17:44:48 +00:00
|
|
|
class AT3PlusReader;
|
|
|
|
|
2020-08-02 19:55:46 +00:00
|
|
|
enum class MenuSFX {
|
|
|
|
SELECT = 0,
|
|
|
|
BACK = 1,
|
|
|
|
CONFIRM = 2,
|
|
|
|
COUNT,
|
|
|
|
};
|
|
|
|
|
2020-08-02 17:44:48 +00:00
|
|
|
class BackgroundAudio {
|
|
|
|
public:
|
2020-08-02 17:56:57 +00:00
|
|
|
BackgroundAudio();
|
|
|
|
~BackgroundAudio();
|
|
|
|
|
2020-08-02 17:44:48 +00:00
|
|
|
void Clear(bool hard);
|
|
|
|
void SetGame(const std::string &path);
|
|
|
|
void Update();
|
|
|
|
int Play();
|
2020-08-02 19:55:46 +00:00
|
|
|
|
|
|
|
void LoadSamples();
|
|
|
|
void PlaySFX(MenuSFX sfx);
|
|
|
|
|
2020-08-02 17:44:48 +00:00
|
|
|
private:
|
2020-08-02 17:56:57 +00:00
|
|
|
enum {
|
|
|
|
BUFSIZE = 44100,
|
|
|
|
};
|
|
|
|
|
2020-08-02 17:44:48 +00:00
|
|
|
std::mutex g_bgMutex;
|
|
|
|
std::string bgGamePath;
|
|
|
|
int playbackOffset = 0;
|
|
|
|
AT3PlusReader *at3Reader;
|
|
|
|
double gameLastChanged = 0.0;
|
|
|
|
double lastPlaybackTime = 0.0;
|
2020-08-02 17:56:57 +00:00
|
|
|
int *buffer = nullptr;
|
2020-08-02 17:44:48 +00:00
|
|
|
bool fadingOut = true;
|
|
|
|
float volume = 0.0f;
|
|
|
|
float delta = -0.0001f;
|
2020-08-02 19:55:46 +00:00
|
|
|
|
|
|
|
struct PlayInstance {
|
|
|
|
MenuSFX sound;
|
|
|
|
int offset;
|
2020-08-02 21:02:30 +00:00
|
|
|
int volume; // 0..255
|
|
|
|
bool done;
|
2020-08-02 19:55:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Sample {
|
|
|
|
// data must be new-ed.
|
|
|
|
Sample(int16_t *data, int length) : data_(data), length_(length) {}
|
|
|
|
~Sample() {
|
|
|
|
delete[] data_;
|
|
|
|
}
|
|
|
|
int16_t *data_;
|
|
|
|
int length_; // stereo samples.
|
|
|
|
};
|
|
|
|
|
|
|
|
static Sample *LoadSample(const std::string &path);
|
|
|
|
|
|
|
|
std::vector<PlayInstance> plays_;
|
|
|
|
std::vector<std::unique_ptr<Sample>> samples_;
|
2020-08-02 17:44:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern BackgroundAudio g_BackgroundAudio;
|