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

Side by Side Diff: celt/celt_decoder.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/celt.c ('k') | celt/celt_encoder.c » ('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-2010 Xiph.Org Foundation 2 Copyright (c) 2007-2010 Xiph.Org Foundation
3 Copyright (c) 2008 Gregory Maxwell 3 Copyright (c) 2008 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "entcode.h" 44 #include "entcode.h"
45 #include "quant_bands.h" 45 #include "quant_bands.h"
46 #include "rate.h" 46 #include "rate.h"
47 #include "stack_alloc.h" 47 #include "stack_alloc.h"
48 #include "mathops.h" 48 #include "mathops.h"
49 #include "float_cast.h" 49 #include "float_cast.h"
50 #include <stdarg.h> 50 #include <stdarg.h>
51 #include "celt_lpc.h" 51 #include "celt_lpc.h"
52 #include "vq.h" 52 #include "vq.h"
53 53
54 #if defined(SMALL_FOOTPRINT) && defined(FIXED_POINT)
55 #define NORM_ALIASING_HACK
56 #endif
54 /**********************************************************************/ 57 /**********************************************************************/
55 /* */ 58 /* */
56 /* DECODER */ 59 /* DECODER */
57 /* */ 60 /* */
58 /**********************************************************************/ 61 /**********************************************************************/
59 #define DECODE_BUFFER_SIZE 2048 62 #define DECODE_BUFFER_SIZE 2048
60 63
61 /** Decoder state 64 /** Decoder state
62 @brief Decoder state 65 @brief Decoder state
63 */ 66 */
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return OPUS_OK; 171 return OPUS_OK;
169 } 172 }
170 173
171 #ifdef CUSTOM_MODES 174 #ifdef CUSTOM_MODES
172 void opus_custom_decoder_destroy(CELTDecoder *st) 175 void opus_custom_decoder_destroy(CELTDecoder *st)
173 { 176 {
174 opus_free(st); 177 opus_free(st);
175 } 178 }
176 #endif /* CUSTOM_MODES */ 179 #endif /* CUSTOM_MODES */
177 180
178 static OPUS_INLINE opus_val16 SIG2WORD16(celt_sig x)
179 {
180 #ifdef FIXED_POINT
181 x = PSHR32(x, SIG_SHIFT);
182 x = MAX32(x, -32768);
183 x = MIN32(x, 32767);
184 return EXTRACT16(x);
185 #else
186 return (opus_val16)x;
187 #endif
188 }
189 181
190 #ifndef RESYNTH 182 #ifndef RESYNTH
191 static 183 static
192 #endif 184 #endif
193 void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, c onst opus_val16 *coef, celt_sig *mem, celt_sig * OPUS_RESTRICT scratch) 185 void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, c onst opus_val16 *coef,
186 celt_sig *mem, int accum)
194 { 187 {
195 int c; 188 int c;
196 int Nd; 189 int Nd;
197 int apply_downsampling=0; 190 int apply_downsampling=0;
198 opus_val16 coef0; 191 opus_val16 coef0;
199 192 VARDECL(celt_sig, scratch);
193 SAVE_STACK;
194 #ifndef FIXED_POINT
195 (void)accum;
196 celt_assert(accum==0);
197 #endif
198 ALLOC(scratch, N, celt_sig);
200 coef0 = coef[0]; 199 coef0 = coef[0];
201 Nd = N/downsample; 200 Nd = N/downsample;
202 c=0; do { 201 c=0; do {
203 int j; 202 int j;
204 celt_sig * OPUS_RESTRICT x; 203 celt_sig * OPUS_RESTRICT x;
205 opus_val16 * OPUS_RESTRICT y; 204 opus_val16 * OPUS_RESTRICT y;
206 celt_sig m = mem[c]; 205 celt_sig m = mem[c];
207 x =in[c]; 206 x =in[c];
208 y = pcm+c; 207 y = pcm+c;
209 #ifdef CUSTOM_MODES 208 #ifdef CUSTOM_MODES
(...skipping 17 matching lines...) Expand all
227 /* Shortcut for the standard (non-custom modes) case */ 226 /* Shortcut for the standard (non-custom modes) case */
228 for (j=0;j<N;j++) 227 for (j=0;j<N;j++)
229 { 228 {
230 celt_sig tmp = x[j] + m + VERY_SMALL; 229 celt_sig tmp = x[j] + m + VERY_SMALL;
231 m = MULT16_32_Q15(coef0, tmp); 230 m = MULT16_32_Q15(coef0, tmp);
232 scratch[j] = tmp; 231 scratch[j] = tmp;
233 } 232 }
234 apply_downsampling=1; 233 apply_downsampling=1;
235 } else { 234 } else {
236 /* Shortcut for the standard (non-custom modes) case */ 235 /* Shortcut for the standard (non-custom modes) case */
237 for (j=0;j<N;j++) 236 #ifdef FIXED_POINT
237 if (accum)
238 { 238 {
239 celt_sig tmp = x[j] + m + VERY_SMALL; 239 for (j=0;j<N;j++)
240 m = MULT16_32_Q15(coef0, tmp); 240 {
241 y[j*C] = SCALEOUT(SIG2WORD16(tmp)); 241 celt_sig tmp = x[j] + m + VERY_SMALL;
242 m = MULT16_32_Q15(coef0, tmp);
243 y[j*C] = SAT16(ADD32(y[j*C], SCALEOUT(SIG2WORD16(tmp))));
244 }
245 } else
246 #endif
247 {
248 for (j=0;j<N;j++)
249 {
250 celt_sig tmp = x[j] + m + VERY_SMALL;
251 m = MULT16_32_Q15(coef0, tmp);
252 y[j*C] = SCALEOUT(SIG2WORD16(tmp));
253 }
242 } 254 }
243 } 255 }
244 mem[c] = m; 256 mem[c] = m;
245 257
246 if (apply_downsampling) 258 if (apply_downsampling)
247 { 259 {
248 /* Perform down-sampling */ 260 /* Perform down-sampling */
249 for (j=0;j<Nd;j++) 261 #ifdef FIXED_POINT
250 y[j*C] = SCALEOUT(SIG2WORD16(scratch[j*downsample])); 262 if (accum)
263 {
264 for (j=0;j<Nd;j++)
265 y[j*C] = SAT16(ADD32(y[j*C], SCALEOUT(SIG2WORD16(scratch[j*downsa mple]))));
266 } else
267 #endif
268 {
269 for (j=0;j<Nd;j++)
270 y[j*C] = SCALEOUT(SIG2WORD16(scratch[j*downsample]));
271 }
251 } 272 }
252 } while (++c<C); 273 } while (++c<C);
274 RESTORE_STACK;
253 } 275 }
254 276
255 /** Compute the IMDCT and apply window for all sub-frames and
256 all channels in a frame */
257 #ifndef RESYNTH 277 #ifndef RESYNTH
258 static 278 static
259 #endif 279 #endif
260 void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X, 280 void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[],
261 celt_sig * OPUS_RESTRICT out_mem[], int C, int LM) 281 opus_val16 *oldBandE, int start, int effEnd, int C, int CC, int isTransien t,
282 int LM, int downsample, int silence)
262 { 283 {
263 int b, c; 284 int c, i;
285 int M;
286 int b;
264 int B; 287 int B;
265 int N; 288 int N, NB;
266 int shift; 289 int shift;
267 const int overlap = OVERLAP(mode); 290 int nbEBands;
291 int overlap;
292 VARDECL(celt_sig, freq);
293 SAVE_STACK;
268 294
269 if (shortBlocks) 295 overlap = mode->overlap;
296 nbEBands = mode->nbEBands;
297 N = mode->shortMdctSize<<LM;
298 ALLOC(freq, N, celt_sig); /**< Interleaved signal MDCTs */
299 M = 1<<LM;
300
301 if (isTransient)
270 { 302 {
271 B = shortBlocks; 303 B = M;
272 N = mode->shortMdctSize; 304 NB = mode->shortMdctSize;
273 shift = mode->maxLM; 305 shift = mode->maxLM;
274 } else { 306 } else {
275 B = 1; 307 B = 1;
276 N = mode->shortMdctSize<<LM; 308 NB = mode->shortMdctSize<<LM;
277 shift = mode->maxLM-LM; 309 shift = mode->maxLM-LM;
278 } 310 }
279 c=0; do { 311
280 /* IMDCT on the interleaved the sub-frames, overlap-add is performed by th e IMDCT */ 312 if (CC==2&&C==1)
313 {
314 /* Copying a mono streams to two channels */
315 celt_sig *freq2;
316 denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M,
317 downsample, silence);
318 /* Store a temporary copy in the output buffer because the IMDCT destroys its input. */
319 freq2 = out_syn[1]+overlap/2;
320 OPUS_COPY(freq2, freq, N);
281 for (b=0;b<B;b++) 321 for (b=0;b<B;b++)
282 clt_mdct_backward(&mode->mdct, &X[b+c*N*B], out_mem[c]+N*b, mode->windo w, overlap, shift, B); 322 clt_mdct_backward(&mode->mdct, &freq2[b], out_syn[0]+NB*b, mode->window , overlap, shift, B);
283 } while (++c<C); 323 for (b=0;b<B;b++)
324 clt_mdct_backward(&mode->mdct, &freq[b], out_syn[1]+NB*b, mode->window, overlap, shift, B);
325 } else if (CC==1&&C==2)
326 {
327 /* Downmixing a stereo stream to mono */
328 celt_sig *freq2;
329 freq2 = out_syn[0]+overlap/2;
330 denormalise_bands(mode, X, freq, oldBandE, start, effEnd, M,
331 downsample, silence);
332 /* Use the output buffer as temp array before downmixing. */
333 denormalise_bands(mode, X+N, freq2, oldBandE+nbEBands, start, effEnd, M,
334 downsample, silence);
335 for (i=0;i<N;i++)
336 freq[i] = HALF32(ADD32(freq[i],freq2[i]));
337 for (b=0;b<B;b++)
338 clt_mdct_backward(&mode->mdct, &freq[b], out_syn[0]+NB*b, mode->window, overlap, shift, B);
339 } else {
340 /* Normal case (mono or stereo) */
341 c=0; do {
342 denormalise_bands(mode, X+c*N, freq, oldBandE+c*nbEBands, start, effEnd , M,
343 downsample, silence);
344 for (b=0;b<B;b++)
345 clt_mdct_backward(&mode->mdct, &freq[b], out_syn[c]+NB*b, mode->wind ow, overlap, shift, B);
346 } while (++c<CC);
347 }
348 RESTORE_STACK;
284 } 349 }
285 350
286 static void tf_decode(int start, int end, int isTransient, int *tf_res, int LM, ec_dec *dec) 351 static void tf_decode(int start, int end, int isTransient, int *tf_res, int LM, ec_dec *dec)
287 { 352 {
288 int i, curr, tf_select; 353 int i, curr, tf_select;
289 int tf_select_rsv; 354 int tf_select_rsv;
290 int tf_changed; 355 int tf_changed;
291 int logp; 356 int logp;
292 opus_uint32 budget; 357 opus_uint32 budget;
293 opus_uint32 tell; 358 opus_uint32 tell;
(...skipping 29 matching lines...) Expand all
323 } 388 }
324 389
325 /* The maximum pitch lag to allow in the pitch-based PLC. It's possible to save 390 /* The maximum pitch lag to allow in the pitch-based PLC. It's possible to save
326 CPU time in the PLC pitch search by making this smaller than MAX_PERIOD. The 391 CPU time in the PLC pitch search by making this smaller than MAX_PERIOD. The
327 current value corresponds to a pitch of 66.67 Hz. */ 392 current value corresponds to a pitch of 66.67 Hz. */
328 #define PLC_PITCH_LAG_MAX (720) 393 #define PLC_PITCH_LAG_MAX (720)
329 /* The minimum pitch lag to allow in the pitch-based PLC. This corresponds to a 394 /* The minimum pitch lag to allow in the pitch-based PLC. This corresponds to a
330 pitch of 480 Hz. */ 395 pitch of 480 Hz. */
331 #define PLC_PITCH_LAG_MIN (100) 396 #define PLC_PITCH_LAG_MIN (100)
332 397
333 static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R ESTRICT pcm, int N, int LM) 398 static int celt_plc_pitch_search(celt_sig *decode_mem[2], int C, int arch)
399 {
400 int pitch_index;
401 VARDECL( opus_val16, lp_pitch_buf );
402 SAVE_STACK;
403 ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 );
404 pitch_downsample(decode_mem, lp_pitch_buf,
405 DECODE_BUFFER_SIZE, C, arch);
406 pitch_search(lp_pitch_buf+(PLC_PITCH_LAG_MAX>>1), lp_pitch_buf,
407 DECODE_BUFFER_SIZE-PLC_PITCH_LAG_MAX,
408 PLC_PITCH_LAG_MAX-PLC_PITCH_LAG_MIN, &pitch_index, arch);
409 pitch_index = PLC_PITCH_LAG_MAX-pitch_index;
410 RESTORE_STACK;
411 return pitch_index;
412 }
413
414 static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, int N, int LM)
334 { 415 {
335 int c; 416 int c;
336 int i; 417 int i;
337 const int C = st->channels; 418 const int C = st->channels;
338 celt_sig *decode_mem[2]; 419 celt_sig *decode_mem[2];
339 celt_sig *out_syn[2]; 420 celt_sig *out_syn[2];
340 opus_val16 *lpc; 421 opus_val16 *lpc;
341 opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE; 422 opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
342 const OpusCustomMode *mode; 423 const OpusCustomMode *mode;
343 int nbEBands; 424 int nbEBands;
344 int overlap; 425 int overlap;
345 int start; 426 int start;
346 int downsample;
347 int loss_count; 427 int loss_count;
348 int noise_based; 428 int noise_based;
349 const opus_int16 *eBands; 429 const opus_int16 *eBands;
350 VARDECL(celt_sig, scratch);
351 SAVE_STACK; 430 SAVE_STACK;
352 431
353 mode = st->mode; 432 mode = st->mode;
354 nbEBands = mode->nbEBands; 433 nbEBands = mode->nbEBands;
355 overlap = mode->overlap; 434 overlap = mode->overlap;
356 eBands = mode->eBands; 435 eBands = mode->eBands;
357 436
358 c=0; do { 437 c=0; do {
359 decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+overlap); 438 decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+overlap);
360 out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N; 439 out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N;
361 } while (++c<C); 440 } while (++c<C);
362 lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+overlap)*C); 441 lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+overlap)*C);
363 oldBandE = lpc+C*LPC_ORDER; 442 oldBandE = lpc+C*LPC_ORDER;
364 oldLogE = oldBandE + 2*nbEBands; 443 oldLogE = oldBandE + 2*nbEBands;
365 oldLogE2 = oldLogE + 2*nbEBands; 444 oldLogE2 = oldLogE + 2*nbEBands;
366 backgroundLogE = oldLogE2 + 2*nbEBands; 445 backgroundLogE = oldLogE2 + 2*nbEBands;
367 446
368 loss_count = st->loss_count; 447 loss_count = st->loss_count;
369 start = st->start; 448 start = st->start;
370 downsample = st->downsample;
371 noise_based = loss_count >= 5 || start != 0; 449 noise_based = loss_count >= 5 || start != 0;
372 ALLOC(scratch, noise_based?N*C:N, celt_sig);
373 if (noise_based) 450 if (noise_based)
374 { 451 {
375 /* Noise-based PLC/CNG */ 452 /* Noise-based PLC/CNG */
376 celt_sig *freq; 453 #ifdef NORM_ALIASING_HACK
454 celt_norm *X;
455 #else
377 VARDECL(celt_norm, X); 456 VARDECL(celt_norm, X);
457 #endif
378 opus_uint32 seed; 458 opus_uint32 seed;
379 opus_val16 *plcLogE; 459 opus_val16 *plcLogE;
380 int end; 460 int end;
381 int effEnd; 461 int effEnd;
382 462
383 end = st->end; 463 end = st->end;
384 effEnd = IMAX(start, IMIN(end, mode->effEBands)); 464 effEnd = IMAX(start, IMIN(end, mode->effEBands));
385 465
386 /* Share the interleaved signal MDCT coefficient buffer with the 466 #ifdef NORM_ALIASING_HACK
387 deemphasis scratch buffer. */ 467 /* This is an ugly hack that breaks aliasing rules and would be easily bro ken,
388 freq = scratch; 468 but it saves almost 4kB of stack. */
469 X = (celt_norm*)(out_syn[C-1]+overlap/2);
470 #else
389 ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ 471 ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */
472 #endif
390 473
391 if (loss_count >= 5) 474 if (loss_count >= 5)
392 plcLogE = backgroundLogE; 475 plcLogE = backgroundLogE;
393 else { 476 else {
394 /* Energy decay */ 477 /* Energy decay */
395 opus_val16 decay = loss_count==0 ? 478 opus_val16 decay = loss_count==0 ?
396 QCONST16(1.5f, DB_SHIFT) : QCONST16(.5f, DB_SHIFT); 479 QCONST16(1.5f, DB_SHIFT) : QCONST16(.5f, DB_SHIFT);
397 c=0; do 480 c=0; do
398 { 481 {
399 for (i=start;i<end;i++) 482 for (i=start;i<end;i++)
400 oldBandE[c*nbEBands+i] -= decay; 483 oldBandE[c*nbEBands+i] -= decay;
401 } while (++c<C); 484 } while (++c<C);
402 plcLogE = oldBandE; 485 plcLogE = oldBandE;
403 } 486 }
404 seed = st->rng; 487 seed = st->rng;
405 for (c=0;c<C;c++) 488 for (c=0;c<C;c++)
406 { 489 {
407 for (i=start;i<effEnd;i++) 490 for (i=start;i<effEnd;i++)
408 { 491 {
409 int j; 492 int j;
410 int boffs; 493 int boffs;
411 int blen; 494 int blen;
412 boffs = N*c+(eBands[i]<<LM); 495 boffs = N*c+(eBands[i]<<LM);
413 blen = (eBands[i+1]-eBands[i])<<LM; 496 blen = (eBands[i+1]-eBands[i])<<LM;
414 for (j=0;j<blen;j++) 497 for (j=0;j<blen;j++)
415 { 498 {
416 seed = celt_lcg_rand(seed); 499 seed = celt_lcg_rand(seed);
417 X[boffs+j] = (celt_norm)((opus_int32)seed>>20); 500 X[boffs+j] = (celt_norm)((opus_int32)seed>>20);
418 } 501 }
419 renormalise_vector(X+boffs, blen, Q15ONE); 502 renormalise_vector(X+boffs, blen, Q15ONE, st->arch);
420 } 503 }
421 } 504 }
422 st->rng = seed; 505 st->rng = seed;
423 506
424 denormalise_bands(mode, X, freq, plcLogE, start, effEnd, C, 1<<LM);
425
426 c=0; do {
427 int bound = eBands[effEnd]<<LM;
428 if (downsample!=1)
429 bound = IMIN(bound, N/downsample);
430 for (i=bound;i<N;i++)
431 freq[c*N+i] = 0;
432 } while (++c<C);
433 c=0; do { 507 c=0; do {
434 OPUS_MOVE(decode_mem[c], decode_mem[c]+N, 508 OPUS_MOVE(decode_mem[c], decode_mem[c]+N,
435 DECODE_BUFFER_SIZE-N+(overlap>>1)); 509 DECODE_BUFFER_SIZE-N+(overlap>>1));
436 } while (++c<C); 510 } while (++c<C);
437 compute_inv_mdcts(mode, 0, freq, out_syn, C, LM); 511
512 celt_synthesis(mode, X, out_syn, plcLogE, start, effEnd, C, C, 0, LM, st-> downsample, 0);
438 } else { 513 } else {
439 /* Pitch-based PLC */ 514 /* Pitch-based PLC */
440 const opus_val16 *window; 515 const opus_val16 *window;
441 opus_val16 fade = Q15ONE; 516 opus_val16 fade = Q15ONE;
442 int pitch_index; 517 int pitch_index;
443 VARDECL(opus_val32, etmp); 518 VARDECL(opus_val32, etmp);
444 VARDECL(opus_val16, exc); 519 VARDECL(opus_val16, exc);
445 520
446 if (loss_count == 0) 521 if (loss_count == 0)
447 { 522 {
448 VARDECL( opus_val16, lp_pitch_buf ); 523 st->last_pitch_index = pitch_index = celt_plc_pitch_search(decode_mem, C, st->arch);
449 ALLOC( lp_pitch_buf, DECODE_BUFFER_SIZE>>1, opus_val16 );
450 pitch_downsample(decode_mem, lp_pitch_buf,
451 DECODE_BUFFER_SIZE, C, st->arch);
452 pitch_search(lp_pitch_buf+(PLC_PITCH_LAG_MAX>>1), lp_pitch_buf,
453 DECODE_BUFFER_SIZE-PLC_PITCH_LAG_MAX,
454 PLC_PITCH_LAG_MAX-PLC_PITCH_LAG_MIN, &pitch_index, st->arch);
455 pitch_index = PLC_PITCH_LAG_MAX-pitch_index;
456 st->last_pitch_index = pitch_index;
457 } else { 524 } else {
458 pitch_index = st->last_pitch_index; 525 pitch_index = st->last_pitch_index;
459 fade = QCONST16(.8f,15); 526 fade = QCONST16(.8f,15);
460 } 527 }
461 528
462 ALLOC(etmp, overlap, opus_val32); 529 ALLOC(etmp, overlap, opus_val32);
463 ALLOC(exc, MAX_PERIOD, opus_val16); 530 ALLOC(exc, MAX_PERIOD, opus_val16);
464 window = mode->window; 531 window = mode->window;
465 c=0; do { 532 c=0; do {
466 opus_val16 decay; 533 opus_val16 decay;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 of the region for which we're computing the excitation. */ 576 of the region for which we're computing the excitation. */
510 { 577 {
511 opus_val16 lpc_mem[LPC_ORDER]; 578 opus_val16 lpc_mem[LPC_ORDER];
512 for (i=0;i<LPC_ORDER;i++) 579 for (i=0;i<LPC_ORDER;i++)
513 { 580 {
514 lpc_mem[i] = 581 lpc_mem[i] =
515 ROUND16(buf[DECODE_BUFFER_SIZE-exc_length-1-i], SIG_SHIFT); 582 ROUND16(buf[DECODE_BUFFER_SIZE-exc_length-1-i], SIG_SHIFT);
516 } 583 }
517 /* Compute the excitation for exc_length samples before the loss. */ 584 /* Compute the excitation for exc_length samples before the loss. */
518 celt_fir(exc+MAX_PERIOD-exc_length, lpc+c*LPC_ORDER, 585 celt_fir(exc+MAX_PERIOD-exc_length, lpc+c*LPC_ORDER,
519 exc+MAX_PERIOD-exc_length, exc_length, LPC_ORDER, lpc_mem); 586 exc+MAX_PERIOD-exc_length, exc_length, LPC_ORDER, lpc_mem, st- >arch);
520 } 587 }
521 588
522 /* Check if the waveform is decaying, and if so how fast. 589 /* Check if the waveform is decaying, and if so how fast.
523 We do this to avoid adding energy when concealing in a segment 590 We do this to avoid adding energy when concealing in a segment
524 with decaying energy. */ 591 with decaying energy. */
525 { 592 {
526 opus_val32 E1=1, E2=1; 593 opus_val32 E1=1, E2=1;
527 int decay_length; 594 int decay_length;
528 #ifdef FIXED_POINT 595 #ifdef FIXED_POINT
529 int shift = IMAX(0,2*celt_zlog2(celt_maxabs16(&exc[MAX_PERIOD-exc_le ngth], exc_length))-20); 596 int shift = IMAX(0,2*celt_zlog2(celt_maxabs16(&exc[MAX_PERIOD-exc_le ngth], exc_length))-20);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 { 643 {
577 opus_val16 lpc_mem[LPC_ORDER]; 644 opus_val16 lpc_mem[LPC_ORDER];
578 /* Copy the last decoded samples (prior to the overlap region) to 645 /* Copy the last decoded samples (prior to the overlap region) to
579 synthesis filter memory so we can have a continuous signal. */ 646 synthesis filter memory so we can have a continuous signal. */
580 for (i=0;i<LPC_ORDER;i++) 647 for (i=0;i<LPC_ORDER;i++)
581 lpc_mem[i] = ROUND16(buf[DECODE_BUFFER_SIZE-N-1-i], SIG_SHIFT); 648 lpc_mem[i] = ROUND16(buf[DECODE_BUFFER_SIZE-N-1-i], SIG_SHIFT);
582 /* Apply the synthesis filter to convert the excitation back into 649 /* Apply the synthesis filter to convert the excitation back into
583 the signal domain. */ 650 the signal domain. */
584 celt_iir(buf+DECODE_BUFFER_SIZE-N, lpc+c*LPC_ORDER, 651 celt_iir(buf+DECODE_BUFFER_SIZE-N, lpc+c*LPC_ORDER,
585 buf+DECODE_BUFFER_SIZE-N, extrapolation_len, LPC_ORDER, 652 buf+DECODE_BUFFER_SIZE-N, extrapolation_len, LPC_ORDER,
586 lpc_mem); 653 lpc_mem, st->arch);
587 } 654 }
588 655
589 /* Check if the synthesis energy is higher than expected, which can 656 /* Check if the synthesis energy is higher than expected, which can
590 happen with the signal changes during our window. If so, 657 happen with the signal changes during our window. If so,
591 attenuate. */ 658 attenuate. */
592 { 659 {
593 opus_val32 S2=0; 660 opus_val32 S2=0;
594 for (i=0;i<extrapolation_len;i++) 661 for (i=0;i<extrapolation_len;i++)
595 { 662 {
596 opus_val16 tmp = ROUND16(buf[DECODE_BUFFER_SIZE-N+i], SIG_SHIFT); 663 opus_val16 tmp = ROUND16(buf[DECODE_BUFFER_SIZE-N+i], SIG_SHIFT);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 MDCT of the next frame. */ 704 MDCT of the next frame. */
638 for (i=0;i<overlap/2;i++) 705 for (i=0;i<overlap/2;i++)
639 { 706 {
640 buf[DECODE_BUFFER_SIZE+i] = 707 buf[DECODE_BUFFER_SIZE+i] =
641 MULT16_32_Q15(window[i], etmp[overlap-1-i]) 708 MULT16_32_Q15(window[i], etmp[overlap-1-i])
642 + MULT16_32_Q15(window[overlap-i-1], etmp[i]); 709 + MULT16_32_Q15(window[overlap-i-1], etmp[i]);
643 } 710 }
644 } while (++c<C); 711 } while (++c<C);
645 } 712 }
646 713
647 deemphasis(out_syn, pcm, N, C, downsample,
648 mode->preemph, st->preemph_memD, scratch);
649
650 st->loss_count = loss_count+1; 714 st->loss_count = loss_count+1;
651 715
652 RESTORE_STACK; 716 RESTORE_STACK;
653 } 717 }
654 718
655 int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat a, int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec) 719 int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat a,
720 int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum)
656 { 721 {
657 int c, i, N; 722 int c, i, N;
658 int spread_decision; 723 int spread_decision;
659 opus_int32 bits; 724 opus_int32 bits;
660 ec_dec _dec; 725 ec_dec _dec;
661 VARDECL(celt_sig, freq); 726 #ifdef NORM_ALIASING_HACK
727 celt_norm *X;
728 #else
662 VARDECL(celt_norm, X); 729 VARDECL(celt_norm, X);
730 #endif
663 VARDECL(int, fine_quant); 731 VARDECL(int, fine_quant);
664 VARDECL(int, pulses); 732 VARDECL(int, pulses);
665 VARDECL(int, cap); 733 VARDECL(int, cap);
666 VARDECL(int, offsets); 734 VARDECL(int, offsets);
667 VARDECL(int, fine_priority); 735 VARDECL(int, fine_priority);
668 VARDECL(int, tf_res); 736 VARDECL(int, tf_res);
669 VARDECL(unsigned char, collapse_masks); 737 VARDECL(unsigned char, collapse_masks);
670 celt_sig *decode_mem[2]; 738 celt_sig *decode_mem[2];
671 celt_sig *out_syn[2]; 739 celt_sig *out_syn[2];
672 opus_val16 *lpc; 740 opus_val16 *lpc;
673 opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE; 741 opus_val16 *oldBandE, *oldLogE, *oldLogE2, *backgroundLogE;
674 742
675 int shortBlocks; 743 int shortBlocks;
676 int isTransient; 744 int isTransient;
677 int intra_ener; 745 int intra_ener;
678 const int CC = st->channels; 746 const int CC = st->channels;
679 int LM, M; 747 int LM, M;
748 int start;
749 int end;
680 int effEnd; 750 int effEnd;
681 int codedBands; 751 int codedBands;
682 int alloc_trim; 752 int alloc_trim;
683 int postfilter_pitch; 753 int postfilter_pitch;
684 opus_val16 postfilter_gain; 754 opus_val16 postfilter_gain;
685 int intensity=0; 755 int intensity=0;
686 int dual_stereo=0; 756 int dual_stereo=0;
687 opus_int32 total_bits; 757 opus_int32 total_bits;
688 opus_int32 balance; 758 opus_int32 balance;
689 opus_int32 tell; 759 opus_int32 tell;
690 int dynalloc_logp; 760 int dynalloc_logp;
691 int postfilter_tapset; 761 int postfilter_tapset;
692 int anti_collapse_rsv; 762 int anti_collapse_rsv;
693 int anti_collapse_on=0; 763 int anti_collapse_on=0;
694 int silence; 764 int silence;
695 int C = st->stream_channels; 765 int C = st->stream_channels;
696 const OpusCustomMode *mode; 766 const OpusCustomMode *mode;
697 int nbEBands; 767 int nbEBands;
698 int overlap; 768 int overlap;
699 const opus_int16 *eBands; 769 const opus_int16 *eBands;
700 ALLOC_STACK; 770 ALLOC_STACK;
701 771
702 mode = st->mode; 772 mode = st->mode;
703 nbEBands = mode->nbEBands; 773 nbEBands = mode->nbEBands;
704 overlap = mode->overlap; 774 overlap = mode->overlap;
705 eBands = mode->eBands; 775 eBands = mode->eBands;
776 start = st->start;
777 end = st->end;
706 frame_size *= st->downsample; 778 frame_size *= st->downsample;
707 779
708 c=0; do {
709 decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+overlap);
710 } while (++c<CC);
711 lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+overlap)*CC); 780 lpc = (opus_val16*)(st->_decode_mem+(DECODE_BUFFER_SIZE+overlap)*CC);
712 oldBandE = lpc+CC*LPC_ORDER; 781 oldBandE = lpc+CC*LPC_ORDER;
713 oldLogE = oldBandE + 2*nbEBands; 782 oldLogE = oldBandE + 2*nbEBands;
714 oldLogE2 = oldLogE + 2*nbEBands; 783 oldLogE2 = oldLogE + 2*nbEBands;
715 backgroundLogE = oldLogE2 + 2*nbEBands; 784 backgroundLogE = oldLogE2 + 2*nbEBands;
716 785
717 #ifdef CUSTOM_MODES 786 #ifdef CUSTOM_MODES
718 if (st->signalling && data!=NULL) 787 if (st->signalling && data!=NULL)
719 { 788 {
720 int data0=data[0]; 789 int data0=data[0];
721 /* Convert "standard mode" to Opus header */ 790 /* Convert "standard mode" to Opus header */
722 if (mode->Fs==48000 && mode->shortMdctSize==120) 791 if (mode->Fs==48000 && mode->shortMdctSize==120)
723 { 792 {
724 data0 = fromOpus(data0); 793 data0 = fromOpus(data0);
725 if (data0<0) 794 if (data0<0)
726 return OPUS_INVALID_PACKET; 795 return OPUS_INVALID_PACKET;
727 } 796 }
728 st->end = IMAX(1, mode->effEBands-2*(data0>>5)); 797 st->end = end = IMAX(1, mode->effEBands-2*(data0>>5));
729 LM = (data0>>3)&0x3; 798 LM = (data0>>3)&0x3;
730 C = 1 + ((data0>>2)&0x1); 799 C = 1 + ((data0>>2)&0x1);
731 data++; 800 data++;
732 len--; 801 len--;
733 if (LM>mode->maxLM) 802 if (LM>mode->maxLM)
734 return OPUS_INVALID_PACKET; 803 return OPUS_INVALID_PACKET;
735 if (frame_size < mode->shortMdctSize<<LM) 804 if (frame_size < mode->shortMdctSize<<LM)
736 return OPUS_BUFFER_TOO_SMALL; 805 return OPUS_BUFFER_TOO_SMALL;
737 else 806 else
738 frame_size = mode->shortMdctSize<<LM; 807 frame_size = mode->shortMdctSize<<LM;
739 } else { 808 } else {
740 #else 809 #else
741 { 810 {
742 #endif 811 #endif
743 for (LM=0;LM<=mode->maxLM;LM++) 812 for (LM=0;LM<=mode->maxLM;LM++)
744 if (mode->shortMdctSize<<LM==frame_size) 813 if (mode->shortMdctSize<<LM==frame_size)
745 break; 814 break;
746 if (LM>mode->maxLM) 815 if (LM>mode->maxLM)
747 return OPUS_BAD_ARG; 816 return OPUS_BAD_ARG;
748 } 817 }
749 M=1<<LM; 818 M=1<<LM;
750 819
751 if (len<0 || len>1275 || pcm==NULL) 820 if (len<0 || len>1275 || pcm==NULL)
752 return OPUS_BAD_ARG; 821 return OPUS_BAD_ARG;
753 822
754 N = M*mode->shortMdctSize; 823 N = M*mode->shortMdctSize;
824 c=0; do {
825 decode_mem[c] = st->_decode_mem + c*(DECODE_BUFFER_SIZE+overlap);
826 out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N;
827 } while (++c<CC);
755 828
756 effEnd = st->end; 829 effEnd = end;
757 if (effEnd > mode->effEBands) 830 if (effEnd > mode->effEBands)
758 effEnd = mode->effEBands; 831 effEnd = mode->effEBands;
759 832
760 if (data == NULL || len<=1) 833 if (data == NULL || len<=1)
761 { 834 {
762 celt_decode_lost(st, pcm, N, LM); 835 celt_decode_lost(st, N, LM);
836 deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph _memD, accum);
763 RESTORE_STACK; 837 RESTORE_STACK;
764 return frame_size/st->downsample; 838 return frame_size/st->downsample;
765 } 839 }
766 840
767 if (dec == NULL) 841 if (dec == NULL)
768 { 842 {
769 ec_dec_init(&_dec,(unsigned char*)data,len); 843 ec_dec_init(&_dec,(unsigned char*)data,len);
770 dec = &_dec; 844 dec = &_dec;
771 } 845 }
772 846
(...skipping 15 matching lines...) Expand all
788 if (silence) 862 if (silence)
789 { 863 {
790 /* Pretend we've read all the remaining bits */ 864 /* Pretend we've read all the remaining bits */
791 tell = len*8; 865 tell = len*8;
792 dec->nbits_total+=tell-ec_tell(dec); 866 dec->nbits_total+=tell-ec_tell(dec);
793 } 867 }
794 868
795 postfilter_gain = 0; 869 postfilter_gain = 0;
796 postfilter_pitch = 0; 870 postfilter_pitch = 0;
797 postfilter_tapset = 0; 871 postfilter_tapset = 0;
798 if (st->start==0 && tell+16 <= total_bits) 872 if (start==0 && tell+16 <= total_bits)
799 { 873 {
800 if(ec_dec_bit_logp(dec, 1)) 874 if(ec_dec_bit_logp(dec, 1))
801 { 875 {
802 int qg, octave; 876 int qg, octave;
803 octave = ec_dec_uint(dec, 6); 877 octave = ec_dec_uint(dec, 6);
804 postfilter_pitch = (16<<octave)+ec_dec_bits(dec, 4+octave)-1; 878 postfilter_pitch = (16<<octave)+ec_dec_bits(dec, 4+octave)-1;
805 qg = ec_dec_bits(dec, 3); 879 qg = ec_dec_bits(dec, 3);
806 if (ec_tell(dec)+2<=total_bits) 880 if (ec_tell(dec)+2<=total_bits)
807 postfilter_tapset = ec_dec_icdf(dec, tapset_icdf, 2); 881 postfilter_tapset = ec_dec_icdf(dec, tapset_icdf, 2);
808 postfilter_gain = QCONST16(.09375f,15)*(qg+1); 882 postfilter_gain = QCONST16(.09375f,15)*(qg+1);
(...skipping 10 matching lines...) Expand all
819 isTransient = 0; 893 isTransient = 0;
820 894
821 if (isTransient) 895 if (isTransient)
822 shortBlocks = M; 896 shortBlocks = M;
823 else 897 else
824 shortBlocks = 0; 898 shortBlocks = 0;
825 899
826 /* Decode the global flags (first symbols in the stream) */ 900 /* Decode the global flags (first symbols in the stream) */
827 intra_ener = tell+3<=total_bits ? ec_dec_bit_logp(dec, 3) : 0; 901 intra_ener = tell+3<=total_bits ? ec_dec_bit_logp(dec, 3) : 0;
828 /* Get band energies */ 902 /* Get band energies */
829 unquant_coarse_energy(mode, st->start, st->end, oldBandE, 903 unquant_coarse_energy(mode, start, end, oldBandE,
830 intra_ener, dec, C, LM); 904 intra_ener, dec, C, LM);
831 905
832 ALLOC(tf_res, nbEBands, int); 906 ALLOC(tf_res, nbEBands, int);
833 tf_decode(st->start, st->end, isTransient, tf_res, LM, dec); 907 tf_decode(start, end, isTransient, tf_res, LM, dec);
834 908
835 tell = ec_tell(dec); 909 tell = ec_tell(dec);
836 spread_decision = SPREAD_NORMAL; 910 spread_decision = SPREAD_NORMAL;
837 if (tell+4 <= total_bits) 911 if (tell+4 <= total_bits)
838 spread_decision = ec_dec_icdf(dec, spread_icdf, 5); 912 spread_decision = ec_dec_icdf(dec, spread_icdf, 5);
839 913
840 ALLOC(cap, nbEBands, int); 914 ALLOC(cap, nbEBands, int);
841 915
842 init_caps(mode,cap,LM,C); 916 init_caps(mode,cap,LM,C);
843 917
844 ALLOC(offsets, nbEBands, int); 918 ALLOC(offsets, nbEBands, int);
845 919
846 dynalloc_logp = 6; 920 dynalloc_logp = 6;
847 total_bits<<=BITRES; 921 total_bits<<=BITRES;
848 tell = ec_tell_frac(dec); 922 tell = ec_tell_frac(dec);
849 for (i=st->start;i<st->end;i++) 923 for (i=start;i<end;i++)
850 { 924 {
851 int width, quanta; 925 int width, quanta;
852 int dynalloc_loop_logp; 926 int dynalloc_loop_logp;
853 int boost; 927 int boost;
854 width = C*(eBands[i+1]-eBands[i])<<LM; 928 width = C*(eBands[i+1]-eBands[i])<<LM;
855 /* quanta is 6 bits, but no more than 1 bit/sample 929 /* quanta is 6 bits, but no more than 1 bit/sample
856 and no less than 1/8 bit/sample */ 930 and no less than 1/8 bit/sample */
857 quanta = IMIN(width<<BITRES, IMAX(6<<BITRES, width)); 931 quanta = IMIN(width<<BITRES, IMAX(6<<BITRES, width));
858 dynalloc_loop_logp = dynalloc_logp; 932 dynalloc_loop_logp = dynalloc_logp;
859 boost = 0; 933 boost = 0;
(...skipping 18 matching lines...) Expand all
878 alloc_trim = tell+(6<<BITRES) <= total_bits ? 952 alloc_trim = tell+(6<<BITRES) <= total_bits ?
879 ec_dec_icdf(dec, trim_icdf, 7) : 5; 953 ec_dec_icdf(dec, trim_icdf, 7) : 5;
880 954
881 bits = (((opus_int32)len*8)<<BITRES) - ec_tell_frac(dec) - 1; 955 bits = (((opus_int32)len*8)<<BITRES) - ec_tell_frac(dec) - 1;
882 anti_collapse_rsv = isTransient&&LM>=2&&bits>=((LM+2)<<BITRES) ? (1<<BITRES) : 0; 956 anti_collapse_rsv = isTransient&&LM>=2&&bits>=((LM+2)<<BITRES) ? (1<<BITRES) : 0;
883 bits -= anti_collapse_rsv; 957 bits -= anti_collapse_rsv;
884 958
885 ALLOC(pulses, nbEBands, int); 959 ALLOC(pulses, nbEBands, int);
886 ALLOC(fine_priority, nbEBands, int); 960 ALLOC(fine_priority, nbEBands, int);
887 961
888 codedBands = compute_allocation(mode, st->start, st->end, offsets, cap, 962 codedBands = compute_allocation(mode, start, end, offsets, cap,
889 alloc_trim, &intensity, &dual_stereo, bits, &balance, pulses, 963 alloc_trim, &intensity, &dual_stereo, bits, &balance, pulses,
890 fine_quant, fine_priority, C, LM, dec, 0, 0, 0); 964 fine_quant, fine_priority, C, LM, dec, 0, 0, 0);
891 965
892 unquant_fine_energy(mode, st->start, st->end, oldBandE, fine_quant, dec, C); 966 unquant_fine_energy(mode, start, end, oldBandE, fine_quant, dec, C);
967
968 c=0; do {
969 OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2);
970 } while (++c<CC);
893 971
894 /* Decode fixed codebook */ 972 /* Decode fixed codebook */
895 ALLOC(collapse_masks, C*nbEBands, unsigned char); 973 ALLOC(collapse_masks, C*nbEBands, unsigned char);
974
975 #ifdef NORM_ALIASING_HACK
976 /* This is an ugly hack that breaks aliasing rules and would be easily broken ,
977 but it saves almost 4kB of stack. */
978 X = (celt_norm*)(out_syn[CC-1]+overlap/2);
979 #else
896 ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */ 980 ALLOC(X, C*N, celt_norm); /**< Interleaved normalised MDCTs */
981 #endif
897 982
898 quant_all_bands(0, mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_m asks, 983 quant_all_bands(0, mode, start, end, X, C==2 ? X+N : NULL, collapse_masks,
899 NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_ res, 984 NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_ res,
900 len*(8<<BITRES)-anti_collapse_rsv, balance, dec, LM, codedBands, &st->r ng); 985 len*(8<<BITRES)-anti_collapse_rsv, balance, dec, LM, codedBands, &st->r ng, st->arch);
901 986
902 if (anti_collapse_rsv > 0) 987 if (anti_collapse_rsv > 0)
903 { 988 {
904 anti_collapse_on = ec_dec_bits(dec, 1); 989 anti_collapse_on = ec_dec_bits(dec, 1);
905 } 990 }
906 991
907 unquant_energy_finalise(mode, st->start, st->end, oldBandE, 992 unquant_energy_finalise(mode, start, end, oldBandE,
908 fine_quant, fine_priority, len*8-ec_tell(dec), dec, C); 993 fine_quant, fine_priority, len*8-ec_tell(dec), dec, C);
909 994
910 if (anti_collapse_on) 995 if (anti_collapse_on)
911 anti_collapse(mode, X, collapse_masks, LM, C, N, 996 anti_collapse(mode, X, collapse_masks, LM, C, N,
912 st->start, st->end, oldBandE, oldLogE, oldLogE2, pulses, st->rng); 997 start, end, oldBandE, oldLogE, oldLogE2, pulses, st->rng, st->arch);
913
914 ALLOC(freq, IMAX(CC,C)*N, celt_sig); /**< Interleaved signal MDCTs */
915 998
916 if (silence) 999 if (silence)
917 { 1000 {
918 for (i=0;i<C*nbEBands;i++) 1001 for (i=0;i<C*nbEBands;i++)
919 oldBandE[i] = -QCONST16(28.f,DB_SHIFT); 1002 oldBandE[i] = -QCONST16(28.f,DB_SHIFT);
920 for (i=0;i<C*N;i++)
921 freq[i] = 0;
922 } else {
923 /* Synthesis */
924 denormalise_bands(mode, X, freq, oldBandE, st->start, effEnd, C, M);
925 }
926 c=0; do {
927 OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2);
928 } while (++c<CC);
929
930 c=0; do {
931 int bound = M*eBands[effEnd];
932 if (st->downsample!=1)
933 bound = IMIN(bound, N/st->downsample);
934 for (i=bound;i<N;i++)
935 freq[c*N+i] = 0;
936 } while (++c<C);
937
938 c=0; do {
939 out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N;
940 } while (++c<CC);
941
942 if (CC==2&&C==1)
943 {
944 for (i=0;i<N;i++)
945 freq[N+i] = freq[i];
946 }
947 if (CC==1&&C==2)
948 {
949 for (i=0;i<N;i++)
950 freq[i] = HALF32(ADD32(freq[i],freq[N+i]));
951 } 1003 }
952 1004
953 /* Compute inverse MDCTs */ 1005 celt_synthesis(mode, X, out_syn, oldBandE, start, effEnd, C, CC, isTransient, LM, st->downsample, silence);
954 compute_inv_mdcts(mode, shortBlocks, freq, out_syn, CC, LM);
955 1006
956 c=0; do { 1007 c=0; do {
957 st->postfilter_period=IMAX(st->postfilter_period, COMBFILTER_MINPERIOD); 1008 st->postfilter_period=IMAX(st->postfilter_period, COMBFILTER_MINPERIOD);
958 st->postfilter_period_old=IMAX(st->postfilter_period_old, COMBFILTER_MINPE RIOD); 1009 st->postfilter_period_old=IMAX(st->postfilter_period_old, COMBFILTER_MINPE RIOD);
959 comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfil ter_period, mode->shortMdctSize, 1010 comb_filter(out_syn[c], out_syn[c], st->postfilter_period_old, st->postfil ter_period, mode->shortMdctSize,
960 st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_ old, st->postfilter_tapset, 1011 st->postfilter_gain_old, st->postfilter_gain, st->postfilter_tapset_ old, st->postfilter_tapset,
961 mode->window, overlap); 1012 mode->window, overlap);
962 if (LM!=0) 1013 if (LM!=0)
963 comb_filter(out_syn[c]+mode->shortMdctSize, out_syn[c]+mode->shortMdctS ize, st->postfilter_period, postfilter_pitch, N-mode->shortMdctSize, 1014 comb_filter(out_syn[c]+mode->shortMdctSize, out_syn[c]+mode->shortMdctS ize, st->postfilter_period, postfilter_pitch, N-mode->shortMdctSize,
964 st->postfilter_gain, postfilter_gain, st->postfilter_tapset, post filter_tapset, 1015 st->postfilter_gain, postfilter_gain, st->postfilter_tapset, post filter_tapset,
965 mode->window, overlap); 1016 mode->window, overlap);
966 1017
967 } while (++c<CC); 1018 } while (++c<CC);
968 st->postfilter_period_old = st->postfilter_period; 1019 st->postfilter_period_old = st->postfilter_period;
969 st->postfilter_gain_old = st->postfilter_gain; 1020 st->postfilter_gain_old = st->postfilter_gain;
970 st->postfilter_tapset_old = st->postfilter_tapset; 1021 st->postfilter_tapset_old = st->postfilter_tapset;
971 st->postfilter_period = postfilter_pitch; 1022 st->postfilter_period = postfilter_pitch;
972 st->postfilter_gain = postfilter_gain; 1023 st->postfilter_gain = postfilter_gain;
973 st->postfilter_tapset = postfilter_tapset; 1024 st->postfilter_tapset = postfilter_tapset;
974 if (LM!=0) 1025 if (LM!=0)
975 { 1026 {
976 st->postfilter_period_old = st->postfilter_period; 1027 st->postfilter_period_old = st->postfilter_period;
977 st->postfilter_gain_old = st->postfilter_gain; 1028 st->postfilter_gain_old = st->postfilter_gain;
978 st->postfilter_tapset_old = st->postfilter_tapset; 1029 st->postfilter_tapset_old = st->postfilter_tapset;
979 } 1030 }
980 1031
981 if (C==1) { 1032 if (C==1)
982 for (i=0;i<nbEBands;i++) 1033 OPUS_COPY(&oldBandE[nbEBands], oldBandE, nbEBands);
983 oldBandE[nbEBands+i]=oldBandE[i];
984 }
985 1034
986 /* In case start or end were to change */ 1035 /* In case start or end were to change */
987 if (!isTransient) 1036 if (!isTransient)
988 { 1037 {
989 for (i=0;i<2*nbEBands;i++) 1038 OPUS_COPY(oldLogE2, oldLogE, 2*nbEBands);
990 oldLogE2[i] = oldLogE[i]; 1039 OPUS_COPY(oldLogE, oldBandE, 2*nbEBands);
991 for (i=0;i<2*nbEBands;i++)
992 oldLogE[i] = oldBandE[i];
993 for (i=0;i<2*nbEBands;i++) 1040 for (i=0;i<2*nbEBands;i++)
994 backgroundLogE[i] = MIN16(backgroundLogE[i] + M*QCONST16(0.001f,DB_SHIF T), oldBandE[i]); 1041 backgroundLogE[i] = MIN16(backgroundLogE[i] + M*QCONST16(0.001f,DB_SHIF T), oldBandE[i]);
995 } else { 1042 } else {
996 for (i=0;i<2*nbEBands;i++) 1043 for (i=0;i<2*nbEBands;i++)
997 oldLogE[i] = MIN16(oldLogE[i], oldBandE[i]); 1044 oldLogE[i] = MIN16(oldLogE[i], oldBandE[i]);
998 } 1045 }
999 c=0; do 1046 c=0; do
1000 { 1047 {
1001 for (i=0;i<st->start;i++) 1048 for (i=0;i<start;i++)
1002 { 1049 {
1003 oldBandE[c*nbEBands+i]=0; 1050 oldBandE[c*nbEBands+i]=0;
1004 oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-QCONST16(28.f,DB_SHIFT); 1051 oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-QCONST16(28.f,DB_SHIFT);
1005 } 1052 }
1006 for (i=st->end;i<nbEBands;i++) 1053 for (i=end;i<nbEBands;i++)
1007 { 1054 {
1008 oldBandE[c*nbEBands+i]=0; 1055 oldBandE[c*nbEBands+i]=0;
1009 oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-QCONST16(28.f,DB_SHIFT); 1056 oldLogE[c*nbEBands+i]=oldLogE2[c*nbEBands+i]=-QCONST16(28.f,DB_SHIFT);
1010 } 1057 }
1011 } while (++c<2); 1058 } while (++c<2);
1012 st->rng = dec->rng; 1059 st->rng = dec->rng;
1013 1060
1014 /* We reuse freq[] as scratch space for the de-emphasis */ 1061 deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_me mD, accum);
1015 deemphasis(out_syn, pcm, N, CC, st->downsample, mode->preemph, st->preemph_me mD, freq);
1016 st->loss_count = 0; 1062 st->loss_count = 0;
1017 RESTORE_STACK; 1063 RESTORE_STACK;
1018 if (ec_tell(dec) > 8*len) 1064 if (ec_tell(dec) > 8*len)
1019 return OPUS_INTERNAL_ERROR; 1065 return OPUS_INTERNAL_ERROR;
1020 if(ec_get_error(dec)) 1066 if(ec_get_error(dec))
1021 st->error = 1; 1067 st->error = 1;
1022 return frame_size/st->downsample; 1068 return frame_size/st->downsample;
1023 } 1069 }
1024 1070
1025 1071
1026 #ifdef CUSTOM_MODES 1072 #ifdef CUSTOM_MODES
1027 1073
1028 #ifdef FIXED_POINT 1074 #ifdef FIXED_POINT
1029 int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data , int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size) 1075 int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data , int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size)
1030 { 1076 {
1031 return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL); 1077 return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0);
1032 } 1078 }
1033 1079
1034 #ifndef DISABLE_FLOAT_API 1080 #ifndef DISABLE_FLOAT_API
1035 int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size) 1081 int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size)
1036 { 1082 {
1037 int j, ret, C, N; 1083 int j, ret, C, N;
1038 VARDECL(opus_int16, out); 1084 VARDECL(opus_int16, out);
1039 ALLOC_STACK; 1085 ALLOC_STACK;
1040 1086
1041 if (pcm==NULL) 1087 if (pcm==NULL)
1042 return OPUS_BAD_ARG; 1088 return OPUS_BAD_ARG;
1043 1089
1044 C = st->channels; 1090 C = st->channels;
1045 N = frame_size; 1091 N = frame_size;
1046 1092
1047 ALLOC(out, C*N, opus_int16); 1093 ALLOC(out, C*N, opus_int16);
1048 ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL); 1094 ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0);
1049 if (ret>0) 1095 if (ret>0)
1050 for (j=0;j<C*ret;j++) 1096 for (j=0;j<C*ret;j++)
1051 pcm[j]=out[j]*(1.f/32768.f); 1097 pcm[j]=out[j]*(1.f/32768.f);
1052 1098
1053 RESTORE_STACK; 1099 RESTORE_STACK;
1054 return ret; 1100 return ret;
1055 } 1101 }
1056 #endif /* DISABLE_FLOAT_API */ 1102 #endif /* DISABLE_FLOAT_API */
1057 1103
1058 #else 1104 #else
1059 1105
1060 int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size) 1106 int opus_custom_decode_float(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data, int len, float * OPUS_RESTRICT pcm, int frame_size)
1061 { 1107 {
1062 return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL); 1108 return celt_decode_with_ec(st, data, len, pcm, frame_size, NULL, 0);
1063 } 1109 }
1064 1110
1065 int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data , int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size) 1111 int opus_custom_decode(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data , int len, opus_int16 * OPUS_RESTRICT pcm, int frame_size)
1066 { 1112 {
1067 int j, ret, C, N; 1113 int j, ret, C, N;
1068 VARDECL(celt_sig, out); 1114 VARDECL(celt_sig, out);
1069 ALLOC_STACK; 1115 ALLOC_STACK;
1070 1116
1071 if (pcm==NULL) 1117 if (pcm==NULL)
1072 return OPUS_BAD_ARG; 1118 return OPUS_BAD_ARG;
1073 1119
1074 C = st->channels; 1120 C = st->channels;
1075 N = frame_size; 1121 N = frame_size;
1076 ALLOC(out, C*N, celt_sig); 1122 ALLOC(out, C*N, celt_sig);
1077 1123
1078 ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL); 1124 ret=celt_decode_with_ec(st, data, len, out, frame_size, NULL, 0);
1079 1125
1080 if (ret>0) 1126 if (ret>0)
1081 for (j=0;j<C*ret;j++) 1127 for (j=0;j<C*ret;j++)
1082 pcm[j] = FLOAT2INT16 (out[j]); 1128 pcm[j] = FLOAT2INT16 (out[j]);
1083 1129
1084 RESTORE_STACK; 1130 RESTORE_STACK;
1085 return ret; 1131 return ret;
1086 } 1132 }
1087 1133
1088 #endif 1134 #endif
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 } 1232 }
1187 va_end(ap); 1233 va_end(ap);
1188 return OPUS_OK; 1234 return OPUS_OK;
1189 bad_arg: 1235 bad_arg:
1190 va_end(ap); 1236 va_end(ap);
1191 return OPUS_BAD_ARG; 1237 return OPUS_BAD_ARG;
1192 bad_request: 1238 bad_request:
1193 va_end(ap); 1239 va_end(ap);
1194 return OPUS_UNIMPLEMENTED; 1240 return OPUS_UNIMPLEMENTED;
1195 } 1241 }
OLDNEW
« no previous file with comments | « celt/celt.c ('k') | celt/celt_encoder.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698