34 $ThisFileInfo[
'fileformat'] =
'aac';
35 $ThisFileInfo[
'audio'][
'dataformat'] =
'aac';
36 $ThisFileInfo[
'audio'][
'lossless'] =
false;
38 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
39 $AACheader =
fread($fd, 1024);
42 if (substr($AACheader, 0, 4) ==
'ADIF') {
67 $ThisFileInfo[
'aac'][
'header_type'] =
'ADIF';
69 $ThisFileInfo[
'aac'][
'header'][
'mpeg_version'] = 4;
71 $ThisFileInfo[
'aac'][
'header'][
'copyright'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) ==
'1');
73 if ($ThisFileInfo[
'aac'][
'header'][
'copyright']) {
74 $ThisFileInfo[
'aac'][
'header'][
'copyright_id'] =
getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 72));
77 $ThisFileInfo[
'aac'][
'header'][
'original_copy'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) ==
'1');
79 $ThisFileInfo[
'aac'][
'header'][
'home'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) ==
'1');
81 $ThisFileInfo[
'aac'][
'header'][
'is_vbr'] = (bool) (substr($AACheaderBitstream, $bitoffset, 1) ==
'1');
83 if ($ThisFileInfo[
'aac'][
'header'][
'is_vbr']) {
84 $ThisFileInfo[
'audio'][
'bitrate_mode'] =
'vbr';
85 $ThisFileInfo[
'aac'][
'header'][
'bitrate_max'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
88 $ThisFileInfo[
'audio'][
'bitrate_mode'] =
'cbr';
89 $ThisFileInfo[
'aac'][
'header'][
'bitrate'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 23));
91 $ThisFileInfo[
'audio'][
'bitrate'] = $ThisFileInfo[
'aac'][
'header'][
'bitrate'];
93 if ($ThisFileInfo[
'audio'][
'bitrate'] == 0) {
94 $ThisFileInfo[
'error'][] =
'Corrupt AAC file: bitrate_audio == zero';
97 $ThisFileInfo[
'aac'][
'header'][
'num_program_configs'] = 1 +
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
100 for ($i = 0; $i < $ThisFileInfo[
'aac'][
'header'][
'num_program_configs']; $i++) {
149 if (!$ThisFileInfo[
'aac'][
'header'][
'is_vbr']) {
150 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'buffer_fullness'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 20));
153 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'element_instance_tag'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
155 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'object_type'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
157 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'sampling_frequency_index'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
159 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_front_channel_elements'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
161 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_side_channel_elements'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
163 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_back_channel_elements'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
165 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_lfe_channel_elements'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
167 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_assoc_data_elements'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 3));
169 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_valid_cc_elements'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
171 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'mono_mixdown_present'] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
173 if ($ThisFileInfo[
'aac'][
'program_configs'][$i][
'mono_mixdown_present']) {
174 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'mono_mixdown_element_number'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
177 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'stereo_mixdown_present'] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
179 if ($ThisFileInfo[
'aac'][
'program_configs'][$i][
'stereo_mixdown_present']) {
180 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'stereo_mixdown_element_number'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
183 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'matrix_mixdown_idx_present'] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
185 if ($ThisFileInfo[
'aac'][
'program_configs'][$i][
'matrix_mixdown_idx_present']) {
186 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'matrix_mixdown_idx'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 2));
188 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'pseudo_surround_enable'] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
191 for ($j = 0; $j < $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_front_channel_elements']; $j++) {
192 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'front_element_is_cpe'][$j] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
194 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'front_element_tag_select'][$j] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
197 for ($j = 0; $j < $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_side_channel_elements']; $j++) {
198 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'side_element_is_cpe'][$j] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
200 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'side_element_tag_select'][$j] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
203 for ($j = 0; $j < $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_back_channel_elements']; $j++) {
204 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'back_element_is_cpe'][$j] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
206 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'back_element_tag_select'][$j] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
209 for ($j = 0; $j < $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_lfe_channel_elements']; $j++) {
210 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'lfe_element_tag_select'][$j] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
213 for ($j = 0; $j < $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_assoc_data_elements']; $j++) {
214 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'assoc_data_element_tag_select'][$j] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
217 for ($j = 0; $j < $ThisFileInfo[
'aac'][
'program_configs'][$i][
'num_valid_cc_elements']; $j++) {
218 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'cc_element_is_ind_sw'][$j] = (bool)
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 1));
220 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'valid_cc_element_tag_select'][$j] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 4));
224 $bitoffset = ceil($bitoffset / 8) * 8;
226 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'comment_field_bytes'] =
getid3_lib::Bin2Dec(substr($AACheaderBitstream, $bitoffset, 8));
228 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'comment_field'] =
getid3_lib::Bin2String(substr($AACheaderBitstream, $bitoffset, 8 * $ThisFileInfo[
'aac'][
'program_configs'][$i][
'comment_field_bytes']));
229 $bitoffset += 8 * $ThisFileInfo[
'aac'][
'program_configs'][$i][
'comment_field_bytes'];
232 $ThisFileInfo[
'aac'][
'header'][
'profile_text'] = $this->
AACprofileLookup($ThisFileInfo[
'aac'][
'program_configs'][$i][
'object_type'], $ThisFileInfo[
'aac'][
'header'][
'mpeg_version']);
233 $ThisFileInfo[
'aac'][
'program_configs'][$i][
'sampling_frequency'] = $this->
AACsampleRateLookup($ThisFileInfo[
'aac'][
'program_configs'][$i][
'sampling_frequency_index']);
234 $ThisFileInfo[
'audio'][
'sample_rate'] = $ThisFileInfo[
'aac'][
'program_configs'][$i][
'sampling_frequency'];
236 if ($ThisFileInfo[
'aac'][
'program_configs'][$i][
'comment_field']) {
237 $ThisFileInfo[
'aac'][
'comments'][] = $ThisFileInfo[
'aac'][
'program_configs'][$i][
'comment_field'];
240 $ThisFileInfo[
'playtime_seconds'] = (($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']) * 8) / $ThisFileInfo[
'audio'][
'bitrate'];
242 $ThisFileInfo[
'audio'][
'encoder_options'] = $ThisFileInfo[
'aac'][
'header_type'].
' '.$ThisFileInfo[
'aac'][
'header'][
'profile_text'];
250 unset($ThisFileInfo[
'fileformat']);
251 unset($ThisFileInfo[
'aac']);
252 $ThisFileInfo[
'error'][] =
'AAC-ADIF synch not found at offset '.$ThisFileInfo[
'avdataoffset'].
' (expected "ADIF", found "'.substr($AACheader, 0, 4).
'" instead)';
AACchannelCountCalculate($program_configs)
AACsampleRateLookup($samplerateid)
Bin2Dec($binstring, $signed=false)
AACprofileLookup($profileid, $mpegversion)
fseek($bytes, $whence=SEEK_SET)