48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
|
#ifndef AUDIO_H
|
||
|
#define AUDIO_H
|
||
|
|
||
|
#include <memory>
|
||
|
#include <array>
|
||
|
#include <string>
|
||
|
|
||
|
#include <SFML/Audio.hpp>
|
||
|
|
||
|
enum SOUND_TYPE {
|
||
|
FOOTSTEP_SOUND = 0,
|
||
|
|
||
|
N_SOUNDS
|
||
|
};
|
||
|
|
||
|
class Audio
|
||
|
{
|
||
|
private:
|
||
|
// Struct for small sounds, like shots, foot steps, etc.
|
||
|
// As we always need to store SoundBuffer in the same scope as Sound, it's better to make struct.
|
||
|
struct SoundEffect {
|
||
|
sf::SoundBuffer buffer;
|
||
|
sf::Sound sound;
|
||
|
};
|
||
|
|
||
|
using SfMusicPtr = std::unique_ptr<sf::Music>;
|
||
|
using SoundEffectPtr = std::unique_ptr<SoundEffect>;
|
||
|
|
||
|
std::array<SoundEffectPtr, N_SOUNDS> array_sounds;
|
||
|
SfMusicPtr background_music;
|
||
|
|
||
|
public:
|
||
|
Audio(const std::string &background_file_name, std::array<std::string, N_SOUNDS> &&sounds_paths);
|
||
|
|
||
|
bool setSound(const SOUND_TYPE &type, const std::string &sound_file_path);
|
||
|
void playSound(const SOUND_TYPE &type);
|
||
|
|
||
|
bool setBackground(const std::string &music_file_path);
|
||
|
void playBackground();
|
||
|
void stopBackground();
|
||
|
void pauseBackground();
|
||
|
void setBackgroundVolume(const float &volume);
|
||
|
};
|
||
|
|
||
|
using AudioPtr = std::unique_ptr<Audio>;
|
||
|
|
||
|
#endif // AUDIO_H
|