2017-10-31 17:12:50 +00:00
|
|
|
#pragma once
|
|
|
|
#ifndef ES_CORE_SOUND_H
|
|
|
|
#define ES_CORE_SOUND_H
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SDL_audio.h"
|
2014-01-03 16:40:36 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2013-05-14 19:31:39 +00:00
|
|
|
|
2014-01-03 16:40:36 +00:00
|
|
|
class ThemeData;
|
2012-10-13 18:29:53 +00:00
|
|
|
|
|
|
|
class Sound
|
|
|
|
{
|
2013-05-14 19:31:39 +00:00
|
|
|
std::string mPath;
|
|
|
|
SDL_AudioSpec mSampleFormat;
|
|
|
|
Uint8 * mSampleData;
|
|
|
|
Uint32 mSamplePos;
|
|
|
|
Uint32 mSampleLength;
|
|
|
|
bool playing;
|
|
|
|
|
2012-10-13 18:29:53 +00:00
|
|
|
public:
|
2014-01-03 16:40:36 +00:00
|
|
|
static std::shared_ptr<Sound> get(const std::string& path);
|
|
|
|
static std::shared_ptr<Sound> getFromTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& elem);
|
|
|
|
|
2012-10-13 18:29:53 +00:00
|
|
|
~Sound();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
void deinit();
|
|
|
|
|
2013-05-14 19:31:39 +00:00
|
|
|
void loadFile(const std::string & path);
|
2012-10-13 18:29:53 +00:00
|
|
|
|
|
|
|
void play();
|
2013-05-14 19:31:39 +00:00
|
|
|
bool isPlaying() const;
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
const Uint8 * getData() const;
|
|
|
|
Uint32 getPosition() const;
|
|
|
|
void setPosition(Uint32 newPosition);
|
|
|
|
Uint32 getLength() const;
|
2013-08-06 13:15:20 +00:00
|
|
|
Uint32 getLengthMS() const;
|
2014-01-03 16:40:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Sound(const std::string & path = "");
|
|
|
|
static std::map< std::string, std::shared_ptr<Sound> > sMap;
|
2012-10-13 18:29:53 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_SOUND_H
|