Fix LPC Synthesis Bug
Use gainQ16 for the current subframe. Before we always used gainQ16[0] incorrectly.
This commit is contained in:
parent
2e21fbab86
commit
782c09fe4c
|
@ -1362,7 +1362,7 @@ func (d *Decoder) ltpSynthesis(signalType frameSignalType, eQ23 []int32) (res []
|
|||
// after either
|
||||
//
|
||||
// https://www.rfc-editor.org/rfc/rfc6716.html#section-4.2.7.9.2
|
||||
func (d *Decoder) lpcSynthesis(out []float64, bandwidth Bandwidth, dLPC int, aQ12, res, gainQ16 []float64) {
|
||||
func (d *Decoder) lpcSynthesis(out []float64, bandwidth Bandwidth, currentSubframe, dLPC int, aQ12, res, gainQ16 []float64) {
|
||||
finalLPCValuesIndex := 0
|
||||
|
||||
// let n be the number of samples in a subframe
|
||||
|
@ -1387,8 +1387,8 @@ func (d *Decoder) lpcSynthesis(out []float64, bandwidth Bandwidth, dLPC int, aQ1
|
|||
//
|
||||
var currentLPCVal float64
|
||||
for i := j; i < (j + n); i++ {
|
||||
lpcVal := gainQ16[0] / 65536.0
|
||||
lpcVal *= res[i]
|
||||
lpcVal := gainQ16[currentSubframe] / 65536.0
|
||||
lpcVal *= res[i+(n*currentSubframe)]
|
||||
|
||||
for k := 0; k < dLPC; k++ {
|
||||
if i-k > 0 {
|
||||
|
@ -1415,7 +1415,7 @@ func (d *Decoder) lpcSynthesis(out []float64, bandwidth Bandwidth, dLPC int, aQ1
|
|||
//
|
||||
// out[i] = clamp(-1.0, lpc[i], 1.0)
|
||||
//
|
||||
out[i] = clampFloat(-1.0, lpc[i], 1.0)
|
||||
out[i+(n*currentSubframe)] = clampFloat(-1.0, lpc[i], 1.0)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1528,7 +1528,7 @@ func (d *Decoder) Decode(in []byte, out []float64, isStereo bool, nanoseconds in
|
|||
res := d.ltpSynthesis(signalType, eQ23)
|
||||
|
||||
//https://www.rfc-editor.org/rfc/rfc6716.html#section-4.2.7.9.2
|
||||
d.lpcSynthesis(out, bandwidth, dLPC, aQ12, res, gainQ16)
|
||||
d.lpcSynthesis(out, bandwidth, i, dLPC, aQ12, res, gainQ16)
|
||||
}
|
||||
|
||||
// n0Q15 is the LSF coefficients decoded for the prior frame
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"github.com/pion/opus/internal/rangecoding"
|
||||
)
|
||||
|
||||
const floatEqualityThreshold = 0.000001
|
||||
|
||||
func testSilkFrame() []byte {
|
||||
return []byte{0x0B, 0xE4, 0xC1, 0x36, 0xEC, 0xC5, 0x80}
|
||||
}
|
||||
|
@ -377,10 +379,10 @@ func TestLPCSynthesis(t *testing.T) {
|
|||
|
||||
for i := range expectedOut {
|
||||
out := make([]float64, 80)
|
||||
d.lpcSynthesis(out, bandwidth, dLPC, aQ12, res, gainQ16)
|
||||
d.lpcSynthesis(out, bandwidth, i, dLPC, aQ12, res, gainQ16)
|
||||
for j := range out {
|
||||
if out[j]-expectedOut[i][j] > 0.0001 {
|
||||
t.Fatalf("%d (%f) != (%f)", j, out[j], expectedOut[i][j])
|
||||
if out[j]-expectedOut[i][j] > floatEqualityThreshold {
|
||||
t.Fatalf("run(%d) index(%d) (%f) != (%f)", i, j, out[j], expectedOut[i][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -432,99 +434,85 @@ func TestDecode(t *testing.T) {
|
|||
d := NewDecoder()
|
||||
out := make([]float64, 320)
|
||||
|
||||
compareBuffer := func(out, expectedOut []float64, t *testing.T) {
|
||||
for i := range expectedOut {
|
||||
if out[i]-expectedOut[i] > floatEqualityThreshold {
|
||||
t.Fatalf("%d (%f) != (%f)", i, out[i], expectedOut[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("Unvoiced Single Frame", func(t *testing.T) {
|
||||
if err := d.Decode(testSilkFrame(), out, false, nanoseconds20Ms, BandwidthWideband); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expectedOut := []float64{
|
||||
0.000000, 0.000000, 0.000023, 0.000025,
|
||||
0.000027, -0.000018, 0.000025, -0.000021,
|
||||
0.000021, -0.000024, 0.000021, 0.000021,
|
||||
-0.000022, -0.000026, 0.000018, 0.000022,
|
||||
-0.000023, -0.000025, -0.000027, 0.000017,
|
||||
0.000020, -0.000021, 0.000023, 0.000027,
|
||||
-0.000018, -0.000023, -0.000024, 0.000020,
|
||||
-0.000024, 0.000021, 0.000023, 0.000027,
|
||||
0.000029, -0.000016, -0.000020, -0.000025,
|
||||
0.000018, -0.000026, -0.000028, -0.000028,
|
||||
-0.000028, 0.000016, -0.000025, -0.000025,
|
||||
0.000021, 0.000025, 0.000027, -0.000016,
|
||||
0.000030, -0.000016, -0.000020, -0.000024,
|
||||
-0.000026, 0.000019, 0.000022, 0.000025,
|
||||
-0.000019, -0.000021, -0.000024, -0.000027,
|
||||
-0.000029, -0.000030, 0.000017, 0.000022,
|
||||
0.000026, 0.000030, 0.000033, -0.000012,
|
||||
-0.000018, -0.000023, -0.000026, -0.000029,
|
||||
-0.000029, 0.000016, -0.000025, 0.000021,
|
||||
0.000024, 0.000028, -0.000017, 0.000027,
|
||||
0.000028, 0.000029, -0.000006, 0.000017,
|
||||
0.000015, 0.000015, -0.000011, 0.000011,
|
||||
0.000011, -0.000014, 0.000008, -0.000016,
|
||||
0.000008, -0.000016, -0.000016, -0.000018,
|
||||
-0.000017, -0.000017, 0.000008, -0.000014,
|
||||
-0.000013, -0.000013, -0.000012, 0.000011,
|
||||
-0.000010, 0.000015, 0.000016, -0.000006,
|
||||
0.000015, -0.000008, -0.000009, -0.000012,
|
||||
0.000012, 0.000012, 0.000013, -0.000009,
|
||||
-0.000011, 0.000011, 0.000012, -0.000012,
|
||||
0.000012, 0.000013, 0.000014, -0.000011,
|
||||
0.000013, -0.000011, -0.000013, -0.000016,
|
||||
0.000008, -0.000015, 0.000010, -0.000013,
|
||||
-0.000013, -0.000015, 0.000010, -0.000013,
|
||||
0.000011, -0.000011, -0.000011, -0.000013,
|
||||
0.000012, -0.000011, 0.000013, 0.000015,
|
||||
0.000016, 0.000016, 0.000017, -0.000007,
|
||||
-0.000010, -0.000013, -0.000015, -0.000017,
|
||||
0.000007, -0.000015, -0.000015, 0.000009,
|
||||
0.000012, -0.000011, 0.000012, -0.000010,
|
||||
0.000013, -0.000011, 0.000012, 0.000012,
|
||||
0.000014, 0.000014, -0.000007, 0.000012,
|
||||
-0.000010, 0.000010, 0.000010, 0.000011,
|
||||
-0.000010, 0.000009, -0.000011, 0.000008,
|
||||
0.000009, -0.000010, -0.000013, -0.000013,
|
||||
-0.000014, 0.000006, 0.000009, -0.000010,
|
||||
-0.000011, -0.000011, -0.000012, 0.000008,
|
||||
0.000011, 0.000013, -0.000007, -0.000008,
|
||||
-0.000010, -0.000011, 0.000009, -0.000010,
|
||||
-0.000011, 0.000009, -0.000010, -0.000011,
|
||||
0.000010, 0.000012, -0.000009, -0.000010,
|
||||
-0.000010, -0.000012, 0.000009, 0.000011,
|
||||
0.000012, 0.000014, -0.000007, 0.000012,
|
||||
-0.000009, 0.000011, -0.000010, 0.000010,
|
||||
-0.000011, -0.000012, -0.000013, -0.000013,
|
||||
-0.000014, 0.000007, -0.000012, 0.000009,
|
||||
-0.000010, -0.000010, -0.000011, 0.000010,
|
||||
0.000012, 0.000013, -0.000006, 0.000013,
|
||||
-0.000007, -0.000009, 0.000010, -0.000010,
|
||||
-0.000011, 0.000008, -0.000010, -0.000012,
|
||||
-0.000012, 0.000009, 0.000009, 0.000011,
|
||||
0.000013, 0.000014, 0.000015, 0.000014,
|
||||
-0.000007, 0.000012, 0.000011, 0.000012,
|
||||
-0.000010, -0.000012, 0.000008, 0.000008,
|
||||
0.000009, 0.000009, -0.000010, -0.000012,
|
||||
-0.000014, -0.000014, 0.000006, 0.000008,
|
||||
-0.000010, -0.000012, 0.000010, -0.000010,
|
||||
0.000010, 0.000012, 0.000013, -0.000008,
|
||||
-0.000009, -0.000010, 0.000009, -0.000010,
|
||||
-0.000011, 0.000008, -0.000011, -0.000012,
|
||||
-0.000012, -0.000012, -0.000013, 0.000008,
|
||||
-0.000011, -0.000011, 0.000010, 0.000013,
|
||||
-0.000007, -0.000008, -0.000009, -0.000010,
|
||||
0.000009, 0.000011, 0.000013, -0.000007,
|
||||
0.000013, -0.000008, 0.000011, -0.000010,
|
||||
0.000011, 0.000011, 0.000012, 0.000012,
|
||||
0.000013, -0.000008, 0.000010, -0.000011,
|
||||
0.000009, -0.000012, -0.000013, -0.000014,
|
||||
0.000006, -0.000013, -0.000013, 0.000008,
|
||||
-0.000011, -0.000012, -0.000012, 0.000010,
|
||||
0.000023, 0.000025, 0.000027, -0.000018, 0.000025,
|
||||
-0.000021, 0.000021, -0.000024, 0.000021, 0.000021,
|
||||
-0.000022, -0.000026, 0.000018, 0.000022, -0.000023,
|
||||
-0.000025, -0.000027, 0.000017, 0.000020, -0.000021,
|
||||
0.000023, 0.000027, -0.000018, -0.000023, -0.000024,
|
||||
0.000020, -0.000024, 0.000021, 0.000023, 0.000027,
|
||||
0.000029, -0.000016, -0.000020, -0.000025, 0.000018,
|
||||
-0.000026, -0.000028, -0.000028, -0.000028, 0.000016,
|
||||
-0.000025, -0.000025, 0.000021, 0.000025, 0.000027,
|
||||
-0.000016, 0.000030, -0.000016, -0.000020, -0.000024,
|
||||
-0.000026, 0.000019, 0.000022, 0.000025, -0.000019,
|
||||
-0.000021, -0.000024, -0.000027, -0.000029, -0.000030,
|
||||
0.000017, 0.000022, 0.000026, 0.000030, 0.000033,
|
||||
-0.000012, -0.000018, -0.000023, -0.000026, -0.000029,
|
||||
-0.000029, 0.000016, -0.000025, 0.000021, 0.000024,
|
||||
0.000028, -0.000017, 0.000027, 0.000028, 0.000029,
|
||||
-0.000006, 0.000017, 0.000015, 0.000015, -0.000011,
|
||||
0.000011, 0.000011, -0.000014, 0.000008, -0.000016,
|
||||
0.000008, -0.000016, -0.000016, -0.000018, -0.000017,
|
||||
-0.000017, 0.000008, -0.000014, -0.000013, -0.000013,
|
||||
-0.000012, 0.000011, -0.000010, 0.000015, 0.000016,
|
||||
-0.000006, 0.000015, -0.000008, -0.000009, -0.000012,
|
||||
0.000012, 0.000012, 0.000013, -0.000009, -0.000011,
|
||||
0.000011, 0.000012, -0.000012, 0.000012, 0.000013,
|
||||
0.000014, -0.000011, 0.000013, -0.000011, -0.000013,
|
||||
-0.000016, 0.000008, -0.000015, 0.000010, -0.000013,
|
||||
-0.000013, -0.000015, 0.000010, -0.000013, 0.000011,
|
||||
-0.000011, -0.000011, -0.000013, 0.000012, -0.000011,
|
||||
0.000013, 0.000015, 0.000016, 0.000016, 0.000017,
|
||||
-0.000007, -0.000010, -0.000013, -0.000015, -0.000017,
|
||||
0.000007, -0.000015, -0.000015, 0.000009, 0.000012,
|
||||
-0.000011, 0.000012, -0.000010, 0.000013, -0.000011,
|
||||
0.000012, 0.000012, 0.000014, 0.000014, -0.000007,
|
||||
0.000012, -0.000010, 0.000010, 0.000010, 0.000011,
|
||||
-0.000010, 0.000009, -0.000011, 0.000008, 0.000009,
|
||||
-0.000010, -0.000013, -0.000013, -0.000014, 0.000006,
|
||||
0.000009, -0.000010, -0.000011, -0.000011, -0.000012,
|
||||
0.000008, 0.000011, 0.000013, -0.000007, -0.000008,
|
||||
-0.000010, -0.000011, 0.000009, -0.000010, -0.000011,
|
||||
0.000009, -0.000010, -0.000011, 0.000010, 0.000012,
|
||||
-0.000009, -0.000010, -0.000010, -0.000012, 0.000009,
|
||||
0.000011, 0.000012, 0.000014, -0.000007, 0.000012,
|
||||
-0.000009, 0.000011, -0.000010, 0.000010, -0.000011,
|
||||
-0.000012, -0.000013, -0.000013, -0.000014, 0.000007,
|
||||
-0.000012, 0.000009, -0.000010, -0.000010, -0.000011,
|
||||
0.000010, 0.000012, 0.000013, -0.000006, 0.000013,
|
||||
-0.000007, -0.000009, 0.000010, -0.000010, -0.000011,
|
||||
0.000008, -0.000010, -0.000012, -0.000012, 0.000009,
|
||||
0.000009, 0.000011, 0.000013, 0.000014, 0.000015,
|
||||
0.000014, -0.000007, 0.000012, 0.000011, 0.000012,
|
||||
-0.000010, -0.000012, 0.000008, 0.000008, 0.000009,
|
||||
0.000009, -0.000010, -0.000012, -0.000014, -0.000014,
|
||||
0.000006, 0.000008, -0.000010, -0.000012, 0.000010,
|
||||
-0.000010, 0.000010, 0.000012, 0.000013, -0.000008,
|
||||
-0.000009, -0.000010, 0.000009, -0.000010, -0.000011,
|
||||
0.000008, -0.000011, -0.000012, -0.000012, -0.000012,
|
||||
-0.000013, 0.000008, -0.000011, -0.000011, 0.000010,
|
||||
0.000013, -0.000007, -0.000008, -0.000009, -0.000010,
|
||||
0.000009, 0.000011, 0.000013, -0.000007, 0.000013,
|
||||
-0.000008, 0.000011, -0.000010, 0.000011, 0.000011,
|
||||
0.000012, 0.000012, 0.000013, -0.000008, 0.000010,
|
||||
-0.000011, 0.000009, -0.000012, -0.000013, -0.000014,
|
||||
0.000006, -0.000013, -0.000013, 0.000008, -0.000011,
|
||||
-0.000012, -0.000012, 0.000010, 0.000011, 0.000013,
|
||||
}
|
||||
|
||||
for i := range expectedOut {
|
||||
if out[i]-expectedOut[i] > 0.0001 {
|
||||
t.Fatalf("%d (%f) != (%f)", i, out[i], expectedOut[i])
|
||||
}
|
||||
}
|
||||
|
||||
compareBuffer(out, expectedOut, t)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue