Optimizing the sound system when someone is speaking#323
Conversation
| hook.Add( "Tick", "Glide.CheckVoiceActivity", function() | ||
| local isAnyoneTalking = false | ||
| hook.Add( "PlayerStartVoice", "Glide.PlayerStartVoice", function( ply ) | ||
| if ply == LocalPlayer() then return end |
There was a problem hiding this comment.
This ignores players using voice_loopback 1
There was a problem hiding this comment.
Yeah the hook does execute, but then if ply == LocalPlayer() then return end ignores the local player, making the volume reduction not apply when the local player is speaking
There was a problem hiding this comment.
It wasn't applying yet, because of my tests.
| local tPlayersTalking = {} | ||
|
|
||
| local function AniamtionVoice( bSpeak ) | ||
| timer.Create( "Glide.VoiceChatAnimation", 0.001, 0, function() |
There was a problem hiding this comment.
I'm pretty sure that using a timer with a value as low as 0.001 is the same as running every tick on a Tick hook
There was a problem hiding this comment.
It's not exactly the same. I don't recommend using it—especially since you can't hear the difference between having the animation and not having it. I left it in because it's part of the base code, but I'm actually going to remove it in favor of a Tick hook (I can achieve the same result using Tick).
There was a problem hiding this comment.
It's not exactly the same
Actually for 0.001 it is. Even in the wiki for timer.Simple says
The delay interval in seconds. If the delay is too small, the timer will fire on the next Tick.
There was a problem hiding this comment.
We can do 0.01 if necessary. It remains to be seen whether you need to keep that.
| glideVolume = Approach( | ||
| glideVolume, | ||
| bSpeak and Config.vcVolume or 1, | ||
| FrameTime() * ( bSpeak and 10 or 4 ) |
There was a problem hiding this comment.
Using a timer breaks the correct usage for FrameTime(), although it was my mistake for using it inside a Tick hook, which is also incorrect
There was a problem hiding this comment.
Wouldn't it be better to completely disable the volume up/down animation? Because honestly, I don't see any difference.
There was a problem hiding this comment.
The slight "animation" during the audio switch is negligible
The issue I presented here might've been the cause
There was a problem hiding this comment.
The slight "animation" during the audio switch is negligible
The issue I presented here might've been the cause
Right, and yet it didn't bother anyone? If it had been glaringly obvious, I would have understood, but this was just adding a bit of realism for no reason, even though the issue has been resolved.
There was a problem hiding this comment.
Right, and yet it didn't bother anyone?
It depends on how much FPS you have, it does bother me which is how I noticed
There was a problem hiding this comment.
Actually, based on the tests, it drops from 1 to 0.6 very, very quickly. It goes something like 1, 0.76...... (and decimal numbers), 0.6 in under 0.7 seconds, I’d say. I’m running at around 140 fps, so that might be why,it would be interesting to see how it behaves at lower frame rates.
|
Relying on tracking player entities with the start/stop voice hooks also introduces new issues when it comes to invalid players (out-of-PVS or players who disconnect while talking), possibly making the volume reduction get stuck, which is why it was using I also don't know how/if that could break when the "one player stuck speaking" gmod bug happens, or what happens if the player tries to workaround that bug by using |
It can be done via SteamID32. I'll have that changed. This will prevent PVS or disconnection issues. |
Thats still about as fast as
I was doing some tests just now, and I remembered that smoothing "animation" exists not only to prevent audio popping, but also to deal with |
|
Oh another big thing: Some servers/addons return |
|
Yeah, but we can't just leave a It kills performance for no reason. |
That's kinda hacky and prone to compatibility issues
Doesn't matter if we can't rely on |
For just a |
Do we really have a choice? Or should we just leave that inefficient piece of code as is? I was mainly referring to the fact that when
Otherwise, we could rely on |
True, but we're still fetching all the players 140 times just to check if someone is speaking, so technically, we don't even need to do that. Actually, for sandbox, it makes no difference; you won't notice it. But on servers, or for people playing solo with a large number of addons, the difference will be noticeable. |
That's not even a client-side hook
Please pay attention, the |
Yes, and it works with a net system, but it's still a bit of a makeshift setup.
Oh, sorry excuse me, I got mixed up between 144 fps and 66-tick servers. Even so, I still find that "huge" for so little. |
|
87291e4 That optimizes things a bit, but I remain convinced that the voice system can be detected outside of a |
|
87291e4 capped the voice checks to at most 30 times per second. I'm now experimenting with checking one player at a time per frame instead of all players in one go. |
|
I tried overwriting The only idea that actually works is overwriting Below is a quick example I put together to get this working and make the hook reliable. local voice_loop = GetConVar( "voice_loopback" )
-- Example HUD voice
hook.Add( "PlayerStartVoice", "TestAA", function()
return true
end )
-- Overwrite
for sNameHook, fcHook in pairs( hook.GetTable()["PlayerStartVoice"] ) do
hook.Remove( "PlayerStartVoice", sNameHook )
hook.Add( "PlayerBeforeStartVoice", sNameHook, fcHook )
end
VitrozeFCHookAdd = VitrozeFCHookAdd or hook.Add
function hook.Add( sHook, sName, fcFunc )
if sHook == "PlayerStartVoice" and sName ~= "Glide.ManageVoice" then
sHook = "PlayerBeforeStartVoice"
end
VitrozeFCHookAdd( sHook, sName, fcFunc )
end
hook.Add( "PlayerStartVoice", "Glide.ManageVoice", function( ply, plyIndex )
if ply ~= LocalPlayer() or voice_loop:GetBool() then
tPlayersTalking[ply:SteamID()] = true
AniamtionVoice( true )
end
local bShowHUD = hook.Run( "PlayerBeforeStartVoice", ply, plyIndex )
return bShowHUD
end ) |
Hello,
I’ve globally optimized the voice system for when a player speaks (removing the Tick hook). The slight "animation" during the audio switch is negligible—meaning it’s imperceptible to the ear. I decided to leave it in, though I recommend removing it.