Browse Source

Improve speed modification audio

Clément Wolf 2 months ago
parent
commit
61b433f44c

+ 2 - 1
.gitignore

@@ -1,2 +1,3 @@
 build/
-obj/
+obj/
+resources/cfg/osu.cfg

+ 0 - 0
resources/cfg/.gitkeep


+ 2 - 2
src/App/Osu/BanchoNetworking.cpp

@@ -70,12 +70,12 @@ void disconnect() {
     curl_slist_free_all(chunk);
     curl_easy_cleanup(curl);
 
-    delete packet.memory;
+    delete[] packet.memory;
   }
 
   try_logging_in = false;
   auth_header = "";
-  delete outgoing.memory;
+  delete[] outgoing.memory;
   outgoing = {0};
   bancho.user_id = 0;
   bancho.submit_scores = false;

+ 1 - 29
src/App/Osu/Osu.cpp

@@ -71,7 +71,7 @@
 
 // release configuration
 ConVar auto_update("auto_update", true, FCVAR_NONE);
-ConVar osu_version("osu_version", 34.04f, FCVAR_NONE);
+ConVar osu_version("osu_version", 34.05f, FCVAR_NONE);
 #ifdef MCENGINE_FEATURE_OPENVR
 ConVar osu_release_stream("osu_release_stream", "vr", FCVAR_NONE);
 #else
@@ -99,7 +99,6 @@ ConVar osu_hud_volume_duration("osu_hud_volume_duration", 1.0f, FCVAR_NONE);
 ConVar osu_hud_volume_size_multiplier("osu_hud_volume_size_multiplier", 1.5f, FCVAR_NONE);
 
 ConVar osu_speed_override("osu_speed_override", -1.0f, FCVAR_CHEAT);
-ConVar osu_pitch_override("osu_pitch_override", -1.0f, FCVAR_NONE);
 
 ConVar osu_pause_on_focus_loss("osu_pause_on_focus_loss", true, FCVAR_NONE);
 ConVar osu_quick_retry_delay("osu_quick_retry_delay", 0.27f, FCVAR_NONE);
@@ -302,7 +301,6 @@ Osu::Osu(int instanceID)
 	osu_skin_reload.setCallback( fastdelegate::MakeDelegate(this, &Osu::onSkinReload) );
 
 	osu_speed_override.setCallback( fastdelegate::MakeDelegate(this, &Osu::onSpeedChange) );
-	osu_pitch_override.setCallback( fastdelegate::MakeDelegate(this, &Osu::onPitchChange) );
 
 	m_osu_playfield_rotation->setCallback( fastdelegate::MakeDelegate(this, &Osu::onPlayfieldChange) );
 	m_osu_playfield_stretch_x->setCallback( fastdelegate::MakeDelegate(this, &Osu::onPlayfieldChange) );
@@ -1266,7 +1264,6 @@ void Osu::updateMods()
 
 	// static overrides
 	onSpeedChange("", osu_speed_override.getString());
-	onPitchChange("", osu_pitch_override.getString());
 
 	// autopilot overrides auto
 	if (m_bModAutopilot)
@@ -2007,22 +2004,6 @@ float Osu::getSpeedMultiplier()
 	return speedMultiplier;
 }
 
-float Osu::getPitchMultiplier()
-{
-	float pitchMultiplier = 1.0f;
-
-	if (m_bModDC)
-		pitchMultiplier = 0.92f;
-
-	if (m_bModNC)
-		pitchMultiplier = 1.1166f;
-
-	if (osu_pitch_override.getFloat() > 0.0f)
-		return osu_pitch_override.getFloat();
-
-	return pitchMultiplier;
-}
-
 bool Osu::isInPlayMode()
 {
 	return (m_songBrowser2 != NULL && m_songBrowser2->hasSelectedAndIsPlaying());
@@ -2374,15 +2355,6 @@ void Osu::onSpeedChange(UString oldValue, UString newValue)
 	}
 }
 
