fix: add minimum AudioDataBytes floor for low-bandwidth servers
The auto-bitrate formula 'bandwidth/840 - 42' produces negative values for servers with bandwidth below ~35 kbps. A negative AudioDataBytes would cause the Opus encoder to be configured with zero or negative bitrate, producing invalid output. Add a floor of 10 bytes per frame (8 kbps), the minimum usable Opus bitrate for intelligible voice.
This commit is contained in:
committed by
Brandon McGinty
parent
1bdf15e8e1
commit
64a3ea6c32
@@ -9,10 +9,16 @@ import (
|
|||||||
var autoBitrate = &Listener{
|
var autoBitrate = &Listener{
|
||||||
Connect: func(e *gumble.ConnectEvent) {
|
Connect: func(e *gumble.ConnectEvent) {
|
||||||
if e.MaximumBitrate != nil {
|
if e.MaximumBitrate != nil {
|
||||||
const safety = 5
|
const (
|
||||||
|
safety = 5
|
||||||
|
minBytes = 10 // minimum bytes per frame for usable Opus (8 kbps)
|
||||||
|
)
|
||||||
interval := e.Client.Config.AudioInterval
|
interval := e.Client.Config.AudioInterval
|
||||||
dataBytes := (*e.MaximumBitrate / (8 * (int(time.Second/interval) + safety))) - 32 - 10
|
dataBytes := (*e.MaximumBitrate / (8 * (int(time.Second/interval) + safety))) - 32 - 10
|
||||||
|
|
||||||
|
if dataBytes < minBytes {
|
||||||
|
dataBytes = minBytes
|
||||||
|
}
|
||||||
e.Client.Config.AudioDataBytes = dataBytes
|
e.Client.Config.AudioDataBytes = dataBytes
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user