33import org .sela .data .LpcDecodedData ;
44import org .sela .data .LpcEncodedData ;
55
6- public final class ResidueGenerator extends LinearPredictionBase {
6+ public final class ResidueGenerator {
77 private final int [] samples ;
88 private final int [] residues ;
99 private final double [] quantizedSamples ;
1010 private final double [] autocorrelationFactors ;
11+ private final LinearPredictor linearPredictor ;
1112
1213 private final int maxShort = 32767 ;
1314 private final double sqrt2 = 1.4142135623730950488016887242096 ;
1415
1516 public ResidueGenerator (final LpcDecodedData data ) {
17+ this .linearPredictor = new LinearPredictor ();
1618 this .samples = data .samples ;
1719 this .quantizedSamples = new double [samples .length ];
18- this .autocorrelationFactors = new double [super .maxLpcOrder + 1 ];
20+ this .autocorrelationFactors = new double [linearPredictor .maxLpcOrder + 1 ];
1921 this .residues = new int [samples .length ];
2022 }
2123
@@ -35,86 +37,86 @@ private void generateAutoCorrelation() {
3537 mean = sum / quantizedSamples .length ;
3638
3739 // Generate autocorrelation coefficients
38- for (int i = 0 ; i <= super .maxLpcOrder ; i ++) {
40+ for (int i = 0 ; i <= linearPredictor .maxLpcOrder ; i ++) {
3941 autocorrelationFactors [i ] = 0.0 ;
4042 for (int j = i ; j < quantizedSamples .length ; j ++) {
4143 autocorrelationFactors [i ] += (quantizedSamples [j ] - mean ) * (quantizedSamples [j - i ] - mean );
4244 }
4345 }
4446
4547 // Normalise the coefficients
46- for (int i = 1 ; i <= super .maxLpcOrder ; i ++) {
48+ for (int i = 1 ; i <= linearPredictor .maxLpcOrder ; i ++) {
4749 autocorrelationFactors [i ] /= autocorrelationFactors [0 ];
4850 }
4951 autocorrelationFactors [0 ] = 1.0 ;
5052 }
5153
5254 private void generateReflectionCoefficients () {
5355 double error ;
54- final double [][] gen = new double [2 ][super .maxLpcOrder ];
56+ final double [][] gen = new double [2 ][linearPredictor .maxLpcOrder ];
5557
56- for (int i = 0 ; i < super .maxLpcOrder ; i ++) {
58+ for (int i = 0 ; i < linearPredictor .maxLpcOrder ; i ++) {
5759 gen [0 ][i ] = gen [1 ][i ] = autocorrelationFactors [i + 1 ];
5860 }
5961
6062 error = autocorrelationFactors [0 ];
61- super .reflectionCoefficients [0 ] = -gen [1 ][0 ] / error ;
62- error += gen [1 ][0 ] * super .reflectionCoefficients [0 ];
63+ linearPredictor .reflectionCoefficients [0 ] = -gen [1 ][0 ] / error ;
64+ error += gen [1 ][0 ] * linearPredictor .reflectionCoefficients [0 ];
6365
64- for (int i = 1 ; i < super .maxLpcOrder ; i ++) {
65- for (int j = 0 ; j < super .maxLpcOrder - i ; j ++) {
66- gen [1 ][j ] = gen [1 ][j + 1 ] + super .reflectionCoefficients [i - 1 ] * gen [0 ][j ];
67- gen [0 ][j ] = gen [1 ][j + 1 ] * super .reflectionCoefficients [i - 1 ] + gen [0 ][j ];
66+ for (int i = 1 ; i < linearPredictor .maxLpcOrder ; i ++) {
67+ for (int j = 0 ; j < linearPredictor .maxLpcOrder - i ; j ++) {
68+ gen [1 ][j ] = gen [1 ][j + 1 ] + linearPredictor .reflectionCoefficients [i - 1 ] * gen [0 ][j ];
69+ gen [0 ][j ] = gen [1 ][j + 1 ] * linearPredictor .reflectionCoefficients [i - 1 ] + gen [0 ][j ];
6870 }
69- super .reflectionCoefficients [i ] = -gen [1 ][0 ] / error ;
70- error += gen [1 ][0 ] * super .reflectionCoefficients [i ];
71+ linearPredictor .reflectionCoefficients [i ] = -gen [1 ][0 ] / error ;
72+ error += gen [1 ][0 ] * linearPredictor .reflectionCoefficients [i ];
7173 }
7274 }
7375
7476 private void generateoptimalLpcOrder () {
75- for (int i = super .maxLpcOrder - 1 ; i >= 0 ; i --) {
76- if (Math .abs (super .reflectionCoefficients [i ]) > 0.05 ) {
77- super .optimalLpcOrder = (byte ) (i + 1 );
77+ for (int i = linearPredictor .maxLpcOrder - 1 ; i >= 0 ; i --) {
78+ if (Math .abs (linearPredictor .reflectionCoefficients [i ]) > 0.05 ) {
79+ linearPredictor .optimalLpcOrder = (byte ) (i + 1 );
7880 break ;
7981 }
8082 }
8183 }
8284
8385 private void quantizeReflectionCoefficients () {
84- super .quantizedReflectionCoefficients = new int [super .optimalLpcOrder ];
86+ linearPredictor .quantizedReflectionCoefficients = new int [linearPredictor .optimalLpcOrder ];
8587
86- if (super .quantizedReflectionCoefficients .length > 0 ) {
87- super .quantizedReflectionCoefficients [0 ] = (int ) Math
88- .floor (64 * (-1 + (sqrt2 * Math .sqrt (super .reflectionCoefficients [0 ] + 1 ))));
88+ if (linearPredictor .quantizedReflectionCoefficients .length > 0 ) {
89+ linearPredictor .quantizedReflectionCoefficients [0 ] = (int ) Math
90+ .floor (64 * (-1 + (sqrt2 * Math .sqrt (linearPredictor .reflectionCoefficients [0 ] + 1 ))));
8991 }
90- if (super .quantizedReflectionCoefficients .length > 1 ) {
91- super .quantizedReflectionCoefficients [1 ] = (int ) Math
92- .floor (64 * (-1 + (sqrt2 * Math .sqrt (-super .reflectionCoefficients [1 ] + 1 ))));
92+ if (linearPredictor .quantizedReflectionCoefficients .length > 1 ) {
93+ linearPredictor .quantizedReflectionCoefficients [1 ] = (int ) Math
94+ .floor (64 * (-1 + (sqrt2 * Math .sqrt (-linearPredictor .reflectionCoefficients [1 ] + 1 ))));
9395 }
94- for (int i = 2 ; i < super .optimalLpcOrder ; i ++) {
95- super .quantizedReflectionCoefficients [i ] = (int ) Math .floor (64 * super .reflectionCoefficients [i ]);
96+ for (int i = 2 ; i < linearPredictor .optimalLpcOrder ; i ++) {
97+ linearPredictor .quantizedReflectionCoefficients [i ] = (int ) Math .floor (64 * linearPredictor .reflectionCoefficients [i ]);
9698 }
9799 }
98100
99101 private void generateResidues () {
100- final long correction = (long ) 1 << (super .correctionFactor - 1 );
102+ final long correction = (long ) 1 << (linearPredictor .correctionFactor - 1 );
101103
102104 residues [0 ] = samples [0 ];
103105
104- for (int i = 1 ; i <= super .optimalLpcOrder ; i ++) {
106+ for (int i = 1 ; i <= linearPredictor .optimalLpcOrder ; i ++) {
105107 long temp = correction ;
106108 for (int j = 1 ; j <= i ; j ++) {
107- temp += super .linearPredictionCoefficients [j ] * samples [i - j ];
109+ temp += linearPredictor .linearPredictionCoefficients [j ] * samples [i - j ];
108110 }
109- residues [i ] = samples [i ] - (int ) (temp >> super .correctionFactor );
111+ residues [i ] = samples [i ] - (int ) (temp >> linearPredictor .correctionFactor );
110112 }
111113
112- for (int i = super .optimalLpcOrder + 1 ; i < samples .length ; i ++) {
114+ for (int i = linearPredictor .optimalLpcOrder + 1 ; i < samples .length ; i ++) {
113115 long temp = correction ;
114- for (int j = 0 ; j <= super .optimalLpcOrder ; j ++) {
115- temp += (super .linearPredictionCoefficients [j ] * samples [i - j ]);
116+ for (int j = 0 ; j <= linearPredictor .optimalLpcOrder ; j ++) {
117+ temp += (linearPredictor .linearPredictionCoefficients [j ] * samples [i - j ]);
116118 }
117- residues [i ] = samples [i ] - (int ) (temp >> super .correctionFactor );
119+ residues [i ] = samples [i ] - (int ) (temp >> linearPredictor .correctionFactor );
118120 }
119121 }
120122
@@ -124,9 +126,9 @@ public LpcEncodedData process() {
124126 generateReflectionCoefficients ();
125127 generateoptimalLpcOrder ();
126128 quantizeReflectionCoefficients ();
127- super .dequantizeReflectionCoefficients ();
128- super .generatelinearPredictionCoefficients ();
129+ linearPredictor .dequantizeReflectionCoefficients ();
130+ linearPredictor .generatelinearPredictionCoefficients ();
129131 generateResidues ();
130- return new LpcEncodedData (optimalLpcOrder , quantizedReflectionCoefficients , residues );
132+ return new LpcEncodedData (linearPredictor . optimalLpcOrder , linearPredictor . quantizedReflectionCoefficients , residues );
131133 }
132134}
0 commit comments