⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cod_main.c

📁 关于AMR-WB+语音压缩编码的实现代码
💻 C
📖 第 1 页 / 共 3 页
字号:
        /* right HF was stored into channel_right */
        mvr2r(channel_right, new_speech+L_FRAME_PLUS-L_NEXT_ST, L_NEXT_ST);
      }
      else {
        /* right HF was stored into channel_right */
        mvr2r(channel_right, new_speech+L_FRAME_PLUS-L_NEXT, L_NEXT);
      }
    }
    mvr2r(old_speech+L_FRAME_PLUS, st->right.old_speech_hf, L_OLD_SPEECH_ST);
    if (n_channel == 2)
    {
      if (fscale == 0)
      {
        /* copy memory into working space */
        mvr2r(channel_left, buffer+L_FRAME_FSMAX-L_next, L_next);
        decim_12k8(buffer+L_FRAME_FSMAX-L_frame, L_frame, new_speech, 
                   st->left.mem_decim_hf, (fscale == 0)?1:2);
      }
      else
      {
        /* left HF was stored into channel_left */
        mvr2r(channel_left, new_speech+L_FRAME_PLUS-L_NEXT_ST, L_NEXT_ST);
      }
      mvr2r(old_speech+L_FRAME_PLUS, st->left.old_speech_hf, L_OLD_SPEECH_ST);
    }
  }
  return(nb_samp);
}
/*-----------------------------------------------------------------*
 * Funtion  coder_amrwb_plus_stereo                                *
 *          ~~~~~~~~~~~~~~~~                                       *
 *   - Main stereo coder routine.                                  *
 *                                                                 *
 *-----------------------------------------------------------------*/
