www.pudn.com > AVS_M_ver10.rar > util_stereo_x.c
/* *********************************************************************** * COPYRIGHT AND WARRANTY INFORMATION * * Copyright 2007 Audio Video Coding Standard, Part ¢ú * * This software module was developed by AVS Audio sub-group * * DISCLAIMER OF WARRANTY * * These software programs are available to the users without any * license fee or royalty on an "as is" basis. The AVS disclaims * any and all warranties, whether express, implied, or statutory, * including any implied warranties of merchantability or of fitness * for a particular purpose. In no event shall the contributors or * the AVS be liable for any incidental, punitive, or consequential * damages of any kind whatsoever arising from the use of this program. * * This disclaimer of warranty extends to the user of this program * and user's customers, employees, agents, transferees, successors, * and assigns. * * The AVS does not represent or warrant that the program furnished * hereunder are free of infringement of any third-party patents. * Commercial implementations of AVS, including shareware, may be * subject to royalty fees to patent holders. Information regarding * the AVS patent policy is available from the AVS Web site at * http://www.avs.org.cn * * THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY. ************************************************************************ */ #include#include "../include/amr_plus.h" #ifndef PI2 #define PI2 6.283185307F #endif #define MAX_VECT_DIM 16 #define EPSILON 1e-16f #define BUF_SIZ (L_SUBFR+M) float my_max(float x, float y) { if (x > y) { return x; } return y; } float my_min(float x, float y) { if (x < y) { return x; } return y; } void fir_filt(float *h, /* input : filter coefficients */ int m, /* input : order of filter */ float *x, /* input : input signal (usually mono) */ float *y, /* output: output signal (usually stereo) */ int l /* input : size of filtering */ ) { float s; int i, j; for (i = 0; i < l; i++) { s = 0.0f; for (j = 0; j < m; j++) { s += h[j]*x[i-j]; } y[i] = s; } return; } void band_join_2k(float sig[], float sig_2k[], float sig_hi[], int lg) { int i; /* interpolate to 12.8k fs*/ interpol(sig_2k-L_FDEL_2k,sig,lg, (float *) filter_2k,L_FDEL_2k,32,5,32.0f); for(i=0;i vdim : vector dimension */ ) { int i,j; const float *y; float distanz,d; for (i=0;i = *m_dist) goto endloop; } *m_dist = dist[*m_best] = distanz; for (j=0;j *m_dist) { *m_dist = dist[j]; *m_best = j; } } endloop: ; } } /****************************************************************************/ static void msvq(float *y, int *inds, float *x, const MSVQ *msvq_tab) /* <- y : reconstruction vector */ /* <- inds : the best path through the msvq trellis */ /* -> x : vector to be encoded */ /* -> msvq_tab : all required parameters and tables */ { int i,j,k,l,pfadanz_max,arg; int m_best; float m_dist; float e[MAX_VECT_DIM]; int mpfade_mem1[INTENS_MAX][MAX_NUMSTAGES]; int mpfade_mem2[INTENS_MAX][MAX_NUMSTAGES]; int (*mpfade)[INTENS_MAX][MAX_NUMSTAGES]; int (*alt_mpfade)[INTENS_MAX][MAX_NUMSTAGES]; int (*tmp_pfad)[INTENS_MAX][MAX_NUMSTAGES]; float dist[MAX_NUMSTAGES][INTENS_MAX]; const int *cbsize = msvq_tab->cbsizes; const int vdim = msvq_tab->vdim; const int stages = msvq_tab->nstages; const int m = msvq_tab->intens; const float **cb = msvq_tab->cbs; mpfade = &mpfade_mem1; alt_mpfade = &mpfade_mem2; for (j=0;j inds : array of indices */ /* -> msvq_tab : all required parameters and tables */ { int j,l; const int vdim = msvq_tab->vdim; const int stages = msvq_tab->nstages; const float **cb = msvq_tab->cbs; for (j=0;j mean; float a=filt_hi_pmsvq->a; int n=filt_hi_pmsvq->msvq.vdim; int *inds = *prm; *prm += filt_hi_pmsvq->msvq.nstages; /* compute the predictor error */ for(i=0;i msvq); /* save for next frame */ for(i=0;i mean; int n=filt_hi_pmsvq->msvq.vdim; float a=( bfi ? filt_hi_pmsvq->a_fe : filt_hi_pmsvq->a); *prm += filt_hi_pmsvq->msvq.nstages; if (!bfi) { /* dequantize the prediction error */ msvq_inv(eq, inds, &filt_hi_pmsvq->msvq); } else { set_zero(eq,n); } /* reconstruct and save for next frame */ for(i=0;i no memory update */ ) /* 1 --> update of memory */ { int i, j; float s, *yy; float buf[BUF_SIZ]; yy=&buf[0]; /* copy initial filter states into synthesis buffer */ for (i = 0; i < m; i++) { *yy++ = mem[i]; } for (i = 0; i < l; i++) { s = x[i]; for (j = 1; j <= m; j++) { s -= a[j]*yy[i-j]; } yy[i] = s; y[i] = s; } /* Update memory if required */ if (update_m) { for (i = 0; i < m; i++) { mem[i] = yy[l-m+i]; } } return; } /* Lpc residual */ void residu( float *a, /* input : LP filter coefficients */ int m, /* input : order of LP filter */ float *x, /* input : input signal (usually speech) */ float *y, /* output: output signal (usually residual) */ int l /* input : size of filtering */ ) { float s; int i, j; for (i = 0; i < l; i++) { s = x[i]; for (j = 1; j <= m; j++) { s += a[j]*x[i-j]; } y[i] = s; } return; } /* Constrained cholseky linear equation solver */ int cholsolc(float r[HI_FILT_ORDER][HI_FILT_ORDER], float c[HI_FILT_ORDER], float h[HI_FILT_ORDER], int n) { float p[HI_FILT_ORDER]; int i,j,k; float sum; float lambda; float v[HI_FILT_ORDER]; /* cholesky decomposition */ for(i=0;i =0;k--) { sum -= r[i][k]*r[j][k]; } if(i==j) { if(sum < EPSILON) { return(1); } p[i] = (float)sqrt(sum); } else { r[j][i] = sum/p[i]; } } } /* linear system solving */ for(i=0;i =0;k--) { sum -= r[i][k]*h[k]; lambda -= r[i][k]*v[k]; } h[i] = sum/p[i]; v[i] = lambda/p[i]; } for(i=n-1;i>=0;i--) { for(sum=h[i],lambda=v[i],k=i+1;k 1.0) { sum = 1.0f/sum; for(i=0;i