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

📄 mp3dec_api_fp.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 2 页
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2003-2007 Intel Corporation. All Rights Reserved.
//
*/

#include "mp3dec_own_fp.h"

MP3Status mp3decUpdateMemMap(MP3Dec *state, Ipp32s shift)
{
  Ipp32s i;
  mp3decUpdateMemMap_com(&state->com, shift);

  for (i = 0; i < 34; i++) {
    MP3_UPDATE_PTR(void, state->com.huff_table[i].phuftable, shift)
  }
  MP3_UPDATE_PTR(IppsMDCTInvSpec_32f, state->pMDCTSpecLong, shift)
  MP3_UPDATE_PTR(IppsMDCTInvSpec_32f, state->pMDCTSpecShort, shift)
  MP3_UPDATE_PTR(Ipp8u, state->mdct_buffer, shift)
  MP3_UPDATE_PTR(Ipp8u, state->pqmf_mem, shift)
  for (i = 0; i < NUM_CHANNELS; i++) {
    MP3_UPDATE_PTR(IppsFilterSpec_PQMF_MP3, state->pPQMFSpec[i], shift)
  }

  MP3_UPDATE_PTR(samplefloat, state->smpl_xr, shift)
  MP3_UPDATE_PTR(samplefloat, state->smpl_ro, shift)
  MP3_UPDATE_PTR(samplefloat, state->smpl_re, shift)
  MP3_UPDATE_PTR(samplefloatrw, state->smpl_rw, shift)
  MP3_UPDATE_PTR(samplefloat, state->smpl_sb, shift)
  MP3_UPDATE_PTR(sampleshort, state->com.smpl_xs, shift)

  return MP3_OK;
}

MP3Status mp3decInit(MP3Dec *state, Ipp32s mc_lfe_filter_off, Ipp32s synchro_mode, Ipp32s *size_all)
{
    Ipp32s ch, size, ts, size_init, size_buf;
    Ipp32s ts1, size_init1, size_buf1;
    Ipp8u *mem, *mem_init;

    if (mc_lfe_filter_off < 0 || mc_lfe_filter_off > 1) {
      return MP3_FAILED_TO_INITIALIZE;
    }

    if (synchro_mode < 0 || synchro_mode > 1) {
      return MP3_FAILED_TO_INITIALIZE;
    }

    size = 0;
    mem = 0;

    ts = sizeof(MP3Dec);
    size += ts;
    if (state) {
      ippsZero_8u((Ipp8u *)state, sizeof(MP3Dec));
      mem = (Ipp8u *)state + ts;
    }

    mp3decGetSize_com(&ts);
    size += ts;
    if (mem) {
      mp3decInit_com(&state->com, mem);
      mem += ts;
    }

    mp3dec_initialize_huffman(mem ? state->com.huff_table : 0, mem, &ts);
    size += ts;
    if (mem) mem += ts;

    ippsMDCTInvGetSize_32f(36, &ts, &size_init, &size_buf);
    ippsMDCTInvGetSize_32f(12, &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;
      }

      ippsMDCTInvInit_32f(&(state->pMDCTSpecLong), 36, mem, mem_init);
      mem += ts;
      ippsMDCTInvInit_32f(&(state->pMDCTSpecShort), 12, mem, mem_init);
      mem += ts1;
      state->mdct_buffer = mem;
      mem += size_buf;
      if(mem_init)
        ippsFree(mem_init);
    }

    ippsSynthesisFilterGetSize_PQMF_MP3_32f(&ts);
    size += ts * NUM_CHANNELS;

    if (mem) {
      state->pqmf_size = ts;
      state->pqmf_mem = mem;
      for (ch = 0; ch < NUM_CHANNELS; ch++) {
        ippsSynthesisFilterInit_PQMF_MP3_32f(&state->pPQMFSpec[ch],
          state->pqmf_mem + state->pqmf_size * ch);
      }
      mem += ts * NUM_CHANNELS;
    }

    if (state) {
      /* out of dequantizer */
      state->smpl_xr =
      /* out of reordering */
      state->smpl_ro =
      /* out of antialiasing */
      state->smpl_re =
      /* out of subband synth */
      state->smpl_sb = (samplefloat *) state->global;
      /* out of imdct */
      state->smpl_rw = (samplefloatrw *) ((Ipp8s *)(state->global) + sizeof(samplefloat));
      /* out of huffman */
      state->com.smpl_xs = (sampleshort *) ((Ipp8s *)(state->global) +
          sizeof(samplefloat) * 2);

      state->com.mc_lfe_filter_off = mc_lfe_filter_off;
      state->com.synchro_mode = synchro_mode;
    }

    if(size_all)
      *size_all = size;

    return MP3_OK;
}

