-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecoder_dred_48k.go
More file actions
77 lines (73 loc) · 2.37 KB
/
Copy pathdecoder_dred_48k.go
File metadata and controls
77 lines (73 loc) · 2.37 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//go:build gopus_dred || gopus_osce
package gopus
import "github.com/thesyncim/gopus/internal/lpcnetplc"
// applyDREDNeuralConcealment48kMono drives one 48 kHz neural CELT
// concealment frame. libopus is fundamentally mono DRED (single
// LPCNetPLCState in opus_decoder.c; mono-downmix on entry, mono-duplicate on
// exit). For stereo decoders we run the same mono pipeline and rely on the
// CELT wrapper to mirror channel-0 state into channel-1 and to interleave the
// mono PCM across both output channels (celt_decoder.c:1066-1067).
func (d *Decoder) applyDREDNeuralConcealment48kMono(pcm []float32, samplesPerChannel int) bool {
if d == nil || d.channels < 1 || d.channels > 2 || samplesPerChannel <= 0 {
return false
}
channels := int(d.channels)
sampleRate := int(d.sampleRate)
if len(pcm) < samplesPerChannel*channels {
return false
}
r := d.dredRecoveryState()
n := d.dredNeuralState()
b := d.dred48kBridgeState()
if r == nil || n == nil || b == nil || d.celtDecoder == nil {
return false
}
generate := func(frame []float32) bool {
if len(frame) < lpcnetplc.FrameSize {
return false
}
if r.dredPLC.Blend() == 0 {
return r.dredPLC.GenerateConcealedFrameFloatWithAnalysis(&n.dredAnalysis, &n.dredPredictor, &n.dredFARGAN, frame[:lpcnetplc.FrameSize])
}
return r.dredPLC.GenerateConcealedFrameFloat(&n.dredPredictor, &n.dredFARGAN, frame[:lpcnetplc.FrameSize])
}
frameSize48 := samplesPerChannel
downsample := 1
celtPCM := pcm[:samplesPerChannel*channels]
if sampleRate != 48000 {
frameSize48 = d.frameSize48FromAPI(samplesPerChannel)
downsample = 48000 / sampleRate
}
// Mono-downmix-in / mono-duplicate-out: the stereo path runs the mono
// CELT neural concealment helper against the channel-0 slot of the CELT
// state and mirrors the channel-0 result into channel-1 for both the
// retained CELT state and the interleaved output PCM.
var ok bool
if r.dredPLC.FECFillPos() > r.dredPLC.FECReadPos() {
ok = d.celtDecoder.ConcealDRED48kDownsampleToFloat32(
celtPCM,
frameSize48,
downsample,
&b.dredLastNeural,
b.dredPLCPCM[:],
&b.dredPLCFill,
&b.dredPLCPreemphMem,
generate,
)
} else {
ok = d.celtDecoder.ConcealPLCNeural48kDownsampleToFloat32(
celtPCM,
frameSize48,
downsample,
&b.dredLastNeural,
b.dredPLCPCM[:],
&b.dredPLCFill,
&b.dredPLCPreemphMem,
generate,
)
}
if !ok {
return false
}
return true
}