make per-user audio state thread-safe

Move volume, boost, mute, and OpenAL source behind accessors guarded
by a per-user mutex.
The audio goroutine reads these fields on every decoded packet while
the UI writes them from key handlers, which is a data race on the
gain a stream is currently rendering with.

Also add the per-user sequence fields the decoder needs to notice
gaps in a user's audio stream.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Brandon McGinty
2026-08-20 14:22:33 -04:00
co-authored by Claude Opus 5
parent b67940ddbc
commit 60470ad091
6 changed files with 117 additions and 50 deletions
+9 -9
View File
@@ -231,13 +231,13 @@ func (s *Stream) SetMicVolume(change float32, relative bool) {
func (s *Stream) OnAudioStream(e *gumble.AudioStreamEvent) {
go func(e *gumble.AudioStreamEvent) {
var source = openal.NewSource()
e.User.AudioSource = &source
e.User.SetAudioSource(&source)
// Set initial gain based on volume and mute state
if e.User.LocallyMuted {
e.User.AudioSource.SetGain(0)
if e.User.LocallyMuted() {
source.SetGain(0)
} else {
e.User.AudioSource.SetGain(e.User.Volume)
source.SetGain(e.User.Volume())
}
bufferCount := e.Client.Config.Buffers
@@ -258,7 +258,7 @@ func (s *Stream) OnAudioStream(e *gumble.AudioStreamEvent) {
for packet := range e.C {
// Skip processing if user is locally muted
if e.User.LocallyMuted {
if e.User.LocallyMuted() {
continue
}
@@ -268,7 +268,7 @@ func (s *Stream) OnAudioStream(e *gumble.AudioStreamEvent) {
continue
}
boost = e.User.Boost
boost = e.User.Boost()
recorder := s.getRecorder()
var recordBuffer []int16
recordPtr := 0
@@ -301,7 +301,7 @@ func (s *Stream) OnAudioStream(e *gumble.AudioStreamEvent) {
}
}
if recorder != nil {
recordBuffer[recordPtr] = scaleForRecording(sample, e.User.Volume)
recordBuffer[recordPtr] = scaleForRecording(sample, e.User.Volume())
recordPtr++
}
binary.LittleEndian.PutUint16(raw[rawPtr:], uint16(sample))
@@ -320,7 +320,7 @@ func (s *Stream) OnAudioStream(e *gumble.AudioStreamEvent) {
}
}
if recorder != nil {
recordBuffer[recordPtr] = scaleForRecording(sample, e.User.Volume)
recordBuffer[recordPtr] = scaleForRecording(sample, e.User.Volume())
recordPtr++
}
binary.LittleEndian.PutUint16(raw[rawPtr:], uint16(sample))
@@ -341,7 +341,7 @@ func (s *Stream) OnAudioStream(e *gumble.AudioStreamEvent) {
}
}
if recorder != nil {
recordSample := scaleForRecording(sample, e.User.Volume)
recordSample := scaleForRecording(sample, e.User.Volume())
recordBuffer[recordPtr] = recordSample
recordBuffer[recordPtr+1] = recordSample
recordPtr += 2