Finish decodeLTPScalingParamater
Defined in section-4.2.7.6.3
This commit is contained in:
parent
2067ca5ac0
commit
e2d581a590
|
@ -1226,7 +1226,7 @@ func (d *Decoder) decodePitchLags(signalType frameSignalType, bandwidth Bandwidt
|
|||
// packets against the recovery time after packet loss.
|
||||
//
|
||||
// https://www.rfc-editor.org/rfc/rfc6716.html#section-4.2.7.6.3
|
||||
func (d *Decoder) decodeLTPScalingParamater(signalType frameSignalType) (float64, error) {
|
||||
func (d *Decoder) decodeLTPScalingParamater(signalType frameSignalType) (LTPscaleQ14 float64) {
|
||||
// An LTP scaling parameter appears after the LTP filter coefficients if
|
||||
// and only if
|
||||
//
|
||||
|
@ -1242,11 +1242,23 @@ func (d *Decoder) decodeLTPScalingParamater(signalType frameSignalType) (float64
|
|||
// Frames that do not code the scaling parameter
|
||||
// use the default factor of 15565 (approximately 0.95).
|
||||
if signalType != frameSignalTypeVoiced {
|
||||
return 15565.0, nil
|
||||
return 15565.0
|
||||
}
|
||||
|
||||
// TODO
|
||||
return 0, errUnsupportedVoicedFrames
|
||||
// The three possible values represent Q14 scale factors of
|
||||
// 15565, 12288, and 8192, respectively (corresponding to approximately
|
||||
// 0.95, 0.75, and 0.5)
|
||||
scaleFactorIndex := d.rangeDecoder.DecodeSymbolWithICDF(icdfLTPScalingParameter)
|
||||
switch scaleFactorIndex {
|
||||
case 0:
|
||||
return 15565.0
|
||||
case 1:
|
||||
return 12288.0
|
||||
case 2:
|
||||
return 8192.0
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// SILK uses a separate 5-tap pitch filter for each subframe, selected
|
||||
|
@ -1470,10 +1482,7 @@ func (d *Decoder) Decode(in []byte, out []float64, isStereo bool, nanoseconds in
|
|||
d.decodeLTPFilterCoefficients(signalType)
|
||||
|
||||
// https://www.rfc-editor.org/rfc/rfc6716.html#section-4.2.7.6.3
|
||||
_, err := d.decodeLTPScalingParamater(signalType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = d.decodeLTPScalingParamater(signalType)
|
||||
|
||||
// https://www.rfc-editor.org/rfc/rfc6716.html#section-4.2.7.7
|
||||
lcgSeed := d.decodeLinearCongruentialGeneratorSeed()
|
||||
|
|
|
@ -343,3 +343,21 @@ func TestDecodeLTPFilterCoefficients(t *testing.T) {
|
|||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeLTPScalingParameter(t *testing.T) {
|
||||
t.Run("Voiced", func(t *testing.T) {
|
||||
silkFrame := []byte{0xb4, 0xe2, 0x2c, 0xe, 0x10, 0x65, 0x1d, 0xa9, 0x7, 0x5c, 0x36, 0x8f, 0x96, 0x7b, 0xf4, 0x89, 0x41, 0x55, 0x98, 0x7a, 0x39, 0x2e, 0x6b, 0x71, 0xa4, 0x3, 0x70, 0xbf}
|
||||
d := &Decoder{rangeDecoder: createRangeDecoder(silkFrame, 105, 160412192, 164623240)}
|
||||
|
||||
if d.decodeLTPScalingParamater(frameSignalTypeVoiced) != 15565.0 {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Unvoiced", func(t *testing.T) {
|
||||
d := &Decoder{}
|
||||
if d.decodeLTPScalingParamater(frameSignalTypeUnvoiced) != 15565.0 {
|
||||
t.Fatal()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -754,4 +754,15 @@ var (
|
|||
133, 142, 151, 160, 168, 176, 184, 192, 199, 206, 212,
|
||||
218, 223, 227, 232, 236, 240, 244, 247, 251, 254, 256,
|
||||
}
|
||||
|
||||
// +-------------------+
|
||||
// | PDF |
|
||||
// +-------------------+
|
||||
// | {128, 64, 64}/256 |
|
||||
// +-------------------+
|
||||
//
|
||||
// Table 42: PDF for LTP Scaling Parameter
|
||||
//
|
||||
// https://www.rfc-editor.org/rfc/rfc6716.html#section-4.2.7.6.3
|
||||
icdfLTPScalingParameter = []uint{256, 128, 192, 256}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue