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

📄 mp3enc_psychoacoustic_int.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 4 页
字号:
  /* im_prev_prev * tmp1 + re_prev_prev * tmp2 */
  ippsMul_16s_Sfs(im_prev_prev, tmp1, re_pred, NUM_UNPRED_LINES_LONG, 15);
  ippsMul_16s_Sfs(re_prev_prev, tmp2, tmp, NUM_UNPRED_LINES_LONG, 15);
  ippsAdd_16s_ISfs(tmp, re_pred, NUM_UNPRED_LINES_LONG, 1);

  /* re_prev_prev * tmp1 - im_prev_prev * tmp2 */
  ippsMul_16s_Sfs(re_prev_prev, tmp1, im_pred, NUM_UNPRED_LINES_LONG, 15);
  ippsMul_16s_Sfs(im_prev_prev, tmp2, tmp, NUM_UNPRED_LINES_LONG, 15);
  ippsSub_16s_ISfs(tmp, im_pred, NUM_UNPRED_LINES_LONG, 1);

  ippsAbs_16s(r_pred, denum,  NUM_UNPRED_LINES_LONG);

  if (r_predScaleFactor > rScaleFactor) {
    shift0 = 0;
    shift1 = r_predScaleFactor - rScaleFactor;
    if (shift > 16) shift1 = 16;
    ippsRShiftC_16s(r, shift1, tmp0, NUM_UNPRED_LINES_LONG);
    ippsAdd_16s_ISfs(tmp0, denum, NUM_UNPRED_LINES_LONG, 1);
  } else if (r_predScaleFactor < rScaleFactor) {
    shift0 = rScaleFactor - r_predScaleFactor;
    shift1 = 0;
    if (shift0 > 16) shift0 = 16;
    ippsRShiftC_16s(denum, shift0, tmp0, NUM_UNPRED_LINES_LONG);
    ippsAdd_16s_Sfs(r, tmp0, denum, NUM_UNPRED_LINES_LONG, 1);
  } else {
    shift0 = 0;
    shift1 = 0;
    ippsAdd_16s_ISfs(r, denum, NUM_UNPRED_LINES_LONG, 1);
  }

  ippsDiv_16s_Sfs(denum, r_pred, tmp0, NUM_UNPRED_LINES_LONG, -14 + shift0);
  ippsDiv_16s_Sfs(denum, r, tmp1, NUM_UNPRED_LINES_LONG, -14 + shift1);

  ippsMul_16s_Sfs(tmp0, re_pred, tmp2, NUM_UNPRED_LINES_LONG, 15);
  ippsMul_16s_Sfs(tmp0, im_pred, tmp3, NUM_UNPRED_LINES_LONG, 15);
  ippsMul_16s_Sfs(tmp1, re, tmp4, NUM_UNPRED_LINES_LONG, 17);
  ippsMul_16s_Sfs(tmp1, im, tmp5, NUM_UNPRED_LINES_LONG, 17);
  ippsSub_16s_Sfs(tmp2, tmp4, tmp0, NUM_UNPRED_LINES_LONG, 1);
  ippsSub_16s_Sfs(tmp3, tmp5, tmp1, NUM_UNPRED_LINES_LONG, 1);
  ippsMagnitude_16s_Sfs(tmp0, tmp1, c_w, NUM_UNPRED_LINES_LONG, -3);

  ippsSet_16s(13107, &c_w[ NUM_UNPRED_LINES_LONG],
              state->pa_iblen_long -  NUM_UNPRED_LINES_LONG);

  ippsMul_16s32s_Sfs((Ipp16s*)r, (Ipp16s*)r, rsqr_long, state->pa_iblen_long, 0);
  rsqr_longScale[0] = 2 * rScaleFactor;

  index = 0;
  for (b = 0; b < pa_num_ptt_long; b++) {
    Ipp32s *tmp_rsqr = &rsqr_long[index];
    Ipp16s *tmp_c_w = (Ipp16s*)&c_w[index];
    Ipp32s len = mp3ienc_pa_numlines_l[state->com.header.samplingFreq][b];

    ippsSum_32s_Sfs(tmp_rsqr, len, &e_b[b], state->ipa_longScale - 2);
    ippsDotProd_16s32s32s_Sfs(tmp_c_w, tmp_rsqr, len,
                              &c_b[b], state->ipa_longScale + 13);
    index += len;
  }

  nb   = (Ipp32s *)state->ipa_nb_long[ch][state->ipa_nb_curr_index[ch]];
  nb_l = (Ipp32s *)state->ipa_nb_long[ch][state->ipa_nb_prev_index[ch]];

  state->ipa_next_frame_PE[ch] = 0;

  for (b = 0; b < pa_num_ptt_long; b++) {
    Ipp16s *tmp_ptr = (Ipp16s*)state->ipa_sprdngf_long +
                               b * pa_num_ptt_long;

    ippsDotProd_16s32s32s_Sfs(tmp_ptr, e_b, pa_num_ptt_long, &ecb[b], 15);
    ippsDotProd_16s32s32s_Sfs(tmp_ptr, c_b, pa_num_ptt_long, &ct[b], 15);
  }

  ippsMulC_32s_Sfs(ecb, 20219, tmp_ecb, pa_num_ptt_long, 21);
  ippsMulC_32s_Sfs(ct, 17131, tmp_ct, pa_num_ptt_long, 15);

  ippsAdd_32s_Sfs(tmp_ct, tmp_ecb, nb, pa_num_ptt_long, 0);
  ippsMulC_32s_Sfs(ecb, 16462, ecb_h_limit, pa_num_ptt_long, 16);
  ippsMulC_32s_Sfs(ecb, 16619, ecb_l_limit, pa_num_ptt_long, 20);
  ippsMaxEvery_32s_I(ecb_l_limit, nb, pa_num_ptt_long);
  ippsMinEvery_32s_I(ecb_h_limit, nb, pa_num_ptt_long);

  /* instead of nb[b] = MAX( pow(10.0,pBlock->qsthr_long[b]/10.0)/32767.0, */
  /*                         MIN(nb[b],2.0*nb_l[b]));                      */
  /* we use only nb[b] = MIN(nb[b],2.0*nb_l[b]) yet                        */

  nb_ScaleFactor = rsqr_longScale[0] + state->ipa_longScale - 1;
  nb_lScaleFactor = state->ipa_nb_longScaleFactor[ch];

  nb_lScaleFactor += 1;
  if (nb_lScaleFactor > nb_ScaleFactor) {
    shift = nb_lScaleFactor - nb_ScaleFactor;
    /* I use MulC here because LShiftC doesn't provide saturation */
    ippsMulC_32s_ISfs(1, nb_l, pa_num_ptt_long, -shift);
    ippsMinEvery_32s_I(nb_l, nb, pa_num_ptt_long);
    ippsLn_32s16s_Sfs(nb, tmp_ln0, pa_num_ptt_long, -10);
  } else if (nb_lScaleFactor < nb_ScaleFactor) {
    shift = nb_ScaleFactor - nb_lScaleFactor;
    if (shift > 31) shift = 31;
    /* I use MulC here because LShiftC doesn't provide saturation */
    ippsMulC_32s_ISfs(1, nb, pa_num_ptt_long, -shift);
    ippsMinEvery_32s_I(nb_l, nb, pa_num_ptt_long);
    ippsRShiftC_32s(nb, shift, ltmp0, pa_num_ptt_long);
    ippsLn_32s16s_Sfs(ltmp0, tmp_ln0, pa_num_ptt_long, -10);
    nb_ScaleFactor = nb_lScaleFactor;
  } else {
    ippsMinEvery_32s_I(nb_l, nb, pa_num_ptt_long);
    ippsLn_32s16s_Sfs(nb, tmp_ln0, pa_num_ptt_long, -10);
  }

  state->ipa_nb_longScaleFactor[ch] = nb_ScaleFactor;

  ippsLn_32s16s_Sfs(e_b, tmp_ln1, pa_num_ptt_long, -10);
  ippsSub_16s_Sfs(tmp_ln0, tmp_ln1, tmp_ln, pa_num_ptt_long, 1);
  FIND_NORM_SHIFT_16S(tmp_ln, pa_num_ptt_long, shift)
  ippsMul_16s_ISfs(mp3ienc_pa_numlines_l[state->com.header.samplingFreq], tmp_ln, pa_num_ptt_long,
                   state->ipa_longScale - shift);
  ippsSum_16s32s_Sfs(tmp_ln, pa_num_ptt_long, &state->ipa_next_frame_PE[ch],
                     9 - state->ipa_longScale + shift);

  if (state->com.ns_mode) {
    for ( sb = 0; sb < SBBND_L; sb++ ) {
      sum1 = MUL32_MP3_32S(mp3ienc_p2sb_l[freq_ind][sb].w1, e_b[mp3ienc_p2sb_l[freq_ind][sb].bu]);
      sum1 += MUL32_MP3_32S(mp3ienc_p2sb_l[freq_ind][sb].w2, e_b[mp3ienc_p2sb_l[freq_ind][sb].bo]);

      sum2 = MUL32_MP3_32S(mp3ienc_p2sb_l[freq_ind][sb].w1, nb[mp3ienc_p2sb_l[freq_ind][sb].bu]);
      sum2 += MUL32_MP3_32S(mp3ienc_p2sb_l[freq_ind][sb].w2, nb[mp3ienc_p2sb_l[freq_ind][sb].bo]);

      for ( b = mp3ienc_p2sb_l[freq_ind][sb].bu+1; b < mp3ienc_p2sb_l[freq_ind][sb].bo; b++ ) {
        sum1 += e_b[b] >> 3;
        sum2 += nb[b] >> 3;
      }

      if (sum1 > 0)
        ippsDiv_32s_Sfs(&sum1, &sum2, &state->pa_ratio_l_next[ch][sb], 1, -23);
      else
        state->pa_ratio_l_next[ch][sb] = 0;
    }
  }
}

