forked from tsuki/openroller
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#pragma once
|
|
#include <SDL3/SDL.h>
|
|
#include <array>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class AudioManager {
|
|
public:
|
|
enum class GameplaySound : size_t {
|
|
Adlib = 0,
|
|
Tap1 = 1,
|
|
Tap2 = 2,
|
|
};
|
|
|
|
AudioManager();
|
|
~AudioManager();
|
|
|
|
bool loadMusic(const std::string& path, float gain = 1.0f);
|
|
bool loadMusicPair(const std::string& bgmPath, const std::string& shotPath,
|
|
float bgmGain, float shotGain);
|
|
bool loadGameplaySounds(const std::array<std::string, 3>& paths,
|
|
const std::array<float, 3>& gains);
|
|
void playGameplaySound(GameplaySound sound);
|
|
void play();
|
|
void pause();
|
|
void resume();
|
|
void setShotMuted(bool muted);
|
|
|
|
double getTime() const;
|
|
double getDuration() const; // Длина песни в секундах
|
|
|
|
bool isPlaying() const { return playing; }
|
|
|
|
private:
|
|
struct GameplaySoundSlot {
|
|
std::vector<Uint8> data;
|
|
std::array<SDL_AudioStream*, 2> voices{nullptr, nullptr};
|
|
size_t nextVoice = 0;
|
|
};
|
|
|
|
void clear();
|
|
void clearGameplaySounds();
|
|
bool openStreams(const SDL_AudioSpec& bgmSpec, const Uint8* bgmData, Uint32 bgmLen,
|
|
float bgmGain, const SDL_AudioSpec* shotSpec = nullptr,
|
|
const Uint8* shotData = nullptr, Uint32 shotLen = 0,
|
|
float shotGain = 1.0f);
|
|
|
|
SDL_AudioDeviceID device;
|
|
SDL_AudioStream* bgmStream;
|
|
SDL_AudioStream* shotStream;
|
|
std::array<GameplaySoundSlot, 3> gameplaySounds;
|
|
double duration; // Предрассчитанная длительность
|
|
float shotBaseGain;
|
|
bool shotMuted;
|
|
bool playing;
|
|
Uint64 startTime;
|
|
Uint64 accumulatedTicks;
|
|
};
|