AAC
AAC 数据格式
AAC是常见的编码格式,编码后的数据封装格式分为两种:ADIF(Audio Data Interchange Format) 和 ADTS(Audio Data Transport Stream), 常见的主要是ADTS封装。
1 ADIF格式
1.1 序列语法
- adif_header() header of the Audio Data Interchange Format located at the beginning of an adif_sequence。
- adif_sequence() a sequence according to the Audio Data Interchange Format (Table 2).
- raw_data_stream() 编码数据流
1.1.1 adif_header
2 ADTS格式
2.1 adts_sequence
2.1.1 adts_frame
an ADTS frame, consisting of a fixed header, a variable header, an optional error check and a specified number of raw_data_block()'s (Table 5).
- adts_fixed_header()
fixed header of ADTS. The information in this header does not change from frame to frame. It is repeated every frame to allow random access into a bitstream bitstream (Table 8).帧见不变,保证随机访问。 - adts_variable_header()
variable header of ADTS. This header is transmitted every frame as well as the fixed header, but contains data that changes from frame to frame (Table 9). - adts_header_error_check()
The following bits are protected and fed into the CRC algorithm in order of their appearance:- all bits of adts_fixed_header()
- all bits of adts_variable_header()
- all bits of every raw_data_block_position[i]
-raw_data_block()
2.1.1.1 adts_fixed_header
- syncword The bit string ‘1111 1111 1111’.
- ID MPEG identifier, 0-MPEG4/1-MPEG2
- layer Indicates which layer is used. Set to ‘00’.
- protection_absent Indicates whether error_check() data is present or not. Same as syntax element ‘protection_bit’ in ISO/IEC 11172-3, subclause 2.4.1 and 2.4.2 (Table 8).
- profile profile used
- sampling_frequency_index indicates the sampling frequency used according to the following table
- private_bit
- channel_configuration indicates the channel configuration used. If channel_configuration is greater than 0, the channel configuration is given by the ‘Default bitstream index number’ in Table 42, see subclause 8.5. If channel_configuration equals 0, the channel configuration is not specified in the
header and must be given by a program_config_element() following as first syntactic element in the first raw_data_block() after the header, or by the implicit configuration (see subclause 8.5) or must be known in the application (Table 8).
伪代码
adts_sequence()
{
while (nextbits() == syncword)
{
adts_frame()
{
adts_fixed_header()
{
syncword; //12 bslbf
ID; //1 bslbf
layer; //2 uimsbf
protection_absent; //1 bslbf
profile; //2 uimsbf
sampling_frequency_index; //4 uimsbf
private_bit; //1 bslbf
channel_configuration; //3 uimsbf
original / copy; //1 bslbf
home; //1 bslbf
}
adts_variable_header()
{
copyright_identification_bit; // 1 bslbf
copyright_identification_start; // 1 bslbf
frame_length; // 13 bslbf
adts_buffer_fullness; // 11 bslbf
number_of_raw_data_blocks_in_frame; // 2 uimsfb
}
if (number_of_raw_data_blocks_in_frame == 0)
{
adts_error_check()
{
if (protection_absent == '0')
crc_check; // 16 rpchof
}
raw_data_block();
}
else
{
adts_header_error_check()
{
if (protection_absent == '0')
{
for (i = 1; i <= number_of_raw_data_blocks_in_frame; i++)
{
raw_data_block_position[i]; //16 uimsfb
}
crc_check; //16 rpchof
}
}
for (i = 0; i <= number_of_raw_data_blocks_in_frame; i++)
{
raw_data_block()
{
while ((id = id_syn_ele) != ID_END) // id_syn_ele 3 uimsbf
{
switch (id)
{
case ID_SCE:
single_channel_element();
break;
case ID_CPE:
channel_pair_element();
break;
case ID_CCE:
coupling_channel_element();
break;
case ID_LFE:
lfe_channel_element();
break;
case ID_DSE:
data_stream_element();
break;
case ID_PCE:
program_config_element()
{
element_instance_tag; // 4 uimsbf
object_type; // 2 uimsbf
sampling_frequency_index; // 4 uimsbf
num_front_channel_elements; // 4 uimsbf
num_side_channel_elements; // 4 uimsbf
num_back_channel_elements; // 4 uimsbf
num_lfe_channel_elements; // 2 uimsbf
num_assoc_data_elements; // 3 uimsbf
num_valid_cc_elements; // 4 uimsbf
mono_mixdown_present 1 uimsbf if (mono_mixdown_present == 1)
mono_mixdown_element_number; // 4 uimsbf
stereo_mixdown_present; // 1 uimsbf
if (stereo_mixdown_present == 1)
stereo_mixdown_element_number; // 4 uimsbf
matrix_mixdown_idx_present; // 1 uimsbf
if (matrix_mixdown_idx_present == 1)
{
matrix_mixdown_idx; // 2 uimsbf
pseudo_surround_enable; // 1 uimsbf
}
for (i = 0; i < num_front_channel_elements; i++)
{
front_element_is_cpe[i]; // 1 bslbf
front_element_tag_select[i]; // 4 uimsbf
}
for (i = 0; i < num_side_channel_elements; i++)
{
side_element_is_cpe[i]; // 1 bslbf
side_element_tag_select[i]; // 4 uimsbf
}
for (i = 0; i < num_back_channel_elements; i++)
{
back_element_is_cpe[i]; // 1 bslbf
back_element_tag_select[i]; // 4 uimsbf
}
for (i = 0; i < num_lfe_channel_elements; i++)
lfe_element_tag_select[i]; // 4 uimsbf
for (i = 0; i < num_assoc_data_elements; i++)
assoc_data_element_tag_select[i]; // 4 uimsbf
for (i = 0; i < num_valid_cc_elements; i++)
{
cc_element_is_ind_sw[i]; // 1 uimsbf
valid_cc_element_tag_select[i]; // 4 uimsbf
}
byte_alignment()
comment_field_bytes; // 8 uimsbf
for (i = 0; i < comment_field_bytes; i++)
comment_field_data[i]; // 8 uimsbf
}
break;
case ID_FIL:
fill_element();
}
}
byte_alignment();
}
adts_raw_data_block_error_check()
{
if (protection_absent == '0')
crc_check; // 16 rpchof
}
}
}
}
}
}