comparison flacenc.c @ 10424:94595d0e617c libavcodec

Move autocorrelation function from flacenc.c to lpc.c. Also rename the corresponding dsputil functions and remove their dependency on the FLAC encoder. Fixes Issue1486.
author jbr
date Sat, 17 Oct 2009 21:00:39 +0000
parents 7955db355703
children 8a4984c5cacc
comparison
equal deleted inserted replaced
10423:2e4967487e59 10424:94595d0e617c
549 pmax = get_max_p_order(pmax, n, pred_order); 549 pmax = get_max_p_order(pmax, n, pred_order);
550 bits = pred_order*bps + 4 + 5 + pred_order*precision + 6; 550 bits = pred_order*bps + 4 + 5 + pred_order*precision + 6;
551 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order); 551 bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order);
552 return bits; 552 return bits;
553 } 553 }
554
555 /**
556 * Apply Welch window function to audio block
557 */
558 static void apply_welch_window(const int32_t *data, int len, double *w_data)
559 {
560 int i, n2;
561 double w;
562 double c;
563
564 assert(!(len&1)); //the optimization in r11881 does not support odd len
565 //if someone wants odd len extend the change in r11881
566
567 n2 = (len >> 1);
568 c = 2.0 / (len - 1.0);
569
570 w_data+=n2;
571 data+=n2;
572 for(i=0; i<n2; i++) {
573 w = c - n2 + i;
574 w = 1.0 - (w * w);
575 w_data[-i-1] = data[-i-1] * w;
576 w_data[+i ] = data[+i ] * w;
577 }
578 }
579
580 /**
581 * Calculates autocorrelation data from audio samples
582 * A Welch window function is applied before calculation.
583 */
584 void ff_flac_compute_autocorr(const int32_t *data, int len, int lag,
585 double *autoc)
586 {
587 int i, j;
588 double tmp[len + lag + 1];
589 double *data1= tmp + lag;
590
591 apply_welch_window(data, len, data1);
592
593 for(j=0; j<lag; j++)
594 data1[j-lag]= 0.0;
595 data1[len] = 0.0;
596
597 for(j=0; j<lag; j+=2){
598 double sum0 = 1.0, sum1 = 1.0;
599 for(i=j; i<len; i++){
600 sum0 += data1[i] * data1[i-j];
601 sum1 += data1[i] * data1[i-j-1];
602 }
603 autoc[j ] = sum0;
604 autoc[j+1] = sum1;
605 }
606
607 if(j==lag){
608 double sum = 1.0;
609 for(i=j-1; i<len; i+=2){
610 sum += data1[i ] * data1[i-j ]
611 + data1[i+1] * data1[i-j+1];
612 }
613 autoc[j] = sum;
614 }
615 }
616
617 554
618 static void encode_residual_verbatim(int32_t *res, int32_t *smp, int n) 555 static void encode_residual_verbatim(int32_t *res, int32_t *smp, int n)
619 { 556 {
620 assert(n > 0); 557 assert(n > 0);
621 memcpy(res, smp, n * sizeof(int32_t)); 558 memcpy(res, smp, n * sizeof(int32_t));