int coder_amrwb_plus_stereo(  /* output: number of sample processed */
  float channel_right[], /* input: used on mono and stereo       */
  float channel_left[],  /* input: used on stereo only           */
  int codec_mode,    /* input: AMR-WB+ mode (see cnst.h)         */
  int L_frame,       /* input: 80ms frame size                   */
  short serial[],    /* output: serial parameters                */
  Coder_State_Plus *st,   /* i/o : coder memory state                 */
  short use_case_mode,
  int fscale,
  int   StbrMode
)
{
  /* LPC coefficients of lower frequency */
  float AqLF[(NB_SUBFR+1)*(M+1)];
  int param[NB_DIV*NPRM_DIV];
  int prm_stereo[MAX_NPRM_STEREO_DIV*NB_DIV];   /* see cnst.h */
  int prm_hf_left[NB_DIV*NPRM_BWE_DIV];
  int prm_hf_right[NB_DIV*NPRM_BWE_DIV];
  /* vector working at fs=12.8kHz */
  float sig_left[L_FRAME_PLUS];
  float sig_right[L_FRAME_PLUS];
  float old_speech[L_TOTAL_ST];
  float *speech, *new_speech;
  float old_synth[M+L_FRAME_PLUS];
  float *synth;
  float *syn_hf = old_synth;   
  /* Scalars */
  int i, k, nbits_pack;
  int mod[NB_DIV];
  /* LTP parameters for high band */
  float ol_gain[NB_DIV];  
  int   T_out[NB_DIV];    
  float p_out[NB_DIV];    
  int nb_samp, fac_fs;
  /*ClassB parameters*/
  short excType[4];  
  int WorkLen,fac_up,fac_down;
  
  /* decimation and band split (HF temporary into channel_right) */
  if ((L_frame-L_FRAME32k) == 0) 
  {
    fac_fs = FSCALE_DENOM*3/2;    
  }
  else 
  {
    fac_fs = fscale;              
  }

  /* 48k setting*/
  fac_up = (fac_fs<<3);
  fac_down = 180*8;       

  if (fscale != 0)
  {

#ifdef FILTER_44kHz
      if ((L_frame-(2*L_FRAME44k)) == 0)
      {
        fac_up = (fac_fs<<3);
        fac_down = 3*441;    
      }
#endif
      /*L_frame = ((L_frame_int*fac_down)+(*frac_mem))/fac_up;*/
      WorkLen = ((L_FRAME_PLUS*2*fac_down)+(st->right.decim_frac))/fac_up;
  }
  else
  {
      WorkLen = L_frame;       
  }
 /*---------------------------------------------------------------------*
  * Initialize pointers to speech vector.                               *
  *                                                                     *
  *                     20ms     20ms     20ms     20ms    >=20ms       *
  *             |----|--------|--------|--------|--------|--------|     *
  *           past sp   div1     div2     div3     div4    L_NEXT       *
  *             <--------  Total speech buffer (L_TOTAL_PLUS)  -------->     *
  *        old_speech                                                   *
  *                  <----- present frame (L_FRAME_PLUS) ----->              *
  *                  |        <------ new speech (L_FRAME_PLUS) ------->     *
  *                  |        |                                         *
  *                speech     |                                         *
  *                         new_speech                                  *
  *---------------------------------------------------------------------*/
  new_speech = old_speech + L_OLD_SPEECH_ST;
  speech     = old_speech + L_TOTAL_ST - L_FRAME_PLUS - L_A_MAX - L_BSP;
  synth = old_synth + M;
 /*-----------------------------------------------------------------*
  * STEREO signal downsampling (codec working at 6.4kHz)            *
  * - decimate signal to fs=12.8kHz                                 *
  * - Perform 50Hz HP filtering of signal at fs=12.8kHz.            *
  *-----------------------------------------------------------------*/
  if (fscale == 0)
  {
    decim_12k8(channel_left, L_frame, sig_left, st->left.mem_decim, 0);
    decim_12k8(channel_right, L_frame, sig_right, st->right.mem_decim, 0);
    nb_samp = L_frame;
  }
  else
  {
    decim_split_12k8(channel_left, L_frame, sig_left, channel_left,
                     L_FRAME_PLUS, fac_fs, 
                     fac_up,
                     fac_down,
                     WorkLen,
                     st->left.mem_decim, &(st->left.decim_frac));

    nb_samp = decim_split_12k8(channel_right, L_frame, sig_right, channel_right,
                    L_FRAME_PLUS, fac_fs, 
                     fac_up,
                     fac_down,
                     WorkLen,
                    st->right.mem_decim, &(st->right.decim_frac));
  }
  hp50_12k8(sig_left, L_FRAME_PLUS, st->left.mem_sig_in, fscale);
  hp50_12k8(sig_right, L_FRAME_PLUS, st->right.mem_sig_in, fscale);
 /*-----------------------------------------------------------------*
  * Encode MONO low frequency band.                                 *
  * - Mix left and right channels (mono signal)                     *
  * - Perform fixed preemphasis through 1 - g z^-1                  *
  * - Encode low frequency band using ACELP/TCX model               *
  *-----------------------------------------------------------------*/
  mix_ch(sig_left,sig_right,new_speech,L_FRAME_PLUS,1.0f,1.0f);
  /* Apply preemphasis (for core codec only */
  E_UTIL_f_preemph(new_speech, PREEMPH_FAC, L_FRAME_PLUS, &(st->right.mem_preemph));
  /* copy memory into working space */
  mvr2r(st->old_speech_pe, old_speech, L_OLD_SPEECH_ST);
  mvr2r(st->old_synth, old_synth, M);
  if (use_case_mode == USE_CASE_B) {
    for(i=0;i<4;i++){
      st->stClass->vadFlag[i] = wb_vad(st->vadSt, &new_speech[256*i]);
      if (st->stClass->vadFlag[i] == 0){
        st->vad_hist++;
      }	 
      else {
        st->vad_hist = 0;
      }
      excType[i] = (short)(classifyExcitation(st->stClass, st->vadSt->level, (short)i));
    }
    /* encode mono lower band */
    coder_lf_b(codec_mode, speech, synth, mod, AqLF, st->window, param, 
               ol_gain, T_out, p_out, excType, fscale, st);
  } 
  else {
    for (i=0;i<4;i++) {
      excType[i] = 0;
    }
    /* encode mono lower band */
    coder_lf(codec_mode, speech, synth, mod, AqLF, st->window, param, 
             ol_gain, T_out, p_out, excType, fscale, st);
  }
  for(i=0;i<4;i++){ 
    mod[i] = excType[i];
  }
  /* update lower band memory for next frame */
  mvr2r(&old_speech[L_FRAME_PLUS], st->old_speech_pe, L_OLD_SPEECH_ST);
  mvr2r(&old_synth[L_FRAME_PLUS], st->old_synth, M);
 /*------------------------------------------------------------*
  * STEREO Bandwidth extension (2 channels used)               *
  * - fold and decimate higher band into new_speech_hf         *
  *   (2000Hz..6400Hz <-- 6400Hz..10800 Hz)                    *
  * - encode HF using 0.8kbps per channel.                     *
  *------------------------------------------------------------*/
  if (L_frame > L_FRAME8k)
  {
    float old_speech_hf[L_TOTAL_ST];
    float *new_speech_hf, *speech_hf;

    new_speech_hf = old_speech_hf + L_OLD_SPEECH_ST;
    speech_hf     = old_speech_hf + L_TOTAL_ST - L_FRAME_PLUS - L_A_MAX - L_BSP;

//left
    mvr2r(st->left.old_speech_hf, old_speech_hf, L_OLD_SPEECH_ST);
    if (fscale == 0)
    {
      decim_12k8(channel_left, L_frame, new_speech_hf, st->left.mem_decim_hf, (fscale == 0)?1:2);
    }
    else
    {
      /* left HF was stored into channel_left */
      mvr2r(channel_left, new_speech_hf, L_FRAME_PLUS);
    }
    mvr2r(&old_speech_hf[L_FRAME_PLUS], st->left.old_speech_hf, L_OLD_SPEECH_ST);
    if (StbrMode < 0) mvr2r(speech_hf, channel_left, L_FRAME_PLUS+L_A_MAX+L_BSP);
    else 
      coder_hf(mod, AqLF, speech, speech_hf, syn_hf, st->window, prm_hf_left,fscale, &(st->left));

//right
    mvr2r(st->right.old_speech_hf, old_speech_hf, L_OLD_SPEECH_ST);
    if (fscale == 0)
    {
      decim_12k8(channel_right, L_frame, new_speech_hf, st->right.mem_decim_hf, (fscale == 0)?1:2);
    }
    else
    {
      /* right HF was stored into channel_right */
      mvr2r(channel_right, new_speech_hf, L_FRAME_PLUS);
    }
    if (StbrMode < 0)
    {
      for (i=0; i<L_FRAME_PLUS+L_A_MAX+L_BSP; i++) 
        speech_hf[i] = 0.5f*speech_hf[i] + 0.5f*channel_left[i];
    }
    mvr2r(&old_speech_hf[L_FRAME_PLUS], st->right.old_speech_hf, L_OLD_SPEECH_ST);
    coder_hf(mod, AqLF, speech, speech_hf, syn_hf, st->window, prm_hf_right,fscale, &(st->right));

  } else {
    for (i=0; i<NB_DIV*NPRM_BWE_DIV; i++) {
      prm_hf_right[i] = 0;
      prm_hf_left[i] = 0;
    }
  }
 /*------------------------------------------------------------*
  * STEREO low frequency band encoder                          *
  * - Mix left and right channels (mono signal)                *
  * - split mono and right signal (2k, hi).                    *
  * - perform parametric stereo encoding				   *
  *------------------------------------------------------------*/
{
  float old_mono_2k[L_TOTAL_ST_2k];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -