www.pudn.com > AVS_M_ver10.rar > tcx_ecu.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 #include #include "../include/amr_plus.h" /* phasor computations */ void get_phasor(float xri[],float ph[]) { float tmp = 0.0; tmp = xri[0]*xri[0] + xri[1]*xri[1]; if(tmp == 0.0f) { ph[0] = 1; ph[1] = 0; } else { tmp = 1.0f/(float) sqrt(tmp); ph[0] = xri[0] * tmp; ph[1] = xri[1] * tmp; } } void mult_phasor(float ph1[],float ph2[],float res[]) { float ph_re,ph_im; ph_re = ph1[0]*ph2[0] - ph1[1]* ph2[1]; ph_im = ph1[1]*ph2[0] + ph1[0]* ph2[1]; res[0] = ph_re; res[1] = ph_im; } void div_phasor(float ph1[],float ph2[],float res[]) { float ph_re,ph_im; ph_re = ph1[0]*ph2[0] + ph1[1]* ph2[1]; ph_im = ph1[1]*ph2[0] - ph1[0]* ph2[1]; res[0] = ph_re; res[1] = ph_im; } /*---------------------------------------------------------------*/ /* Adaptive low frequency de-emphasis in case of packet loss */ /* */ /* */ /*---------------------------------------------------------------*/ void adapt_low_freq_deemph_ecu(float xri[], int lg, Decoder_State_Plus *st) { int i,j; float buf[L_TCX/4]; float max,fac,tmp; float pred_max; int curr_mode=3; /*---------------------------------------------------------------* * Set correct buffer lengths * *---------------------------------------------------------------*/ if(lg == 1152) {curr_mode =3;} if(lg == 576) {curr_mode =2;} if(lg == 288) {curr_mode =1;} if((st->last_mode != curr_mode) || (curr_mode <= 2)) { pred_max = 0.0f; } else { /*---------------------------------------------------------------* * Temporary working buffer * *---------------------------------------------------------------*/ mvr2r(st->old_xri,buf,lg/4); /*---------------------------------------------------------------* * Find spectral peak under 1600Hz (lg = 6400Hz) * * (find maximum of energy of all Re8 subvector under 1600Hz) * *---------------------------------------------------------------*/ max = 0.01f; for(i=0; i max) { max = tmp; } } pred_max = (float)sqrt(max); /* sqrt of energy */ } /*---------------------------------------------------------------* * Find spectral peak under 1600Hz (lg = 6400Hz) * * (find maximum of energy of all Re8 subvector under 1600Hz) * *---------------------------------------------------------------*/ max = 0.01f; for(i=0; i max) { max = tmp; } } max = (float)sqrt(max); /* sqrt of energy */ /*---------------------------------------------------------------*/ /* Set the new max */ /*---------------------------------------------------------------*/ if(max < pred_max) { max = pred_max; } /*---------------------------------------------------------------* * Deemphasis of all subvector below 1600 Hz. * *---------------------------------------------------------------*/ fac = 0.1f; for(i=0; i fac) { fac = tmp; } for(j=i; j 0.0f) { energy += sp[i]; old_energy += old_sp[i]; } } gain_sq = energy / old_energy; pessimize(); gain = (float)sqrt(gain_sq); /* limit the gain */ if(gain >1.4142f) { gain = 1.4142f; gain_sq = 2.0f; } /*---------------------------------------------------------------* * merge with the new spectrum * *---------------------------------------------------------------*/ for(i=0;i