From: Côme Chilliet Date: Tue, 29 Nov 2016 10:15:23 +0000 (+0700) Subject: Cleaned a bit OPENAL_SetFrequency, fixing some clang warnings X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=commitdiff_plain;h=6d11a49d92131240215a368792dff612f01f49ee Cleaned a bit OPENAL_SetFrequency, fixing some clang warnings It would be best to check if calls to OPENAL_SetFrequency are really needed --- diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index d935138..177cfe9 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -5307,7 +5307,7 @@ void MenuTick() } } - OPENAL_SetFrequency(channels[stream_menutheme], 22050); + OPENAL_SetFrequency(channels[stream_menutheme]); if (entername) { inputText(displaytext[0], &displayselected); @@ -5421,7 +5421,7 @@ void Game::Tick() fireSound(); flash(); if (musictoggle) { - OPENAL_SetFrequency(OPENAL_ALL, 0.001); + OPENAL_SetFrequency(OPENAL_ALL); emit_stream_np(stream_menutheme); pause_sound(leveltheme); } @@ -5438,7 +5438,7 @@ void Game::Tick() } //play menu theme if (musictoggle && (mainmenu == 1 || mainmenu == 2)) { - OPENAL_SetFrequency(OPENAL_ALL, 0.001); + OPENAL_SetFrequency(OPENAL_ALL); emit_stream_np(stream_menutheme); pause_sound(leveltheme); } @@ -5492,14 +5492,14 @@ void Game::Tick() if (Input::isKeyPressed(SDL_SCANCODE_V) && debugmode) { freeze = !freeze; if (freeze) { - OPENAL_SetFrequency(OPENAL_ALL, 0.001); + OPENAL_SetFrequency(OPENAL_ALL); } } if (Input::isKeyPressed(consolekey) && debugmode) { console = !console; if (console) { - OPENAL_SetFrequency(OPENAL_ALL, 0.001); + OPENAL_SetFrequency(OPENAL_ALL); } else { freeze = 0; waiting = false; @@ -5530,7 +5530,7 @@ void Game::Tick() static int oldwinfreeze; if (winfreeze && !oldwinfreeze) { - OPENAL_SetFrequency(OPENAL_ALL, 0.001); + OPENAL_SetFrequency(OPENAL_ALL); emit_sound_np(consolesuccesssound); } if (winfreeze == 0) @@ -6840,10 +6840,7 @@ void Game::Tick() envsound[j] = envsound[numenvsounds]; } } - if (slomo) - OPENAL_SetFrequency(OPENAL_ALL, slomofreq); - else - OPENAL_SetFrequency(OPENAL_ALL, 22050); + OPENAL_SetFrequency(OPENAL_ALL, slomo); if (tutoriallevel == 1) { XYZ temp; @@ -6865,7 +6862,7 @@ void Game::Tick() if (tutorialstage >= 51) if (distsq(&temp, &Person::players[0]->coords) >= distsq(&temp, &temp2) - 1 || distsq(&temp3, &Person::players[0]->coords) < 4) { OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu... - OPENAL_SetFrequency(OPENAL_ALL, 0.001); + OPENAL_SetFrequency(OPENAL_ALL); emit_stream_np(stream_menutheme); diff --git a/Source/openal_wrapper.cpp b/Source/openal_wrapper.cpp index b597065..4331c69 100644 --- a/Source/openal_wrapper.cpp +++ b/Source/openal_wrapper.cpp @@ -27,6 +27,8 @@ along with Lugaru. If not, see . #include "Sounds.h" #include "Game.h" +extern float slomofreq; + // NOTE: // FMOD uses a Left Handed Coordinate system, OpenAL uses a Right Handed // one...so we just need to flip the sign on the Z axis when appropriate. @@ -430,21 +432,20 @@ static signed char OPENAL_Sample_SetMode(OPENAL_SAMPLE *sptr, unsigned int mode) return true; } -AL_API signed char OPENAL_SetFrequency(int channel, int freq) +AL_API signed char OPENAL_SetFrequency(int channel, bool slomo) { if (!initialized) return false; if (channel == OPENAL_ALL) { for (int i = 0; i < num_channels; i++) - OPENAL_SetFrequency(i, freq); + OPENAL_SetFrequency(i, slomo); return true; } if ((channel < 0) || (channel >= num_channels)) return false; - if (freq == 8012) - // hack - alSourcef(impl_channels[channel].sid, AL_PITCH, 8012.0f / 44100.0f); + if (slomo) + alSourcef(impl_channels[channel].sid, AL_PITCH, ((ALfloat) slomofreq) / 44100.0f); else alSourcef(impl_channels[channel].sid, AL_PITCH, 1.0f); return true; diff --git a/Source/openal_wrapper.h b/Source/openal_wrapper.h index 51a9f5c..16d4f67 100644 --- a/Source/openal_wrapper.h +++ b/Source/openal_wrapper.h @@ -94,7 +94,7 @@ extern "C" { AL_API void OPENAL_Close(); AL_API OPENAL_SAMPLE *OPENAL_Sample_Load(int index, const char *name_or_data, unsigned int mode, int offset, int length); AL_API void OPENAL_Sample_Free(OPENAL_SAMPLE *sptr); - AL_API signed char OPENAL_SetFrequency(int channel, int freq); + AL_API signed char OPENAL_SetFrequency(int channel, bool slomo = false); AL_API signed char OPENAL_SetVolume(int channel, int vol); AL_API signed char OPENAL_SetPaused(int channel, signed char paused); AL_API void OPENAL_SetSFXMasterVolume(int volume);