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

📄 cod_main.c

📁 关于AMR-WB+语音压缩编码的实现代码
💻 C
📖 第 1 页 / 共 3 页
字号:
#include <float.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "../lib_amr/enc_if.h"
#include "../lib_amr/dec_if.h"
#include "../include/amr_plus.h"
#include "../include/s_util.h"
/*-----------------------------------------------------------------*
 * Funtion  init_coder_amr_plus                                    *
 *          ~~~~~~~~~~~~~~~~~~~                                    *
 *   - Allocate memory for static variables.                       *	
 *   - Initialization of variables for the coder section.          *
 *   - compute lag window and LP analysis window (if not done)     *
 *-----------------------------------------------------------------*/
void init_coder_amrwb_plus(Coder_State_Plus *st, int num_chan, int fscale, short use_case_mode, short full_reset)
{
  if (full_reset && use_case_mode == 1) {
    /* initialize memories (ClassB part) */
    st->vad_hist = 0;	
    wb_vad_init (&(st->vadSt));
    st->stClass = malloc(sizeof(NCLASSDATA));
    initClassifyExcitation(st->stClass);
  }
  /* initialize bwe codebooks */
  if (fscale == 0) {
    st->left.mean_isf_hf = (float*)mean_isf_hf_low_rate;
    st->left.dico1_isf_hf =(float*)dico1_isf_hf_low_rate;
    st->right.mean_isf_hf = (float*)mean_isf_hf_low_rate;
    st->right.dico1_isf_hf =(float*)dico1_isf_hf_low_rate;
  }
  else { 
    st->left.mean_isf_hf = (float*)mean_isf_hf_12k8;
    st->left.dico1_isf_hf =(float*)dico1_isf_hf_12k8;
    st->right.mean_isf_hf = (float*)mean_isf_hf_12k8;
    st->right.dico1_isf_hf =(float*)dico1_isf_hf_12k8;
  }
  /* initialize memories (stereo part) */
  st->right.decim_frac = 0;
  st->left.decim_frac = 0;
  if (full_reset) {
    /* initialize memories (stereo part) */
    set_zero(st->right.mem_decim_hf, 2*L_FILT24k);
    set_zero(st->right.old_speech_hf, L_OLD_SPEECH_ST);
    set_zero(st->right.mem_decim, L_MEM_DECIM_SPLIT);
    st->right.mem_preemph = 0.0;
    init_coder_hf(&(st->right));
    set_zero(st->left.mem_decim, L_MEM_DECIM_SPLIT);
    set_zero(st->left.mem_decim_hf, 2*L_FILT24k);
    set_zero(st->left.old_speech_hf, L_OLD_SPEECH_ST);
    st->left.mem_preemph = 0.0;
    init_coder_hf(&(st->left));
    /* initialize memories (mono part) */
    set_zero(st->old_speech, L_OLD_SPEECH_ST);
    set_zero(st->old_synth, M);
    set_zero(st->left.mem_sig_in,4);
    set_zero(st->right.mem_sig_in,4);
    /* init band splitting memories */
    set_zero(st->old_chan, L_OLD_SPEECH_ST);
    set_zero(st->old_chan_2k, L_OLD_SPEECH_2k);
    set_zero(st->old_speech_2k, L_OLD_SPEECH_2k);
    set_zero(st->old_chan_hi, L_OLD_SPEECH_hi);
    set_zero(st->old_speech_hi, L_OLD_SPEECH_hi);
    init_coder_lf(st);

    if(num_chan == 2){
      init_coder_stereo_x(st);
    }
    st->SwitchFlagPlusToWB = 0;
    set_zero(st->mem_gain_code, 4);
    st->prev_mod = 0;
  } else {
  }
  /* Initialize the LP analysis window */
  if(fscale <= FSCALE_DENOM) 
  {
    cos_window(st->window, L_WINDOW/2, L_WINDOW/2);
  }
  else {
    cos_window(st->window, L_WINDOW_HIGH_RATE/2, L_WINDOW_HIGH_RATE/2);
  }
  return;
}
/*-----------------------------------------------------------------*
 * Funtion  coder_amrwb_plus_first                                 *
 *          ~~~~~~~~~~~~~~~~                                       *
 *   - Fill lookahead buffers                                      *
 *                                                                 *
 *-----------------------------------------------------------------*/
