2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2023-12-16 18:48:25 +00:00
|
|
|
// ES-DE
|
2020-06-21 12:25:28 +00:00
|
|
|
// Sound.h
|
|
|
|
//
|
|
|
|
// Higher-level audio functions.
|
2022-12-22 16:15:15 +00:00
|
|
|
// Navigation sounds, audio sample playback etc.
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
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-23 14:15:06 +00:00
|
|
|
#include <SDL2/SDL_audio.h>
|
2021-11-16 16:49:05 +00:00
|
|
|
#include <atomic>
|
2014-01-03 16:40:36 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2020-12-22 22:27:23 +00:00
|
|
|
#include <sstream>
|
2020-11-28 21:27:00 +00:00
|
|
|
#include <string>
|
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
|
|
|
|
{
|
|
|
|
public:
|
2021-07-07 18:31:46 +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();
|
2021-11-16 16:49:05 +00:00
|
|
|
bool isPlaying() const { return mPlaying; }
|
2020-06-21 12:25:28 +00:00
|
|
|
void stop();
|
2013-05-14 19:31:39 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
const Uint8* getData() const { return mSampleData; }
|
|
|
|
Uint32 getPosition() const { return mSamplePos; }
|
2020-06-21 12:25:28 +00:00
|
|
|
void setPosition(Uint32 newPosition);
|
2021-07-07 18:31:46 +00:00
|
|
|
Uint32 getLength() const { return mSampleLength; }
|
2020-12-22 22:27:23 +00:00
|
|
|
|
|
|
|
static std::shared_ptr<Sound> get(const std::string& path);
|
2021-11-15 21:43:06 +00:00
|
|
|
static std::shared_ptr<Sound> getFromTheme(ThemeData* const theme,
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::string& view,
|
|
|
|
const std::string& elem);
|
2014-01-03 16:40:36 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-18 17:45:26 +00:00
|
|
|
Sound(const std::string& path = "");
|
2020-12-22 22:27:23 +00:00
|
|
|
|
2022-12-22 16:15:15 +00:00
|
|
|
static inline std::map<std::string, std::shared_ptr<Sound>> sMap;
|
2020-12-22 22:27:23 +00:00
|
|
|
std::string mPath;
|
|
|
|
SDL_AudioSpec mSampleFormat;
|
|
|
|
Uint8* mSampleData;
|
|
|
|
Uint32 mSamplePos;
|
|
|
|
Uint32 mSampleLength;
|
2021-11-16 16:49:05 +00:00
|
|
|
std::atomic<bool> mPlaying;
|
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:
|
2021-11-15 21:43:06 +00:00
|
|
|
static NavigationSounds& getInstance();
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void deinit();
|
2021-11-15 21:43:06 +00:00
|
|
|
void loadThemeNavigationSounds(ThemeData* const theme);
|
2020-06-21 12:25:28 +00:00
|
|
|
void playThemeNavigationSound(NavigationSoundsID soundID);
|
|
|
|
bool isPlayingThemeNavigationSound(NavigationSoundsID soundID);
|
2020-05-15 16:21:24 +00:00
|
|
|
|
|
|
|
private:
|
2022-01-04 20:21:26 +00:00
|
|
|
NavigationSounds() noexcept {};
|
2021-11-15 21:43:06 +00:00
|
|
|
std::vector<std::shared_ptr<Sound>> mNavigationSounds;
|
2020-05-15 16:21:24 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_SOUND_H
|