📄 mp3dec_common.c
字号:
&state->nbal_alloc_table,
&state->alloc_table,
&state->sblimit);
state->jsbound = 32;
if (header->mode == 0x01) {
state->jsbound = (header->modeExt + 1) * 4;
}
if (state->jsbound > state->sblimit) {
state->jsbound = state->sblimit;
}
} else if (header->layer == 1) {
state->jsbound = 32;
if (header->mode == 0x01) {
state->jsbound = (header->modeExt + 1) * 4;
}
}
return MP3_OK;
}
/******************************************************************************
// Name:
// ReadMainData
//
// Description:
// Copy data form global buffer, which contains all streams, into special buffer,
// which contains only main data (i.e. headers of frames & side information are excluded)
//
// Input Arguments:
// DC - point to sDecoderContext structure
//
// Output Arguments:
// MainData - special buffer
//
// Returns:
// 1 - is not ok.
// 0 - all ok
//
******************************************************************************/
Ipp32s mp3dec_ReadMainData(MP3Dec_com *state)
{
Ipp8u *GlBS;
Ipp8u *MDBS;
Ipp32s nSlots;
Ipp32s status = 0;
sBitsreamBuffer *m_MainData = &state->m_MainData;
sBitsreamBuffer *m_StreamData = &state->m_StreamData;
// detect start point
if ((Ipp32s)(m_MainData->nDataLen - state->si_main_data_begin) >= 0)
{
m_MainData->pCurrent_dword =
m_MainData->pBuffer + (m_MainData->nDataLen - state->si_main_data_begin) / 4;
m_MainData->dword = BSWAP(m_MainData->pCurrent_dword[0]);
m_MainData->nBit_offset =
32 - ((m_MainData->nDataLen - state->si_main_data_begin) % 4) * 8;
} else {
status = 1;
}
// GIBS points to the start point of the undecoded main data in globalBuffer
GlBS =
(Ipp8u *)(m_StreamData->pCurrent_dword) + (4 -
m_StreamData->
nBit_offset / 8);
// nSlots = number of bytes between two successive frames (without header and
// side info).
nSlots = state->MP3nSlots + mp3dec_main_data_slots(state->stereo, state->header.id,
state->header.protectionBit);
// nSlots contains only main data cannot be bigger than the defined maximum
// (MAINDATASIZE).
if (nSlots > state->MAINDATASIZE) {
return 1;
}
if (nSlots + m_MainData->nDataLen > state->MAINDATASIZE) {
// bytes = number of bytes which have been received, but not decoded yet.
Ipp32s bytes;
if (status == 0) {
bytes =
m_MainData->nDataLen - (m_MainData->pCurrent_dword -
m_MainData->pBuffer) * 4;
// copies the undecoded bytes (bytes beginning at pBuffer+iDWDoneNum)
// to the start of the MainData buffer.
ippsCopy_8u((Ipp8u *)(m_MainData->pCurrent_dword),
(Ipp8u *)m_MainData->pBuffer, bytes);
} else {
bytes =
m_MainData->nDataLen - (state->MAINDATASIZE - nSlots);
ippsCopy_8u((Ipp8u *)m_MainData->pBuffer +
m_MainData->nDataLen - bytes,
(Ipp8u *)m_MainData->pBuffer, bytes);
}
// effectively shifts the undecoded bytes to the start of the MainData buffer
m_MainData->pCurrent_dword = m_MainData->pBuffer;
m_MainData->nDataLen = bytes;
}
// MDBS points to the first
MDBS = (Ipp8u *)m_MainData->pBuffer + m_MainData->nDataLen;
ippsCopy_8u(GlBS, MDBS, nSlots);
m_MainData->nDataLen += nSlots;
return status;
}
MP3Status mp3dec_ReceiveBuffer(sBitsreamBuffer *m_StreamData, void *in_GetPointer, Ipp32s in_GetDataSize)
{
GET_INIT_BITSTREAM(m_StreamData, in_GetPointer)
m_StreamData->nDataLen = in_GetDataSize;
return MP3_OK;
}
MP3Status mp3dec_GetID3Len(Ipp8u *in,
Ipp32s inDataSize,
MP3Dec_com *state)
{
if ((state->m_bInit != 0) || (state->id3_size) > 0)
return MP3_OK;
if (inDataSize < 10)
return MP3_NOT_ENOUGH_DATA;
if ((in[0] == 'I') && (in[1] == 'D') && (in[2] == '3') && /* 'ID3' */
(in[3] < 0xFF) && (in[4] < 0xFF) && /* Version or revision will never be 0xFF */
(in[6] < 0x80) && (in[7] < 0x80) && (in[8] < 0x80) && (in[9] < 0x80)) { /* size */
state->id3_size = (in[6] << 21) + (in[7] << 14) + (in[8] << 7) + in[9] + 10;
} else {
state->id3_size = 0;
}
return MP3_OK;
}
MP3Status mp3dec_SkipID3(Ipp32s inDataSize,
Ipp32s *skipped,
MP3Dec_com *state)
{
*skipped = 0;
if (state->id3_size > 0) {
if (inDataSize < state->id3_size) {
*skipped = inDataSize;
state->id3_size -= inDataSize;
return MP3_NOT_ENOUGH_DATA;
} else {
*skipped = state->id3_size;
state->id3_size = 0;
return MP3_OK;
}
}
return MP3_OK;
}
void mp3dec_mc_header(MP3Dec_com *state)
{
sBitsreamBuffer *m_data = &(state->m_StreamData);
mp3_mc_header *mc_header = &(state->mc_header);
GET_BITS(m_data, mc_header->ext_bit_stream_present, 1, Ipp32s);
if (mc_header->ext_bit_stream_present)
GET_BITS(m_data, mc_header->n_ad_bytes, 8, Ipp32s);
GET_BITS(m_data, mc_header->center, 2, Ipp32s);
GET_BITS(m_data, mc_header->surround, 2, Ipp32s);
GET_BITS(m_data, mc_header->lfe, 1, Ipp32s);
GET_BITS(m_data, mc_header->audio_mix, 1, Ipp32s);
GET_BITS(m_data, mc_header->dematrix_procedure, 2, Ipp32s);
GET_BITS(m_data, mc_header->no_of_multi_lingual_ch, 3, Ipp32s);
GET_BITS(m_data, mc_header->multi_lingual_fs, 1, Ipp32s);
GET_BITS(m_data, mc_header->multi_lingual_layer, 1, Ipp32s);
GET_BITS(m_data, mc_header->copyright_identification_bit, 1, Ipp32s);
GET_BITS(m_data, mc_header->copyright_identification_start, 1, Ipp32s);
if (mc_header->ext_bit_stream_present)
state->crc_nbits = 24;
else
state->crc_nbits = 16;
GET_BITS(m_data, state->crc_check, 16, Ipp32s);
/*
printf("\nMC Header:\n");
printf("ext_bit_stream_present = %d\n",mc_header->ext_bit_stream_present);
printf("n_ad_bytes = %d\n",mc_header->n_ad_bytes);
printf("center = %d\n",mc_header->center);
printf("surround = %d\n",mc_header->surround);
printf("lfe = %d\n",mc_header->lfe);
printf("audio_mix = %d\n",mc_header->audio_mix);
printf("dematrix_procedure = %d\n",mc_header->dematrix_procedure);
printf("no_of_multi_lingual_ch = %d\n",mc_header->no_of_multi_lingual_ch);
printf("multi_lingual_fs = %d\n",mc_header->multi_lingual_fs);
printf("multi_lingual_layer = %d\n",mc_header->multi_lingual_layer);
printf("copyright_identification_bit = %d\n",mc_header->copyright_identification_bit);
printf("copyright_identification_start = %d\n",mc_header->copyright_identification_start);
*/
}
void mp3dec_mc_params(MP3Dec_com *state)
{
mp3_mc_header *mc_header = &(state->mc_header);
if (mp3_frequency[state->header.id + state->mpg25][state->header.samplingFreq] == 48000) {
state->alloc_table = mp3_alloc_table1;
state->nbal_alloc_table = mp3_nbal_alloc_table1;
state->sblimit = mp3_sblimit_table[0];
} else {
state->alloc_table = mp3_alloc_table2;
state->nbal_alloc_table = mp3_nbal_alloc_table2;
state->sblimit = mp3_sblimit_table[1];
}
if (mc_header->surround == 3)
if (mc_header->center == 1 || mc_header->center == 3) {
state->mc_channel = 3;
state->mc_alloc_bits = 2;
state->mc_dyn_cross_bits = 1;
state->mc_pred_mode = 2;
}
else {
state->mc_channel = 2;
state->mc_alloc_bits = 0;
state->mc_dyn_cross_bits = 0;
state->mc_pred_mode = 5;
}
else if (mc_header->surround == 2)
if (mc_header->center == 1 || mc_header->center == 3) {
state->mc_channel = 3;
state->mc_alloc_bits = 3;
state->mc_dyn_cross_bits = 4;
state->mc_pred_mode = 0;
}
else {
state->mc_channel = 2;
state->mc_alloc_bits = 2;
state->mc_dyn_cross_bits = 3;
state->mc_pred_mode = 3;
}
else if (mc_header->surround == 1)
if (mc_header->center == 1 || mc_header->center == 3) {
state->mc_channel = 2;
state->mc_alloc_bits = 3;
state->mc_dyn_cross_bits = 3;
state->mc_pred_mode = 1;
}
else {
state->mc_channel = 1;
state->mc_alloc_bits = 2;
state->mc_dyn_cross_bits = 1;
state->mc_pred_mode = 4;
}
else
if (mc_header->center == 1 || mc_header->center == 3) {
state->mc_channel = 1;
state->mc_alloc_bits = 2;
state->mc_dyn_cross_bits = 1;
state->mc_pred_mode = 2;
}
else {
state->mc_channel = 0;
state->mc_alloc_bits = 0;
state->mc_dyn_cross_bits = 0;
state->mc_pred_mode = 5;
}
if ( (mc_header->no_of_multi_lingual_ch > 0) &&
(mc_header->multi_lingual_layer > 0) ) {
mc_header->no_of_multi_lingual_ch = 0;
}
}
void mp3dec_mc_composite_status_info(MP3Dec_com *state)
{
sBitsreamBuffer *m_data = &(state->m_StreamData);
Ipp32s i, sb, nbits = 0;
GET_BITS(m_data, state->mc_tc_sbgr_select, 1, Ipp32s);
GET_BITS(m_data, state->mc_dyn_cross_on, 1, Ipp32s);
GET_BITS(m_data, state->mc_prediction_on, 1, Ipp32s);
nbits += 3;
for(sb = 0; sb < 12; sb++) {
state->mc_tc_alloc[sb] = 0;
state->mc_dyn_cross_mode[sb] = 0;
}
if(!state->mc_alloc_bits) {
state->mc_tc_allocation = 0;
}
else if(state->mc_tc_sbgr_select == 1) {
GET_BITS(m_data, state->mc_tc_allocation, state->mc_alloc_bits, Ipp32s);
nbits += state->mc_alloc_bits;
for(sb = 0; sb < 12; sb++)
state->mc_tc_alloc[sb] = state->mc_tc_allocation;
}
else {
state->mc_tc_allocation = 0;
for(sb = 0; sb < 12; sb++) {
GET_BITS(m_data, state->mc_tc_alloc[sb], state->mc_alloc_bits, Ipp32s);
nbits += state->mc_alloc_bits;
}
}
if( state->mc_dyn_cross_on == 1) {
GET_BITS(m_data, state->mc_dyn_cross_LR, 1, Ipp32s);
nbits++;
if(state->mc_dyn_cross_bits)
for(sb = 0; sb < 12; sb++) {
GET_BITS(m_data, state->mc_dyn_cross_mode[sb], state->mc_dyn_cross_bits, Ipp32s);
nbits += state->mc_dyn_cross_bits;
if (state->mc_header.surround == 3) {
GET_BITS(m_data, state->mc_dyn_second_stereo[sb], 1, Ipp32s);
nbits++;
}
}
}
else state->mc_dyn_cross_LR = 0;
if( state->mc_prediction_on == 1) {
for(sb = 0; sb < 8; sb++) {
GET_BITS(m_data, state->mc_prediction[sb], 1, Ipp32s);
nbits++;
if ( state->mc_prediction[sb] == 1 ) {
Ipp32s val;
val = mp3_mc_pred_coef_table[state->mc_pred_mode][state->mc_dyn_cross_mode[sb]];
for(i = 0; i < val ; i++) {
GET_BITS(m_data, state->mc_predsi[sb][i], 2, Ipp32s);
nbits += 2;
}
}
}
}
state->crc_nbits += nbits;
}
void mp3dec_CRC_start(MP3Dec_com *state)
{
sBitsreamBuffer *m_data = &(state->m_StreamData);
state->crc_nbits = 0;
state->crc_ptr = m_data->pCurrent_dword;
state->crc_offset = m_data->nBit_offset;
}
void mp3dec_CRC_update(MP3Dec_com *state, Ipp32u *crc)
{
bs_CRC_update(state->crc_ptr, state->crc_offset,
state->crc_nbits, crc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -