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

📄 aac_dec_decoding_int.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 2 页
字号:
            Ipp32s exp;
            Ipp32s mant = pow2table[itmp & 3];

            noise_generator(p_spectrum + sfb_offset[sfb] * len_window_group,
                            (sfb_offset[sfb + 1] - sfb_offset[sfb]) * len_window_group,
                            noiseState, &norm, &normScale);

            mant = (Ipp32s)(((Ipp64s)norm * mant) >> 30);
            exp = normScale - (itmp >> 2);

            if (exp > 0) {
              if (exp > 63) exp = 63;

              for (i = sfb_offset[sfb] * len_window_group;
                   i < sfb_offset[sfb + 1]  * len_window_group; i++) {
                p_spectrum[i] = (Ipp32s)(((Ipp64s)p_spectrum[i] * mant) >> exp);
              }
            } else {
              for (i = sfb_offset[sfb] * len_window_group;
                   i < sfb_offset[sfb + 1]  * len_window_group; i++) {
                p_spectrum[i] = (Ipp32s)(((Ipp64s)p_spectrum[i] * mant) << exp);
              }
            }
          }
        }
      }
      p_spectrum += sfb_offset[max_sfb] * len_window_group;
      p_spectrum_l += sfb_offset[max_sfb] * len_window_group;
    }

    pData = pDataR;
    p_spectrum = p_spectrumR;
    p_spectrum_l = p_spectrumL;
  }

  return 0;
}

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

Ipp32s aacidec_deinterlieve(s_SE_Individual_channel_stream *pData,
                            Ipp32s *p_spectrum)
{
  if ((pData->window_sequence == EIGHT_SHORT_SEQUENCE)) {
    Ipp32s *sfb_offset = pData->sfb_offset_short_window;
    Ipp32s num_window_groups = pData->num_window_groups;
    Ipp32s max_sfb = pData->max_sfb;
    Ipp32s buf[1024];
    Ipp32s *pBuf = buf;
    Ipp32s g, sfb, b;

    ippsCopy_32s(p_spectrum, buf, 1024);

    for (g = 0; g < num_window_groups; g++) {
      Ipp32s len_window_group = pData->len_window_group[g];
      Ipp32s offset = 0;
      for (sfb = 0; sfb < max_sfb; sfb++) {
        Ipp32s len = sfb_offset[sfb + 1] - sfb_offset[sfb];
        for (b = 0; b < len_window_group; b++) {
          ippsCopy_32s(pBuf, p_spectrum + b * 128 + offset, (Ipp16s)len);
          pBuf += len;
        }
        offset += len;

        for (b = 0; b < len_window_group; b++) {
          ippsZero_32s(p_spectrum + b * 128 + offset, 128 - offset);
        }
      }
      p_spectrum += 128*len_window_group;
    }
  }
  return 0;
}

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

Ipp32s aacidec_gain_table[4][8] = {
{ 1073741824, 1170923776, 1276901376, 1392470912,
  1518500224, 1655936256, 1805811328, 1969251200 },
{ 1073741824, 1276901376, 1518500224, 1805811328, 0, 0, 0, 0},
{ 1073741824, 1518500224, 0, 0, 0, 0, 0, 0},
{ 1073741824, 0, 0, 0, 0, 0, 0, 0}
};

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

