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
|
|
|
// AudioManager.h
|
|
|
|
//
|
2020-06-26 16:11:24 +00:00
|
|
|
// Low-level audio functions (using SDL2).
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_AUDIO_MANAGER_H
|
|
|
|
#define ES_CORE_AUDIO_MANAGER_H
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2020-06-26 16:03:55 +00:00
|
|
|
#include <SDL2/SDL_audio.h>
|
2021-11-16 16:49:05 +00:00
|
|
|
#include <atomic>
|
2013-05-14 19:31:39 +00:00
|
|
|
#include <memory>
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <vector>
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
class Sound;
|
2013-05-14 19:31:39 +00:00
|
|
|
|
|
|
|
class AudioManager
|
2012-10-13 18:29:53 +00:00
|
|
|
{
|
2013-05-14 19:31:39 +00:00
|
|
|
public:
|
2020-12-22 22:27:23 +00:00
|
|
|
virtual ~AudioManager();
|
2021-11-15 21:43:06 +00:00
|
|
|
static AudioManager& getInstance();
|
2013-05-21 08:40:01 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void init();
|
|
|
|
void deinit();
|
2013-05-21 08:40:01 +00:00
|
|
|
|
2021-11-15 21:43:06 +00:00
|
|
|
void registerSound(std::shared_ptr<Sound> sound);
|
|
|
|
void unregisterSound(std::shared_ptr<Sound> sound);
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void play();
|
|
|
|
void stop();
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2020-12-22 22:27:23 +00:00
|
|
|
// Used for streaming audio from videos.
|
2021-05-09 20:47:46 +00:00
|
|
|
void setupAudioStream(int sampleRate);
|
|
|
|
void processStream(const void* samples, unsigned count);
|
|
|
|
void clearStream();
|
2020-12-22 22:27:23 +00:00
|
|
|
|
2021-11-16 16:49:05 +00:00
|
|
|
void muteStream() { sMuteStream = true; }
|
|
|
|
void unmuteStream() { sMuteStream = false; }
|
2021-05-29 08:52:40 +00:00
|
|
|
|
|
|
|
bool getHasAudioDevice() { return sHasAudioDevice; }
|
2020-12-31 13:27:31 +00:00
|
|
|
|
2021-11-15 21:43:06 +00:00
|
|
|
inline static SDL_AudioDeviceID sAudioDevice = 0;
|
|
|
|
inline static SDL_AudioSpec sAudioFormat;
|
2020-12-22 22:27:23 +00:00
|
|
|
|
|
|
|
private:
|
2022-01-04 20:21:26 +00:00
|
|
|
AudioManager() noexcept;
|
2020-12-22 22:27:23 +00:00
|
|
|
|
|
|
|
static void mixAudio(void* unused, Uint8* stream, int len);
|
|
|
|
static void mixAudio2(void* unused, Uint8* stream, int len);
|
2021-11-15 21:43:06 +00:00
|
|
|
|
|
|
|
inline static SDL_AudioStream* sConversionStream;
|
|
|
|
inline static std::vector<std::shared_ptr<Sound>> sSoundVector;
|
2021-11-16 16:49:05 +00:00
|
|
|
inline static std::atomic<bool> sMuteStream = false;
|
2021-11-15 21:43:06 +00:00
|
|
|
inline static bool sHasAudioDevice = true;
|
2013-05-14 19:31:39 +00:00
|
|
|
};
|
2012-10-13 18:29:53 +00:00
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_AUDIO_MANAGER_H
|