summaryrefslogtreecommitdiffstats
path: root/vendor/layeh.com/gumble/gumbleutil/bitrate.go
blob: 6b93caa9bfbfebe51d886ebbfae3235f12cdec60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package gumbleutil

import (
	"time"

	"layeh.com/gumble/gumble"
)

var autoBitrate = &Listener{
	Connect: func(e *gumble.ConnectEvent) {
		if e.MaximumBitrate != nil {
			const safety = 5
			interval := e.Client.Config.AudioInterval
			dataBytes := (*e.MaximumBitrate / (8 * (int(time.Second/interval) + safety))) - 32 - 10

			e.Client.Config.AudioDataBytes = dataBytes
		}
	},
}

// AutoBitrate is a gumble.EventListener that automatically sets the client's
// AudioDataBytes to suitable value, based on the server's bitrate.
var AutoBitrate gumble.EventListener

func init() {
	AutoBitrate = autoBitrate
}