aboutsummaryrefslogtreecommitdiff
path: root/pkg/messages/types/svcVoiceInit.go
blob: eb6093f5efc2cc4eae98077cf8ad4cebf2d34903 (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
28
29
package messages

import (
	"github.com/pektezol/bitreader"
)

type SvcVoiceInit struct {
	Codec      string
	Quality    uint8
	SampleRate int32
}

func ParseSvcVoiceInit(reader *bitreader.Reader) SvcVoiceInit {
	svcVoiceInit := SvcVoiceInit{
		Codec:   reader.TryReadString(),
		Quality: reader.TryReadUInt8(),
	}
	if svcVoiceInit.Quality == 0b11111111 {
		svcVoiceInit.SampleRate = reader.TryReadSInt32()
	} else {
		if svcVoiceInit.Codec == "vaudio_celt" {
			svcVoiceInit.SampleRate = 22050
		} else {
			svcVoiceInit.SampleRate = 11025
		}
	}

	return svcVoiceInit
}