Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: celt/bands.c

Issue 882843002: Update to opus-HEAD-66611f1. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/opus.git@master
Patch Set: Add the contents of Makefile.mips back. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « celt/bands.h ('k') | celt/celt.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2007-2008 CSIRO 1 /* Copyright (c) 2007-2008 CSIRO
2 Copyright (c) 2007-2009 Xiph.Org Foundation 2 Copyright (c) 2007-2009 Xiph.Org Foundation
3 Copyright (c) 2008-2009 Gregory Maxwell 3 Copyright (c) 2008-2009 Gregory Maxwell
4 Written by Jean-Marc Valin and Gregory Maxwell */ 4 Written by Jean-Marc Valin and Gregory Maxwell */
5 /* 5 /*
6 Redistribution and use in source and binary forms, with or without 6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions 7 modification, are permitted provided that the following conditions
8 are met: 8 are met:
9 9
10 - Redistributions of source code must retain the above copyright 10 - Redistributions of source code must retain the above copyright
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ls=EC_ILOG(isin); 85 ls=EC_ILOG(isin);
86 icos<<=15-lc; 86 icos<<=15-lc;
87 isin<<=15-ls; 87 isin<<=15-ls;
88 return (ls-lc)*(1<<11) 88 return (ls-lc)*(1<<11)
89 +FRAC_MUL16(isin, FRAC_MUL16(isin, -2597) + 7932) 89 +FRAC_MUL16(isin, FRAC_MUL16(isin, -2597) + 7932)
90 -FRAC_MUL16(icos, FRAC_MUL16(icos, -2597) + 7932); 90 -FRAC_MUL16(icos, FRAC_MUL16(icos, -2597) + 7932);
91 } 91 }
92 92
93 #ifdef FIXED_POINT 93 #ifdef FIXED_POINT
94 /* Compute the amplitude (sqrt energy) in each of the bands */ 94 /* Compute the amplitude (sqrt energy) in each of the bands */
95 void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *band E, int end, int C, int M) 95 void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *band E, int end, int C, int LM)
96 { 96 {
97 int i, c, N; 97 int i, c, N;
98 const opus_int16 *eBands = m->eBands; 98 const opus_int16 *eBands = m->eBands;
99 N = M*m->shortMdctSize; 99 N = m->shortMdctSize<<LM;
100 c=0; do { 100 c=0; do {
101 for (i=0;i<end;i++) 101 for (i=0;i<end;i++)
102 { 102 {
103 int j; 103 int j;
104 opus_val32 maxval=0; 104 opus_val32 maxval=0;
105 opus_val32 sum = 0; 105 opus_val32 sum = 0;
106 106
107 j=M*eBands[i]; do { 107 maxval = celt_maxabs32(&X[c*N+(eBands[i]<<LM)], (eBands[i+1]-eBands[i]) <<LM);
108 maxval = MAX32(maxval, X[j+c*N]);
109 maxval = MAX32(maxval, -X[j+c*N]);
110 } while (++j<M*eBands[i+1]);
111
112 if (maxval > 0) 108 if (maxval > 0)
113 { 109 {
114 int shift = celt_ilog2(maxval)-10; 110 int shift = celt_ilog2(maxval) - 14 + (((m->logN[i]>>BITRES)+LM+1)>> 1);
115 j=M*eBands[i]; do { 111 j=eBands[i]<<LM;
116 sum = MAC16_16(sum, EXTRACT16(VSHR32(X[j+c*N],shift)), 112 if (shift>0)
117 EXTRACT16(VSHR32(X[j+c*N],shift))); 113 {
118 } while (++j<M*eBands[i+1]); 114 do {
115 sum = MAC16_16(sum, EXTRACT16(SHR32(X[j+c*N],shift)),
116 EXTRACT16(SHR32(X[j+c*N],shift)));
117 } while (++j<eBands[i+1]<<LM);
118 } else {
119 do {
120 sum = MAC16_16(sum, EXTRACT16(SHL32(X[j+c*N],-shift)),
121 EXTRACT16(SHL32(X[j+c*N],-shift)));
122 } while (++j<eBands[i+1]<<LM);
123 }
119 /* We're adding one here to ensure the normalized band isn't larger than unity norm */ 124 /* We're adding one here to ensure the normalized band isn't larger than unity norm */
120 bandE[i+c*m->nbEBands] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-sh ift); 125 bandE[i+c*m->nbEBands] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-sh ift);
121 } else { 126 } else {
122 bandE[i+c*m->nbEBands] = EPSILON; 127 bandE[i+c*m->nbEBands] = EPSILON;
123 } 128 }
124 /*printf ("%f ", bandE[i+c*m->nbEBands]);*/ 129 /*printf ("%f ", bandE[i+c*m->nbEBands]);*/
125 } 130 }
126 } while (++c<C); 131 } while (++c<C);
127 /*printf ("\n");*/ 132 /*printf ("\n");*/
128 } 133 }
(...skipping 14 matching lines...) Expand all
143 g = EXTRACT16(celt_rcp(SHL32(E,3))); 148 g = EXTRACT16(celt_rcp(SHL32(E,3)));
144 j=M*eBands[i]; do { 149 j=M*eBands[i]; do {
145 X[j+c*N] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g); 150 X[j+c*N] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g);
146 } while (++j<M*eBands[i+1]); 151 } while (++j<M*eBands[i+1]);
147 } while (++i<end); 152 } while (++i<end);
148 } while (++c<C); 153 } while (++c<C);
149 } 154 }
150 155
151 #else /* FIXED_POINT */ 156 #else /* FIXED_POINT */
152 /* Compute the amplitude (sqrt energy) in each of the bands */ 157 /* Compute the amplitude (sqrt energy) in each of the bands */
153 void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *band E, int end, int C, int M) 158 void compute_band_energies(const CELTMode *m, const celt_sig *X, celt_ener *band E, int end, int C, int LM)
154 { 159 {
155 int i, c, N; 160 int i, c, N;
156 const opus_int16 *eBands = m->eBands; 161 const opus_int16 *eBands = m->eBands;
157 N = M*m->shortMdctSize; 162 N = m->shortMdctSize<<LM;
158 c=0; do { 163 c=0; do {
159 for (i=0;i<end;i++) 164 for (i=0;i<end;i++)
160 { 165 {
161 int j; 166 opus_val32 sum;
162 opus_val32 sum = 1e-27f; 167 sum = 1e-27f + celt_inner_prod_c(&X[c*N+(eBands[i]<<LM)], &X[c*N+(eBand s[i]<<LM)], (eBands[i+1]-eBands[i])<<LM);
163 for (j=M*eBands[i];j<M*eBands[i+1];j++)
164 sum += X[j+c*N]*X[j+c*N];
165 bandE[i+c*m->nbEBands] = celt_sqrt(sum); 168 bandE[i+c*m->nbEBands] = celt_sqrt(sum);
166 /*printf ("%f ", bandE[i+c*m->nbEBands]);*/ 169 /*printf ("%f ", bandE[i+c*m->nbEBands]);*/
167 } 170 }
168 } while (++c<C); 171 } while (++c<C);
169 /*printf ("\n");*/ 172 /*printf ("\n");*/
170 } 173 }
171 174
172 /* Normalise each band such that the energy is one. */ 175 /* Normalise each band such that the energy is one. */
173 void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, cel t_norm * OPUS_RESTRICT X, const celt_ener *bandE, int end, int C, int M) 176 void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, cel t_norm * OPUS_RESTRICT X, const celt_ener *bandE, int end, int C, int M)
174 { 177 {
175 int i, c, N; 178 int i, c, N;
176 const opus_int16 *eBands = m->eBands; 179 const opus_int16 *eBands = m->eBands;
177 N = M*m->shortMdctSize; 180 N = M*m->shortMdctSize;
178 c=0; do { 181 c=0; do {
179 for (i=0;i<end;i++) 182 for (i=0;i<end;i++)
180 { 183 {
181 int j; 184 int j;
182 opus_val16 g = 1.f/(1e-27f+bandE[i+c*m->nbEBands]); 185 opus_val16 g = 1.f/(1e-27f+bandE[i+c*m->nbEBands]);
183 for (j=M*eBands[i];j<M*eBands[i+1];j++) 186 for (j=M*eBands[i];j<M*eBands[i+1];j++)
184 X[j+c*N] = freq[j+c*N]*g; 187 X[j+c*N] = freq[j+c*N]*g;
185 } 188 }
186 } while (++c<C); 189 } while (++c<C);
187 } 190 }
188 191
189 #endif /* FIXED_POINT */ 192 #endif /* FIXED_POINT */
190 193
191 /* De-normalise the energy to produce the synthesis from the unit-energy bands * / 194 /* De-normalise the energy to produce the synthesis from the unit-energy bands * /
192 void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, 195 void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X,
193 celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandLogE, int start, int end, int C, int M) 196 celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandLogE, int start,
197 int end, int M, int downsample, int silence)
194 { 198 {
195 int i, c, N; 199 int i, N;
200 int bound;
201 celt_sig * OPUS_RESTRICT f;
202 const celt_norm * OPUS_RESTRICT x;
196 const opus_int16 *eBands = m->eBands; 203 const opus_int16 *eBands = m->eBands;
197 N = M*m->shortMdctSize; 204 N = M*m->shortMdctSize;
198 celt_assert2(C<=2, "denormalise_bands() not implemented for >2 channels"); 205 bound = M*eBands[end];
199 c=0; do { 206 if (downsample!=1)
200 celt_sig * OPUS_RESTRICT f; 207 bound = IMIN(bound, N/downsample);
201 const celt_norm * OPUS_RESTRICT x; 208 if (silence)
202 f = freq+c*N; 209 {
203 x = X+c*N+M*eBands[start]; 210 bound = 0;
204 for (i=0;i<M*eBands[start];i++) 211 start = end = 0;
205 *f++ = 0; 212 }
206 for (i=start;i<end;i++) 213 f = freq;
214 x = X+M*eBands[start];
215 for (i=0;i<M*eBands[start];i++)
216 *f++ = 0;
217 for (i=start;i<end;i++)
218 {
219 int j, band_end;
220 opus_val16 g;
221 opus_val16 lg;
222 #ifdef FIXED_POINT
223 int shift;
224 #endif
225 j=M*eBands[i];
226 band_end = M*eBands[i+1];
227 lg = ADD16(bandLogE[i], SHL16((opus_val16)eMeans[i],6));
228 #ifndef FIXED_POINT
229 g = celt_exp2(lg);
230 #else
231 /* Handle the integer part of the log energy */
232 shift = 16-(lg>>DB_SHIFT);
233 if (shift>31)
207 { 234 {
208 int j, band_end; 235 shift=0;
209 opus_val16 g; 236 g=0;
210 opus_val16 lg; 237 } else {
211 #ifdef FIXED_POINT 238 /* Handle the fractional part. */
212 int shift; 239 g = celt_exp2_frac(lg&((1<<DB_SHIFT)-1));
213 #endif 240 }
214 j=M*eBands[i]; 241 /* Handle extreme gains with negative shift. */
215 band_end = M*eBands[i+1]; 242 if (shift<0)
216 lg = ADD16(bandLogE[i+c*m->nbEBands], SHL16((opus_val16)eMeans[i],6)); 243 {
217 #ifndef FIXED_POINT 244 /* For shift < -2 we'd be likely to overflow, so we're capping
218 g = celt_exp2(lg);
219 #else
220 /* Handle the integer part of the log energy */
221 shift = 16-(lg>>DB_SHIFT);
222 if (shift>31)
223 {
224 shift=0;
225 g=0;
226 } else {
227 /* Handle the fractional part. */
228 g = celt_exp2_frac(lg&((1<<DB_SHIFT)-1));
229 }
230 /* Handle extreme gains with negative shift. */
231 if (shift<0)
232 {
233 /* For shift < -2 we'd be likely to overflow, so we're capping
234 the gain here. This shouldn't happen unless the bitstream is 245 the gain here. This shouldn't happen unless the bitstream is
235 already corrupted. */ 246 already corrupted. */
236 if (shift < -2) 247 if (shift < -2)
237 { 248 {
238 g = 32767; 249 g = 32767;
239 shift = -2; 250 shift = -2;
240 } 251 }
241 do { 252 do {
242 *f++ = SHL32(MULT16_16(*x++, g), -shift); 253 *f++ = SHL32(MULT16_16(*x++, g), -shift);
243 } while (++j<band_end); 254 } while (++j<band_end);
244 } else 255 } else
245 #endif 256 #endif
246 /* Be careful of the fixed-point "else" just above when changing this c ode */ 257 /* Be careful of the fixed-point "else" just above when changing this c ode */
247 do { 258 do {
248 *f++ = SHR32(MULT16_16(*x++, g), shift); 259 *f++ = SHR32(MULT16_16(*x++, g), shift);
249 } while (++j<band_end); 260 } while (++j<band_end);
250 } 261 }
251 celt_assert(start <= end); 262 celt_assert(start <= end);
252 for (i=M*eBands[end];i<N;i++) 263 OPUS_CLEAR(&freq[bound], N-bound);
253 *f++ = 0;
254 } while (++c<C);
255 } 264 }
256 265
257 /* This prevents energy collapse for transients with multiple short MDCTs */ 266 /* This prevents energy collapse for transients with multiple short MDCTs */
258 void anti_collapse(const CELTMode *m, celt_norm *X_, unsigned char *collapse_mas ks, int LM, int C, int size, 267 void anti_collapse(const CELTMode *m, celt_norm *X_, unsigned char *collapse_mas ks, int LM, int C, int size,
259 int start, int end, opus_val16 *logE, opus_val16 *prev1logE, 268 int start, int end, const opus_val16 *logE, const opus_val16 *prev1logE,
260 opus_val16 *prev2logE, int *pulses, opus_uint32 seed) 269 const opus_val16 *prev2logE, const int *pulses, opus_uint32 seed, int arch )
261 { 270 {
262 int c, i, j, k; 271 int c, i, j, k;
263 for (i=start;i<end;i++) 272 for (i=start;i<end;i++)
264 { 273 {
265 int N0; 274 int N0;
266 opus_val16 thresh, sqrt_1; 275 opus_val16 thresh, sqrt_1;
267 int depth; 276 int depth;
268 #ifdef FIXED_POINT 277 #ifdef FIXED_POINT
269 int shift; 278 int shift;
270 opus_val32 thresh32; 279 opus_val32 thresh32;
271 #endif 280 #endif
272 281
273 N0 = m->eBands[i+1]-m->eBands[i]; 282 N0 = m->eBands[i+1]-m->eBands[i];
274 /* depth in 1/8 bits */ 283 /* depth in 1/8 bits */
275 depth = (1+pulses[i])/((m->eBands[i+1]-m->eBands[i])<<LM); 284 celt_assert(pulses[i]>=0);
285 depth = celt_udiv(1+pulses[i], (m->eBands[i+1]-m->eBands[i]))>>LM;
276 286
277 #ifdef FIXED_POINT 287 #ifdef FIXED_POINT
278 thresh32 = SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1); 288 thresh32 = SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1);
279 thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,thresh32)); 289 thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,thresh32));
280 { 290 {
281 opus_val32 t; 291 opus_val32 t;
282 t = N0<<LM; 292 t = N0<<LM;
283 shift = celt_ilog2(t)>>1; 293 shift = celt_ilog2(t)>>1;
284 t = SHL32(t, (7-shift)<<1); 294 t = SHL32(t, (7-shift)<<1);
285 sqrt_1 = celt_rsqrt_norm(t); 295 sqrt_1 = celt_rsqrt_norm(t);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 for (j=0;j<N0;j++) 348 for (j=0;j<N0;j++)
339 { 349 {
340 seed = celt_lcg_rand(seed); 350 seed = celt_lcg_rand(seed);
341 X[(j<<LM)+k] = (seed&0x8000 ? r : -r); 351 X[(j<<LM)+k] = (seed&0x8000 ? r : -r);
342 } 352 }
343 renormalize = 1; 353 renormalize = 1;
344 } 354 }
345 } 355 }
346 /* We just added some energy, so we need to renormalise */ 356 /* We just added some energy, so we need to renormalise */
347 if (renormalize) 357 if (renormalize)
348 renormalise_vector(X, N0<<LM, Q15ONE); 358 renormalise_vector(X, N0<<LM, Q15ONE, arch);
349 } while (++c<C); 359 } while (++c<C);
350 } 360 }
351 } 361 }
352 362
353 static void intensity_stereo(const CELTMode *m, celt_norm *X, celt_norm *Y, cons t celt_ener *bandE, int bandID, int N) 363 static void intensity_stereo(const CELTMode *m, celt_norm * OPUS_RESTRICT X, con st celt_norm * OPUS_RESTRICT Y, const celt_ener *bandE, int bandID, int N)
354 { 364 {
355 int i = bandID; 365 int i = bandID;
356 int j; 366 int j;
357 opus_val16 a1, a2; 367 opus_val16 a1, a2;
358 opus_val16 left, right; 368 opus_val16 left, right;
359 opus_val16 norm; 369 opus_val16 norm;
360 #ifdef FIXED_POINT 370 #ifdef FIXED_POINT
361 int shift = celt_zlog2(MAX32(bandE[i], bandE[i+m->nbEBands]))-13; 371 int shift = celt_zlog2(MAX32(bandE[i], bandE[i+m->nbEBands]))-13;
362 #endif 372 #endif
363 left = VSHR32(bandE[i],shift); 373 left = VSHR32(bandE[i],shift);
364 right = VSHR32(bandE[i+m->nbEBands],shift); 374 right = VSHR32(bandE[i+m->nbEBands],shift);
365 norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right )); 375 norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right ));
366 a1 = DIV32_16(SHL32(EXTEND32(left),14),norm); 376 a1 = DIV32_16(SHL32(EXTEND32(left),14),norm);
367 a2 = DIV32_16(SHL32(EXTEND32(right),14),norm); 377 a2 = DIV32_16(SHL32(EXTEND32(right),14),norm);
368 for (j=0;j<N;j++) 378 for (j=0;j<N;j++)
369 { 379 {
370 celt_norm r, l; 380 celt_norm r, l;
371 l = X[j]; 381 l = X[j];
372 r = Y[j]; 382 r = Y[j];
373 X[j] = MULT16_16_Q14(a1,l) + MULT16_16_Q14(a2,r); 383 X[j] = EXTRACT16(SHR32(MAC16_16(MULT16_16(a1, l), a2, r), 14));
374 /* Side is not encoded, no need to calculate */ 384 /* Side is not encoded, no need to calculate */
375 } 385 }
376 } 386 }
377 387
378 static void stereo_split(celt_norm *X, celt_norm *Y, int N) 388 static void stereo_split(celt_norm * OPUS_RESTRICT X, celt_norm * OPUS_RESTRICT Y, int N)
379 { 389 {
380 int j; 390 int j;
381 for (j=0;j<N;j++) 391 for (j=0;j<N;j++)
382 { 392 {
383 celt_norm r, l; 393 opus_val32 r, l;
384 l = MULT16_16_Q15(QCONST16(.70710678f,15), X[j]); 394 l = MULT16_16(QCONST16(.70710678f, 15), X[j]);
385 r = MULT16_16_Q15(QCONST16(.70710678f,15), Y[j]); 395 r = MULT16_16(QCONST16(.70710678f, 15), Y[j]);
386 X[j] = l+r; 396 X[j] = EXTRACT16(SHR32(ADD32(l, r), 15));
387 Y[j] = r-l; 397 Y[j] = EXTRACT16(SHR32(SUB32(r, l), 15));
388 } 398 }
389 } 399 }
390 400
391 static void stereo_merge(celt_norm *X, celt_norm *Y, opus_val16 mid, int N) 401 static void stereo_merge(celt_norm * OPUS_RESTRICT X, celt_norm * OPUS_RESTRICT Y, opus_val16 mid, int N)
392 { 402 {
393 int j; 403 int j;
394 opus_val32 xp=0, side=0; 404 opus_val32 xp=0, side=0;
395 opus_val32 El, Er; 405 opus_val32 El, Er;
396 opus_val16 mid2; 406 opus_val16 mid2;
397 #ifdef FIXED_POINT 407 #ifdef FIXED_POINT
398 int kl, kr; 408 int kl, kr;
399 #endif 409 #endif
400 opus_val32 t, lgain, rgain; 410 opus_val32 t, lgain, rgain;
401 411
402 /* Compute the norm of X+Y and X-Y as |X|^2 + |Y|^2 +/- sum(xy) */ 412 /* Compute the norm of X+Y and X-Y as |X|^2 + |Y|^2 +/- sum(xy) */
403 dual_inner_prod(Y, X, Y, N, &xp, &side); 413 dual_inner_prod(Y, X, Y, N, &xp, &side);
404 /* Compensating for the mid normalization */ 414 /* Compensating for the mid normalization */
405 xp = MULT16_32_Q15(mid, xp); 415 xp = MULT16_32_Q15(mid, xp);
406 /* mid and side are in Q15, not Q14 like X and Y */ 416 /* mid and side are in Q15, not Q14 like X and Y */
407 mid2 = SHR32(mid, 1); 417 mid2 = SHR32(mid, 1);
408 El = MULT16_16(mid2, mid2) + side - 2*xp; 418 El = MULT16_16(mid2, mid2) + side - 2*xp;
409 Er = MULT16_16(mid2, mid2) + side + 2*xp; 419 Er = MULT16_16(mid2, mid2) + side + 2*xp;
410 if (Er < QCONST32(6e-4f, 28) || El < QCONST32(6e-4f, 28)) 420 if (Er < QCONST32(6e-4f, 28) || El < QCONST32(6e-4f, 28))
411 { 421 {
412 for (j=0;j<N;j++) 422 OPUS_COPY(Y, X, N);
413 Y[j] = X[j];
414 return; 423 return;
415 } 424 }
416 425
417 #ifdef FIXED_POINT 426 #ifdef FIXED_POINT
418 kl = celt_ilog2(El)>>1; 427 kl = celt_ilog2(El)>>1;
419 kr = celt_ilog2(Er)>>1; 428 kr = celt_ilog2(Er)>>1;
420 #endif 429 #endif
421 t = VSHR32(El, (kl-7)<<1); 430 t = VSHR32(El, (kl-7)<<1);
422 lgain = celt_rsqrt_norm(t); 431 lgain = celt_rsqrt_norm(t);
423 t = VSHR32(Er, (kr-7)<<1); 432 t = VSHR32(Er, (kr-7)<<1);
424 rgain = celt_rsqrt_norm(t); 433 rgain = celt_rsqrt_norm(t);
425 434
426 #ifdef FIXED_POINT 435 #ifdef FIXED_POINT
427 if (kl < 7) 436 if (kl < 7)
428 kl = 7; 437 kl = 7;
429 if (kr < 7) 438 if (kr < 7)
430 kr = 7; 439 kr = 7;
431 #endif 440 #endif
432 441
433 for (j=0;j<N;j++) 442 for (j=0;j<N;j++)
434 { 443 {
435 celt_norm r, l; 444 celt_norm r, l;
436 /* Apply mid scaling (side is already scaled) */ 445 /* Apply mid scaling (side is already scaled) */
437 l = MULT16_16_Q15(mid, X[j]); 446 l = MULT16_16_P15(mid, X[j]);
438 r = Y[j]; 447 r = Y[j];
439 X[j] = EXTRACT16(PSHR32(MULT16_16(lgain, SUB16(l,r)), kl+1)); 448 X[j] = EXTRACT16(PSHR32(MULT16_16(lgain, SUB16(l,r)), kl+1));
440 Y[j] = EXTRACT16(PSHR32(MULT16_16(rgain, ADD16(l,r)), kr+1)); 449 Y[j] = EXTRACT16(PSHR32(MULT16_16(rgain, ADD16(l,r)), kr+1));
441 } 450 }
442 } 451 }
443 452
444 /* Decide whether we should spread the pulses in the current frame */ 453 /* Decide whether we should spread the pulses in the current frame */
445 int spreading_decision(const CELTMode *m, celt_norm *X, int *average, 454 int spreading_decision(const CELTMode *m, const celt_norm *X, int *average,
446 int last_decision, int *hf_average, int *tapset_decision, int update_hf, 455 int last_decision, int *hf_average, int *tapset_decision, int update_hf,
447 int end, int C, int M) 456 int end, int C, int M)
448 { 457 {
449 int i, c, N0; 458 int i, c, N0;
450 int sum = 0, nbBands=0; 459 int sum = 0, nbBands=0;
451 const opus_int16 * OPUS_RESTRICT eBands = m->eBands; 460 const opus_int16 * OPUS_RESTRICT eBands = m->eBands;
452 int decision; 461 int decision;
453 int hf_sum=0; 462 int hf_sum=0;
454 463
455 celt_assert(end>0); 464 celt_assert(end>0);
456 465
457 N0 = M*m->shortMdctSize; 466 N0 = M*m->shortMdctSize;
458 467
459 if (M*(eBands[end]-eBands[end-1]) <= 8) 468 if (M*(eBands[end]-eBands[end-1]) <= 8)
460 return SPREAD_NONE; 469 return SPREAD_NONE;
461 c=0; do { 470 c=0; do {
462 for (i=0;i<end;i++) 471 for (i=0;i<end;i++)
463 { 472 {
464 int j, N, tmp=0; 473 int j, N, tmp=0;
465 int tcount[3] = {0,0,0}; 474 int tcount[3] = {0,0,0};
466 celt_norm * OPUS_RESTRICT x = X+M*eBands[i]+c*N0; 475 const celt_norm * OPUS_RESTRICT x = X+M*eBands[i]+c*N0;
467 N = M*(eBands[i+1]-eBands[i]); 476 N = M*(eBands[i+1]-eBands[i]);
468 if (N<=8) 477 if (N<=8)
469 continue; 478 continue;
470 /* Compute rough CDF of |x[j]| */ 479 /* Compute rough CDF of |x[j]| */
471 for (j=0;j<N;j++) 480 for (j=0;j<N;j++)
472 { 481 {
473 opus_val32 x2N; /* Q13 */ 482 opus_val32 x2N; /* Q13 */
474 483
475 x2N = MULT16_16(MULT16_16_Q15(x[j], x[j]), N); 484 x2N = MULT16_16(MULT16_16_Q15(x[j], x[j]), N);
476 if (x2N < QCONST16(0.25f,13)) 485 if (x2N < QCONST16(0.25f,13))
477 tcount[0]++; 486 tcount[0]++;
478 if (x2N < QCONST16(0.0625f,13)) 487 if (x2N < QCONST16(0.0625f,13))
479 tcount[1]++; 488 tcount[1]++;
480 if (x2N < QCONST16(0.015625f,13)) 489 if (x2N < QCONST16(0.015625f,13))
481 tcount[2]++; 490 tcount[2]++;
482 } 491 }
483 492
484 /* Only include four last bands (8 kHz and up) */ 493 /* Only include four last bands (8 kHz and up) */
485 if (i>m->nbEBands-4) 494 if (i>m->nbEBands-4)
486 hf_sum += 32*(tcount[1]+tcount[0])/N; 495 hf_sum += celt_udiv(32*(tcount[1]+tcount[0]), N);
487 tmp = (2*tcount[2] >= N) + (2*tcount[1] >= N) + (2*tcount[0] >= N); 496 tmp = (2*tcount[2] >= N) + (2*tcount[1] >= N) + (2*tcount[0] >= N);
488 sum += tmp*256; 497 sum += tmp*256;
489 nbBands++; 498 nbBands++;
490 } 499 }
491 } while (++c<C); 500 } while (++c<C);
492 501
493 if (update_hf) 502 if (update_hf)
494 { 503 {
495 if (hf_sum) 504 if (hf_sum)
496 hf_sum /= C*(4-m->nbEBands+end); 505 hf_sum = celt_udiv(hf_sum, C*(4-m->nbEBands+end));
497 *hf_average = (*hf_average+hf_sum)>>1; 506 *hf_average = (*hf_average+hf_sum)>>1;
498 hf_sum = *hf_average; 507 hf_sum = *hf_average;
499 if (*tapset_decision==2) 508 if (*tapset_decision==2)
500 hf_sum += 4; 509 hf_sum += 4;
501 else if (*tapset_decision==0) 510 else if (*tapset_decision==0)
502 hf_sum -= 4; 511 hf_sum -= 4;
503 if (hf_sum > 22) 512 if (hf_sum > 22)
504 *tapset_decision=2; 513 *tapset_decision=2;
505 else if (hf_sum > 18) 514 else if (hf_sum > 18)
506 *tapset_decision=1; 515 *tapset_decision=1;
507 else 516 else
508 *tapset_decision=0; 517 *tapset_decision=0;
509 } 518 }
510 /*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/ 519 /*printf("%d %d %d\n", hf_sum, *hf_average, *tapset_decision);*/
511 celt_assert(nbBands>0); /* end has to be non-zero */ 520 celt_assert(nbBands>0); /* end has to be non-zero */
512 sum /= nbBands; 521 celt_assert(sum>=0);
522 sum = celt_udiv(sum, nbBands);
513 /* Recursive averaging */ 523 /* Recursive averaging */
514 sum = (sum+*average)>>1; 524 sum = (sum+*average)>>1;
515 *average = sum; 525 *average = sum;
516 /* Hysteresis */ 526 /* Hysteresis */
517 sum = (3*sum + (((3-last_decision)<<7) + 64) + 2)>>2; 527 sum = (3*sum + (((3-last_decision)<<7) + 64) + 2)>>2;
518 if (sum < 80) 528 if (sum < 80)
519 { 529 {
520 decision = SPREAD_AGGRESSIVE; 530 decision = SPREAD_AGGRESSIVE;
521 } else if (sum < 256) 531 } else if (sum < 256)
522 { 532 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 for (i=0;i<stride;i++) 570 for (i=0;i<stride;i++)
561 { 571 {
562 for (j=0;j<N0;j++) 572 for (j=0;j<N0;j++)
563 tmp[ordery[i]*N0+j] = X[j*stride+i]; 573 tmp[ordery[i]*N0+j] = X[j*stride+i];
564 } 574 }
565 } else { 575 } else {
566 for (i=0;i<stride;i++) 576 for (i=0;i<stride;i++)
567 for (j=0;j<N0;j++) 577 for (j=0;j<N0;j++)
568 tmp[i*N0+j] = X[j*stride+i]; 578 tmp[i*N0+j] = X[j*stride+i];
569 } 579 }
570 for (j=0;j<N;j++) 580 OPUS_COPY(X, tmp, N);
571 X[j] = tmp[j];
572 RESTORE_STACK; 581 RESTORE_STACK;
573 } 582 }
574 583
575 static void interleave_hadamard(celt_norm *X, int N0, int stride, int hadamard) 584 static void interleave_hadamard(celt_norm *X, int N0, int stride, int hadamard)
576 { 585 {
577 int i,j; 586 int i,j;
578 VARDECL(celt_norm, tmp); 587 VARDECL(celt_norm, tmp);
579 int N; 588 int N;
580 SAVE_STACK; 589 SAVE_STACK;
581 N = N0*stride; 590 N = N0*stride;
582 ALLOC(tmp, N, celt_norm); 591 ALLOC(tmp, N, celt_norm);
583 if (hadamard) 592 if (hadamard)
584 { 593 {
585 const int *ordery = ordery_table+stride-2; 594 const int *ordery = ordery_table+stride-2;
586 for (i=0;i<stride;i++) 595 for (i=0;i<stride;i++)
587 for (j=0;j<N0;j++) 596 for (j=0;j<N0;j++)
588 tmp[j*stride+i] = X[ordery[i]*N0+j]; 597 tmp[j*stride+i] = X[ordery[i]*N0+j];
589 } else { 598 } else {
590 for (i=0;i<stride;i++) 599 for (i=0;i<stride;i++)
591 for (j=0;j<N0;j++) 600 for (j=0;j<N0;j++)
592 tmp[j*stride+i] = X[i*N0+j]; 601 tmp[j*stride+i] = X[i*N0+j];
593 } 602 }
594 for (j=0;j<N;j++) 603 OPUS_COPY(X, tmp, N);
595 X[j] = tmp[j];
596 RESTORE_STACK; 604 RESTORE_STACK;
597 } 605 }
598 606
599 void haar1(celt_norm *X, int N0, int stride) 607 void haar1(celt_norm *X, int N0, int stride)
600 { 608 {
601 int i, j; 609 int i, j;
602 N0 >>= 1; 610 N0 >>= 1;
603 for (i=0;i<stride;i++) 611 for (i=0;i<stride;i++)
604 for (j=0;j<N0;j++) 612 for (j=0;j<N0;j++)
605 { 613 {
606 celt_norm tmp1, tmp2; 614 opus_val32 tmp1, tmp2;
607 tmp1 = MULT16_16_Q15(QCONST16(.70710678f,15), X[stride*2*j+i]); 615 tmp1 = MULT16_16(QCONST16(.70710678f,15), X[stride*2*j+i]);
608 tmp2 = MULT16_16_Q15(QCONST16(.70710678f,15), X[stride*(2*j+1)+i]); 616 tmp2 = MULT16_16(QCONST16(.70710678f,15), X[stride*(2*j+1)+i]);
609 X[stride*2*j+i] = tmp1 + tmp2; 617 X[stride*2*j+i] = EXTRACT16(PSHR32(ADD32(tmp1, tmp2), 15));
610 X[stride*(2*j+1)+i] = tmp1 - tmp2; 618 X[stride*(2*j+1)+i] = EXTRACT16(PSHR32(SUB32(tmp1, tmp2), 15));
611 } 619 }
612 } 620 }
613 621
614 static int compute_qn(int N, int b, int offset, int pulse_cap, int stereo) 622 static int compute_qn(int N, int b, int offset, int pulse_cap, int stereo)
615 { 623 {
616 static const opus_int16 exp2_table8[8] = 624 static const opus_int16 exp2_table8[8] =
617 {16384, 17866, 19483, 21247, 23170, 25267, 27554, 30048}; 625 {16384, 17866, 19483, 21247, 23170, 25267, 27554, 30048};
618 int qn, qb; 626 int qn, qb;
619 int N2 = 2*N-1; 627 int N2 = 2*N-1;
620 if (stereo && N==2) 628 if (stereo && N==2)
621 N2--; 629 N2--;
622 /* The upper limit ensures that in a stereo split with itheta==16384, we'll 630 /* The upper limit ensures that in a stereo split with itheta==16384, we'll
623 always have enough bits left over to code at least one pulse in the 631 always have enough bits left over to code at least one pulse in the
624 side; otherwise it would collapse, since it doesn't get folded. */ 632 side; otherwise it would collapse, since it doesn't get folded. */
625 qb = IMIN(b-pulse_cap-(4<<BITRES), (b+N2*offset)/N2); 633 qb = celt_sudiv(b+N2*offset, N2);
634 qb = IMIN(b-pulse_cap-(4<<BITRES), qb);
626 635
627 qb = IMIN(8<<BITRES, qb); 636 qb = IMIN(8<<BITRES, qb);
628 637
629 if (qb<(1<<BITRES>>1)) { 638 if (qb<(1<<BITRES>>1)) {
630 qn = 1; 639 qn = 1;
631 } else { 640 } else {
632 qn = exp2_table8[qb&0x7]>>(14-(qb>>BITRES)); 641 qn = exp2_table8[qb&0x7]>>(14-(qb>>BITRES));
633 qn = (qn+1)>>1<<1; 642 qn = (qn+1)>>1<<1;
634 } 643 }
635 celt_assert(qn <= 256); 644 celt_assert(qn <= 256);
636 return qn; 645 return qn;
637 } 646 }
638 647
639 struct band_ctx { 648 struct band_ctx {
640 int encode; 649 int encode;
641 const CELTMode *m; 650 const CELTMode *m;
642 int i; 651 int i;
643 int intensity; 652 int intensity;
644 int spread; 653 int spread;
645 int tf_change; 654 int tf_change;
646 ec_ctx *ec; 655 ec_ctx *ec;
647 opus_int32 remaining_bits; 656 opus_int32 remaining_bits;
648 const celt_ener *bandE; 657 const celt_ener *bandE;
649 opus_uint32 seed; 658 opus_uint32 seed;
659 int arch;
650 }; 660 };
651 661
652 struct split_ctx { 662 struct split_ctx {
653 int inv; 663 int inv;
654 int imid; 664 int imid;
655 int iside; 665 int iside;
656 int delta; 666 int delta;
657 int itheta; 667 int itheta;
658 int qalloc; 668 int qalloc;
659 }; 669 };
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 offset = (pulse_cap>>1) - (stereo&&N==2 ? QTHETA_OFFSET_TWOPHASE : QTHETA_OFF SET); 701 offset = (pulse_cap>>1) - (stereo&&N==2 ? QTHETA_OFFSET_TWOPHASE : QTHETA_OFF SET);
692 qn = compute_qn(N, *b, offset, pulse_cap, stereo); 702 qn = compute_qn(N, *b, offset, pulse_cap, stereo);
693 if (stereo && i>=intensity) 703 if (stereo && i>=intensity)
694 qn = 1; 704 qn = 1;
695 if (encode) 705 if (encode)
696 { 706 {
697 /* theta is the atan() of the ratio between the (normalized) 707 /* theta is the atan() of the ratio between the (normalized)
698 side and mid. With just that parameter, we can re-scale both 708 side and mid. With just that parameter, we can re-scale both
699 mid and side because we know that 1) they have unit norm and 709 mid and side because we know that 1) they have unit norm and
700 2) they are orthogonal. */ 710 2) they are orthogonal. */
701 itheta = stereo_itheta(X, Y, stereo, N); 711 itheta = stereo_itheta(X, Y, stereo, N, ctx->arch);
702 } 712 }
703 tell = ec_tell_frac(ec); 713 tell = ec_tell_frac(ec);
704 if (qn!=1) 714 if (qn!=1)
705 { 715 {
706 if (encode) 716 if (encode)
707 itheta = (itheta*qn+8192)>>14; 717 itheta = (itheta*qn+8192)>>14;
708 718
709 /* Entropy coding of the angle. We use a uniform pdf for the 719 /* Entropy coding of the angle. We use a uniform pdf for the
710 time split, a step for stereo, and a triangular one for the rest. */ 720 time split, a step for stereo, and a triangular one for the rest. */
711 if (stereo && N>2) 721 if (stereo && N>2)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 { 772 {
763 itheta = (2*(qn + 1) 773 itheta = (2*(qn + 1)
764 - isqrt32(8*(opus_uint32)(ft - fm - 1) + 1))>>1; 774 - isqrt32(8*(opus_uint32)(ft - fm - 1) + 1))>>1;
765 fs = qn + 1 - itheta; 775 fs = qn + 1 - itheta;
766 fl = ft - ((qn + 1 - itheta)*(qn + 2 - itheta)>>1); 776 fl = ft - ((qn + 1 - itheta)*(qn + 2 - itheta)>>1);
767 } 777 }
768 778
769 ec_dec_update(ec, fl, fl+fs, ft); 779 ec_dec_update(ec, fl, fl+fs, ft);
770 } 780 }
771 } 781 }
772 itheta = (opus_int32)itheta*16384/qn; 782 celt_assert(itheta>=0);
783 itheta = celt_udiv((opus_int32)itheta*16384, qn);
773 if (encode && stereo) 784 if (encode && stereo)
774 { 785 {
775 if (itheta==0) 786 if (itheta==0)
776 intensity_stereo(m, X, Y, bandE, i, N); 787 intensity_stereo(m, X, Y, bandE, i, N);
777 else 788 else
778 stereo_split(X, Y, N); 789 stereo_split(X, Y, N);
779 } 790 }
780 /* NOTE: Renormalising X and Y *may* help fixed-point a bit at very high r ate. 791 /* NOTE: Renormalising X and Y *may* help fixed-point a bit at very high r ate.
781 Let's do that at higher complexity */ 792 Let's do that at higher complexity */
782 } else if (stereo) { 793 } else if (stereo) {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 int j; 1025 int j;
1015 if (resynth) 1026 if (resynth)
1016 { 1027 {
1017 unsigned cm_mask; 1028 unsigned cm_mask;
1018 /* B can be as large as 16, so this shift might overflow an int on a 1029 /* B can be as large as 16, so this shift might overflow an int on a
1019 16-bit platform; use a long to get defined behavior.*/ 1030 16-bit platform; use a long to get defined behavior.*/
1020 cm_mask = (unsigned)(1UL<<B)-1; 1031 cm_mask = (unsigned)(1UL<<B)-1;
1021 fill &= cm_mask; 1032 fill &= cm_mask;
1022 if (!fill) 1033 if (!fill)
1023 { 1034 {
1024 for (j=0;j<N;j++) 1035 OPUS_CLEAR(X, N);
1025 X[j] = 0;
1026 } else { 1036 } else {
1027 if (lowband == NULL) 1037 if (lowband == NULL)
1028 { 1038 {
1029 /* Noise */ 1039 /* Noise */
1030 for (j=0;j<N;j++) 1040 for (j=0;j<N;j++)
1031 { 1041 {
1032 ctx->seed = celt_lcg_rand(ctx->seed); 1042 ctx->seed = celt_lcg_rand(ctx->seed);
1033 X[j] = (celt_norm)((opus_int32)ctx->seed>>20); 1043 X[j] = (celt_norm)((opus_int32)ctx->seed>>20);
1034 } 1044 }
1035 cm = cm_mask; 1045 cm = cm_mask;
1036 } else { 1046 } else {
1037 /* Folded spectrum */ 1047 /* Folded spectrum */
1038 for (j=0;j<N;j++) 1048 for (j=0;j<N;j++)
1039 { 1049 {
1040 opus_val16 tmp; 1050 opus_val16 tmp;
1041 ctx->seed = celt_lcg_rand(ctx->seed); 1051 ctx->seed = celt_lcg_rand(ctx->seed);
1042 /* About 48 dB below the "normal" folding level */ 1052 /* About 48 dB below the "normal" folding level */
1043 tmp = QCONST16(1.0f/256, 10); 1053 tmp = QCONST16(1.0f/256, 10);
1044 tmp = (ctx->seed)&0x8000 ? tmp : -tmp; 1054 tmp = (ctx->seed)&0x8000 ? tmp : -tmp;
1045 X[j] = lowband[j]+tmp; 1055 X[j] = lowband[j]+tmp;
1046 } 1056 }
1047 cm = fill; 1057 cm = fill;
1048 } 1058 }
1049 renormalise_vector(X, N, gain); 1059 renormalise_vector(X, N, gain, ctx->arch);
1050 } 1060 }
1051 } 1061 }
1052 } 1062 }
1053 } 1063 }
1054 1064
1055 return cm; 1065 return cm;
1056 } 1066 }
1057 1067
1058 1068
1059 /* This function is responsible for encoding and decoding a band for the mono ca se. */ 1069 /* This function is responsible for encoding and decoding a band for the mono ca se. */
(...skipping 17 matching lines...) Expand all
1077 #endif 1087 #endif
1078 int k; 1088 int k;
1079 int encode; 1089 int encode;
1080 int tf_change; 1090 int tf_change;
1081 1091
1082 encode = ctx->encode; 1092 encode = ctx->encode;
1083 tf_change = ctx->tf_change; 1093 tf_change = ctx->tf_change;
1084 1094
1085 longBlocks = B0==1; 1095 longBlocks = B0==1;
1086 1096
1087 N_B /= B; 1097 N_B = celt_udiv(N_B, B);
1088 1098
1089 /* Special case for one sample */ 1099 /* Special case for one sample */
1090 if (N==1) 1100 if (N==1)
1091 { 1101 {
1092 return quant_band_n1(ctx, X, NULL, b, lowband_out); 1102 return quant_band_n1(ctx, X, NULL, b, lowband_out);
1093 } 1103 }
1094 1104
1095 if (tf_change>0) 1105 if (tf_change>0)
1096 recombine = tf_change; 1106 recombine = tf_change;
1097 /* Band recombining to increase frequency resolution */ 1107 /* Band recombining to increase frequency resolution */
1098 1108
1099 if (lowband_scratch && lowband && (recombine || ((N_B&1) == 0 && tf_change<0) || B0>1)) 1109 if (lowband_scratch && lowband && (recombine || ((N_B&1) == 0 && tf_change<0) || B0>1))
1100 { 1110 {
1101 int j; 1111 OPUS_COPY(lowband_scratch, lowband, N);
1102 for (j=0;j<N;j++)
1103 lowband_scratch[j] = lowband[j];
1104 lowband = lowband_scratch; 1112 lowband = lowband_scratch;
1105 } 1113 }
1106 1114
1107 for (k=0;k<recombine;k++) 1115 for (k=0;k<recombine;k++)
1108 { 1116 {
1109 static const unsigned char bit_interleave_table[16]={ 1117 static const unsigned char bit_interleave_table[16]={
1110 0,1,1,1,2,3,3,3,2,3,3,3,2,3,3,3 1118 0,1,1,1,2,3,3,3,2,3,3,3,2,3,3,3
1111 }; 1119 };
1112 if (encode) 1120 if (encode)
1113 haar1(X, N>>k, 1<<k); 1121 haar1(X, N>>k, 1<<k);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 int j; 1354 int j;
1347 for (j=0;j<N;j++) 1355 for (j=0;j<N;j++)
1348 Y[j] = -Y[j]; 1356 Y[j] = -Y[j];
1349 } 1357 }
1350 } 1358 }
1351 return cm; 1359 return cm;
1352 } 1360 }
1353 1361
1354 1362
1355 void quant_all_bands(int encode, const CELTMode *m, int start, int end, 1363 void quant_all_bands(int encode, const CELTMode *m, int start, int end,
1356 celt_norm *X_, celt_norm *Y_, unsigned char *collapse_masks, const celt_en er *bandE, int *pulses, 1364 celt_norm *X_, celt_norm *Y_, unsigned char *collapse_masks,
1357 int shortBlocks, int spread, int dual_stereo, int intensity, int *tf_res, 1365 const celt_ener *bandE, int *pulses, int shortBlocks, int spread,
1358 opus_int32 total_bits, opus_int32 balance, ec_ctx *ec, int LM, int codedBa nds, opus_uint32 *seed) 1366 int dual_stereo, int intensity, int *tf_res, opus_int32 total_bits,
1367 opus_int32 balance, ec_ctx *ec, int LM, int codedBands,
1368 opus_uint32 *seed, int arch)
1359 { 1369 {
1360 int i; 1370 int i;
1361 opus_int32 remaining_bits; 1371 opus_int32 remaining_bits;
1362 const opus_int16 * OPUS_RESTRICT eBands = m->eBands; 1372 const opus_int16 * OPUS_RESTRICT eBands = m->eBands;
1363 celt_norm * OPUS_RESTRICT norm, * OPUS_RESTRICT norm2; 1373 celt_norm * OPUS_RESTRICT norm, * OPUS_RESTRICT norm2;
1364 VARDECL(celt_norm, _norm); 1374 VARDECL(celt_norm, _norm);
1365 celt_norm *lowband_scratch; 1375 celt_norm *lowband_scratch;
1366 int B; 1376 int B;
1367 int M; 1377 int M;
1368 int lowband_offset; 1378 int lowband_offset;
(...skipping 21 matching lines...) Expand all
1390 lowband_scratch = X_+M*eBands[m->nbEBands-1]; 1400 lowband_scratch = X_+M*eBands[m->nbEBands-1];
1391 1401
1392 lowband_offset = 0; 1402 lowband_offset = 0;
1393 ctx.bandE = bandE; 1403 ctx.bandE = bandE;
1394 ctx.ec = ec; 1404 ctx.ec = ec;
1395 ctx.encode = encode; 1405 ctx.encode = encode;
1396 ctx.intensity = intensity; 1406 ctx.intensity = intensity;
1397 ctx.m = m; 1407 ctx.m = m;
1398 ctx.seed = *seed; 1408 ctx.seed = *seed;
1399 ctx.spread = spread; 1409 ctx.spread = spread;
1410 ctx.arch = arch;
1400 for (i=start;i<end;i++) 1411 for (i=start;i<end;i++)
1401 { 1412 {
1402 opus_int32 tell; 1413 opus_int32 tell;
1403 int b; 1414 int b;
1404 int N; 1415 int N;
1405 opus_int32 curr_balance; 1416 opus_int32 curr_balance;
1406 int effective_lowband=-1; 1417 int effective_lowband=-1;
1407 celt_norm * OPUS_RESTRICT X, * OPUS_RESTRICT Y; 1418 celt_norm * OPUS_RESTRICT X, * OPUS_RESTRICT Y;
1408 int tf_change=0; 1419 int tf_change=0;
1409 unsigned x_cm; 1420 unsigned x_cm;
(...skipping 11 matching lines...) Expand all
1421 N = M*eBands[i+1]-M*eBands[i]; 1432 N = M*eBands[i+1]-M*eBands[i];
1422 tell = ec_tell_frac(ec); 1433 tell = ec_tell_frac(ec);
1423 1434
1424 /* Compute how many bits we want to allocate to this band */ 1435 /* Compute how many bits we want to allocate to this band */
1425 if (i != start) 1436 if (i != start)
1426 balance -= tell; 1437 balance -= tell;
1427 remaining_bits = total_bits-tell-1; 1438 remaining_bits = total_bits-tell-1;
1428 ctx.remaining_bits = remaining_bits; 1439 ctx.remaining_bits = remaining_bits;
1429 if (i <= codedBands-1) 1440 if (i <= codedBands-1)
1430 { 1441 {
1431 curr_balance = balance / IMIN(3, codedBands-i); 1442 curr_balance = celt_sudiv(balance, IMIN(3, codedBands-i));
1432 b = IMAX(0, IMIN(16383, IMIN(remaining_bits+1,pulses[i]+curr_balance))) ; 1443 b = IMAX(0, IMIN(16383, IMIN(remaining_bits+1,pulses[i]+curr_balance))) ;
1433 } else { 1444 } else {
1434 b = 0; 1445 b = 0;
1435 } 1446 }
1436 1447
1437 if (resynth && M*eBands[i]-N >= M*eBands[start] && (update_lowband || lowb and_offset==0)) 1448 if (resynth && M*eBands[i]-N >= M*eBands[start] && (update_lowband || lowb and_offset==0))
1438 lowband_offset = i; 1449 lowband_offset = i;
1439 1450
1440 tf_change = tf_res[i]; 1451 tf_change = tf_res[i];
1441 ctx.tf_change = tf_change; 1452 ctx.tf_change = tf_change;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 balance += pulses[i] + tell; 1520 balance += pulses[i] + tell;
1510 1521
1511 /* Update the folding position only as long as we have 1 bit/sample depth. */ 1522 /* Update the folding position only as long as we have 1 bit/sample depth. */
1512 update_lowband = b>(N<<BITRES); 1523 update_lowband = b>(N<<BITRES);
1513 } 1524 }
1514 *seed = ctx.seed; 1525 *seed = ctx.seed;
1515 1526
1516 RESTORE_STACK; 1527 RESTORE_STACK;
1517 } 1528 }
1518 1529
OLDNEW
« no previous file with comments | « celt/bands.h ('k') | celt/celt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698