📄 aac_enc_elements.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-2007 Intel Corporation. All Rights Reserved.
//
// Intel Integrated Performance Primitives AAC Encode 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 Integrated
// Performance Primitives product previously accepted by you. Please refer
// to the file ippEULA.rtf located in the root directory of your Intel 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 "aac_enc_huff_tables.h"
#include "bstream.h"
#include "aaccmn_adts.h"
#include "aaccmn_adif.h"
#include "aac_enc_own.h"
Ipp32u sf_huff_codebook[];
Ipp32s enc_ltp_data(sEnc_individual_channel_stream* pStream,
sBitsreamBuffer* pBS,
Ipp32s writing);
/********************************************************************/
//void tns_data(sEnc_individual_channel_stream* pStream,
// sBitsreamBuffer* pBS);
/****************************************************************************/
Ipp32s fill_program_config_element(sProgram_config_element* p_data,
Ipp32s element_instance_tag,
AACEnc_com *state_com)
{
Ipp32s chNum = state_com->m_channel_number;
sOneChannelInfo* chInfo = state_com->chInfo;
Ipp32s num_channel_elements[3];
Ipp32s *element_tag_select[3];
Ipp32s *element_is_cpe[3];
Ipp32s i;
switch (state_com->audioObjectType) {
case AOT_AAC_MAIN:
p_data->object_type = 0;
break;
case AOT_AAC_LC:
p_data->object_type = 1;
break;
case AOT_AAC_SSR:
p_data->object_type = 2;
break;
case AOT_AAC_LTP:
p_data->object_type = 3;
break;
}
p_data->element_instance_tag = element_instance_tag;
p_data->sampling_frequency_index = state_com->sampling_frequency_index;
p_data->num_assoc_data_elements = 0;
p_data->num_valid_cc_elements = 0;
p_data->mono_mixdown_present = 0;
p_data->stereo_mixdown_present = 0;
p_data->matrix_mixdown_idx_present = 0;
p_data->comment_field_bytes = 0;
p_data->num_lfe_channel_elements = 0;
element_tag_select[0] = p_data->front_element_tag_select;
element_tag_select[1] = p_data->side_element_tag_select;
element_tag_select[2] = p_data->back_element_tag_select;
element_is_cpe[0] = p_data->front_element_is_cpe;
element_is_cpe[1] = p_data->side_element_is_cpe;
element_is_cpe[2] = p_data->back_element_is_cpe;
num_channel_elements[0] = 0;
num_channel_elements[1] = 0;
num_channel_elements[2] = 0;
i = 0;
while (chNum > 0) {
chNum--;
if (chInfo[0].element_id == ID_LFE) {
if (p_data->num_lfe_channel_elements == MAX_CHANNELS_ELEMENTS) {
return -1;
}
p_data->lfe_element_tag_select[p_data->num_lfe_channel_elements] =
chInfo[0].element_instance_tag;
p_data->num_lfe_channel_elements++;
chInfo++;
} else {
element_tag_select[i][num_channel_elements[i]] = chInfo[0].element_instance_tag;
element_is_cpe[i][num_channel_elements[i]] = 0;
if (chInfo[0].element_id == ID_CPE) {
element_is_cpe[i][num_channel_elements[i]] = 1;
chNum--;
chInfo++;
}
chInfo++;
num_channel_elements[i]++;
if (num_channel_elements[i] == MAX_CHANNELS_ELEMENTS) {
i++;
if ((i > 2) && (chNum > 0)) {
return -1;
}
}
}
}
p_data->num_front_channel_elements = num_channel_elements[0];
p_data->num_side_channel_elements = num_channel_elements[1];
p_data->num_back_channel_elements = num_channel_elements[2];
return 0;
}
/****************************************************************************/
void enc_program_config_element(sProgram_config_element* p_data,
sBitsreamBuffer* pBS)
{
Ipp32s i;
PUT_BITS(pBS,p_data->element_instance_tag,4);
PUT_BITS(pBS,p_data->object_type,2);
PUT_BITS(pBS,p_data->sampling_frequency_index,4);
PUT_BITS(pBS,p_data->num_front_channel_elements,4);
PUT_BITS(pBS,p_data->num_side_channel_elements,4);
PUT_BITS(pBS,p_data->num_back_channel_elements,4);
PUT_BITS(pBS,p_data->num_lfe_channel_elements,2);
PUT_BITS(pBS,p_data->num_assoc_data_elements,3);
PUT_BITS(pBS,p_data->num_valid_cc_elements,4);
PUT_BITS(pBS,p_data->mono_mixdown_present,1);
if (p_data->mono_mixdown_present == 1) {
PUT_BITS(pBS,p_data->mono_miwdown_element_number,4);
}
PUT_BITS(pBS,p_data->stereo_mixdown_present,1);
if (p_data->stereo_mixdown_present == 1) {
PUT_BITS(pBS,p_data->stereo_miwdown_element_number,4);
}
PUT_BITS(pBS,p_data->matrix_mixdown_idx_present,1);
if (p_data->matrix_mixdown_idx_present == 1) {
PUT_BITS(pBS,p_data->matrix_mixdown_idx,2);
PUT_BITS(pBS,p_data->pseudo_surround_enable,1);
}
for (i = 0; i < p_data->num_front_channel_elements; i++) {
PUT_BITS(pBS,p_data->front_element_is_cpe[i],1);
PUT_BITS(pBS,p_data->front_element_tag_select[i],4);
}
for (i = 0; i < p_data->num_side_channel_elements; i++) {
PUT_BITS(pBS,p_data->side_element_is_cpe[i],1);
PUT_BITS(pBS,p_data->side_element_tag_select[i],4);
}
for (i = 0; i < p_data->num_back_channel_elements; i++) {
PUT_BITS(pBS,p_data->back_element_is_cpe[i],1);
PUT_BITS(pBS,p_data->back_element_tag_select[i],4);
}
for (i = 0; i < p_data->num_lfe_channel_elements; i++) {
PUT_BITS(pBS,p_data->lfe_element_tag_select[i],4);
}
for (i = 0; i < p_data->num_assoc_data_elements; i++) {
PUT_BITS(pBS,p_data->assoc_data_element_tag_select[i],4);
}
for (i = 0; i < p_data->num_valid_cc_elements; i++) {
PUT_BITS(pBS,p_data->cc_element_is_ind_sw[i],1);
PUT_BITS(pBS,p_data->valid_cc_element_tag_select[i],4);
}
SAVE_BITSTREAM(pBS)
Byte_alignment(pBS);
PUT_BITS(pBS,p_data->comment_field_bytes,8);
for (i = 0; i < p_data->comment_field_bytes; i++) {
PUT_BITS(pBS,p_data->comment_field_data[i],8);
}
SAVE_BITSTREAM(pBS)
}
/****************************************************************************/
void enc_adif_header(sAdif_header* pAdifHeader,
sBitsreamBuffer* pBS)
{
int i;
Byte_alignment(pBS);
PUT_BITS(pBS,pAdifHeader->adif_id,32);
PUT_BITS(pBS,pAdifHeader->copyright_id_present,1);
if (pAdifHeader->copyright_id_present) {
for (i = 0; i < LEN_COPYRIGHT_ID; i++) {
PUT_BITS(pBS,pAdifHeader->copyright_id[i],8);
}
}
PUT_BITS(pBS,pAdifHeader->original_copy,1);
PUT_BITS(pBS,pAdifHeader->home,1);
PUT_BITS(pBS,pAdifHeader->bitstream_type,1);
PUT_BITS(pBS,pAdifHeader->bitrate,23);
PUT_BITS(pBS,pAdifHeader->num_program_config_elements,4);
if (pAdifHeader->bitstream_type == 0) {
PUT_BITS(pBS,pAdifHeader->adif_buffer_fullness,20);
}
for (i = 0; i < pAdifHeader->num_program_config_elements + 1; i++) {
enc_program_config_element(&pAdifHeader->pce[i],pBS);
}
SAVE_BITSTREAM(pBS)
}
/****************************************************************************/
void enc_adts_header(sAdts_fixed_header *pFixedHeader,
sAdts_variable_header *pVarHeader,
sBitsreamBuffer *pBS)
{
Byte_alignment(pBS);
PUT_BITS(pBS,0x0FFF,12);
/// The following puts in bitsream ADTS fixed header
PUT_BITS(pBS,pFixedHeader->ID,1);
PUT_BITS(pBS,pFixedHeader->Layer,2);
PUT_BITS(pBS,pFixedHeader->protection_absent,1);
PUT_BITS(pBS,pFixedHeader->Profile,2);
PUT_BITS(pBS,pFixedHeader->sampling_frequency_index,4);
PUT_BITS(pBS,pFixedHeader->private_bit,1);
PUT_BITS(pBS,pFixedHeader->channel_configuration,3);
PUT_BITS(pBS,pFixedHeader->original_copy,1);
PUT_BITS(pBS,pFixedHeader->Home,1);
/// The following puts in bitsream ADTS variable header
PUT_BITS(pBS,pVarHeader->copyright_identification_bit,1);
PUT_BITS(pBS,pVarHeader->copyright_identification_start,1);
PUT_BITS(pBS,pVarHeader->aac_frame_length,13);
PUT_BITS(pBS,pVarHeader->adts_buffer_fullness,11);
PUT_BITS(pBS,pVarHeader->no_raw_data_blocks_in_frame,2);
SAVE_BITSTREAM(pBS)
}
/****************************************************************************/
Ipp32s enc_ics_info(sEnc_individual_channel_stream* pStream,
sBitsreamBuffer* pBS,
Ipp32s writing)
{
Ipp32s i;
Ipp32s count_bits;
if (writing) {
PUT_BITS(pBS,pStream->ics_reserved_bit,1);
PUT_BITS(pBS,pStream->windows_sequence,2);
PUT_BITS(pBS,pStream->window_shape,1);
}
count_bits = 4;
if (pStream->windows_sequence == EIGHT_SHORT_SEQUENCE) {
if (writing) {
PUT_BITS(pBS,pStream->max_sfb,4);
for (i = 0; i < 7; i ++) {
PUT_BITS(pBS,pStream->scale_factor_grouping[i],1);
}
}
count_bits += 11;
} else {
if (writing) {
PUT_BITS(pBS,pStream->max_sfb,6);
PUT_BITS(pBS, pStream->predictor_data_present, 1)
}
count_bits += 7;
if (pStream->predictor_data_present) {
if (pStream->audioObjectType == AOT_AAC_LTP) {
if (writing) {
PUT_BITS(pBS, pStream->ltp_data_present, 1)
}
count_bits++;
if (pStream->ltp_data_present) {
count_bits += enc_ltp_data(pStream, pBS, writing);
}
}
}
}
return count_bits;
}
/****************************************************************************/
void enc_section_data(sEnc_individual_channel_stream* pStream,
sBitsreamBuffer* pBS)
{
Ipp16s* sfb_cb;
Ipp32s len_esc_value;
Ipp32s sect_esc_value;
Ipp32s sect_len;
Ipp32s i;
Ipp32s win;
Ipp32s sect_counter;
Ipp32s last_sect_counter;
Ipp32s sect_cb;
if (pStream->windows_sequence == EIGHT_SHORT_SEQUENCE) {
len_esc_value = 3;
sect_esc_value = (1<<3) - 1;
} else {
len_esc_value = 5;
sect_esc_value = (1<<5) - 1;
}
sfb_cb = pStream->sfb_cb;
sect_counter = -1;
last_sect_counter = -1;
for (win = 0; win < pStream->num_window_groups; win++) {
sect_cb = sfb_cb[0];
sect_counter++;
pStream->sect_cb[sect_counter] = sect_cb;
pStream->sect_len[sect_counter] = 0;
for (i = 0; i < pStream->max_sfb; i++) {
if (sfb_cb[i] == sect_cb) {
pStream->sect_len[sect_counter]++;
} else {
sect_cb = sfb_cb[i];
sect_counter++;
pStream->sect_cb[sect_counter] = sect_cb;
pStream->sect_len[sect_counter] = 1;
}
}
sfb_cb += pStream->max_sfb;
pStream->sect_num[win] = sect_counter - last_sect_counter;
last_sect_counter = sect_counter;
}
sect_counter ++;
for (i = 0; i < sect_counter; i++) {
PUT_BITS(pBS,pStream->sect_cb[i],4);
sect_len = pStream->sect_len[i];
while (sect_len >= sect_esc_value) {
PUT_BITS(pBS,sect_esc_value,len_esc_value);
sect_len -= sect_esc_value;
}
PUT_BITS(pBS,sect_len,len_esc_value);
}
}
/****************************************************************************/
Ipp32s enc_scale_factor_data(sEnc_individual_channel_stream* pStream,
sBitsreamBuffer* pBS,
Ipp32s writing)
{
Ipp32s i;
Ipp32s last_sf;
Ipp32s index;
Ipp32s len;
Ipp32u code;
Ipp32s num_scale_factor;
Ipp32s count_bits;
num_scale_factor = pStream->num_window_groups * pStream->max_sfb;
count_bits = 0;
if (writing) {
last_sf = pStream->global_gain;
} else {
for (i = 0; i < num_scale_factor; i++) {
if (pStream->sfb_cb[i] != 0) {
last_sf = pStream->scale_factors[i];
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -