-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecoder_misc.go
More file actions
56 lines (49 loc) · 1.21 KB
/
decoder_misc.go
File metadata and controls
56 lines (49 loc) · 1.21 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gopus
import "math"
func packetFrameCount(data []byte) (TOC, int, error) {
if len(data) < 1 {
return TOC{}, 0, ErrPacketTooShort
}
toc := ParseTOC(data[0])
switch toc.FrameCode {
case 0:
return toc, 1, nil
case 1, 2:
return toc, 2, nil
case 3:
if len(data) < 2 {
return TOC{}, 0, ErrPacketTooShort
}
m := int(data[1] & 0x3F)
if m == 0 || m > 48 {
return TOC{}, 0, ErrInvalidFrameCount
}
return toc, m, nil
default:
return TOC{}, 0, ErrInvalidPacket
}
}
func decodeGainLinear(gainQ8 int) float32 {
return float32(math.Pow(10.0, float64(gainQ8)/(20.0*256.0)))
}
func (d *Decoder) applyOutputGain(samples []float32) {
if d.decodeGainQ8 == 0 || len(samples) == 0 {
return
}
g := decodeGainLinear(d.decodeGainQ8)
for i := range samples {
samples[i] *= g
}
}
// DebugPrevMode returns the previous decode mode (SILK/Hybrid/CELT).
func (d *Decoder) DebugPrevMode() Mode {
return d.prevMode
}
// DebugPrevRedundancy reports whether the previous frame used CELT redundancy.
func (d *Decoder) DebugPrevRedundancy() bool {
return d.prevRedundancy
}
// DebugPrevPacketStereo returns the last packet's stereo flag.
func (d *Decoder) DebugPrevPacketStereo() bool {
return d.prevPacketStereo
}