void aacidec_coupling_gain_calculation(sCoupling_channel_element *pElement,
                                       sCoupling_channel_data *pData,
                                       Ipp32s cc_gain[18][MAX_GROUP_NUMBER][MAX_SFB],
                                       Ipp32s cc_gain_factor[18][MAX_GROUP_NUMBER][MAX_SFB])
{
  Ipp32s *pgain_table = aacidec_gain_table[pData->gain_element_scale];
  Ipp32s shift = (3 - pData->gain_element_scale);
  Ipp32s ch = 0;
  Ipp32s c, g, sfb;

  for (c = 0; c < pData->num_gain_element_lists; c++) {
    if (pData->cge[c]) {
      Ipp32s fac = -pElement->cc_fact[c][0][0];
      Ipp32s ifac = fac >> shift;
      Ipp32s scale = pgain_table[fac - (ifac << shift)];

      for (g = 0; g < pElement->stream.num_window_groups; g++) {
        for (sfb = 0; sfb < pElement->stream.max_sfb; sfb++) {
          if (pElement->stream.sfb_cb[g][sfb] != ZERO_HCB) {
            cc_gain[ch][g][sfb] = scale;
            cc_gain_factor[ch][g][sfb] = ifac - 30;
          } else {
            cc_gain[ch][g][sfb] = 0;
            cc_gain_factor[ch][g][sfb] = 0;
          }
        }
      }
    } else {
      if (pData->gain_element_sign) {
        for (g = 0; g < pElement->stream.num_window_groups; g++) {
          for (sfb = 0; sfb < pElement->stream.max_sfb; sfb++) {
            if (pElement->stream.sfb_cb[g][sfb] != ZERO_HCB) {
              Ipp32s sign = pElement->cc_fact[c][g][sfb] & 1;
              Ipp32s fac = -(pElement->cc_fact[c][g][sfb] >> 1);
              Ipp32s ifac = fac >> shift;
              Ipp32s scale = pgain_table[fac - (ifac << shift)];

              if (sign) scale = -scale;
              cc_gain[ch][g][sfb] = scale;
              cc_gain_factor[ch][g][sfb] = ifac - 30;
            } else {
              cc_gain[ch][g][sfb] = 0;
              cc_gain_factor[ch][g][sfb] = 0;
            }
          }
        }
      } else {
        for (g = 0; g < pElement->stream.num_window_groups; g++) {
          for (sfb = 0; sfb < pElement->stream.max_sfb; sfb++) {
            if (pElement->stream.sfb_cb[g][sfb] != ZERO_HCB) {
              Ipp32s fac = -(pElement->cc_fact[c][g][sfb]);
              Ipp32s ifac = fac >> shift;
              Ipp32s scale = pgain_table[fac - (ifac << shift)];
              cc_gain[ch][g][sfb] = scale;
              cc_gain_factor[ch][g][sfb] = ifac - 30;
            } else {
              cc_gain[ch][g][sfb] = 0;
              cc_gain_factor[ch][g][sfb] = 0;
            }
          }
        }
      }
    }

    if (pData->cc_lr[c] == 3) {
      ch++;
    } else {
      ch += 2;
    }
  }
}

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

void aacidec_coupling_spectrum(AACDec *state,
                               sCoupling_channel_data *pData,
                               Ipp32s *c_spectrum,
                               Ipp32s curr_win_sequence,
                               Ipp32s cc_gain[18][MAX_GROUP_NUMBER][MAX_SFB],
                               Ipp32s cc_gain_factor[18][MAX_GROUP_NUMBER][MAX_SFB])
{
  Ipp32s *m_spectrum, *pc_spectrum;
  Ipp32s c, ch, g, m_ch, sfb, w;
  Ipp32s *sfb_offset = pData->sfb_offset;
  Ipp32s max_sfb = pData->max_sfb;
  Ipp32s num_window_groups = pData->num_window_groups;
  Ipp32s num_el = 0;
  Ipp32s tmp[1024];
  Ipp32s target_win_sequence, scalef;

  ch = 0;

  for (c = 0; c < pData->num_coupled_elements + 1; c++) {
    m_ch = pData->cc_target_ch[c];
    if (m_ch < 0) continue;

    /* if cpe and only right channel */
    if ((pData->cc_target_id[c]) && (pData->cc_lr[num_el] == 1))
      m_ch++;

    target_win_sequence = state->com.m_curr_win_sequence[m_ch];
    scalef = 0;
    if ((target_win_sequence == EIGHT_SHORT_SEQUENCE) &&
        (curr_win_sequence != EIGHT_SHORT_SEQUENCE)) {
      scalef = -3;
    } else if ((target_win_sequence != EIGHT_SHORT_SEQUENCE) &&
               (curr_win_sequence == EIGHT_SHORT_SEQUENCE)) {
      scalef = 3;
    }

    m_spectrum = state->m_spectrum_data[m_ch];
    pc_spectrum = c_spectrum;
    for (g = 0; g < num_window_groups; g++) {
      Ipp32s len_window_group = pData->len_window_group[g];
      for (w = 0; w < len_window_group; w++) {
        for (sfb = 0; sfb < max_sfb; sfb++) {
          Ipp32s len = sfb_offset[sfb + 1] - sfb_offset[sfb];
          ippsMulC_32s_Sfs(pc_spectrum + sfb_offset[sfb], cc_gain[ch][g][sfb],
                           tmp, len, scalef - cc_gain_factor[ch][g][sfb]);
          ippsAdd_32s_ISfs(tmp, m_spectrum + sfb_offset[sfb], len, 0);
        }
        m_spectrum += 128;
        pc_spectrum += 128;
      }
    }

    if (pData->cc_target_id[c]) { /* if cpe */
      if (pData->cc_lr[num_el] == 3) {

        target_win_sequence = state->com.m_curr_win_sequence[m_ch+1];
        scalef = 0;
        if ((target_win_sequence == EIGHT_SHORT_SEQUENCE) &&
            (curr_win_sequence != EIGHT_SHORT_SEQUENCE)) {
          scalef = -3;
        } else if ((target_win_sequence != EIGHT_SHORT_SEQUENCE) &&
                  (curr_win_sequence == EIGHT_SHORT_SEQUENCE)) {
          scalef = 3;
        }

        m_spectrum = state->m_spectrum_data[m_ch+1];
        pc_spectrum = c_spectrum;
        for (g = 0; g < num_window_groups; g++) {
          Ipp32s len_window_group = pData->len_window_group[g];
          for (w = 0; w < len_window_group; w++) {
            for (sfb = 0; sfb < max_sfb; sfb++) {
              Ipp32s len = sfb_offset[sfb + 1] - sfb_offset[sfb];
              ippsMulC_32s_Sfs(pc_spectrum + sfb_offset[sfb], cc_gain[ch+1][g][sfb],
                               tmp, len, scalef - cc_gain_factor[ch+1][g][sfb]);
              ippsAdd_32s_ISfs(tmp, m_spectrum + sfb_offset[sfb], len, 0);
            }
            m_spectrum += 128;
            pc_spectrum += 128;
          }
        }
        num_el++;
      } else if (pData->cc_lr[num_el] == 0) {

        target_win_sequence = state->com.m_curr_win_sequence[m_ch+1];
        scalef = 0;
        if ((target_win_sequence == EIGHT_SHORT_SEQUENCE) &&
            (curr_win_sequence != EIGHT_SHORT_SEQUENCE)) {
          scalef = -3;
        } else if ((target_win_sequence != EIGHT_SHORT_SEQUENCE) &&
                  (curr_win_sequence == EIGHT_SHORT_SEQUENCE)) {
          scalef = 3;
        }

        m_spectrum = state->m_spectrum_data[m_ch+1];
        pc_spectrum = c_spectrum;
        for (g = 0; g < num_window_groups; g++) {
          Ipp32s len_window_group = pData->len_window_group[g];
          for (w = 0; w < len_window_group; w++) {
            for (sfb = 0; sfb < max_sfb; sfb++) {
              Ipp32s len = sfb_offset[sfb + 1] - sfb_offset[sfb];
              ippsMulC_32s_Sfs(pc_spectrum + sfb_offset[sfb], cc_gain[ch][g][sfb],
                               tmp, len, scalef - cc_gain_factor[ch][g][sfb]);
              ippsAdd_32s_ISfs(tmp, m_spectrum + sfb_offset[sfb], len, 0);
            }
            m_spectrum += 128;
            pc_spectrum += 128;
          }
        }
      }
    }
    ch += 2;
    num_el++;
  }
}

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

