Parcourir la source

Add fast path for Sound::setPositionMS

kiwec il y a 3 mois
Parent
commit
5fd81c91b3
4 fichiers modifiés avec 40 ajouts et 3 suppressions
  1. 3 3
      src/App/Osu/Beatmap.cpp
  2. 1 0
      src/App/Osu/Changelog.cpp
  3. 34 0
      src/Engine/Sound.cpp
  4. 2 0
      src/Engine/Sound.h

+ 3 - 3
src/App/Osu/Beatmap.cpp

@@ -1790,13 +1790,13 @@ void Beatmap::handlePreviewPlay() {
             should_start_song_at_preview_point = false;
 
             if(start_at_song_beginning) {
-                m_music->setPositionMS(0);
+                m_music->setPositionMS_fast(0);
                 m_bWasSeekFrame = true;
             } else if(m_iContinueMusicPos != 0) {
-                m_music->setPositionMS(m_iContinueMusicPos);
+                m_music->setPositionMS_fast(m_iContinueMusicPos);
                 m_bWasSeekFrame = true;
             } else {
-                m_music->setPositionMS(m_selectedDifficulty2->getPreviewTime() < 0
+                m_music->setPositionMS_fast(m_selectedDifficulty2->getPreviewTime() < 0
                                            ? (unsigned long)(m_music->getLengthMS() * 0.40f)
                                            : m_selectedDifficulty2->getPreviewTime());
                 m_bWasSeekFrame = true;

+ 1 - 0
src/App/Osu/Changelog.cpp

@@ -32,6 +32,7 @@ Changelog::Changelog() : ScreenBackable() {
     latest.changes.push_back("- Added setting to prevent servers from replacing the main menu logo");
     latest.changes.push_back("- Chat: added support for user links");
     latest.changes.push_back("- Chat: improved map link support");
+    latest.changes.push_back("- Fixed freeze when switching between songs in song browser");
     latest.changes.push_back("- Lowered audio latency for default (not ASIO/WASAPI) output");
     changelogs.push_back(latest);
 

+ 34 - 0
src/Engine/Sound.cpp

@@ -198,6 +198,7 @@ void Sound::destroy() {
 void Sound::setPosition(double percent) { return setPositionMS(clamp<f64>(percent, 0.0, 1.0) * m_length); }
 
 void Sound::setPositionMS(unsigned long ms) {
+    if(ms == 0) return setPositionMS_fast(ms);
     if(!m_bReady || ms > getLengthMS()) return;
     if(!m_bStream) {
         engine->showMessageError("Programmer Error", "Called setPositionMS on a sample!");
@@ -268,6 +269,39 @@ void Sound::setPositionMS(unsigned long ms) {
     }
 }
 
+// Inaccurate but fast seeking, to use at song select
+void Sound::setPositionMS_fast(u32 ms) {
+    if(!m_bReady || ms > getLengthMS()) return;
+    if(!m_bStream) {
+        engine->showMessageError("Programmer Error", "Called setPositionMS_fast on a sample!");
+        return;
+    }
+
+    i64 target_pos = BASS_ChannelSeconds2Bytes(m_stream, ms / 1000.0);
+    if(target_pos < 0) {
+        debugLog("setPositionMS_fast: error %d while calling BASS_ChannelSeconds2Bytes\n", BASS_ErrorGetCode());
+        return;
+    }
+
+    if(isPlaying()) {
+        if(!BASS_Mixer_ChannelSetPosition(m_stream, target_pos, BASS_POS_BYTE | BASS_POS_MIXER_RESET)) {
+            if(Osu::debug->getBool()) {
+                debugLog("Sound::setPositionMS_fast( %lu ) BASS_ChannelSetPosition() error %i on file %s\n", ms,
+                         BASS_ErrorGetCode(), m_sFilePath.c_str());
+            }
+        }
+
+        m_fLastPlayTime = m_fChannelCreationTime - ((f64)ms / 1000.0);
+    } else {
+        if(!BASS_ChannelSetPosition(m_stream, target_pos, BASS_POS_BYTE | BASS_POS_FLUSH)) {
+            if(Osu::debug->getBool()) {
+                debugLog("Sound::setPositionMS( %lu ) BASS_ChannelSetPosition() error %i on file %s\n", ms,
+                         BASS_ErrorGetCode(), m_sFilePath.c_str());
+            }
+        }
+    }
+}
+
 void Sound::setVolume(float volume) {
     if(!m_bReady) return;
 

+ 2 - 0
src/Engine/Sound.h

@@ -30,6 +30,8 @@ class Sound : public Resource {
 
     void setPosition(double percent);
     void setPositionMS(unsigned long ms);
+    void setPositionMS_fast(u32 ms);
+
     void setVolume(float volume);
     void setSpeed(float speed);
     void setFrequency(float frequency);