49 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
102 Mix_HookMusicFinished(
nullptr);
109 if (value ==
"playBattleSound")
111 else if (value ==
"playGuiSound")
113 else if (value ==
"playMusic")
115 else if (value ==
"sfxVolume")
117 else if (value ==
"musicVolume")
119 else if (value ==
"fadeoutmusic")
121 else if (value ==
"uselonglivesounds")
123 else if (value ==
"parallelAudioChannels")
133 logger->
log1(
"SoundManager::init() Initializing sound...");
152 if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1)
154 logger->
log1(
"SoundManager::init() Failed to "
155 "initialize audio subsystem");
159 const size_t audioBuffer = 4096;
174 MIX_DEFAULT_FORMAT, channels, audioBuffer);
178 logger->
log(
"SoundManager::init Could not initialize audio: %s",
207 const size_t audioBuffer = 4096;
221 SDL_AudioSpec desired;
222 SDL_AudioSpec actual;
225 desired.format = MIX_DEFAULT_FORMAT;
226 desired.channels =
CAST_U8(channels);
227 desired.samples = audioBuffer;
228 desired.callback =
nullptr;
229 desired.userdata =
nullptr;
231 if (SDL_OpenAudio(&desired, &actual) < 0)
233 logger->
log(
"SoundManager::testAudio error: %s",
237 if (desired.freq != actual.freq)
239 logger->
log(
"SoundManager::testAudio frequence: %d -> %d",
240 actual.freq, desired.freq);
242 if (desired.format != actual.format)
244 logger->
log(
"SoundManager::testAudio format: %d -> %d",
245 actual.format, desired.format);
247 if (desired.channels != actual.channels)
249 logger->
log(
"SoundManager::testAudio channels: %d -> %d",
250 actual.channels, desired.channels);
252 if (desired.samples != actual.samples)
254 logger->
log(
"SoundManager::testAudio samples: %d -> %d",
255 actual.samples, desired.samples);
262 SDL_version compiledVersion;
263 const char *format =
"Unknown";
265 uint16_t audioFormat = 0;
268 MIX_VERSION(&compiledVersion)
269 const SDL_version *
const linkedVersion = Mix_Linked_Version();
272 const char *driver = SDL_GetCurrentAudioDriver();
274 char driver[40] =
"Unknown";
275 SDL_AudioDriverName(driver, 40);
278 Mix_QuerySpec(&rate, &audioFormat, &channels);
285 format =
"S8";
break;
301 logger->
log(
"SoundManager::info() SDL_mixer: %i.%i.%i (compiled)",
302 compiledVersion.major,
303 compiledVersion.minor,
304 compiledVersion.patch);
305 if (linkedVersion !=
nullptr)
307 logger->
log(
"SoundManager::info() SDL_mixer: %i.%i.%i (linked)",
308 linkedVersion->major,
309 linkedVersion->minor,
310 linkedVersion->patch);
314 logger->
log1(
"SoundManager::info() SDL_mixer: unknown");
316 logger->
log(
"SoundManager::info() Driver: %s", driver);
317 logger->
log(
"SoundManager::info() Format: %s", format);
318 logger->
log(
"SoundManager::info() Rate: %i", rate);
319 logger->
log(
"SoundManager::info() Channels: %i", channels);
408 logger->
log(
"SoundManager::fadeOutMusic() Fading-out (%i ms)", ms);
412 Mix_FadeOutMusic(ms);
464 const int x,
const int y)
const
471 if (sample !=
nullptr)
473 logger->
log(
"SoundManager::playSfx() Playing: %s", path.c_str());
483 const int dist = dx > dy ? dx : dy;
489 sample->
play(0, vol, -1);
499 if (sound ==
"(no sound)")
502 std::string(sound).append(
".ogg")));
515 if (path.compare(0, 4,
"sfx/") == 0)
520 if (sample !=
nullptr)
522 logger->
log(
"SoundManager::playGuiSfx() Playing: %s", path.c_str());
544 logger->
log1(
"SoundManager::close() Shutting down sound...");
590 Mix_AllocateChannels(channels);
#define reportAlways(...)
std::string getValue(const std::string &key, const std::string &deflt) const
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void removeListeners(ConfigListener *const listener)
int getIntValue(const std::string &key) const
void log(const char *const log_text,...)
void log1(const char *const log_text)
bool play(const int loops, const int fadeIn) const
bool play(const int loops, const int volume, const int channel) const
std::string mCurrentMusicFile
void optionChanged(const std::string &value)
void fadeOutAndPlayMusic(const std::string &fileName, const int ms)
void playGuiSound(const std::string &name)
void playGuiSfx(const std::string &path)
void setChannels(const int channels) const
void playSfx(const std::string &path, const int x, const int y) const
void playMusic(const std::string &fileName, const SkipError skipError)
void volumeRestore() const
std::string mNextMusicFile
void fadeOutMusic(const int ms)
void setSfxVolume(const int volume)
void setMusicVolume(const int volume)
LocalPlayer * localPlayer
SoundEffect * getSoundEffect(const std::string &idPath)
SDLMusic * getMusic(const std::string &idPath)
void decRefDelete(Resource *const res)
int MixOpenAudio(const int frequency, const uint16_t format, const int nchannels, const int chunksize)
bool exists(std::string name)
#define BLOCK_START(name)
const bool SkipError_false
const bool SkipError_true
SoundManager soundManager
static void fadeOutCallBack()
static SDLMusic * loadMusic(const std::string &fileName, const SkipError skipError)
static bool sFadingOutEnded
std::string pathJoin(std::string str1, const std::string &str2)