-void Osu::onPitchChange(UString oldValue, UString newValue)
-{
-	if (getSelectedBeatmap() != NULL)
-	{
-		float pitch = newValue.toFloat();
-		getSelectedBeatmap()->setPitch(pitch > 0.0f ? pitch : getPitchMultiplier());
-	}
-}
-
 void Osu::onPlayfieldChange(UString oldValue, UString newValue)
 {
 	if (getSelectedBeatmap() != NULL)

+ 0 - 2
src/App/Osu/Osu.h

@@ -166,7 +166,6 @@ public:
 	float getScoreMultiplier();
 	float getRawSpeedMultiplier();	// without override
 	float getSpeedMultiplier();		// with override
-	float getPitchMultiplier();
 
 	inline bool getModAuto() const {return m_bModAuto;}
 	inline bool getModAutopilot() const {return m_bModAutopilot;}
@@ -226,7 +225,6 @@ public:
 	void onSkinChange(UString oldValue, UString newValue);
 
 	void onSpeedChange(UString oldValue, UString newValue);
-	void onPitchChange(UString oldValue, UString newValue);
 
 	void onPlayfieldChange(UString oldValue, UString newValue);
 

+ 7 - 12
src/App/Osu/OsuBeatmap.cpp

@@ -131,7 +131,6 @@ ConVar osu_play_hitsound_on_click_while_playing("osu_play_hitsound_on_click_whil
 
 ConVar osu_debug_draw_timingpoints("osu_debug_draw_timingpoints", false, FCVAR_CHEAT);
 
-ConVar *OsuBeatmap::m_snd_speed_compensate_pitch_ref = NULL;
 ConVar *OsuBeatmap::m_win_snd_fallback_dsound_ref = NULL;
 
 ConVar *OsuBeatmap::m_osu_pvs = &osu_pvs;
@@ -155,8 +154,6 @@ ConVar *OsuBeatmap::m_fposu_draw_scorebarbg_on_top_ref = NULL;
 OsuBeatmap::OsuBeatmap(Osu *osu)
 {
 	// convar refs
-	if (m_snd_speed_compensate_pitch_ref == NULL)
-		m_snd_speed_compensate_pitch_ref = convar->getConVarByName("snd_speed_compensate_pitch");
 	if (m_win_snd_fallback_dsound_ref == NULL)
 		m_win_snd_fallback_dsound_ref = convar->getConVarByName("win_snd_fallback_dsound");
 
@@ -1717,12 +1714,6 @@ void OsuBeatmap::setSpeed(float speed)
 		m_music->setSpeed(speed);
 }
 
-void OsuBeatmap::setPitch(float pitch)
-{
-	if (m_music != NULL)
-		m_music->setPitch(pitch);
-}
-
 void OsuBeatmap::seekPercent(double percent)
 {
 	if (m_selectedDifficulty2 == NULL || (!m_bIsPlaying && !m_bIsPaused) || m_music == NULL || m_bFailed) return;
@@ -2277,6 +2268,7 @@ void OsuBeatmap::handlePreviewPlay()
 				m_music->setPositionMS(m_selectedDifficulty2->getPreviewTime() < 0 ? (unsigned long)(m_music->getLengthMS() * 0.40f) : m_selectedDifficulty2->getPreviewTime());
 
 			m_music->setVolume(m_osu_volume_music_ref->getFloat());
+			m_music->setSpeed(m_osu->getSpeedMultiplier());
 		}
 	}
 
@@ -2439,9 +2431,12 @@ unsigned long OsuBeatmap::getMusicPositionMSInterpolated()
 
 			// calculate final return value
 			returnPos = (unsigned long)std::round(m_fInterpolatedMusicPos);
-			if (speed < 1.0f && osu_compensate_music_speed.getBool() && m_snd_speed_compensate_pitch_ref->getBool())
-				returnPos += (unsigned long)(((1.0f - speed) / 0.75f) * 5); // osu (new)
-				///returnPos += (unsigned long)((1.0f / speed) * 9); // Mc (old)
+
+
+			bool nightcoring = m_osu->getModNC() || m_osu->getModDC();
+			if (speed < 1.0f && osu_compensate_music_speed.getBool() && !nightcoring) {
+				returnPos += (unsigned long)(((1.0f - speed) / 0.75f) * 5);
+			}
 		}
 		else // no interpolation
 		{

+ 0 - 2
src/App/Osu/OsuBeatmap.h

@@ -86,7 +86,6 @@ public:
 	void unloadMusic() {unloadMusicInt();}
 	void setVolume(float volume);
 	void setSpeed(float speed);
-	void setPitch(float pitch);
 	void seekPercent(double percent);
 	void seekPercentPlayable(double percent);
 
@@ -182,7 +181,6 @@ public:
 	inline float getBreakBackgroundFadeAnim() const {return m_fBreakBackgroundFade;}
 
 protected:
-	static ConVar *m_snd_speed_compensate_pitch_ref;
 	static ConVar *m_win_snd_fallback_dsound_ref;
 
 	static ConVar *m_osu_pvs;

+ 1 - 3
src/App/Osu/OsuBeatmapStandard.cpp

@@ -961,10 +961,8 @@ void OsuBeatmapStandard::onModUpdate(bool rebuildSliderVertexBuffers, bool recom
 	if (recomputeDrainRate)
 		computeDrainRate();
 
-	if (m_music != NULL)
-	{
+	if (m_music != NULL) {
 		m_music->setSpeed(m_osu->getSpeedMultiplier());
-		m_music->setPitch(m_osu->getPitchMultiplier());
 	}
 
 	// recalculate slider vertexbuffers

+ 2 - 0
src/App/Osu/OsuChangelog.cpp

@@ -38,6 +38,8 @@ OsuChangelog::OsuChangelog(Osu *osu) : OsuScreenBackable(osu)
 
 	CHANGELOG latest;
 	latest.title = UString::format("%.2f (%s, %s)", convar->getConVarByName("osu_version")->getFloat(), __DATE__, __TIME__);
+	latest.changes.push_back("- Fixed nightcore/daycore sounding like shit");
+	latest.changes.push_back("- Fixed speed modifications not getting applied to song previews when switching songs");
 	latest.changes.push_back("- Disabled ability to fail when using Relax while online");
 	changelogs.push_back(latest);
 

+ 0 - 1
src/App/Osu/OsuChangelog.h

@@ -31,7 +31,6 @@ private:
 
 	void onChangeClicked(CBaseUIButton *button);
 
-	CBaseUIContainer *m_container;
 	CBaseUIScrollView *m_scrollView;
 
 	struct CHANGELOG

+ 6 - 0
src/App/Osu/OsuChat.cpp

@@ -552,6 +552,12 @@ void OsuChat::onDisconnect() {
         delete chan;
     }
     m_channels.clear();
+
+    for(auto chan : chat_channels) {
+        delete chan.second;
+    }
+    chat_channels.clear();
+
     m_selected_channel = nullptr;
     updateLayout(m_osu->getScreenSize());
 

+ 22 - 82
src/Engine/Sound.cpp

@@ -5,6 +5,9 @@
 // $NoKeywords: $snd $os
 //===============================================================================//
 
+#include "Bancho.h"
+#include "Osu.h"
+
 #include <sstream>
 #include "Sound.h"
 #include "ConVar.h"
@@ -37,7 +40,6 @@
 
 ConVar debug_snd("debug_snd", false, FCVAR_NONE);
 
-ConVar snd_speed_compensate_pitch("snd_speed_compensate_pitch", true, FCVAR_NONE, "automatically keep pitch constant if speed changes");
 ConVar snd_play_interp_duration("snd_play_interp_duration", 0.75f, FCVAR_NONE, "smooth over freshly started channel position jitter with engine time over this duration in seconds");
 ConVar snd_play_interp_ratio("snd_play_interp_ratio", 0.50f, FCVAR_NONE, "percentage of snd_play_interp_duration to use 100% engine time over audio time (some devices report 0 for very long)");
 
@@ -245,7 +247,7 @@ Sound::SOUNDHANDLE Sound::getHandle()
 		m_HCHANNELBACKUP = m_HCHANNEL;
 
 		if (m_HCHANNEL == 0) {
-			debugLog(0xffdd3333, "Couldn't BASS_SampleGetChannel \"%s\", stream = %d, errorcode = %d\n", m_sFilePath, (int)m_bStream, BASS_ErrorGetCode());
+			debugLog(0xffdd3333, "Couldn't BASS_SampleGetChannel \"%s\", stream = %d, errorcode = %d\n", m_sFilePath.c_str(), (int)m_bStream, BASS_ErrorGetCode());
 		} else {
 			BASS_ChannelSetAttribute(m_HCHANNEL, BASS_ATTRIB_VOL, m_fVolume);
 		}
@@ -471,58 +473,43 @@ void Sound::setSpeed(float speed)
 {
 	if (!m_bReady) return;
 
-#ifdef MCENGINE_FEATURE_SOUND
-
 	speed = clamp<float>(speed, 0.05f, 50.0f);
 
-	const SOUNDHANDLE handle = getHandle();
-
 	float originalFreq = 44100.0f;
+	const SOUNDHANDLE handle = getHandle();
 	BASS_ChannelGetAttribute(handle, BASS_ATTRIB_FREQ, &originalFreq);
 
-	BASS_ChannelSetAttribute(handle, (snd_speed_compensate_pitch.getBool() ? BASS_ATTRIB_TEMPO : BASS_ATTRIB_TEMPO_FREQ), (snd_speed_compensate_pitch.getBool() ? (speed-1.0f)*100.0f : speed*originalFreq));
+	BASS_ChannelSetAttribute(handle, BASS_ATTRIB_TEMPO, 1.0f);
+	BASS_ChannelSetAttribute(handle, BASS_ATTRIB_TEMPO_FREQ, originalFreq);
 
-	m_fActualSpeedForDisabledPitchCompensation = speed; // NOTE: currently only used for correctly returning getSpeed() if snd_speed_compensate_pitch is disabled
+	bool nightcoring = bancho.osu->getModNC() || bancho.osu->getModDC();	
+	if(nightcoring) {
+		BASS_ChannelSetAttribute(handle, BASS_ATTRIB_TEMPO_FREQ, speed * originalFreq);
+	} else {
+		BASS_ChannelSetAttribute(handle, BASS_ATTRIB_TEMPO, (speed - 1.0f) * 100.0f);
+	}
 
-#endif
+	m_fActualSpeedForDisabledPitchCompensation = speed;
 }
 
 void Sound::setPitch(float pitch)
 {
 	if (!m_bReady) return;
 
-#ifdef MCENGINE_FEATURE_SOUND
-
-	/*
-	if (!m_bStream)
-	{
-		debugLog("Sound::setPitch() invalid call, this sound is not a stream!\n");
-		return;
-	}
-	*/
-
 	pitch = clamp<float>(pitch, 0.0f, 2.0f);
 
 	const SOUNDHANDLE handle = getHandle();
-
 	BASS_ChannelSetAttribute(handle, BASS_ATTRIB_TEMPO_PITCH, (pitch - 1.0f)*60.0f);
-
-#endif
 }
 
 void Sound::setFrequency(float frequency)
 {
 	if (!m_bReady) return;
 
-#ifdef MCENGINE_FEATURE_SOUND
-
 	frequency = (frequency > 99.0f ? clamp<float>(frequency, 100.0f, 100000.0f) : 0.0f);
 
 	const SOUNDHANDLE handle = getHandle();
-
 	BASS_ChannelSetAttribute(handle, BASS_ATTRIB_FREQ, frequency);
-
-#endif
 }
 
 void Sound::setPan(float pan)
@@ -555,13 +542,8 @@ void Sound::setLoop(bool loop)
 
 	m_bIsLooped = loop;
 
-#ifdef MCENGINE_FEATURE_SOUND
-
 	const SOUNDHANDLE handle = getHandle();
-
 	BASS_ChannelFlags(handle, m_bIsLooped ? BASS_SAMPLE_LOOP : 0, BASS_SAMPLE_LOOP);
-
-#endif
 }
 
 float Sound::getPosition()
@@ -687,79 +669,37 @@ float Sound::getSpeed()
 {
 	if (!m_bReady) return 1.0f;
 
-#ifdef MCENGINE_FEATURE_SOUND
-
-	/*
-	if (!m_bStream)
-	{
-		debugLog("Sound::getSpeed() invalid call, this sound is not a stream!\n");
-		return 0.0f;
+	// BASS will always return 1.0x speed when not compensating pitch, since
+	// we're only changing playback frequency in that case.
+	bool nightcoring = bancho.osu->getModNC() || bancho.osu->getModDC();
+	if(nightcoring) {
+		return m_fActualSpeedForDisabledPitchCompensation;
 	}
-	*/
-
-	if (!snd_speed_compensate_pitch.getBool())
-		return m_fActualSpeedForDisabledPitchCompensation; // NOTE: special case, disabled pitch compensation means bass will return 1.0x always, since the playback frequency is the only thing being actually modified.
-
-	const SOUNDHANDLE handle = getHandle();
 
 	float speed = 0.0f;
+	const SOUNDHANDLE handle = getHandle();
 	BASS_ChannelGetAttribute(handle, BASS_ATTRIB_TEMPO, &speed);
-
 	return ((speed / 100.0f) + 1.0f);
-
-#else
-
-	return 1.0f;
-
-#endif
 }
 
 float Sound::getPitch()
 {
 	if (!m_bReady) return 1.0f;
 
-#ifdef MCENGINE_FEATURE_SOUND
-
-	/*
-	if (!m_bStream)
-	{
-		debugLog("Sound::getPitch() invalid call, this sound is not a stream!\n");
-		return 0.0f;
-	}
-	*/
-
-	const SOUNDHANDLE handle = getHandle();
-
 	float pitch = 0.0f;
+	const SOUNDHANDLE handle = getHandle();
 	BASS_ChannelGetAttribute(handle, BASS_ATTRIB_TEMPO_PITCH, &pitch);
-
 	return ((pitch / 60.0f) + 1.0f);
-
-#else
-
-	return 1.0f;
-
-#endif
 }
 
 float Sound::getFrequency()
 {
 	if (!m_bReady) return 44100.0f;
 
-#ifdef MCENGINE_FEATURE_SOUND
-
-	const SOUNDHANDLE handle = getHandle();
-
 	float frequency = 44100.0f;
+	const SOUNDHANDLE handle = getHandle();
 	BASS_ChannelGetAttribute(handle, BASS_ATTRIB_FREQ, &frequency);
-
 	return frequency;
-
-#else
-
-	return 44100.0f;
-
-#endif
 }
 
 bool Sound::isPlaying()