2025-07-20 13:49:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
|
|
|
|
|
#include "FileManager.h"
|
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
|
|
|
|
|
namespace NGame {
|
|
|
|
|
|
|
|
|
|
class TAudioManager {
|
|
|
|
|
public:
|
|
|
|
|
TAudioManager(TFileManager& fileManager);
|
|
|
|
|
DELETE_COPY(TAudioManager)
|
|
|
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
void Play(const std::string& sound);
|
|
|
|
|
void Paint(SDL_AudioStream* stream, std::uint32_t ticks);
|
2025-07-20 15:04:05 +03:00
|
|
|
void SetVolume(float volume);
|
|
|
|
|
float Volume() const;
|
2025-07-20 13:49:53 +03:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct TSound {
|
|
|
|
|
SDL_AudioSpec Spec;
|
|
|
|
|
std::uint8_t* Data;
|
|
|
|
|
std::uint32_t Size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct TSoundChannel {
|
|
|
|
|
bool InUse;
|
|
|
|
|
TSound* Sound;
|
|
|
|
|
std::uint32_t Position;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TSound* Load(const std::string& sound);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TFileManager& FileManager_;
|
2025-07-20 15:04:05 +03:00
|
|
|
float Volume_ = 1.0;
|
2025-07-20 13:49:53 +03:00
|
|
|
TSoundChannel Channels_[16];
|
|
|
|
|
std::unordered_map<std::string, TSound*> Sounds_;
|
|
|
|
|
SDL_AudioDeviceID Device_;
|
|
|
|
|
SDL_AudioStream* Stream_;
|
|
|
|
|
std::uint32_t LastTick_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace NGame
|