2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
// Sound.h
|
|
|
|
//
|
|
|
|
// Higher-level audio functions.
|
|
|
|
// Reading theme sound setings, playing audio samples etc.
|
|
|
|
//
|
|
|
|
|
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
|
|
|
|
2020-07-03 18:23:51 +00:00
|
|
|
#if defined(__linux__) || defined (_WIN64)
|
2020-06-26 16:03:55 +00:00
|
|
|
#include <SDL2/SDL_audio.h>
|
|
|
|
#else
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SDL_audio.h"
|
2020-06-26 16:03:55 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-03 16:40:36 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2020-06-06 11:10:33 +00:00
|
|
|
#include <vector>
|
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
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string mPath;
|
2013-05-14 19:31:39 +00:00
|
|
|
SDL_AudioSpec mSampleFormat;
|
2020-06-21 12:25:28 +00:00
|
|
|
Uint8 * mSampleData;
|
2013-05-14 19:31:39 +00:00
|
|
|
Uint32 mSamplePos;
|
|
|
|
Uint32 mSampleLength;
|
2020-06-21 12:25:28 +00:00
|
|
|
bool playing;
|
2013-05-14 19:31:39 +00:00
|
|
|
|
2012-10-13 18:29:53 +00:00
|
|
|
public:
|
2020-06-21 12:25:28 +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);
|
2014-01-03 16:40:36 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
~Sound();
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void init();
|
|
|
|
void deinit();
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void loadFile(const std::string & path);
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void play();
|
|
|
|
bool isPlaying() const;
|
|
|
|
void stop();
|
2013-05-14 19:31:39 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
const Uint8 * getData() const;
|
|
|
|
Uint32 getPosition() const;
|
|
|
|
void setPosition(Uint32 newPosition);
|
|
|
|
Uint32 getLength() const;
|
|
|
|
Uint32 getLengthMS() const;
|
2014-01-03 16:40:36 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
Sound(const std::string & path = "");
|
|
|
|
static std::map< std::string, std::shared_ptr<Sound> > sMap;
|
2012-10-13 18:29:53 +00:00
|
|
|
};
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
enum NavigationSoundsID {
|
|
|
|
SYSTEMBROWSESOUND,
|
|
|
|
QUICKSYSSELECTSOUND,
|
|
|
|
SELECTSOUND,
|
|
|
|
BACKSOUND,
|
|
|
|
SCROLLSOUND,
|
|
|
|
FAVORITESOUND,
|
|
|
|
LAUNCHSOUND
|
2020-05-15 16:21:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NavigationSounds
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
static NavigationSounds* getInstance();
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void deinit();
|
|
|
|
void loadThemeNavigationSounds(const std::shared_ptr<ThemeData>& theme);
|
|
|
|
void playThemeNavigationSound(NavigationSoundsID soundID);
|
|
|
|
bool isPlayingThemeNavigationSound(NavigationSoundsID soundID);
|
2020-05-15 16:21:24 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
static NavigationSounds* sInstance;
|
|
|
|
std::vector<std::shared_ptr<Sound>> navigationSounds;
|
2020-05-15 16:21:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern NavigationSounds navigationsounds;
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_SOUND_H
|