www.pudn.com > AVS_M_ver10.rar > c_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 #include #include "../include/amr_plus.h" #include "../include/cod_hi_stereo.h" #include "../include/cod_tcx_stereo.h" /*-----------------------------------------------------------------* * Funtion init_coder_stereo * * ~~~~~~~~~~~~~~~~~~~~~~~~~~ * * ->Initialization of variables for the stereo coder. * *-----------------------------------------------------------------*/ void init_coder_stereo_x(Coder_State_Plus *st) { init_cod_hi_stereo(st); init_tcx_stereo_encoder(st); return; } /*-----------------------------------------------------------------* * Funtion coder_stereo * * ~~~~~~~~~~~~~~~~~~~~ * * ->Principle stereo coder routine (working at fs=12.8kHz). * * * * Note: HF band are encoded twice (2 channels) using 0.8kbps BWE. * * Usage of 2xBWE for stereo provide better time domain * * stereo definition in HF without increasing the bit-rate. * * Another advantage is that the stereo decoder is limited * * to the lower band (fs=12.8kHz) and this reduce the * * overall complexity of the AMR-WB+ codec. Also, this * * solution is not dependent of the AMR-WB+ mode where many * * different sampling frequencies are used (16, 24, 32 kHz). * *-----------------------------------------------------------------*/ void coder_stereo_x(float speech_hi[], /* (i) : Mixed channel, hi */ float chan_hi[], /* (i) : Right channel, hi */ float speech_2k[], /* (i) : Mixed channel, lo */ float chan_2k[], /* (i) : Right channel, lo */ float AqLF[], int brMode, int param[], /* (o) : Encoded parameters*/ int fscale, Coder_State_Plus *st) /* (i/o): Encoder states */ { int mod[4]; int i; /* param */ /*-----------------------------------------------------------------* * NPRM_STEREO_HI_X*NB_DIV + 4 (mode) + Rest (TCX) * *-----------------------------------------------------------------*/ if (StereoNbits[brMode]-4 > 300) { st->filt_hi_pmsvq = &filt_hi_pmsvq7; st->gain_hi_pmsvq = &gain_hi_pmsvq5; } else { st->filt_hi_pmsvq = &filt_hi_pmsvq4; st->gain_hi_pmsvq = &gain_hi_pmsvq2; } /* encode the high band */ cod_hi_stereo(speech_hi,chan_hi,AqLF,param,st); /* 64 echantillon look-ahead */ /* encode the low band */ cod_tcx_stereo(speech_2k,chan_2k,param+4+NPRM_STEREO_HI_X*NB_DIV,brMode,mod,fscale,st); /* transmitt the mode in the parameters buffer*/ for(i=0;i<4;i++){ param[i+NPRM_STEREO_HI_X*NB_DIV] = mod[i]; } return; } static int unpack4bits_d(int nbits, int *prm, short *ptr) { int i; i=0; while (nbits > 4) { int2bin(prm[i], 4, ptr); ptr += 4; nbits -= 4; i++; } int2bin(prm[i], nbits, ptr); i++; return(i); } void enc_prm_stereo_x(int param[], /* (i) : parameters */ short serial[], /* (o) : serial bits stream */ int nbits_pack, /* (i) : number of bits per packet of 20ms*/ int nbits_bwe, /* (i) : number of BWE bits per 20ms */ int brMode ) { int nbits, *prm; int k,j; short *ptr; int i; int mod[NB_DIV],nbits_AVQ[NB_DIV]; int mode,n_pack; int prm_AVQ[(NBITS_MAX/4)+N_PACK_MAX]; int hf_bits=0; int hiband_mode; /*----------------------------------------------------------* * Set number of bits used for stereo (per packet of 20 ms) * * When stereo is transmitted, the bit ordering is: * * serial: mode (2bits), core, stereo, 2xBWE(2x16bits) * *----------------------------------------------------------*/ nbits = (StereoNbits[brMode] + (2*nbits_bwe))/4; hiband_mode = 0; if (StereoNbits[brMode]-4 > 300) { hiband_mode = 1; } /*----------------------------------------------------------* * Encode the high band parameters * *----------------------------------------------------------*/ for(k=0;k