📄 audio.cpp
字号:
#include "mpeg4ip.h"#include "mp4v2/mp4.h"#include <mpeg4ip_bitstream.h>void CheckProgramConfigElement (CBitstream *bs) { uint32_t temp, i, num_front_channel_elements, num_side_channel_elements, num_back_channel_elements; uint32_t num_lfe_channel_elements, num_assoc_data_elements, num_valid_cc_elements; printf(" Program Config Element\n"); temp = bs->GetBits(4); printf(" element_instance_tag - 0x%x\n", temp); temp = bs->GetBits(2); printf(" object_type - 0x%x\n", temp); temp = bs->GetBits(4); printf(" sampling_frequency_index - 0x%x\n", temp); num_front_channel_elements = bs->GetBits(4); printf(" num_front_channel_elements - 0x%x\n", num_front_channel_elements); num_side_channel_elements = bs->GetBits(4); printf(" num_side_channel_elements - 0x%x\n", num_side_channel_elements); num_back_channel_elements = bs->GetBits(4); printf(" num_back_channel_elements - 0x%x\n", num_back_channel_elements); num_lfe_channel_elements = bs->GetBits(2); printf(" num_lfe_channel_elements - 0x%x\n", num_lfe_channel_elements); num_assoc_data_elements = bs->GetBits(3); printf(" num_assoc_data_elements - 0x%x\n", num_assoc_data_elements); num_valid_cc_elements = bs->GetBits(4); printf(" num_valid_cc_elements - 0x%x\n", num_valid_cc_elements); temp = bs->GetBits(1); printf(" mono_mixdown_present - 0x%x\n", temp); if(temp) { temp = bs->GetBits(4); printf(" mono_mixdown_element_number - 0x%x\n", temp); } temp = bs->GetBits(1); printf(" stereo_mixdown_present - 0x%x\n", temp); if(temp) { temp = bs->GetBits(4); printf(" stereo_mixdown_element_number - 0x%x\n", temp); } temp = bs->GetBits(1); printf(" matrix_mixdown_idx_present - 0x%x\n", temp); if(temp) { temp = bs->GetBits(2); printf(" matrix_mixdown_idx - 0x%x\n", temp); temp = bs->GetBits(1); printf(" pseudo_surround_enable - 0x%x\n", temp); } for (i = 0; i < num_front_channel_elements; i++) { printf(" front_channel_element - %i\n", i); temp = bs->GetBits(1); printf(" front_element_is_cpei? - 0x%x\n", temp); temp = bs->GetBits(4); printf(" front_element_tag_selecti? - 0x%x\n", temp); } for (i = 0; i < num_side_channel_elements; i++) { printf(" side_channel_element - %i\n", i); temp = bs->GetBits(1); printf(" side_element_is_cpei? - 0x%x\n", temp); temp = bs->GetBits(4); printf(" side_element_tag_selecti? - 0x%x\n", temp); } for (i = 0; i < num_back_channel_elements; i++) { printf(" back_channel_element - %i\n", i); temp = bs->GetBits(1); printf(" back_element_is_cpei? - 0x%x\n", temp); temp = bs->GetBits(4); printf(" back_element_tag_selecti? - 0x%x\n", temp); } for (i = 0; i < num_lfe_channel_elements; i++) { printf(" lfe_channel_element - %i\n", i); temp = bs->GetBits(4); printf(" lfe_element_tag_selecti? - 0x%x\n", temp); } for (i = 0; i < num_assoc_data_elements; i++) { printf(" assoc_data_element - %i\n", i); temp = bs->GetBits(4); printf(" assoc_data_element_tag_selecti? - 0x%x\n", temp); } for (i = 0; i < num_valid_cc_elements; i++) { printf(" valid_cc__element - %i\n", i); temp = bs->GetBits(1); printf(" cc_element_is_ind_swi? - 0x%x\n", temp); temp = bs->GetBits(4); printf(" valid_cc_element_tag_selecti? - 0x%x\n", temp); } bs->byte_align(); uint32_t comment_field_bytes = bs->GetBits(8); printf(" comment_field_bytes - 0x%x\n", comment_field_bytes); if(comment_field_bytes > 0) { char *comment_field = (char *)malloc(comment_field_bytes+1); printf(" comment_field: (0x"); for (i = 0; i < comment_field_bytes; i++) { temp = bs->GetBits(8); printf("%x", temp); comment_field[i] = temp; } comment_field[comment_field_bytes] = '\0'; printf(") %s\n", comment_field); free(comment_field); } printf(" End of Program Config Element\n");}// See ISO 14496-3:2001 section 1.6.2void CheckAudioSpecificConfig (CBitstream *bs) { uint32_t temp; uint32_t audioObjectType, channelConfiguration, extensionFlag; uint32_t i, j; printf("AudioSpecificConfig\n"); // Audio Object Type audioObjectType = bs->GetBits(5); printf("Audio object type (5 bit) - 0x%x - ", audioObjectType); switch(audioObjectType) { case 0: printf("null\n"); break; case 1: printf("AAC Main\n"); break; case 2: printf("AAC LC\n"); break; case 3: printf("AAC SSR\n"); break; case 4: printf("AAC LTP\n"); break; case 5: printf("reserved\n"); break; case 6: printf("AAC Scalable\n"); break; case 7: printf("TwinVQ\n"); break; case 8: printf("CELP\n"); break; case 9: printf("HVXC\n"); break; case 10: printf("reserved\n"); break; case 11: printf("reserved\n"); break; case 12: printf("TTSI\n"); break; case 13: printf("Main synthetic\n"); break; case 14: printf("Wavetable synthesis\n"); break; case 15: printf("General MIDI\n"); break; case 16: printf("Algorithmic Syntesis and Audio FX\n"); break; case 17: printf("ER AAC LC\n"); break; case 18: printf("ER AAC SSR\n"); break; case 19: printf("ER AAC LTP\n"); break; case 20: printf("ER AAC scaleable\n"); break; case 21: printf("ER TwinVQ\n"); break; case 22: printf("ER Fine Granule Audio\n"); break; case 23: printf("ER AAC LD\n"); break; case 24: printf("ER CELP\n"); break; case 25: printf("ER HVXC\n"); break; case 26: printf("ER HILN\n"); break; case 27: printf("ER Parametric\n"); break; case 28: printf("reserved\n"); break; case 29: printf("reserved\n"); break; case 30: printf("reserved\n"); break; case 31: printf("reserved\n"); break; default: printf("unknown\n"); } // Sample Frequency Index temp = bs->GetBits(4); printf("Sampling frequency Index (4 bit) - 0x%x\n", temp); if(temp == 0xf) { temp = bs->GetBits(24); printf("Sampling frequency (24 bit) - 0x%x\n", temp); } // Channel configuration channelConfiguration = bs->GetBits(4); printf("Channel configuration (4 bit) - 0x%x\n", channelConfiguration); if ( audioObjectType == 1 || audioObjectType == 2 || audioObjectType == 3 || audioObjectType == 4 || audioObjectType == 6 || audioObjectType == 7 || /* the following Objects are Amendment 1 Objects */ audioObjectType == 17 || audioObjectType == 19 || audioObjectType == 20 || audioObjectType == 21 || audioObjectType == 22 || audioObjectType == 23 ) { // GASpecificConfig printf("GASpecificConfig\n"); temp = bs->GetBits(1); printf(" FrameLength (1 bit) - 0x%x\n", temp); temp = bs->GetBits(1); printf(" DependsOnCoreCoder (1 bit) - 0x%x\n", temp); if(temp) { temp = bs->GetBits(14); printf(" CoreCoderDelay (14 bit) - 0x%x\n", temp); } extensionFlag = bs->GetBits(1); printf(" ExtensionFlag (1 bit) - 0x%x\n", extensionFlag); if ( !channelConfiguration ) { //program_config_element(); CheckProgramConfigElement(bs); } if ( extensionFlag ) { if ( audioObjectType == 22 ) { temp = bs->GetBits(5); printf(" NumOfSubFrame (5 bit) - 0x%x\n", temp); temp = bs->GetBits(11); printf(" Layer_length (11 bit) - 0x%x\n", temp); } if( audioObjectType==17 || audioObjectType == 18 || audioObjectType == 19 || audioObjectType == 20 || audioObjectType == 21 || audioObjectType == 23) { temp = bs->GetBits(1); printf(" AacSectionDataResilienceFlag (1 bit) - 0x%x\n", temp); temp = bs->GetBits(1); printf(" AacScalefactorDataResilienceFlag (1 bit) - 0x%x\n", temp); temp = bs->GetBits(1); printf(" AacSpectralDataResilienceFlag (1 bit) - 0x%x\n", temp); } temp = bs->GetBits(1); printf(" ExtensionFlag3 (1 bit) - 0x%x\n", temp); if ( temp ) { /* tbd in version 3 */ } } printf("End of GASpecificConfig\n"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -