www.pudn.com > AVS_M_ver10.rar > cod_hi_stereo.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" #include "../include/s_util.h" void init_cod_hi_stereo(Coder_State_Plus *st) { int i; set_zero(st->old_exc_mono,HI_FILT_ORDER); st->filt_energy_threshold= 0.0f; set_zero(st->old_wh,HI_FILT_ORDER); set_zero(st->old_wh_q,HI_FILT_ORDER); set_zero(st->old_gm_gain,2); cos_window(st->w_window,0,L_SUBFR); for(i=0;i w_window[i] = st->w_window[i]*st->w_window[i]; } } /* gain quantizer */ static void quant_gain(float gain_left, /* i/o */ float gain_right, /* i/o */ float old_gain[], int **prm, const PMSVQ *gain_hi_pmsvq ) { float tmp[2]; tmp[0] = gain_left; tmp[1] = gain_right ; pmsvq(tmp, prm, tmp, old_gain, gain_hi_pmsvq); } /* filter quantizer */ static void quant_filt(float h[], /* i/o */ float old_h[], /* i/o */ int **prm, const PMSVQ *filt_hi_pmsvq ) { pmsvq(h, prm, h, old_h, filt_hi_pmsvq); } /* filter smoother */ static void smooth_ener_filter(float *filter, float *threshold) { float tmp, ener,old_ener; int i; /* compute energy over subframe */ ener = 0.0001f; for (i=0; i 16.0f){ ener= 16.0f; } /* if energy *threshold) { tmp = *threshold; } } else { tmp = tmp/1.414f; if (tmp < *threshold) { tmp = *threshold; } } /* set the threshold for next subframer to the current modified energy */ *threshold = tmp; /* apply correction scale factor to HF signal */ tmp = (float)sqrt(tmp/old_ener); for (i=0; i old_exc_mono,exc_mono-HI_FILT_ORDER,HI_FILT_ORDER); /* compute the residual of the hi mono and right */ p_Aq = AqLF; for (i_subfr=0; i_subfr old_exc_mono,HI_FILT_ORDER); /* compute the wiener filters, raw on each frame with covariance method*/ p_h = wh; for(i=0;i filt_energy_threshold); /* quantize the filters*/ quant_filt(p_h,st->old_wh_q,&prm,st->filt_hi_pmsvq); /* local synthesis */ fir_filt(p_h,HI_FILT_ORDER,x,buf,L_DIV+L_SUBFR); /* compute the gain matching figures in the excitation domain */ energy_left = 0.001f; energy_right = 0.001f; energy_left_q = 0.001f; energy_right_q = 0.001f; energy_mono = 0.001f; corr_left_right = 0.00f; for(t=0;t 0.0f){ gain_right[i] = my_max(gain_right[i]+10.0f*(float)log10(gain_fact),0.0f); } if(gain_left[i] > 0.0f){ gain_left[i] = my_max(gain_left[i]+10.0f*(float)log10(gain_fact),0.0f); } } /* quantize the gains */ quant_gain(gain_left[i],gain_right[i],st->old_gm_gain,&prm,st->gain_hi_pmsvq); /* next frame */ p_h += HI_FILT_ORDER; } /* save last filter*/ mvr2r(&wh[(NB_DIV-1)*HI_FILT_ORDER],st->old_wh,HI_FILT_ORDER); }