void ALAudio::BGS_Play(std::string const &file, int volume, int pitch, int fadein) { SET_CONTEXT(ctx_); BGM_Pitch(pitch); BGM_Volume(volume); bgm_src_->set_buffer_loader(getSound(*bgm_src_, file)); bgm_src_->fade_in(fadein); }
void SdlAudio::BGM_Play(std::string const& file, int volume, int /* pitch */, int fadein) { if (file.empty() || file == "(OFF)") { BGM_Stop(); return; } std::string const path = FileFinder::FindMusic(file); if (path.empty()) { //HACK: Polish RTP translation replaced (OFF) reserved string with (Brak) if (file != "(Brak)") Output::Warning("Music not found: %s", file.c_str()); BGM_Stop(); return; } SDL_RWops *rw = SDL_RWFromFile(path.c_str(), "rb"); #if SDL_MIXER_MAJOR_VERSION>1 bgm.reset(Mix_LoadMUS_RW(rw, 1), &Mix_FreeMusic); #else bgm.reset(Mix_LoadMUS_RW(rw), &Mix_FreeMusic); #endif if (!bgm) { Output::Warning("Couldn't load %s BGM.\n%s\n", file.c_str(), Mix_GetError()); return; } #if SDL_MAJOR_VERSION>1 // SDL2_mixer produces noise when playing wav. // Workaround: Use Mix_LoadWAV // https://bugzilla.libsdl.org/show_bug.cgi?id=2094 if (bgs_playing) { BGS_Stop(); } if (Mix_GetMusicType(bgm.get()) == MUS_WAV) { BGM_Stop(); BGS_Play(file, volume, 0, fadein); return; } #endif BGM_Volume(volume); if (!me_stopped_bgm && #ifdef _WIN32 (Mix_GetMusicType(bgm.get()) == MUS_MID && WindowsUtils::GetWindowsVersion() >= 6 ? Mix_PlayMusic(bgm.get(), -1) : Mix_FadeInMusic(bgm.get(), -1, fadein)) #else Mix_FadeInMusic(bgm.get(), -1, fadein) #endif == -1) { Output::Warning("Couldn't play %s BGM.\n%s\n", file.c_str(), Mix_GetError()); return; } }