2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
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
|
|
|
#ifndef ES_CORE_SOUND_H
|
|
|
|
#define ES_CORE_SOUND_H
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2020-08-17 17:15:05 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <sstream>
|
|
|
|
#endif
|
|
|
|
|
2020-08-23 14:15:06 +00:00
|
|
|
#include <SDL2/SDL_audio.h>
|
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-10-18 17:45:26 +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-10-18 17:45:26 +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-10-18 17:45:26 +00:00
|
|
|
const Uint8* getData() const;
|
2020-06-21 12:25:28 +00:00
|
|
|
Uint32 getPosition() const;
|
|
|
|
void setPosition(Uint32 newPosition);
|
|
|
|
Uint32 getLength() const;
|
|
|
|
Uint32 getLengthMS() const;
|
2014-01-03 16:40:36 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-18 17:45:26 +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
|