📄 aac_enc_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_enc_own_fp.h"#include "aac_enc_own.h"#include "aac_enc.h"#include "aac_sfb_tables.h"#include "aac_enc_huff_tables.h"#include "aaccmn_const.h"#include "aac_enc_psychoacoustic_fp.h"#include "aac_filterbank_fp.h"#include "aac_enc_quantization_fp.h"#include "aac_enc_ltp_fp.h"#include "align.h"/********************************************************************/AACStatus aacencInit(AACEnc **state_ptr, int sampling_frequency, int chNum, int bit_rate, enum AudioObjectType audioObjectType){ AACEnc *state; AACEnc_com *state_com; Ipp8u *ptr; Ipp32f **m_buff_pointers; Ipp32f **ltp_buff; Ipp32f **ltp_overlap; Ipp16s **buff; int sf_index; int ch; int i, k, w; int sizeOfAACenc, sizeOfOneChannelInfo; int sizeOfPsychoacousticBlock, sizeOfPointers; int size; int num_sfb_for_long; int num_sfb_for_short; int* sfb_offset_for_long; int* sfb_offset_for_short; float f_bits_per_frame; float cutoff_frequency; int bits_per_frame; int bits_for_lfe = 0; int lfe_channel_present; int max_line, max_sfb; float samp_rate_per_ch; if (!state_ptr) return AAC_NULL_PTR; if (chNum < 1) { return AAC_BAD_PARAMETER; } sf_index = 12; for (i = 0; i < 12; i ++) { if (sfb_tables[i].samp_rate == sampling_frequency) { sf_index = i; break; } } if (sf_index == 12) return AAC_BAD_PARAMETER; sizeOfAACenc = (sizeof(AACEnc) + 31) & (~31); sizeOfOneChannelInfo = (sizeof(sOneChannelInfo) + 31) & (~31); sizeOfPsychoacousticBlock = (sizeof(sPsychoacousticBlock) + 31) & (~31); sizeOfPointers = (chNum * 5 * sizeof(Ipp32f*) + chNum * sizeof(Ipp16s*) + 31) & (~31); size = sizeOfAACenc + sizeOfPointers + chNum * (sizeOfOneChannelInfo + sizeOfPsychoacousticBlock + 3 * 1024 * sizeof(Ipp32f) + 1024 * sizeof(Ipp16s)) + 32; if (audioObjectType == AOT_AAC_LTP) { size += chNum * (4096 + 32 + 1024) * sizeof(Ipp32f); } ptr = (Ipp8u *)ippsMalloc_8u(size); if (ptr == NULL) return AAC_ALLOC; ippsZero_8u(ptr, size); state = (AACEnc *)(ptr + (32 - ((int)ptr & 31))); state_com = &(state->com); state_com->real_state = ptr; ptr = (Ipp8u *)state + sizeOfAACenc; state_com->chInfo = (sOneChannelInfo *)ptr; ptr += chNum * sizeOfOneChannelInfo; state_com->m_channel_number = chNum; state_com->sampling_frequency_index = sf_index; state_com->m_sampling_frequency = sampling_frequency; state_com->m_bitrate = bit_rate; state_com->m_frame_number = 0; m_buff_pointers = (Ipp32f**)ptr; ltp_buff = m_buff_pointers + 3 * chNum; ltp_overlap = ltp_buff + chNum; buff = (Ipp16s**)(ltp_overlap + chNum); ptr += sizeOfPointers; state->psychoacoustic_block = (sPsychoacousticBlock *)ptr; ptr += chNum * sizeOfPsychoacousticBlock; for (i = 0; i < 3 * chNum; i++) { m_buff_pointers[i] = (Ipp32f*)ptr; ptr += 1024 * sizeof(Ipp32f); } if (audioObjectType == AOT_AAC_LTP) { for (i = 0; i < chNum; i++) { ltp_buff[i] = (Ipp32f*)ptr; ptr += (4096 + 32) * sizeof(Ipp32f); } for (i = 0; i < chNum; i++) { ltp_overlap[i] = (Ipp32f*)ptr; ptr += 1024 * sizeof(Ipp32f); } } for (i = 0; i < chNum; i++) { buff[i] = (Ipp16s*)ptr; ptr += 1024 * sizeof(Ipp16s); } state->m_buff_pointers = m_buff_pointers; state->ltp_buff = ltp_buff; state->ltp_overlap = ltp_overlap; state_com->buff = buff; state_com->m_buff_prev_index = 0; state_com->m_buff_curr_index = 1; state_com->m_buff_next_index = 2; num_sfb_for_long = state_com->real_num_sfb[0] = state_com->real_num_sfb[1] = state_com->real_num_sfb[3] = sfb_tables[sf_index].num_sfb_long_window; num_sfb_for_short = state_com->real_num_sfb[2] = sfb_tables[sf_index].num_sfb_short_window; sfb_offset_for_short = sfb_tables[sf_index].sfb_offset_short_window; state_com->sfb_offset_for_short_window[0] = 0; k = 1; for (w = 0; w < 8; w ++) { for ( i = 0; i < num_sfb_for_short; i++) { state_com->sfb_offset_for_short_window[k] = state_com->sfb_offset_for_short_window[k-1] + (sfb_offset_for_short[i + 1] - sfb_offset_for_short[i]); k++; } } state_com->sfb_offset[0] = state_com->sfb_offset[1] = state_com->sfb_offset[3] = sfb_tables[sf_index].sfb_offset_long_window; state_com->sfb_offset[2] = state_com->sfb_offset_for_short_window; BuildHuffmanTables((IppsVLCEncodeSpec_32s**)(&state_com->huffman_tables)); lfe_channel_present = 0; for (ch = 0; ch < chNum;) { if (ch == 0) { if (state_com->m_channel_number == 2) { state_com->chInfo[ch].element_id = ID_CPE; state_com->chInfo[ch + 1].element_id = ID_CPE; ch += 2; } else { state_com->chInfo[ch].element_id = ID_SCE; ch += 1; } } else { if (state_com->m_channel_number != state_com->m_channel_number - 1) { state_com->chInfo[ch].element_id = ID_CPE; state_com->chInfo[ch + 1].element_id = ID_CPE; ch += 2; } else { state_com->chInfo[ch].element_id = ID_LFE; ch += 1; lfe_channel_present++; } } } bits_per_frame = (int)(((float)bit_rate) * 1024/(sfb_tables[sf_index].samp_rate)); bits_per_frame &= ~7; bits_per_frame -= 3; /* for ID_END */ f_bits_per_frame = (float)bits_per_frame; samp_rate_per_ch = ((float)bit_rate) / chNum; sfb_offset_for_long = sfb_tables[sf_index].sfb_offset_long_window; ippsPow34_32f(&samp_rate_per_ch, &cutoff_frequency, 1); cutoff_frequency *= 4; max_line = (int)(2048 * cutoff_frequency / (float)sampling_frequency); max_sfb = num_sfb_for_long; for (i = 0; i < num_sfb_for_long; i++) { if (sfb_offset_for_long[i] > max_line) { max_sfb = i; break; } } state_com->real_max_sfb[0] = state_com->real_max_sfb[1] = state_com->real_max_sfb[3] = max_sfb; max_line = (int)(256 * cutoff_frequency / (float)sampling_frequency); max_sfb = num_sfb_for_short; for (i = 0; i < num_sfb_for_short; i++) { if (sfb_offset_for_short[i] > max_line) { max_sfb = i; break; } } state_com->real_max_sfb[2] = max_sfb; /* max_sfb for LFE channel calculating */ if (cutoff_frequency > MAX_LFE_FREQUENCY) { cutoff_frequency = MAX_LFE_FREQUENCY; max_line = (int)(2048 * cutoff_frequency / (float)sampling_frequency); max_sfb = num_sfb_for_long; for (i = 0; i < num_sfb_for_long; i++) { if (sfb_offset_for_long[i] > max_line) { max_sfb = i; break; } } state_com->real_max_sfb_lfe[0] = state_com->real_max_sfb_lfe[1] = state_com->real_max_sfb_lfe[3] = max_sfb; max_line = (int)(256 * cutoff_frequency / (float)sampling_frequency); max_sfb = num_sfb_for_short; for (i = 0; i < num_sfb_for_short; i++) { if (sfb_offset_for_short[i] > max_line) { max_sfb = i; break; } } state_com->real_max_sfb_lfe[2] = max_sfb; } else { state_com->real_max_sfb_lfe[0] = state_com->real_max_sfb_lfe[1] = state_com->real_max_sfb_lfe[3] = state_com->real_max_sfb[0]; state_com->real_max_sfb_lfe[2] = state_com->real_max_sfb[2]; } if (InitFilterbank(&(state->filterbank_block), FB_DECODER | FB_ENCODER) != AAC_OK) { aacencClose(state); return AAC_ALLOC; } if (InitPsychoacousticCom(&state->psychoacoustic_block_com, sf_index) != AAC_OK) { aacencClose(state); return AAC_ALLOC; } state->psychoacoustic_block_com.prev_prev_f_r_index = state_com->m_buff_prev_index; state->psychoacoustic_block_com.prev_f_r_index = state_com->m_buff_curr_index; state->psychoacoustic_block_com.current_f_r_index = state_com->m_buff_next_index; for (ch = 0; ch < chNum; ch++) { InitPsychoacoustic(&state->psychoacoustic_block[ch]); } if (lfe_channel_present != 0) { bits_for_lfe = (int)(0.2 * f_bits_per_frame / ((state_com->m_channel_number - lfe_channel_present) + 0.2 * lfe_channel_present)); if (bits_for_lfe < 300) bits_for_lfe = 300; else if (bits_for_lfe > 768 * 8) bits_for_lfe = 768 * 8; f_bits_per_frame -= (float)(bits_for_lfe * lfe_channel_present); } for (ch = 0; ch < chNum;) { int sce_tag = 0; int cpe_tag = 0; int lfe_tag = 0; float num_channel = (float)(state_com->m_channel_number - lfe_channel_present); state_com->chInfo[ch].prev_window_shape = 1; state_com->chInfo[ch].common_scalefactor_update = 2; state_com->chInfo[ch].last_frame_common_scalefactor = 0; if (state_com->chInfo[ch].element_id == ID_CPE) { state_com->chInfo[ch+1].common_scalefactor_update = 2; state_com->chInfo[ch+1].last_frame_common_scalefactor = 0; state_com->chInfo[ch].element_instance_tag = cpe_tag; state_com->chInfo[ch].bits_in_buf = 0; state_com->chInfo[ch].mean_bits = (int)(2 * f_bits_per_frame/num_channel); state_com->chInfo[ch].max_bits_in_buf = 768 * 8 * 2; f_bits_per_frame -= (float)(state_com->chInfo[ch].mean_bits); cpe_tag++; ch += 2; num_channel -= 2; } else if (state_com->chInfo[ch].element_id == ID_SCE) { state_com->chInfo[ch].element_instance_tag = sce_tag; state_com->chInfo[ch].bits_in_buf = 0; state_com->chInfo[ch].mean_bits = (int)(f_bits_per_frame/num_channel); state_com->chInfo[ch].max_bits_in_buf = 768 * 8; f_bits_per_frame -= (float)(state_com->chInfo[ch].mean_bits); sce_tag++; ch += 1; num_channel -= 1; } else { state_com->chInfo[ch].element_instance_tag = lfe_tag; state_com->chInfo[ch].bits_in_buf = 0; state_com->chInfo[ch].mean_bits = bits_for_lfe; state_com->chInfo[ch].max_bits_in_buf = 768 * 8; lfe_tag++; ch += 1; } } state_com->audioObjectType = audioObjectType; if (state_com->audioObjectType == AOT_AAC_LTP) { if (ippsFFTInitAlloc_R_32f(&state->corrFft, 12, IPP_FFT_DIV_INV_BY_N, ippAlgHintNone) != ippStsOk) { aacencClose(state); return AAC_ALLOC; } if (ippsFFTGetBufSize_R_32f(state->corrFft, &size) != ippStsOk) { aacencClose(state); return AAC_ALLOC; } if (size != 0) { state->corrBuff = ippsMalloc_8u(size); if (state->corrBuff== NULL) { aacencClose(state); aacencClose(state); } } } *state_ptr = state; return AAC_OK;}/********************************************************************/AACStatus aacencGetFrame(Ipp16s *inPointer, int *encodedBytes, Ipp8u *outPointer, AACEnc *state){ __ALIGN Ipp32f mdct_line[1024]; __ALIGN Ipp32f mdct_line_i[1024]; __ALIGN Ipp32f mdct_line_pred[1024]; __ALIGN Ipp32f predictedBuf[2048]; __ALIGN Ipp32f predictedSpectrum[1024]; __ALIGN Ipp32f inSignal[4 * 1024]; Ipp32f *p_mdct_line; Ipp32f *p_mdct_line_pred;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -