📄 aac_dec_api_fp.c
字号:
/*//// 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-2005 Intel Corporation. All Rights Reserved.//// Intel(R) Integrated Performance Primitives AAC Decode Sample for Windows*//// By downloading and installing this sample, you hereby agree that the// accompanying Materials are being provided to you under the terms and// conditions of the End User License Agreement for the Intel(R) Integrated// Performance Primitives product previously accepted by you. Please refer// to the file ipplic.htm located in the root directory of your Intel(R) IPP// product installation for more information.//// MPEG-4 and AAC are international standards promoted by ISO, IEC, ITU, ETSI// and other organizations. Implementations of these standards, or the standard// enabled platforms may require licenses from various entities, including// Intel Corporation.//*//********************************************************************/#include <stdlib.h>#include "aac_dec_decoding_fp.h"#include "aac_dec_own_fp.h"#include "aac_dec_huff_tables.h"#include "sbrdec_api_fp.h"#include "sbrdec_tables.h"/********************************************************************/#ifndef UMC_MAX#define UMC_MAX(a,b) (((a) > (b)) ? (a) : (b))#endif/********************************************************************/AACStatus aacdecReset(AACDec *state){ int i; if (!state) return AAC_NULL_PTR; state->com.m_frame_number = 0; state->com.m_index_1st = 0; state->com.m_index_2nd = 1; state->com.m_index_3rd = 2; state->com.noiseState = 0; state->com.SbrFlagPresent = 0; state->com.ModeDecodeHEAACprofile = HEAAC_HQ_MODE; state->com.ModeDwnmxHEAACprofile = HEAAC_DWNSMPL_OFF; for (i = 0; i < CH_MAX; i++) { ippsZero_32f(state->m_ltp_buf[i][0], 2048); ippsZero_32f(state->m_ltp_buf[i][1], 2048); ippsZero_32f(state->m_ltp_buf[i][2], 2048); ippsZero_32f(state->m_prev_samples[i], 2048); state->com.m_prev_win_shape[i] = 0; } return AAC_OK;}/********************************************************************/AACStatus aacdecInit(AACDec **state_ptr){ AACDec *state; int i; /* HE-AAC */ int SizeWorkBuf = 0; if (!state_ptr) return AAC_NULL_PTR; state = (AACDec *)ippsMalloc_8u(sizeof(AACDec)); if (state == NULL) return AAC_ALLOC; aacdecReset(state); state->com.m_is_chmap_valid = 0; state->com.m_is_pce_valid = 0; state->com.m_sampling_frequency = 0; state->com.m_sampling_frequency_index = 0; state->com.m_channel_number = 1; state->com.m_channel_number_save = 1; state->com.m_channel_config = 0; state->com.m_frame_size = 1024; state->com.adts_channel_configuration = -1; state->com.m_audio_object_type = AOT_UNDEF; for (i = 0; i < 16; i++) { state->com.huffman_tables[i] = NULL; } for (i = 0; i < 10; i++) { state->com.sbrHuffTables[i] = NULL; } for (i = 0; i < CH_MAX; i++) { state->sbrBlock[i] = NULL; state->sbr_filter[i] = NULL; } state->pWorkBuffer = NULL; state->m_filterbank.p_mdct_inv_long = NULL; state->m_filterbank.p_mdct_inv_short = NULL; state->m_filterbank.p_buffer_inv = NULL; state->m_filterbank.p_mdct_fwd_long = NULL; state->m_filterbank.p_mdct_fwd_short = NULL; state->m_filterbank.p_buffer_fwd = NULL; for (i = 0; i < 12; i++) { if (ippsVLCDecodeInitAlloc_32s(vlcBooks[i], vlcTableSizes[i], vlcSubTablesSizes[i], vlcNumSubTables[i], (IppsVLCDecodeSpec_32s**) (&(state->com.huffman_tables[i]))) != ippStsOk) { aacdecClose(state); return AAC_ALLOC; } } for (i = 0; i < 10; i++) { if (ippsVLCDecodeInitAlloc_32s(vlcSbrBooks[i], vlcSbrTableSizes[i], vlcSbrSubTablesSizes[i], vlcSbrNumSubTables[i], (IppsVLCDecodeSpec_32s**) (&(state->com.sbrHuffTables[i]))) != ippStsOk) { aacdecClose(state); return AAC_ALLOC; } } (state->com.m_sce).stream.p_huffman_tables = (void **)&(state->com.huffman_tables[0]); (state->com.m_cpe).streams[0].p_huffman_tables = (void **)&(state->com.huffman_tables[0]); (state->com.m_cpe).streams[1].p_huffman_tables = (void **)&(state->com.huffman_tables[0]); (state->com.m_cce).stream.p_huffman_tables = (void **)&(state->com.huffman_tables[0]); (state->com.m_lfe).stream.p_huffman_tables = (void **)&(state->com.huffman_tables[0]); if (InitFilterbank(&(state->m_filterbank), FB_DECODER | FB_ENCODER) != AAC_OK) { aacdecClose(state); return AAC_ALLOC; } sbrdecInitFilter( state->sbr_filter, &SizeWorkBuf ); SizeWorkBuf = UMC_MAX( SizeWorkBuf, SBR_MINSIZE_OF_WORK_BUFFER ); state->pWorkBuffer = ippsMalloc_8u( SizeWorkBuf ); for (i = 0; i < CH_MAX; i++) { state->sbrBlock[i] = sbrInitDecoder( ); ippsCopy_8u((const Ipp8u *)(state->com.sbrHuffTables), (Ipp8u *)(state->sbrBlock[i]->sbr_com.sbrHuffTables), 10 * sizeof(void *)); } *state_ptr = state; return AAC_OK;}/********************************************************************/#define RETURN_AAC_BAD_STREAM \{ \ GET_BITS_COUNT(pBS, (*decodedBytes)) \ *decodedBytes >>= 3; \ state_com->m_channel_number = state_com->m_channel_number_save; \ ippsZero_16s(outPointer, 1024 * state_com->m_channel_number); \ return AAC_BAD_STREAM; \}/********************************************************************/AACStatus aacdecGetFrame(Ipp8u *inPointer, int *decodedBytes, Ipp16s *outPointer, AACDec *state){ sData_stream_element m_data; sDynamic_range_info m_drc_info; sBitsreamBuffer BS; sBitsreamBuffer *pBS = &BS; AACDec_com *state_com; int el_num = 0; int ch_num = 0; int order_counter = 0; int id; int tag = 0; int ch = 0;/* HE-AAC param */ int cnt_fill_sbr_element = 0; int cnt_idaac_sbr_element = 0; int sbrFlagPresentLFE = 0; int NumRealCh = 0; int ch_counter; int errSBRParser = 0; s_tns_data tns_data0; s_tns_data tns_data1; int i, j; if (!inPointer || !outPointer) return AAC_NULL_PTR; GET_INIT_BITSTREAM(pBS, inPointer) // init state_com = &(state->com); state->com.m_up_sample = 1; GET_BITS(pBS, id, 3) while (id != ID_END) { if (CH_MAX - 1 < NumRealCh) RETURN_AAC_BAD_STREAM; switch (id) { case ID_SCE: /* may be there is HE-AAC element */ state->sbrBlock[cnt_idaac_sbr_element++]->sbr_com.id_aac = ID_SCE; NumRealCh++; /* Parsing bitstream */ if (dec_sce_channel_element(&(state_com->m_sce), pBS, state_com->m_audio_object_type) < 0) RETURN_AAC_BAD_STREAM; tag = (state_com->m_sce).element_instance_tag; break; case ID_CPE: /* may be there is HE-AAC element */ state->sbrBlock[cnt_idaac_sbr_element++]->sbr_com.id_aac = ID_CPE; NumRealCh += 2; /* Parsing bitstream */ if (dec_cpe_channel_element(&(state_com->m_cpe), pBS, state_com->m_audio_object_type) < 0) RETURN_AAC_BAD_STREAM; tag = (state_com->m_cpe).element_instance_tag; break; case ID_CCE: if (dec_coupling_channel_element(&(state_com->m_cce), pBS, state_com->m_audio_object_type) < 0) RETURN_AAC_BAD_STREAM; tag = (state_com->m_cce).element_instance_tag; break; case ID_LFE: /* may be there is HE-AAC element */ if (CH_MAX - 1 < cnt_idaac_sbr_element) RETURN_AAC_BAD_STREAM; state->sbrBlock[cnt_idaac_sbr_element++]->sbr_com.id_aac = ID_LFE; if (cnt_fill_sbr_element > 0) { sbrFlagPresentLFE++; if ( CH_MAX - 1 < cnt_fill_sbr_element ) RETURN_AAC_BAD_STREAM; cnt_fill_sbr_element++; } /* Parsing bitstream */ if (dec_lfe_channel_element(&(state_com->m_lfe), pBS, state_com->m_audio_object_type) < 0) RETURN_AAC_BAD_STREAM; tag = (state_com->m_lfe).element_instance_tag; NumRealCh++; break; case ID_DSE: dec_data_stream_element(&m_data, pBS); break; case ID_PCE: dec_program_config_element(&(state_com->m_pce), pBS); state_com->m_is_chmap_valid = 0; state_com->m_is_pce_valid = 1; break; case ID_FIL:/** NOTES:* (1)SBR FILL ELEMENT there is for SCE & CPE modes only.* (2)If AOT AAC is MAIN, LC or LTP* then* <SCE> <FIL <EXT_SBR_DATA(SCE)>> // center* <CPE> <FIL <EXT_SBR_DATA(CPE)>> // front L/R* <CPE> <FIL <EXT_SBR_DATA(CPE)>> // back L/R* <LFE> // sub* <END> // (end of raw data block)** (3)If AOT AAC is ER LC or ER LTP* then* <SCE> <CPE> <CPE> <LFE> <EXT <SBR(SCE)> <SBR(CPE)> <SBR(CPE)>>** (4) may be more then one FILL ELEMENT, for ex:* <SCE> <FILL.. <CPE> <FILL.. <CPE> <FILL..><FILL..> <LFE><FILL..><FILL..><FILL..>*/ if ( CH_MAX - 1 < cnt_fill_sbr_element ) RETURN_AAC_BAD_STREAM; state->sbrBlock[cnt_fill_sbr_element]->sbr_com.FreqSbr = state_com->m_sampling_frequency * 2; if (state->com.m_sampling_frequency_index >= 3) state->sbrBlock[cnt_fill_sbr_element]->sbr_com.sbr_freq_indx = state->com.m_sampling_frequency_index - 3; state->sbrBlock[cnt_fill_sbr_element]->sbr_com.sbrFlagError = 0; errSBRParser = dec_fill_element( &(state->sbrBlock[cnt_fill_sbr_element]->sbr_com), &cnt_fill_sbr_element, &m_drc_info, pBS); /************************************************************* * if there is problem with HE-AAC parser then QUIT *************************************************************/ if ( errSBRParser ) RETURN_AAC_BAD_STREAM break; } if (ID_DSE > id) { if (0 == state_com->m_is_chmap_valid) { state_com->m_chmap[id][tag].ch = (short)ch_num; state_com->m_elmap[el_num].id = (short)id; state_com->m_elmap[el_num].tag = (short)tag; if (ID_CCE != id) { state_com->m_elmap[el_num].ch = (short)ch_num; state_com->m_order[order_counter++] = ch_num; } else { state_com->m_elmap[el_num].ch = -1; } el_num++; ch_num++; if (ID_CPE == id) { state_com->m_order[order_counter++] = ch_num; ch_num++; } } ch = state_com->m_chmap[id][tag].ch; if (ch < 0) continue; /* only parsing */; } switch (id) { case ID_SCE: state_com->m_curr_win_shape[ch] = (state_com->m_sce).stream.window_shape; state_com->m_curr_win_sequence[ch] = (state_com->m_sce).stream.window_sequence; if (0 != (state_com->m_sce).stream.pulse_data_present) { ics_apply_pulse_I(&(state_com->m_sce).stream); } ics_apply_scale_factors(&(state_com->m_sce).stream, state->m_spectrum_data[ch]); apply_pns(&(state_com->m_sce).stream, NULL, state->m_spectrum_data[ch], NULL, 1, 0, NULL, &(state_com->noiseState)); ics_calc_tns_data(&(state_com->m_sce).stream, &tns_data0); if (AOT_AAC_LTP == state_com->m_audio_object_type) { state->m_ltp.p_samples_1st_part = state->m_ltp_buf[ch][state_com->m_index_1st]; state->m_ltp.p_samples_2nd_part = state->m_ltp_buf[ch][state_com->m_index_2nd]; state->m_ltp.p_samples_3rd_part = state->m_ltp_buf[ch][state_com->m_index_3rd]; state->m_ltp.prev_windows_shape = state_com->m_prev_win_shape[ch]; state->m_ltp.p_filterbank_data = &(state->m_filterbank); state->m_ltp.p_tns_data = &tns_data0; ics_apply_ltp_I(&(state->m_ltp), &(state_com->m_sce).stream, state->m_spectrum_data[ch]); } if (0 != (state_com->m_sce).stream.tns_data_present) { ics_apply_tns_dec_I(&tns_data0, state->m_spectrum_data[ch]); } break; case ID_CPE: state_com->m_curr_win_shape[ch] = (state_com->m_cpe).streams[0].window_shape; state_com->m_curr_win_sequence[ch] = (state_com->m_cpe).streams[0].window_sequence; state_com->m_curr_win_shape[ch + 1] = (state_com->m_cpe).streams[1].window_shape; state_com->m_curr_win_sequence[ch + 1] = (state_com->m_cpe).streams[1].window_sequence; if (0 != (state_com->m_cpe).streams[0].pulse_data_present) { ics_apply_pulse_I(&(state_com->m_cpe).streams[0]); } if (0 != (state_com->m_cpe).streams[1].pulse_data_present) { ics_apply_pulse_I(&(state_com->m_cpe).streams[1]); } ics_apply_scale_factors(&(state_com->m_cpe).streams[0], state->m_spectrum_data[ch]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -