@@ -138,20 +138,25 @@ static void celt_fir5(opus_val16 *x,
138138
139139
140140void pitch_downsample (celt_sig * OPUS_RESTRICT x [], opus_val16 * OPUS_RESTRICT x_lp ,
141- int len , int C , int arch )
141+ int len , int C , int factor , int arch )
142142{
143143 int i ;
144144 opus_val32 ac [5 ];
145145 opus_val16 tmp = Q15ONE ;
146146 opus_val16 lpc [4 ];
147147 opus_val16 lpc2 [5 ];
148148 opus_val16 c1 = QCONST16 (.8f ,15 );
149+ int offset ;
149150#ifdef FIXED_POINT
150151 int shift ;
151- opus_val32 maxabs = celt_maxabs32 (x [0 ], len );
152+ opus_val32 maxabs ;
153+ #endif
154+ offset = factor /2 ;
155+ #ifdef FIXED_POINT
156+ maxabs = celt_maxabs32 (x [0 ], len * factor );
152157 if (C == 2 )
153158 {
154- opus_val32 maxabs_1 = celt_maxabs32 (x [1 ], len );
159+ opus_val32 maxabs_1 = celt_maxabs32 (x [1 ], len * factor );
155160 maxabs = MAX32 (maxabs , maxabs_1 );
156161 }
157162 if (maxabs < 1 )
@@ -161,28 +166,28 @@ void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x
161166 shift = 0 ;
162167 if (C == 2 )
163168 shift ++ ;
164- for (i = 1 ;i < len >> 1 ;i ++ )
165- x_lp [i ] = SHR32 (x [0 ][(2 * i - 1 )], shift + 2 ) + SHR32 (x [0 ][(2 * i + 1 )], shift + 2 ) + SHR32 (x [0 ][2 * i ], shift + 1 );
166- x_lp [0 ] = SHR32 (x [0 ][1 ], shift + 2 ) + SHR32 (x [0 ][0 ], shift + 1 );
169+ for (i = 1 ;i < len ;i ++ )
170+ x_lp [i ] = SHR32 (x [0 ][(factor * i - offset )], shift + 2 ) + SHR32 (x [0 ][(factor * i + offset )], shift + 2 ) + SHR32 (x [0 ][factor * i ], shift + 1 );
171+ x_lp [0 ] = SHR32 (x [0 ][offset ], shift + 2 ) + SHR32 (x [0 ][0 ], shift + 1 );
167172 if (C == 2 )
168173 {
169- for (i = 1 ;i < len >> 1 ;i ++ )
170- x_lp [i ] += SHR32 (x [1 ][(2 * i - 1 )], shift + 2 ) + SHR32 (x [1 ][(2 * i + 1 )], shift + 2 ) + SHR32 (x [1 ][2 * i ], shift + 1 );
171- x_lp [0 ] += SHR32 (x [1 ][1 ], shift + 2 ) + SHR32 (x [1 ][0 ], shift + 1 );
174+ for (i = 1 ;i < len ;i ++ )
175+ x_lp [i ] += SHR32 (x [1 ][(factor * i - offset )], shift + 2 ) + SHR32 (x [1 ][(factor * i + offset )], shift + 2 ) + SHR32 (x [1 ][factor * i ], shift + 1 );
176+ x_lp [0 ] += SHR32 (x [1 ][offset ], shift + 2 ) + SHR32 (x [1 ][0 ], shift + 1 );
172177 }
173178#else
174- for (i = 1 ;i < len >> 1 ;i ++ )
175- x_lp [i ] = .25f * x [0 ][(2 * i - 1 )] + .25f * x [0 ][(2 * i + 1 )] + .5f * x [0 ][2 * i ];
176- x_lp [0 ] = .25f * x [0 ][1 ] + .5f * x [0 ][0 ];
179+ for (i = 1 ;i < len ;i ++ )
180+ x_lp [i ] = .25f * x [0 ][(factor * i - offset )] + .25f * x [0 ][(factor * i + offset )] + .5f * x [0 ][factor * i ];
181+ x_lp [0 ] = .25f * x [0 ][offset ] + .5f * x [0 ][0 ];
177182 if (C == 2 )
178183 {
179- for (i = 1 ;i < len >> 1 ;i ++ )
180- x_lp [i ] += .25f * x [1 ][(2 * i - 1 )] + .25f * x [1 ][(2 * i + 1 )] + .5f * x [1 ][2 * i ];
181- x_lp [0 ] += .25f * x [1 ][1 ] + .5f * x [1 ][0 ];
184+ for (i = 1 ;i < len ;i ++ )
185+ x_lp [i ] += .25f * x [1 ][(factor * i - offset )] + .25f * x [1 ][(factor * i + offset )] + .5f * x [1 ][factor * i ];
186+ x_lp [0 ] += .25f * x [1 ][offset ] + .5f * x [1 ][0 ];
182187 }
183188#endif
184189 _celt_autocorr (x_lp , ac , NULL , 0 ,
185- 4 , len >> 1 , arch );
190+ 4 , len , arch );
186191
187192 /* Noise floor -40 dB */
188193#ifdef FIXED_POINT
@@ -213,7 +218,7 @@ void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x
213218 lpc2 [2 ] = lpc [2 ] + MULT16_16_Q15 (c1 ,lpc [1 ]);
214219 lpc2 [3 ] = lpc [3 ] + MULT16_16_Q15 (c1 ,lpc [2 ]);
215220 lpc2 [4 ] = MULT16_16_Q15 (c1 ,lpc [3 ]);
216- celt_fir5 (x_lp , lpc2 , len >> 1 );
221+ celt_fir5 (x_lp , lpc2 , len );
217222}
218223
219224/* Pure C implementation. */
0 commit comments