kaliber/src/engine/sound_player.h

53 lines
1.1 KiB
C
Raw Normal View History

2020-04-13 11:24:53 +00:00
#ifndef AUDIO_PLAYER_H
#define AUDIO_PLAYER_H
#include <memory>
#include "../base/closure.h"
namespace eng {
class Sound;
class SoundPlayer {
public:
SoundPlayer();
~SoundPlayer();
void SetSound(std::shared_ptr<Sound> sound);
void SetSound(std::unique_ptr<Sound> sound);
2020-04-13 11:24:53 +00:00
void Play(bool loop, float fade_in_duration = 0);
2020-04-13 11:24:53 +00:00
void Resume(float fade_in_duration = 0);
2020-04-13 11:24:53 +00:00
void Stop(float fade_out_duration = 0);
2020-04-13 11:24:53 +00:00
// Picks a random variation of the sound or the original sound if "variate" is
// false. Variations are obtained by slightly up or down sampling.
void SetVariate(bool variate);
// Enable or disable stereo simulation effect. Disabled by default.
2020-04-13 11:24:53 +00:00
void SetSimulateStereo(bool simulate);
void SetMaxAplitude(float max_amplitude);
// Set callback to be called once playback stops.
void SetEndCallback(base::Closure cb);
private:
2021-09-30 00:00:18 +00:00
size_t resource_id_ = 0;
2020-04-13 11:24:53 +00:00
std::shared_ptr<Sound> sound_;
float max_amplitude_ = 1.0f;
bool variate_ = false;
2020-04-13 11:24:53 +00:00
SoundPlayer(const SoundPlayer&) = delete;
SoundPlayer& operator=(const SoundPlayer&) = delete;
};
} // namespace eng
#endif // AUDIO_PLAYER_H