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

📄 mp3dec_api_fp.c

📁 audio-video-codecs.rar语音编解码器
💻 C
📖 第 1 页 / 共 2 页
字号:
                mp3dec_CRC_start(&state->com);
                mp3dec_mc_header(&state->com);
                mp3dec_CRC_update(&state->com, &state->com.crc);

                mp3dec_CRC_start(&state->com);
                mp3dec_mc_params(&state->com);
                mp3dec_mc_composite_status_info(&state->com);
                mp3dec_mc_audio_data_l2(&state->com);
                mp3dec_CRC_update(&state->com, &state->com.crc);

                if (state->com.crc == state->com.crc_check) {
                  mp3dec_mc_decode_scale_l2(&state->com);

                  mp3dec_mc_decode_sample_l2(&state->com);

                  mp3dec_dequantize_sample_mc_l2(state);

                  mp3dec_mc_denormalize_sample_l2(state);

                  mp3dec_mc_dematricing   (state);
                  mp3dec_mc_denormalizing (state);

                  if(state->com.mc_header.lfe) {
                    mp3dec_mc_lfe_l2(state, lfe_sample);
                  }
                } else {
                  state->com.mc_channel = 0;
                  state->com.mc_header.lfe = 0;
                }
              }

              mp3decGetChannels(&channels, &channels_mask, state);
              if (outBufferSize < frameSize * channels) {
                return MP3_NOT_ENOUGH_BUFFER;
              }

              for (ch = 0; ch < state->com.stereo + state->com.mc_channel; ch++) {
                pSampl[ch] = (*smpl_sb)[ch];
                for (i = 0; i < 36; i++) {
                  ippsSynthesisFilter_PQMF_MP3_32f((*(state->smpl_rw))[ch][i],
                    (*smpl_sb)[ch] + i * 32,
                    state->pPQMFSpec[ch], 1);
                }
              }
              if (state->com.mc_header.lfe) {
                Ipp32s len = 1152, phase = 0;
                if (state->com.mc_lfe_filter_off) {
                  ippsSampleUp_32f(lfe_sample, 12, buf, &len, 96, &phase);
                } else {
                  Ipp32f tval;
                  Ipp32s div96 = 0, lfe_offset = 0;
                  ippsCopy_32f(&state->mc_lfe_buf[12], &state->mc_lfe_buf[0], 5);
                  ippsCopy_32f(lfe_sample, &state->mc_lfe_buf[5], 12);
                  for (i = 0; i < 1152; i++) {
                    Ipp32f *ptr = (Ipp32f *)mp3_lfe_filter + div96;
                    tval = 0.0f;
                    for (j = 0; j < 5; j++) {
                      tval += state->mc_lfe_buf[lfe_offset + j] * *ptr;
                      ptr += 96;
                    }
                    buf[i] = tval;

                    if (div96 == 0) {
                       div96 = 96;
                       lfe_offset++;
                    }
                    div96--;
                  }
                }
                pSampl[state->com.stereo + state->com.mc_channel] = buf;
              }
              ippsJoin_32f16s_D2L((const Ipp32f **)pSampl,
                state->com.stereo + state->com.mc_channel + state->com.mc_header.lfe,
                1152, state->com.m_pOutSamples);
/*              if(state->com.mc_channel) {
                FILE *fp = fopen("o.pcm","wb");
                fwrite(state->com.m_pOutSamples, 2*1152 * state->com.stereo + state->com.mc_channel + state->com.mc_header.lfe, 1, fp);
                fclose(fp);
              }*/
            }
            break;
        case 1:
            mp3dec_audio_data_LayerI(&state->com);
            mp3dec_decode_data_LayerI(state);
            break;
        default:
            res = MP3_UNSUPPORTED;  // unsupported layer
        }
        if (res == MP3_NOT_FIND_SYNCWORD) {
          Ipp32s len = state->com.decodedBytes - prev_decodedBytes;
          *decodedBytes += len;
          inPointer += len;
          inDataSize -= len;
          prev_decodedBytes = state->com.decodedBytes;
        }
    } while (res == MP3_NOT_FIND_SYNCWORD);

    *decodedBytes += (state->com.decodedBytes - prev_decodedBytes);

    ippsCopy_8u((Ipp8u *)&state->com.header, (Ipp8u *)&state->com.header_good,
        sizeof(IppMP3FrameHeader));
    state->com.mpg25_good = state->com.mpg25;
    state->com.m_bInit = 1;

    return res;
}