/****************************************************************************/

void mp3ienc_psychoacousticShortWindow(MP3Enc *state,
                                       Ipp16s *input_data,
                                       Ipp32s *s_en,
                                       Ipp32s ch)
{
  VM_ALIGN16_DECL(Ipp16s) sw_short[3][N_SHORT];
  VM_ALIGN16_DECL(Ipp16s) abs_sw[N_SHORT];
  VM_ALIGN16_DECL(Ipp16s) fft_line[N_SHORT+2];
  Ipp32s eb[MAX_PPT_SHORT];
  Ipp32s thr[MAX_PPT_SHORT];
  Ipp16s *ptr_input_data;
  Ipp16s *r;
  Ipp32s win_counter;
  Ipp32s scaleFactor[8], shift;
  Ipp32s min_shift, maxScaleFactor;
  Ipp32s sum, sum1, sum2;
  Ipp32s pa_num_ptt_short = state->pa_num_ptt_short;
  Ipp32s freq_ind;
  Ipp32s j, b, sb;

  freq_ind = state->com.header.samplingFreq;

  ptr_input_data = input_data;

  for (win_counter = 0; win_counter < 3; win_counter++) {
    ptr_input_data += 192;
    ippsMul_16s_Sfs(ptr_input_data, ipa_hann_window_short,
                    sw_short[win_counter],
                    2 * state->pa_iblen_short, 15);
  }

  min_shift = 100;
  maxScaleFactor = -100;

  for (win_counter = 0; win_counter < 3; win_counter++) {
    ippsAbs_16s(sw_short[win_counter], abs_sw, 2 * state->pa_iblen_short);
    ippsSum_16s32s_Sfs(abs_sw, 2 * state->pa_iblen_short, &sum, 0);

    scaleFactor[win_counter] = 0;
    if (sum != 0) {
      if (sum > 32768) {
        while (sum > 32768) {
          sum >>= 1;
          scaleFactor[win_counter]++;
        }
      } else {
        while (sum <= 16383) {
          sum *= 2;
          scaleFactor[win_counter]--;
        }
      }
    }

    ippsFFTFwd_RToCCS_16s_Sfs(sw_short[win_counter],
                              fft_line, state->ipa_pFFTSpecShort,
                              scaleFactor[win_counter],
                              state->ipa_pBuffer);

    r = (Ipp16s*)state->ipa_r_short[ch][state->ipa_current_f_r_index[ch]][win_counter];

    ippsMagnitude_16sc_Sfs((Ipp16sc *)fft_line, r, state->pa_iblen_short, 1);
    ippsThreshold_LT_16s_I(r, state->pa_iblen_short, 1);
    FIND_NORM_SHIFT_16S(&r[(state->pa_iblen_short >> 2)],
                        state->pa_iblen_short - (state->pa_iblen_short >> 2),
                        shift)
    if (min_shift > shift) min_shift = shift;
    if (maxScaleFactor < scaleFactor[win_counter])
      maxScaleFactor = scaleFactor[win_counter];
  }

  for (win_counter = 0; win_counter < 3; win_counter++) {

    r = (Ipp16s*)state->ipa_r_short[ch][state->ipa_current_f_r_index[ch]][win_counter];

    /* The scalefactor 12 - (2*shift+1) is calculated from max value to multiplay. */
    /* This value less than                                                        */
    /* (pBlock->iblen_short - (pBlock->iblen_short >> 2)) * 25 < 96 * 25 = 2400    */
    /* The value 25 is used in comparison (Psychoacoustic module)                  */
    ippsDotProd_16s32s_Sfs(&r[(state->pa_iblen_short >> 2)],
      &r[(state->pa_iblen_short >> 2)],
      state->pa_iblen_short - (state->pa_iblen_short >> 2),
      &s_en[win_counter],
      12 + 2 * (maxScaleFactor- scaleFactor[win_counter])
      - (2*min_shift+1));

    if (state->com.ns_mode) {
      for ( j=0, b = 0; b < pa_num_ptt_short; b++ ) {
        Ipp32s tp = mp3ienc_ptbl_s[freq_ind][b].numlines;

        ippsDotProd_16s32s_Sfs(&r[j], &r[j], tp, &eb[b],
          12 + 2 * (maxScaleFactor- scaleFactor[win_counter])
          - (2*min_shift+1));
        j += tp;
      }

      for ( b = 0; b < pa_num_ptt_short; b++ ){
        Ipp32s ecb, nb;
        Ipp16s *tmp_ptr = (Ipp16s*)state->ipa_sprdngf_short + b * pa_num_ptt_short;
        ippsDotProd_16s32s32s_Sfs(tmp_ptr, eb, pa_num_ptt_short, &ecb, 15);

        nb = MUL32_MP3_32S(ecb, mp3ienc_ptbl_s[freq_ind][b].SNR);
        thr[b] = IPP_MAX(mp3ienc_ptbl_s[freq_ind][b].qthr,nb);
      }
      for ( sb = 0; sb < SBBND_S; sb++ ) {
        sum1 = MUL32_MP3_32S(mp3ienc_p2sb_s[freq_ind][sb].w1, eb[mp3ienc_p2sb_s[freq_ind][sb].bu]);
        sum1 += MUL32_MP3_32S(mp3ienc_p2sb_s[freq_ind][sb].w2, eb[mp3ienc_p2sb_s[freq_ind][sb].bo]);

        sum2 = MUL32_MP3_32S(mp3ienc_p2sb_s[freq_ind][sb].w1, thr[mp3ienc_p2sb_s[freq_ind][sb].bu]);
        sum2 += MUL32_MP3_32S(mp3ienc_p2sb_s[freq_ind][sb].w2, thr[mp3ienc_p2sb_s[freq_ind][sb].bo]);

        for ( b = mp3ienc_p2sb_s[freq_ind][sb].bu+1; b < mp3ienc_p2sb_s[freq_ind][sb].bo; b++ ) {
          sum1 += eb[b] >> 3;
          sum2 += thr[b] >> 3;
        }

        if (sum1 > 0)
          ippsDiv_32s_Sfs(&sum1, &sum2, &state->pa_ratio_s_next[ch][win_counter][sb], 1, -23);
        else
          state->pa_ratio_s_next[ch][win_counter][sb] = 0;
      }
    }
  }
}