void aacidec_coupling_samples(AACDec *state,
                              sCoupling_channel_data *pData,
                              Ipp32s *c_samlpes,
                              Ipp32s cc_gain[18][MAX_GROUP_NUMBER][MAX_SFB],
                              Ipp32s cc_gain_factor[18][MAX_GROUP_NUMBER][MAX_SFB])
{
  Ipp32s c, ch, m_ch;
  Ipp32s num_el = 0;
  Ipp32s tmp[1024];

  ch = 0;

  for (c = 0; c < pData->num_coupled_elements + 1; c++) {
    m_ch = pData->cc_target_ch[c];
    if (m_ch < 0) continue;

    /* if cpe and only right channel */
    if ((pData->cc_target_id[c]) && (pData->cc_lr[num_el] == 1))
      m_ch++;

    ippsMulC_32s_Sfs(c_samlpes, cc_gain[ch][0][0],
                     tmp, 1024, -cc_gain_factor[ch][0][0]);
    ippsAdd_32s_ISfs(tmp, state->m_spectrum_data[m_ch], 1024, 0);

    if (pData->cc_target_id[c]) { /* if cpe */
      if (pData->cc_lr[num_el] == 3) {
        ippsMulC_32s_Sfs(c_samlpes, cc_gain[ch+1][0][0],
                         tmp, 1024, -cc_gain_factor[ch+1][0][0]);
        ippsAdd_32s_ISfs(tmp, state->m_spectrum_data[m_ch+1], 1024, 0);
        num_el++;
      } else if (pData->cc_lr[num_el] == 0) {
        ippsMulC_32s_Sfs(c_samlpes, cc_gain[ch][0][0],
                         tmp, 1024, -cc_gain_factor[ch][0][0]);
        ippsAdd_32s_ISfs(tmp, state->m_spectrum_data[m_ch+1], 1024, 0);
      }
    }
    ch += 2;
    num_el++;
  }
}

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

⌨️ 快捷键说明

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