MP3Status mp3decGetInfo(cAudioCodecParams *a_info, MP3Dec *state)
{
    IppMP3FrameHeader *header;
//    Ipp32s  ch[] = { 2, 2, 2, 1 };
    cAudioStreamType mpeg_type[] = { MPEG2_AUD, MPEG1_AUD };
    cAudioStreamType layer_type[] =
    { MPEG_AUD_LAYER1, MPEG_AUD_LAYER2, MPEG_AUD_LAYER3 };
    Ipp32s ch, ch_mask;

    if (!a_info)
        return MP3_NULL_PTR;

    a_info->m_SuggestedInputSize = 4096;
    a_info->m_SuggestedOutputSize = 1152 * (NUM_CHANNELS + 1) * sizeof(Ipp16s);
    a_info->is_valid = 0;

    if (!state)
      return MP3_OK;

    header = &(state->com.header_good);

    if (state->com.m_bInit) {
        a_info->m_info_in.bitPerSample = 0;
        a_info->m_info_out.bitPerSample = 16;

        a_info->m_info_in.bitrate =
            mp3_bitrate[header->id][3 - header->layer][header->bitRate] * 1000;
        a_info->m_info_out.bitrate = 0;

        mp3decGetChannels(&ch, &ch_mask, state);
        a_info->m_info_in.channels = ch;
        a_info->m_info_out.channels = ch;
        a_info->m_info_in.channel_mask = ch_mask;
        a_info->m_info_out.channel_mask = ch_mask;
        a_info->m_info_in.sample_frequency =
            mp3_frequency[header->id + state->com.mpg25_good][header->samplingFreq];
        a_info->m_info_out.sample_frequency =
            mp3_frequency[header->id + state->com.mpg25_good][header->samplingFreq];

        a_info->m_info_in.stream_type = (cAudioStreamType)
            (mpeg_type[header->id] | layer_type[header->layer - 1]);
        a_info->m_info_out.stream_type = PCM_AUD;

        a_info->m_frame_num = state->com.m_frame_num;

        a_info->is_valid = 1;

        return MP3_OK;
    }

    return MP3_OK;
}

MP3Status mp3decGetDuration(Ipp32f *p_duration, MP3Dec *state)
{
    Ipp32f duration;
    Ipp32s frameSize;
    IppMP3FrameHeader *header;

    if (!state)
        return MP3_NULL_PTR;

    if (state->com.m_bInit)
      header = &(state->com.header_good);
    else
      header = &(state->com.header);

    mp3decGetFrameSize(&frameSize, state);
    duration = (Ipp32f)state->com.m_frame_num * frameSize;

    duration /= (Ipp32f)mp3_frequency[header->id + state->com.mpg25_good][header->samplingFreq];

    *p_duration = duration;

    return MP3_OK;
}

MP3Status mp3decGetChannels(Ipp32s *ch, Ipp32s *ch_mask, MP3Dec *state)
{
/*    IppMP3FrameHeader *header;
    Ipp32s  ch_table[] = { 2, 2, 2, 1 };*/
    Ipp32s nch, mask;

    if (!state)
        return MP3_NULL_PTR;

//    header = &(state->com.header_good);

    nch = state->com.stereo + state->com.mc_channel + state->com.mc_header.lfe;

    if (state->com.stereo == 1) {
      mask = MP3_CHANNEL_CENTER;
    } else {
      mask = MP3_CHANNEL_STEREO;
    }

    if (nch > state->com.stereo) {
      if (state->com.mc_header.center & 1)
        mask |= MP3_CHANNEL_CENTER;
      if (state->com.mc_header.lfe)
        mask |= MP3_CHANNEL_LOW_FREQUENCY;
      switch (state->com.mc_header.surround) {
        case 1:
          mask |= MP3_CHANNEL_SURROUND_MONO; break;
        case 2:
          mask |= MP3_CHANNEL_SURROUND_STEREO; break;
        case 3:
          mask |= MP3_CHANNEL_SURROUND_STEREO_P2; break;
        default: break;
      }
    }

    *ch = nch;
    *ch_mask = mask;

    return MP3_OK;
}

MP3Status mp3decGetFrameSize(Ipp32s *frameSize, MP3Dec *state)
{
    IppMP3FrameHeader *header;
    Ipp32s fs[2][4] = {
        { 0, 384, 1152,  576 },
        { 0, 384, 1152, 1152 }
    };

    if (!state)
        return MP3_NULL_PTR;

    if (state->com.m_bInit)
      header = &(state->com.header_good);
    else
      header = &(state->com.header);

    *frameSize = fs[header->id][header->layer];

    return MP3_OK;
}

MP3Status mp3decGetSampleFrequency(Ipp32s *freq, MP3Dec *state)
{
    IppMP3FrameHeader *header;

    if (!state)
        return MP3_NULL_PTR;

    if (state->com.m_bInit)
      header = &(state->com.header_good);
    else
      header = &(state->com.header);

    *freq = mp3_frequency[header->id + state->com.mpg25_good][header->samplingFreq];

    return MP3_OK;
}

⌨️ 快捷键说明

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