/****************************************************************************/

Ipp32s mp3ienc_psychoacousticInit(MP3Enc *state, Ipp8u *mem, Ipp32s *size_all)
{
  Ipp32s i, j, gr, ch;
  Ipp32s max_len;
  Ipp32s num_ptt, b, bb;
  const Ipp32s num_ptt_long_tbl[3] = {63,62,59};
  const Ipp32s num_ptt_short_tbl[3] = {39,38,42};
  Ipp32s freq_ind;
  const Ipp16s *bval;
  Ipp16s *sprdngf;
  Ipp32s jj;
  Ipp32s size, ts, ts1, size_buf, size_init, size_buf1, size_init1;
  Ipp8u *mem_init;

  size = 0;

  ippsFFTGetSize_R_16s(10, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast, &ts, &size_init, &size_buf);
  ippsFFTGetSize_R_16s(8, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast, &ts1, &size_init1, &size_buf1);
  if (size_buf < size_buf1) size_buf = size_buf1;
  if (size_init < size_init1) size_init = size_init1;

  size += ts + ts1 + size_buf;

  if (mem) {
    mem_init = 0;
    if (size_init) {
      mem_init = ippsMalloc_8u(size_init);
      if (!mem_init)
        return MP3_ALLOC;
    }

    ippsFFTInit_R_16s(&(state->ipa_pFFTSpecLong), 10, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast, mem, mem_init);
    mem += ts;
    ippsFFTInit_R_16s(&(state->ipa_pFFTSpecShort), 8, IPP_FFT_NODIV_BY_ANY, ippAlgHintFast, mem, mem_init);
    mem += ts1;
    state->ipa_pBuffer = mem;
    mem += size_buf;
    if(mem_init)

⌨️ 快捷键说明

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