int coder_amrwb_plus_first(   /* output: number of sample processed */
  float channel_right[], /* input: used on mono and stereo       */
  float channel_left[],  /* input: used on stereo only           */
  int n_channel,     /* input: 1 or 2 (mono/stereo)              */
  int L_frame,       /* input: frame size                        */
  int L_next,        /* input: lookahead                         */
  int fscale,
  Coder_State_Plus *st   /* i/o : coder memory state                 */
)
{
  float buffer[L_FRAME_FSMAX];
  float old_speech[L_TOTAL_ST];
  float *new_speech=old_speech + L_OLD_SPEECH_ST;
  float sig_right[L_FRAME_PLUS];
  float old_mono_2k[L_TOTAL_ST_2k];
  float *new_mono_2k = old_mono_2k + L_OLD_SPEECH_2k;
  float old_mono_hi[L_TOTAL_ST_hi];
  float *new_mono_hi = old_mono_hi + L_OLD_SPEECH_hi;
  int nb_samp, fac_fs;

  int WorkLen,fac_up,fac_down;
  
  
  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
      if (n_channel == 2)
      {
          /*L_frame = ((L_frame_int*fac_down)+(*frac_mem))/fac_up;*/
          WorkLen = ((L_NEXT_ST*2*fac_down)+(st->right.decim_frac))/fac_up;
      }
      else
      {
          /*L_frame = ((L_frame_int*fac_down)+(*frac_mem))/fac_up;*/
          WorkLen = ((L_NEXT*2*fac_down)+(st->right.decim_frac))/fac_up;
      }
  }
  else
  {
      WorkLen = L_next;      
  }

 /*-----------------------------------------------------------------*
  * MONO/STEREO signal downsampling (codec working at 6.4kHz)       *
  * - decimate signal to fs=12.8kHz                                 *
  * - Perform 50Hz HP filtering of signal at fs=12.8kHz.            *
  * - Perform fixed preemphasis through 1 - g z^-1                  *
  * - Mix left and right channels into sum and difference signals   *
  *-----------------------------------------------------------------*/
  set_zero(buffer, L_FRAME_FSMAX);
  set_zero(old_speech, L_OLD_SPEECH_ST);
  if (n_channel == 2)
  {
    set_zero(old_mono_2k, L_OLD_SPEECH_2k);
    set_zero(old_mono_hi, L_OLD_SPEECH_hi);
    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, 0);
      /* copy memory into working space */
      mvr2r(channel_right, buffer+L_FRAME_FSMAX-L_next, L_next);
      decim_12k8(buffer+L_FRAME_FSMAX-L_frame, L_frame, sig_right, st->right.mem_decim, 0);
      nb_samp = L_next;
    }
    else
    {
      set_zero(new_speech, L_FRAME_PLUS-L_NEXT_ST);
      set_zero(sig_right, L_FRAME_PLUS-L_NEXT_ST);

      decim_split_12k8(channel_left, L_frame, new_speech+L_FRAME_PLUS-L_NEXT_ST, channel_left,
                       L_NEXT_ST, 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+L_FRAME_PLUS-L_NEXT_ST, channel_right,
                       L_NEXT_ST, fac_fs, 
                     fac_up,
                     fac_down,
                     WorkLen,
                       st->right.mem_decim, &(st->right.decim_frac));
    }

    hp50_12k8(new_speech, L_FRAME_PLUS, st->left.mem_sig_in, fscale);
    hp50_12k8(sig_right, L_FRAME_PLUS, st->right.mem_sig_in, fscale);
    /* parametric stereo : mix left and right channels */
    mix_ch(new_speech,sig_right,new_speech,L_FRAME_PLUS,1.0f,1.0f);
    /* do the lo,hi band-splitting on the mono signal */
    band_split_taligned_2k(new_speech,new_mono_2k,new_mono_hi,L_FRAME_PLUS);
    /* copy working space into memory */
    mvr2r(old_speech+L_FRAME_PLUS, st->old_speech, L_OLD_SPEECH_ST);
    mvr2r(old_mono_2k+L_FRAME_2k, st->old_speech_2k, L_OLD_SPEECH_2k);
    mvr2r(old_mono_hi+L_FRAME_PLUS, st->old_speech_hi, L_OLD_SPEECH_hi);
  } 
  else {
    if (fscale == 0)
    {
      /* copy memory into working space */
      mvr2r(channel_right, buffer+L_FRAME_FSMAX-L_next, L_next);
      decim_12k8(buffer+L_FRAME_FSMAX-L_frame, L_frame, new_speech, st->right.mem_decim, 0);
      nb_samp = L_next;
    }
    else
    {
      set_zero(new_speech, L_FRAME_PLUS-L_NEXT);
      /* decimation and band split (HF temporary into channel_right) */
      nb_samp = decim_split_12k8(channel_right, L_frame, new_speech+L_FRAME_PLUS-L_NEXT, channel_right,
                                 L_NEXT, fac_fs, 
                                fac_up,
                                fac_down,
                                WorkLen,
                                st->right.mem_decim, &(st->right.decim_frac));
    }
    hp50_12k8(new_speech, L_FRAME_PLUS, st->right.mem_sig_in, fscale);
    /* copy working space into memory */
    mvr2r(old_speech+L_FRAME_PLUS, st->old_speech, L_OLD_SPEECH_ST);
  }
  /* Apply preemphasis (for core codec only */
  E_UTIL_f_preemph(new_speech, PREEMPH_FAC, L_FRAME_PLUS, &(st->right.mem_preemph));
  /* update lower band memory for next frame */
  mvr2r(old_speech+L_FRAME_PLUS, st->old_speech_pe, L_OLD_SPEECH_ST);
  if (n_channel == 2)
  {
    mvr2r(sig_right, new_speech, L_FRAME_PLUS);
    /* do the lo,hi band-splitting on the mono signal */
    band_split_taligned_2k(new_speech,new_mono_2k,new_mono_hi,L_FRAME_PLUS);
    /* copy working space into memory */
    mvr2r(old_speech+L_FRAME_PLUS, st->old_chan, L_OLD_SPEECH_ST);
    mvr2r(old_mono_2k+L_FRAME_2k, st->old_chan_2k, L_OLD_SPEECH_2k);
    mvr2r(old_mono_hi+L_FRAME_PLUS, st->old_chan_hi, L_OLD_SPEECH_hi);
  }
  if (L_frame>L_FRAME8k) {
    /* prepare buffers for MONO/STEREO Bandwidth extension */
    if (fscale == 0)
    {
      /* copy memory into working space */
      mvr2r(channel_right, buffer+L_FRAME_FSMAX-L_next, L_next);
      decim_12k8(buffer+L_FRAME_FSMAX-L_frame, L_frame, new_speech, st->right.mem_decim_hf, (fscale == 0)?1:2);  
    }
    else
    {
      if (n_channel == 2)
      {

⌨️ 快捷键说明

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