Add full decode test

Test a full unvoiced frame through Silk decoder
This commit is contained in:
Sean DuBois 2022-09-15 13:40:42 -04:00
parent 5d12791c86
commit 2e21fbab86
4 changed files with 117 additions and 3 deletions

View file

@ -29,7 +29,7 @@ func main() {
panic(err)
}
out := make([]float64, 1500)
out := make([]float64, 320)
for {
pageData, _, err := ogg.ParseNextPage()
if errors.Is(err, io.EOF) {

View file

@ -1453,10 +1453,14 @@ func (d *Decoder) lpcSynthesis(out []float64, bandwidth Bandwidth, dLPC int, aQ1
//
// https://datatracker.ietf.org/doc/html/rfc6716#section-4.2.1
func (d *Decoder) Decode(in []byte, out []float64, isStereo bool, nanoseconds int, bandwidth Bandwidth) error {
if nanoseconds != nanoseconds20Ms {
subframeSize := d.samplesInSubframe(bandwidth)
switch {
case nanoseconds != nanoseconds20Ms:
return errUnsupportedSilkFrameDuration
} else if isStereo {
case isStereo:
return errUnsupportedSilkStereo
case (subframeSize * subframeCount) > len(out):
return errOutBufferTooSmall
}
d.rangeDecoder.Init(in)

View file

@ -63,6 +63,14 @@ func TestDecodeSubframeQuantizations(t *testing.T) {
}
}
func TestDecodeBufferSize(t *testing.T) {
d := NewDecoder()
err := d.Decode([]byte{}, make([]float64, 50), false, nanoseconds20Ms, BandwidthWideband)
if !errors.Is(err, errOutBufferTooSmall) {
t.Fatal()
}
}
func TestNormalizeLineSpectralFrequencyStageOne(t *testing.T) {
d := &Decoder{rangeDecoder: createRangeDecoder(testSilkFrame(), 47, 722810880, 387065757)}
@ -419,3 +427,104 @@ func TestDecodeLTPScalingParameter(t *testing.T) {
}
})
}
func TestDecode(t *testing.T) {
d := NewDecoder()
out := make([]float64, 320)
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,
}
for i := range expectedOut {
if out[i]-expectedOut[i] > 0.0001 {
t.Fatalf("%d (%f) != (%f)", i, out[i], expectedOut[i])
}
}
})
}

View file

@ -7,4 +7,5 @@ var (
errUnsupportedSilkStereo = errors.New("silk decoder does not support stereo")
errUnsupportedSilkLowBitrateRedundancy = errors.New("silk decoder does not low bit-rate redundancy")
errUnsupportedLSFInterpolation = errors.New("silk decoder does not support LSF Interpolation")
errOutBufferTooSmall = errors.New("out isn't large enough")
)