MP3Status mp3decReset(MP3Dec *state)
{
  Ipp32s ch;
  mp3decReset_com(&state->com);

  state->GlobalScaleFactor[0][0] = 0;
  state->GlobalScaleFactor[0][1] = 0;
  state->GlobalScaleFactor[1][0] = 0;
  state->GlobalScaleFactor[1][1] = 0;

  ippsZero_8u((Ipp8u *)(state->global), (1152 * NUM_CHANNELS * 2 + 576) * sizeof(Ipp32f));
  ippsZero_8u((Ipp8u *)(state->prevblk), 2 * 576 * sizeof(Ipp32f));
  ippsZero_8u((Ipp8u *)(state->mc_pred_buf), 2 * 8 * (36 + 9) * sizeof(Ipp32f));

  for (ch = 0; ch < NUM_CHANNELS; ch++) {
    state->m_ptr[ch][0] = state->m_ptr[ch][1] = 0;
    state->m_even[ch] = 0;
  }
  state->dctnum_prev[0] = state->dctnum_prev[1] = 0;

  for (ch = 0; ch < NUM_CHANNELS; ch++) {
    ippsSynthesisFilterInit_PQMF_MP3_32f(&state->pPQMFSpec[ch],
      state->pqmf_mem + state->pqmf_size * ch);
  }

  return MP3_OK;
}

MP3Status mp3decClose(MP3Dec *state)
{
    if (state == NULL)
        return MP3_OK;

    mp3decClose_com(&state->com);

    return MP3_OK;
}

MP3Status mp3decGetFrame(Ipp8u *inPointer,
                         Ipp32s inDataSize,
                         Ipp32s *decodedBytes,
                         Ipp16s *outPointer,
                         Ipp32s outBufferSize,
                         MP3Dec *state)
{
    MP3Status res;
    Ipp32s prev_decodedBytes = state->com.decodedBytes;
    Ipp32s i, j, ch, frameSize, channels, channels_mask, bits;
    IppMP3FrameHeader *header = &(state->com.header);
    Ipp32f lfe_sample[12];
    Ipp32f *pSampl[NUM_CHANNELS+1];
    Ipp32f buf[1152];
    samplefloat *smpl_sb = state->smpl_sb;       // out of subband synth

    if (!inPointer || !outPointer)
        return MP3_NULL_PTR;

    res = mp3dec_GetID3Len(inPointer, inDataSize, &(state->com));

    if (res != MP3_OK)
      return res;

    res = mp3dec_SkipID3(inDataSize, decodedBytes, &(state->com));

    if (res != MP3_OK) {
      return res;
    } else {
      inDataSize -= *decodedBytes;
      inPointer += *decodedBytes;
    }

    if (inDataSize == 0 && (state->com.m_StreamData.nDataLen <= state->com.decodedBytes + 32))
        return MP3_NOT_ENOUGH_DATA;
    state->com.m_pOutSamples = (Ipp16s *)outPointer;

    do {
        mp3dec_ReceiveBuffer(&(state->com.m_StreamData), inPointer, inDataSize);
        res = mp3dec_GetSynch(&state->com);

        if (res == MP3_BAD_STREAM || res == MP3_UNSUPPORTED || res == MP3_NOT_FIND_SYNCWORD) {
          *decodedBytes += state->com.decodedBytes - prev_decodedBytes;
          return res;
        } else if (res == MP3_NOT_ENOUGH_DATA ) {
          *decodedBytes += state->com.decodedBytes - prev_decodedBytes;
          return MP3_NOT_ENOUGH_DATA;
        }

        mp3decGetFrameSize(&frameSize, state);
        mp3decGetChannels(&channels, &channels_mask, state);

        if (outBufferSize < frameSize * channels) {
            return MP3_NOT_ENOUGH_BUFFER;
        }

        //CMC END
        state->com.m_frame_num++;

        res = MP3_OK;

        switch (header->layer) {
        case 3:
            if (header->id)
                mp3dec_audio_data_LayerIII(&state->com);
            else
                mp3dec_audio_data_LSF_LayerIII(&state->com);
            res = mp3dec_decode_data_LayerIII(state);
            break;
        case 2:
            if (state->com.nbal_alloc_table) {
              if (mp3dec_audio_data_LayerII(&state->com)) {
                res = MP3_NOT_FIND_SYNCWORD;
                state->com.decodedBytes -= state->com.MP3nSlots + 3;
                break;
              }

              mp3dec_decode_data_LayerII(state);

              bits = ((state->com.m_StreamData.pCurrent_dword -
                state->com.start_ptr) << 5) +
                state->com.start_offset -
                state->com.m_StreamData.nBit_offset;
              bits = (state->com.MP3nSlots << 3) - bits;

              state->com.mc_channel = 0;
              state->com.mc_header.lfe = 0;

              if (bits >= 35) {
                bs_CRC_reset(&state->com.crc);

⌨️ 快捷键说明

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