www.pudn.com > AVS_M_ver10.rar > cod_tcx.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" #ifdef PW_UPDATE #ifdef NEW_TVC void coder_tcx( float A[], /* input: coefficients NxAz[M+1] */ float speech[], /* input: speech[-M..lg] */ float *mem_wsp, /* in/out: memory of target */ float *mem_wsyn, /* in/out: memory of quantized xn */ float synth[], /* in/out: synth[-M..lg] */ float exc[], /* output: exc[0..lg] */ float wovlp[], /* i/o: wovlp[0..127] */ int ovlp_size, /* input: 0, 64 or 128 (0=acelp) */ int L_frame, /* input: frame length */ int nb_bits, /* input: number of bits allowed */ int input_t, /* input: superframe edge indication */ int prm[], float *mem_formant, float *mem_tilt, float *mem_formant_exc, float *mem_tilt_exc) { int i, i_subfr, lext, lg, index,ovlp; float gain, fac_ns,tmp; float *p_A, Ap[M+1],Ap1[M+1],Ap2[M+1],Ap3[M+1]; float *xri, *xn, *xnq; float gh, gg, qgband; float window[256]; static int cnt = 1; xn = synth; xnq = xri = exc; /*------ set length of overlap (lext) and length of encoded frame (lg) -----*/ lext = L_OVLP; if (L_frame == (L_FRAME_PLUS/2)) { lext = L_OVLP/2; } if (L_frame == (L_FRAME_PLUS/4)) { lext = L_OVLP/4; } lg = L_frame + lext; /* built window for overlaps section */ //这里对前帧是acelp时进行处理 if (ovlp_size==0) { lext=lext/2; ovlp=lext; //下面是对snr而设定的 /* set_zero(sp, 80); set_zero(synthpost, 80); set_zero(synth2, 64);*/ set_zero(xn, 1152); } else{ ovlp=ovlp_size; } cos_window(window, ovlp, lext); //如果前帧是acelp 就进行如下的分解 if (ovlp_size==0){ if(input_t==0){ for(i=0; i 6 bits (in 2nd packet) TCX-80 -> 9 bits (3 bits in 2nd, 3rd and 4th packet) */ if (L_frame == (L_FRAME_PLUS/2)) { nb_bits -= 6; } if (L_frame == L_FRAME_PLUS) { nb_bits -= 9; } fac_ns = AVQ_get_nf(xri, nb_bits, lg/8); AVQ_gain_allocator(xri, lg, nb_bits, &gh, &gg); /* high half quantization */ AVQ_cod(xri, prm+3, nb_bits, lg/8, &gh, &gg); for(i=0; i 7) { index = 7; } prm[0] = index; /* fac_ns : 3 bits */ /*-----------------------------------------------------------* * Compute inverse FFT for obtaining xnq[] without noise. * * Coefficients (xri[]) order are * * re[0], re[n/2], re[1], re[2], ... re[n/2-1], im[n/2-1] * * Note that last FFT element (re[n/2]) is zeroed. * *-----------------------------------------------------------*/ xri[1] = 0.0; /* freq bin at 6400 Hz zeroed */ ifft9(xri, xnq, (short)lg); /*-----------------------------------------------------------* * find and quantize gain, multiply xnq[] by gain. * * windowing of xnq[] for TCX overlap. * *-----------------------------------------------------------*/ gain = get_gain(xn, xnq, lg); prm[1] = q_gain_tcx(xnq, lg, &gain); for (i=0; i 6 bits (in 2nd packet) TCX-80 -> 9 bits (3 bits in 2nd, 3rd and 4th packet) */ if (L_frame == (L_FRAME_PLUS/2)) { nb_bits -= 6; } if (L_frame == L_FRAME_PLUS) { nb_bits -= 9; } fac_ns = AVQ_cod(xri, prm+2, nb_bits, lg/8); for(i=0; i 7) { index = 7; } prm[0] = index; /* fac_ns : 3 bits */ /*-----------------------------------------------------------* * Compute inverse FFT for obtaining xnq[] without noise. * * Coefficients (xri[]) order are * * re[0], re[n/2], re[1], re[2], ... re[n/2-1], im[n/2-1] * * Note that last FFT element (re[n/2]) is zeroed. * *-----------------------------------------------------------*/ xri[1] = 0.0; /* freq bin at 6400 Hz zeroed */ ifft9(xri, xnq, (short)lg); /*-----------------------------------------------------------* * find and quantize gain, multiply xnq[] by gain. * * windowing of xnq[] for TCX overlap. * *-----------------------------------------------------------*/ gain = get_gain(xn, xnq, lg); prm[1] = q_gain_tcx(xnq, lg, &gain); for (i=0; i 6 bits (in 2nd packet) TCX-80 -> 9 bits (3 bits in 2nd, 3rd and 4th packet) */ if (L_frame == (L_FRAME_PLUS/2)) { nb_bits -= 6; } if (L_frame == L_FRAME_PLUS) { nb_bits -= 9; } fac_ns = AVQ_get_nf(xri, nb_bits, lg/8); AVQ_gain_allocator(xri, lg, nb_bits, &gh, &gg); //printf("gg = %f; gh = %f\r\n", gg, gh); /* high half quantization */ AVQ_cod(xri, prm+3, nb_bits, lg/8, &gh, &gg); for(i=0; i 7) { index = 7; } prm[0] = index; /* fac_ns : 3 bits */ /*-----------------------------------------------------------* * Compute inverse FFT for obtaining xnq[] without noise. * * Coefficients (xri[]) order are * * re[0], re[n/2], re[1], re[2], ... re[n/2-1], im[n/2-1] * * Note that last FFT element (re[n/2]) is zeroed. * *-----------------------------------------------------------*/ xri[1] = 0.0; /* freq bin at 6400 Hz zeroed */ ifft9(xri, xnq, (short)lg); /*-----------------------------------------------------------* * find and quantize gain, multiply xnq[] by gain. * * windowing of xnq[] for TCX overlap. * *-----------------------------------------------------------*/ gain = get_gain(xn, xnq, lg); prm[1] = q_gain_tcx(xnq, lg, &gain); for (i=0; i 6 bits (in 2nd packet) TCX-80 -> 9 bits (3 bits in 2nd, 3rd and 4th packet) */ if (L_frame == (L_FRAME_PLUS/2)) { nb_bits -= 6; } if (L_frame == L_FRAME_PLUS) { nb_bits -= 9; } fac_ns = AVQ_cod(xri, prm+2, nb_bits, lg/8); for(i=0; i 7) { index = 7; } prm[0] = index; /* fac_ns : 3 bits */ /*-----------------------------------------------------------* * Compute inverse FFT for obtaining xnq[] without noise. * * Coefficients (xri[]) order are * * re[0], re[n/2], re[1], re[2], ... re[n/2-1], im[n/2-1] * * Note that last FFT element (re[n/2]) is zeroed. * *-----------------------------------------------------------*/ xri[1] = 0.0; /* freq bin at 6400 Hz zeroed */ ifft9(xri, xnq, (short)lg); /*-----------------------------------------------------------* * find and quantize gain, multiply xnq[] by gain. * * windowing of xnq[] for TCX overlap. * *-----------------------------------------------------------*/ gain = get_gain(xn, xnq, lg); prm[1] = q_gain_tcx(xnq, lg, &gain); for (i=0; i