@@ -598,11 +598,14 @@ func (d *Decoder) normalizeLSFInterpolation(n2Q15 []int16, nanoseconds int) (n1Q
598598 if wQ2 == 4 || ! d .haveDecoded {
599599 return nil , wQ2
600600 }
601+ if len (d .n0Q15 ) != len (n2Q15 ) {
602+ return nil , wQ2
603+ }
601604
602605 n1Q15 = make ([]int16 , len (n2Q15 ))
603606 for k := range n1Q15 {
604- interpolated := int32 (wQ2 ) * (int32 (n2Q15 [k ]) - int32 (d .n0Q15 [k ])) >> 2
605- n1Q15 [k ] = int16 (int32 (d .n0Q15 [k ]) + interpolated ) //nolint:gosec // G115
607+ interpolated := int32 (wQ2 ) * (int32 (n2Q15 [k ]) - int32 (d .n0Q15 [k ])) >> 2 //nolint:gosec // G602
608+ n1Q15 [k ] = int16 (int32 (d .n0Q15 [k ]) + interpolated ) //nolint:gosec // G115
606609 }
607610
608611 return
@@ -1229,7 +1232,7 @@ func (d *Decoder) limitLPCCoefficientsRange(a32Q17 []int32) {
12291232 // sc_Q16[k+1] = (sc_Q16[0]*sc_Q16[k] + 32768) >> 16
12301233 //
12311234 // https://datatracker.ietf.org/doc/html/rfc6716#section-4.2.7.5.7
1232- expandLPCCoefficientsBandwidth (a32Q17 , int32 (scQ16 )) //nolint:gosec // G115
1235+ expandLPCCoefficientsBandwidth (a32Q17 , int32 (scQ16 )) //nolint:gosec // G115
12331236 } else {
12341237 break
12351238 }
@@ -1277,7 +1280,7 @@ func (d *Decoder) limitLPCFilterPredictionGain(a32Q17 []int32) (aQ12 []float32)
12771280 for n := range a32Q17 {
12781281 aQ12Int [n ] = int16 ((a32Q17 [n ] + 16 ) >> 5 ) //nolint:gosec // G115
12791282 }
1280- for i := 0 ; i < 16 ; i ++ {
1283+ for i := range 16 {
12811284 if lpcInversePredictionGain (aQ12Int ) >= 107374 {
12821285 break
12831286 }
@@ -1289,7 +1292,7 @@ func (d *Decoder) limitLPCFilterPredictionGain(a32Q17 []int32) (aQ12 []float32)
12891292 // expansion we re-quantize to Q12 before checking stability again,
12901293 // because the C reference measures the gain on the exact coefficients
12911294 // used by reconstruction.
1292- expandLPCCoefficientsBandwidth (a32Q17 , int32 (65536 - (2 << i )))
1295+ expandLPCCoefficientsBandwidth (a32Q17 , int32 (65536 - (2 << i )))
12931296 for n := range a32Q17 {
12941297 aQ12Int [n ] = int16 ((a32Q17 [n ] + 16 ) >> 5 ) //nolint:gosec // G115
12951298 }
@@ -1300,9 +1303,10 @@ func (d *Decoder) limitLPCFilterPredictionGain(a32Q17 []int32) (aQ12 []float32)
13001303 aQ12 [n ] = float32 (aQ12Int [n ])
13011304 }
13021305
1303- return
1306+ return aQ12
13041307}
13051308
1309+ //nolint:cyclop
13061310func lpcInversePredictionGain (aQ12 []int16 ) int32 {
13071311 const (
13081312 inversePredictionGainQA = 24
@@ -1313,7 +1317,7 @@ func lpcInversePredictionGain(aQ12 []int16) int32 {
13131317 var atmpQA [2 ][16 ]int32
13141318 aNewQA := atmpQA [order & 1 ][:]
13151319 dcResp := int32 (0 )
1316- for k := 0 ; k < order ; k ++ {
1320+ for k := range order {
13171321 dcResp += int32 (aQ12 [k ])
13181322 aNewQA [k ] = int32 (aQ12 [k ]) << (inversePredictionGainQA - 12 )
13191323 }
@@ -1328,27 +1332,30 @@ func lpcInversePredictionGain(aQ12 []int16) int32 {
13281332 }
13291333
13301334 invGainQ30 := int32 (1 << 30 )
1331- for k := order - 1 ; k > 0 ; k -- {
1335+ for coefIndex := order - 1 ; coefIndex > 0 ; coefIndex -- {
13321336 // This is the fixed-point Levinson recurrence from RFC 6716 section
13331337 // 4.2.7.5.8. The code intentionally mirrors
13341338 // silk_LPC_inverse_pred_gain_QA() in LPC_inv_pred_gain.c, including
13351339 // the Q24/Q30 scaling, the reflection-coefficient stability checks,
13361340 // and the saturating numerator update, because tiny arithmetic
13371341 // differences here can flip a filter from stable to unstable.
1338- if aNewQA [k ] > inversePredictionGainALimit || aNewQA [k ] < - inversePredictionGainALimit {
1342+ if aNewQA [coefIndex ] > inversePredictionGainALimit || aNewQA [coefIndex ] < - inversePredictionGainALimit {
13391343 return 0
13401344 }
13411345
1342- rcQ31 := - (aNewQA [k ] << (31 - inversePredictionGainQA ))
1346+ rcQ31 := - (aNewQA [coefIndex ] << (31 - inversePredictionGainQA ))
13431347 rcMult1Q30 := int32 (1 << 30 ) - smmul (rcQ31 , rcQ31 )
13441348 mult2Q := 32 - clz32 (absInt32 (rcMult1Q30 ))
13451349 rcMult2 := inverse32VarQ (rcMult1Q30 , mult2Q + 30 )
13461350 invGainQ30 = smmul (invGainQ30 , rcMult1Q30 ) << 2
13471351
13481352 aOldQA := aNewQA
1349- aNewQA = atmpQA [k & 1 ][:]
1350- for n := 0 ; n < k ; n ++ {
1351- tmpQA := saturatingSubInt32 (aOldQA [n ], int32 (rshiftRound64 (int64 (aOldQA [k - n - 1 ])* int64 (rcQ31 ), 31 )))
1353+ aNewQA = atmpQA [coefIndex & 1 ][:]
1354+ for n := 0 ; n < coefIndex ; n ++ {
1355+ tmpQA := saturatingSubInt32 (
1356+ aOldQA [n ],
1357+ int32 (rshiftRound64 (int64 (aOldQA [coefIndex - n - 1 ])* int64 (rcQ31 ), 31 )), //nolint:gosec // G115
1358+ )
13521359 tmp64 := rshiftRound64 (int64 (tmpQA )* int64 (rcMult2 ), mult2Q )
13531360 if tmp64 > math .MaxInt32 || tmp64 < math .MinInt32 {
13541361 return 0
@@ -1658,7 +1665,7 @@ func (d *Decoder) ltpSynthesis(
16581665 // then let out_end be set to (j - (s-2)*n) and let LTP_scale_Q14 be set
16591666 // to 16384. Otherwise, set out_end to (j - s*n) and set LTP_scale_Q14
16601667 // to the Q14 LTP scaling value from Section 4.2.7.6.3.
1661- var out_end int //nolint:staticcheck,var-naming, revive
1668+ var out_end int //nolint:staticcheck,revive
16621669 if s < 2 || wQ2 == 4 {
16631670 out_end = - s * n
16641671 } else {
0 commit comments