From 4a479ed6f507dd06e2a995df19f4aaf8debe5d5b Mon Sep 17 00:00:00 2001 From: Alayan <25536748+Alayan-stk-2@users.noreply.github.com> Date: Sun, 22 Dec 2024 17:53:47 +0100 Subject: [PATCH] Improvements in the last lap music transition - Group up the code to trigger the fast music and the last lap SFX in the same area - Remove all the code meant to play a music at higher pitch, it was unused and would have been annoying if it was. - Apply the 'last lap SFX' reduced music volume when switching between a normal music and a fast music too - Increase the switch duration between normal and fast music from 1.0s to 1.5s --- src/audio/music.hpp | 1 - src/audio/music_information.cpp | 40 ++++++++++----------------------- src/audio/music_information.hpp | 16 ++++++------- src/audio/music_ogg.cpp | 7 ------ src/audio/music_ogg.hpp | 1 - src/modes/linear_world.cpp | 19 +++++++--------- 6 files changed, 27 insertions(+), 57 deletions(-) diff --git a/src/audio/music.hpp b/src/audio/music.hpp index a848fb6e50f..120b46f42b1 100644 --- a/src/audio/music.hpp +++ b/src/audio/music.hpp @@ -35,7 +35,6 @@ class Music : public NoCopy virtual bool pauseMusic () = 0; virtual bool resumeMusic () = 0; virtual void setVolume (float volume) = 0; - virtual void updateFaster(float percent, float pitch) = 0; virtual void update () = 0; virtual bool isPlaying () = 0; diff --git a/src/audio/music_information.cpp b/src/audio/music_information.cpp index e211664d4ff..511768b4be6 100644 --- a/src/audio/music_information.cpp +++ b/src/audio/music_information.cpp @@ -84,8 +84,7 @@ MusicInformation::MusicInformation(const XMLNode *root, m_fast_loop_end = -1.0f; m_enable_fast = false; m_music_waiting = false; - m_faster_time = 1.0f; - m_max_pitch = 0.1f; + m_faster_time = 1.5f; m_gain = 1.0f; @@ -107,6 +106,8 @@ MusicInformation::MusicInformation(const XMLNode *root, root->get("fast-loop-start", &m_fast_loop_start ); root->get("fast-loop-end", &m_fast_loop_end ); + m_temporary_volume = m_gain; + // Get the path from the filename and add it to the ogg filename std::string path = StringUtils::getPath(filename); m_normal_filename = path + "/" + m_normal_filename; @@ -273,31 +274,15 @@ void MusicInformation::update(float dt) { m_mode=SOUND_FAST; m_normal_music->stopMusic(); + m_fast_music->setVolume(m_temporary_volume); m_fast_music->update(); return; } float fraction=m_time_since_faster/m_faster_time; - m_normal_music->setVolume(1-fraction); - m_fast_music->setVolume(fraction); + m_normal_music->setVolume(m_temporary_volume * (1-fraction)); + m_fast_music->setVolume(m_temporary_volume * fraction); m_normal_music->update(); m_fast_music->update(); - break; - } - case SOUND_FASTER: { - if ( m_normal_music == NULL ) break; - - m_time_since_faster +=dt; - if(m_time_since_faster>=m_faster_time) - { - // Once the pitch is adjusted, just switch back to normal - // mode. We can't switch to fast music mode, since this would - // play m_fast_music, which isn't available. - m_mode=SOUND_NORMAL; - return; - } - float fraction=m_time_since_faster/m_faster_time; - m_normal_music->updateFaster(fraction, m_max_pitch); - break; } case SOUND_NORMAL: @@ -354,6 +339,7 @@ void MusicInformation::resumeMusic() //----------------------------------------------------------------------------- void MusicInformation::setDefaultVolume() { + m_temporary_volume = m_gain; if (m_normal_music && m_normal_music->isPlaying()) m_normal_music->setVolume(m_gain); if (m_fast_music && m_fast_music->isPlaying()) @@ -366,11 +352,14 @@ void MusicInformation::setDefaultVolume() */ void MusicInformation::setTemporaryVolume(float volume) { - if (m_normal_music != NULL) m_normal_music->setVolume(volume); - if (m_fast_music != NULL) m_fast_music->setVolume(volume); + m_temporary_volume = m_gain * volume; + if (m_normal_music != NULL) m_normal_music->setVolume(m_temporary_volume); + if (m_fast_music != NULL) m_fast_music->setVolume(m_temporary_volume); } //----------------------------------------------------------------------------- +/** If there is a fast music available, switch to it. + * */ void MusicInformation::switchToFastMusic() { if(!m_enable_fast) return; @@ -381,11 +370,6 @@ void MusicInformation::switchToFastMusic() m_fast_music->playMusic(); m_fast_music->setVolume(0); } - else - { - // FIXME: for now this music is too annoying, - m_mode = SOUND_FASTER; - } } // switchToFastMusic //----------------------------------------------------------------------------- diff --git a/src/audio/music_information.hpp b/src/audio/music_information.hpp index fd2406f3a9c..183a9e2ef64 100644 --- a/src/audio/music_information.hpp +++ b/src/audio/music_information.hpp @@ -53,8 +53,7 @@ class MusicInformation : public NoCopy * was told not to start right away). */ bool m_music_waiting; - /** If faster music is enabled at all (either separate file or using - * the pitch shift approach). */ + /** If faster music is enabled at all. */ bool m_enable_fast; float m_gain; @@ -64,18 +63,19 @@ class MusicInformation : public NoCopy float m_normal_loop_end; float m_fast_loop_end; - /** Either time for fading faster music in, or time to change pitch. */ + /** Time for fading faster music in. */ float m_faster_time; - /** Maximum pitch for faster music. */ - float m_max_pitch; + + /* Avoid the temporary volume being forgotten */ + float m_temporary_volume; + static const int LOOP_FOREVER=-1; mutable std::mutex m_music_mutex; Music *m_normal_music, *m_fast_music; enum {SOUND_NORMAL, //!< normal music is played SOUND_FADING, //!< normal music fading out, faster fading in - SOUND_FASTER, //!< change pitch of normal music - SOUND_FAST} //!< playing faster music or max pitch reached + SOUND_FAST} //!< playing faster music m_mode; float m_time_since_faster; @@ -127,8 +127,6 @@ class MusicInformation : public NoCopy // ------------------------------------------------------------------------ /** If available, returns the file name of the faster/last-lap music. */ const std::string& getFastFilename() const { return m_fast_filename; } - // ------------------------------------------------------------------------ - float getMaxPitch() const { return m_max_pitch; } }; // MusicInformation #endif diff --git a/src/audio/music_ogg.cpp b/src/audio/music_ogg.cpp index 8b8c421d6b8..805a90a3f67 100644 --- a/src/audio/music_ogg.cpp +++ b/src/audio/music_ogg.cpp @@ -255,13 +255,6 @@ void MusicOggStream::setVolume(float volume) check("volume music"); // clear errors } // setVolume -//----------------------------------------------------------------------------- -void MusicOggStream::updateFaster(float percent, float max_pitch) -{ - alSourcef(m_soundSource,AL_PITCH,1+max_pitch*percent); - update(); -} // updateFaster - //----------------------------------------------------------------------------- void MusicOggStream::update() { diff --git a/src/audio/music_ogg.hpp b/src/audio/music_ogg.hpp index 37c2c352c1e..c1b7fa63917 100644 --- a/src/audio/music_ogg.hpp +++ b/src/audio/music_ogg.hpp @@ -49,7 +49,6 @@ class MusicOggStream : public Music virtual ~MusicOggStream(); virtual void update(); - virtual void updateFaster(float percent, float max_pitch); virtual bool load(const std::string& filename); diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 148a8f97932..ad770659630 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -443,6 +443,14 @@ void LinearWorld::newLap(unsigned int kart_index) m_last_lap_sfx_playing = false; } } + // Switch on faster music if not already done so, if the + // first kart is doing its last lap. + if(!m_faster_music_active && + useFastMusicNearEnd()) + { + music_manager->switchToFastMusic(); + m_faster_music_active=true; + } } else if (raceHasLaps() && kart_info.m_finished_laps > 0 && kart_info.m_finished_laps+1 < lap_count && !isLiveJoinWorld() && m_race_gui) @@ -955,17 +963,6 @@ void LinearWorld::updateRacePosition() assert(false); } #endif - - // Switch on faster music if not already done so, if the - // first kart is doing its last lap. - if(!m_faster_music_active && - p == 1 && - kart_info.m_finished_laps == RaceManager::get()->getNumLaps() - 1 && - useFastMusicNearEnd() ) - { - music_manager->switchToFastMusic(); - m_faster_music_active=true; - } } // for i