From d00d0769a9bf325df5bb25d7a7a4bd376b539b3c Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 11 Sep 2020 23:38:36 +0300 Subject: [PATCH] Lots of blip rate fixes: Remove qElapsedTimer method of blip earrape protection due to major inconsistency issues with this method (the same message would produce wildly different blip sounds - consistency is preferred) More sophisticated blip earrape prevention is calculated in the chat ticker function itself, it also properly adjusts itself depending on the blip_rate used. --- include/aoblipplayer.h | 3 --- src/aoblipplayer.cpp | 4 ---- src/courtroom.cpp | 19 +++++++++++++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/aoblipplayer.h b/include/aoblipplayer.h index 4d3b5f1..a11e29d 100644 --- a/include/aoblipplayer.h +++ b/include/aoblipplayer.h @@ -22,12 +22,9 @@ public: int m_cycle = 0; private: - const int max_blip_ms = 60; - QWidget *m_parent; AOApplication *ao_app; qreal m_volume; - QElapsedTimer delay; void set_volume_internal(qreal p_volume); diff --git a/src/aoblipplayer.cpp b/src/aoblipplayer.cpp index 5b4d625..6607d46 100644 --- a/src/aoblipplayer.cpp +++ b/src/aoblipplayer.cpp @@ -26,10 +26,6 @@ void AOBlipPlayer::set_blips(QString p_sfx) void AOBlipPlayer::blip_tick() { - if (delay.isValid() && delay.elapsed() < max_blip_ms) - return; - - delay.start(); int f_cycle = m_cycle++; if (m_cycle == 5) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 3e00158..13a9a6b 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2943,7 +2943,17 @@ void Courtroom::chat_tick() // I am you // ! ! ! ! // where ! is the blip sound - if (blip_ticker % blip_rate == 0) { + int b_rate = blip_rate; + // Earrape prevention without using timers, this method is more consistent. + if (msg_delay != 0 && msg_delay <= 25) { + // The default blip speed is 40ms, and if current msg_delay is 25ms, + // the formula will result in the blip rate of: + // 40/25 = 1.6 = 2 + // And if it's faster than that: + // 40/10 = 4 + b_rate = qMax(b_rate, qRound(static_cast(message_display_speed[3])/msg_delay)); + } + if (blip_ticker % b_rate == 0) { // ignoring white space unless blank_blip is enabled. if (!formatting_char && (f_character != ' ' || blank_blip)) { blip_player->blip_tick(); @@ -2958,9 +2968,10 @@ void Courtroom::chat_tick() ++blip_ticker; } - // Punctuation delayer - if (punctuation_chars.contains(f_character)) { - msg_delay *= punctuation_modifier; + // Punctuation delayer, only kicks in on speed ticks less than }} + if (current_display_speed > 1 && punctuation_chars.contains(f_character)) { + // Making the user have to wait any longer than 150ms per letter is downright unreasonable + msg_delay = qMin(150, msg_delay * punctuation_modifier); } // If this color is talking