예제 #1
0
파일: sdl_audio.cpp 프로젝트: gadesx/Player
void SdlAudio::BGM_Stop() {
#if SDL_MAJOR_VERSION>1
	// SDL2_mixer bug, see above
	if (Mix_GetMusicType(bgm.get()) == MUS_WAV) {
		BGS_Stop();
		return;
	}
#endif
	Mix_HaltMusic();
	me_stopped_bgm = false;
}
예제 #2
0
void Audio::BGS_Play(std::string const& file, int volume, int pitch)
{
	BGS_Stop();

	alSourceRewind(*bgsSource_);
	alSourcei(*bgsSource_, AL_BUFFER, getSound(file));
	alSourcef(*bgsSource_, AL_GAIN, volume * 0.01f);
	alSourcei(*bgsSource_, AL_PITCH, pitch * 0.01f);
	alSourcei(*bgsSource_, AL_LOOPING, AL_TRUE);
	alSourcePlay(*bgsSource_);
}
예제 #3
0
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;
	}
}