21 define(
'GETID3_MP3_VALID_CHECK_FRAMES', 35);
32 if ($this->allow_bruteforce) {
33 $ThisFileInfo[
'error'][] =
'Rescanning file in BruteForce mode';
39 if (isset($ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode'])) {
40 $ThisFileInfo[
'audio'][
'bitrate_mode'] = strtolower($ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode']);
43 if (((isset($ThisFileInfo[
'id3v2'][
'headerlength']) && ($ThisFileInfo[
'avdataoffset'] > $ThisFileInfo[
'id3v2'][
'headerlength'])) || (!isset($ThisFileInfo[
'id3v2']) && ($ThisFileInfo[
'avdataoffset'] > 0)))) {
45 $synchoffsetwarning =
'Unknown data before synch ';
46 if (isset($ThisFileInfo[
'id3v2'][
'headerlength'])) {
47 $synchoffsetwarning .=
'(ID3v2 header ends at '.$ThisFileInfo[
'id3v2'][
'headerlength'].
', then '.($ThisFileInfo[
'avdataoffset'] - $ThisFileInfo[
'id3v2'][
'headerlength']).
' bytes garbage, ';
49 $synchoffsetwarning .=
'(should be at beginning of file, ';
51 $synchoffsetwarning .=
'synch detected at '.$ThisFileInfo[
'avdataoffset'].
')';
52 if ($ThisFileInfo[
'audio'][
'bitrate_mode'] ==
'cbr') {
54 if (!empty($ThisFileInfo[
'id3v2'][
'headerlength']) && (($ThisFileInfo[
'avdataoffset'] - $ThisFileInfo[
'id3v2'][
'headerlength']) == $ThisFileInfo[
'mpeg'][
'audio'][
'framelength'])) {
56 $synchoffsetwarning .=
'. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.';
57 $ThisFileInfo[
'audio'][
'codec'] =
'LAME';
58 $CurrentDataLAMEversionString =
'LAME3.';
60 } elseif (empty($ThisFileInfo[
'id3v2'][
'headerlength']) && ($ThisFileInfo[
'avdataoffset'] == $ThisFileInfo[
'mpeg'][
'audio'][
'framelength'])) {
62 $synchoffsetwarning .=
'. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.';
63 $ThisFileInfo[
'audio'][
'codec'] =
'LAME';
64 $CurrentDataLAMEversionString =
'LAME3.';
69 $ThisFileInfo[
'warning'][] = $synchoffsetwarning;
73 if (isset($ThisFileInfo[
'mpeg'][
'audio'][
'LAME'])) {
74 $ThisFileInfo[
'audio'][
'codec'] =
'LAME';
75 if (!empty($ThisFileInfo[
'mpeg'][
'audio'][
'LAME'][
'long_version'])) {
76 $ThisFileInfo[
'audio'][
'encoder'] = rtrim($ThisFileInfo[
'mpeg'][
'audio'][
'LAME'][
'long_version'],
"\x00");
77 } elseif (!empty($ThisFileInfo[
'mpeg'][
'audio'][
'LAME'][
'short_version'])) {
78 $ThisFileInfo[
'audio'][
'encoder'] = rtrim($ThisFileInfo[
'mpeg'][
'audio'][
'LAME'][
'short_version'],
"\x00");
82 $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : @$ThisFileInfo[
'audio'][
'encoder']);
83 if (!empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) ==
'LAME3.') && !preg_match(
'[0-9\)]', substr($CurrentDataLAMEversionString, -1))) {
89 $PossiblyLongerLAMEversion_FrameLength = 1441;
92 $PossibleLAMEversionStringOffset = $ThisFileInfo[
'avdataend'] - $PossiblyLongerLAMEversion_FrameLength;
93 fseek($fd, $PossibleLAMEversionStringOffset);
94 $PossiblyLongerLAMEversion_Data = fread($fd, $PossiblyLongerLAMEversion_FrameLength);
95 switch (substr($CurrentDataLAMEversionString, -1)) {
100 $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, -1);
103 if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !==
false) {
104 if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) {
105 $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String,
'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)'));
106 if (strlen($PossiblyLongerLAMEversion_NewString) > strlen(@$ThisFileInfo[
'audio'][
'encoder'])) {
107 $ThisFileInfo[
'audio'][
'encoder'] = $PossiblyLongerLAMEversion_NewString;
112 if (!empty($ThisFileInfo[
'audio'][
'encoder'])) {
113 $ThisFileInfo[
'audio'][
'encoder'] = rtrim($ThisFileInfo[
'audio'][
'encoder'],
"\x00 ");
116 switch (@$ThisFileInfo[
'mpeg'][
'audio'][
'layer']) {
119 $ThisFileInfo[
'audio'][
'dataformat'] =
'mp'.$ThisFileInfo[
'mpeg'][
'audio'][
'layer'];
122 if ($ThisFileInfo[
'fileformat'] ==
'mp3') {
123 switch ($ThisFileInfo[
'audio'][
'dataformat']) {
127 $ThisFileInfo[
'fileformat'] = $ThisFileInfo[
'audio'][
'dataformat'];
131 $ThisFileInfo[
'warning'][] =
'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$ThisFileInfo[
'audio'][
'dataformat'].
'"';
136 if (empty($ThisFileInfo[
'fileformat'])) {
137 unset($ThisFileInfo[
'fileformat']);
138 unset($ThisFileInfo[
'audio'][
'bitrate_mode']);
139 unset($ThisFileInfo[
'avdataoffset']);
140 unset($ThisFileInfo[
'avdataend']);
144 $ThisFileInfo[
'mime_type'] =
'audio/mpeg';
145 $ThisFileInfo[
'audio'][
'lossless'] =
false;
148 if (!isset($ThisFileInfo[
'playtime_seconds']) && isset($ThisFileInfo[
'audio'][
'bitrate']) && ($ThisFileInfo[
'audio'][
'bitrate'] > 0)) {
149 $ThisFileInfo[
'playtime_seconds'] = ($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']) * 8 / $ThisFileInfo[
'audio'][
'bitrate'];
160 if (!empty($ThisFileInfo[
'mpeg'][
'audio'])) {
161 $thisfile_mpeg_audio = &$ThisFileInfo[
'mpeg'][
'audio'];
162 if (!empty($thisfile_mpeg_audio[
'LAME'])) {
163 $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio[
'LAME'];
167 $encoder_options =
'';
168 static $NamedPresetBitrates = array(16, 24, 40, 56, 112, 128, 160, 192, 256);
170 if ((@$thisfile_mpeg_audio[
'VBR_method'] ==
'Fraunhofer') && !empty($thisfile_mpeg_audio[
'VBR_quality'])) {
172 $encoder_options =
'VBR q'.$thisfile_mpeg_audio[
'VBR_quality'];
174 } elseif (!empty($thisfile_mpeg_audio_lame[
'preset_used']) && (!in_array($thisfile_mpeg_audio_lame[
'preset_used_id'], $NamedPresetBitrates))) {
176 $encoder_options = $thisfile_mpeg_audio_lame[
'preset_used'];
178 } elseif (!empty($thisfile_mpeg_audio_lame[
'vbr_quality'])) {
180 static $KnownEncoderValues = array();
181 if (empty($KnownEncoderValues)) {
184 $KnownEncoderValues[0xFF][58][1][1][3][2][20500] =
'--alt-preset insane';
185 $KnownEncoderValues[0xFF][58][1][1][3][2][20600] =
'--alt-preset insane';
186 $KnownEncoderValues[0xFF][57][1][1][3][4][20500] =
'--alt-preset insane';
187 $KnownEncoderValues[
'**'][78][3][2][3][2][19500] =
'--alt-preset extreme';
188 $KnownEncoderValues[
'**'][78][3][2][3][2][19600] =
'--alt-preset extreme';
189 $KnownEncoderValues[
'**'][78][3][1][3][2][19600] =
'--alt-preset extreme';
190 $KnownEncoderValues[
'**'][78][4][2][3][2][19500] =
'--alt-preset fast extreme';
191 $KnownEncoderValues[
'**'][78][4][2][3][2][19600] =
'--alt-preset fast extreme';
192 $KnownEncoderValues[
'**'][78][3][2][3][4][19000] =
'--alt-preset standard';
193 $KnownEncoderValues[
'**'][78][3][1][3][4][19000] =
'--alt-preset standard';
194 $KnownEncoderValues[
'**'][78][4][2][3][4][19000] =
'--alt-preset fast standard';
195 $KnownEncoderValues[
'**'][78][4][1][3][4][19000] =
'--alt-preset fast standard';
196 $KnownEncoderValues[
'**'][88][4][1][3][3][19500] =
'--r3mix';
197 $KnownEncoderValues[
'**'][88][4][1][3][3][19600] =
'--r3mix';
198 $KnownEncoderValues[
'**'][67][4][1][3][4][18000] =
'--r3mix';
199 $KnownEncoderValues[
'**'][68][3][2][3][4][18000] =
'--alt-preset medium';
200 $KnownEncoderValues[
'**'][68][4][2][3][4][18000] =
'--alt-preset fast medium';
202 $KnownEncoderValues[0xFF][99][1][1][1][2][0] =
'--preset studio';
203 $KnownEncoderValues[0xFF][58][2][1][3][2][20600] =
'--preset studio';
204 $KnownEncoderValues[0xFF][58][2][1][3][2][20500] =
'--preset studio';
205 $KnownEncoderValues[0xFF][57][2][1][3][4][20500] =
'--preset studio';
206 $KnownEncoderValues[0xC0][88][1][1][1][2][0] =
'--preset cd';
207 $KnownEncoderValues[0xC0][58][2][2][3][2][19600] =
'--preset cd';
208 $KnownEncoderValues[0xC0][58][2][2][3][2][19500] =
'--preset cd';
209 $KnownEncoderValues[0xC0][57][2][1][3][4][19500] =
'--preset cd';
210 $KnownEncoderValues[0xA0][78][1][1][3][2][18000] =
'--preset hifi';
211 $KnownEncoderValues[0xA0][58][2][2][3][2][18000] =
'--preset hifi';
212 $KnownEncoderValues[0xA0][57][2][1][3][4][18000] =
'--preset hifi';
213 $KnownEncoderValues[0x80][67][1][1][3][2][18000] =
'--preset tape';
214 $KnownEncoderValues[0x80][67][1][1][3][2][15000] =
'--preset radio';
215 $KnownEncoderValues[0x70][67][1][1][3][2][15000] =
'--preset fm';
216 $KnownEncoderValues[0x70][58][2][2][3][2][16000] =
'--preset tape/radio/fm';
217 $KnownEncoderValues[0x70][57][2][1][3][4][16000] =
'--preset tape/radio/fm';
218 $KnownEncoderValues[0x38][58][2][2][0][2][10000] =
'--preset voice';
219 $KnownEncoderValues[0x38][57][2][1][0][4][15000] =
'--preset voice';
220 $KnownEncoderValues[0x38][57][2][1][0][4][16000] =
'--preset voice';
221 $KnownEncoderValues[0x28][65][1][1][0][2][7500] =
'--preset mw-us';
222 $KnownEncoderValues[0x28][65][1][1][0][2][7600] =
'--preset mw-us';
223 $KnownEncoderValues[0x28][58][2][2][0][2][7000] =
'--preset mw-us';
224 $KnownEncoderValues[0x28][57][2][1][0][4][10500] =
'--preset mw-us';
225 $KnownEncoderValues[0x28][57][2][1][0][4][11200] =
'--preset mw-us';
226 $KnownEncoderValues[0x28][57][2][1][0][4][8800] =
'--preset mw-us';
227 $KnownEncoderValues[0x18][58][2][2][0][2][4000] =
'--preset phon+/lw/mw-eu/sw';
228 $KnownEncoderValues[0x18][58][2][2][0][2][3900] =
'--preset phon+/lw/mw-eu/sw';
229 $KnownEncoderValues[0x18][57][2][1][0][4][5900] =
'--preset phon+/lw/mw-eu/sw';
230 $KnownEncoderValues[0x18][57][2][1][0][4][6200] =
'--preset phon+/lw/mw-eu/sw';
231 $KnownEncoderValues[0x18][57][2][1][0][4][3200] =
'--preset phon+/lw/mw-eu/sw';
232 $KnownEncoderValues[0x10][58][2][2][0][2][3800] =
'--preset phone';
233 $KnownEncoderValues[0x10][58][2][2][0][2][3700] =
'--preset phone';
234 $KnownEncoderValues[0x10][57][2][1][0][4][5600] =
'--preset phone';
237 if (isset($KnownEncoderValues[$thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame[
'vbr_quality']][$thisfile_mpeg_audio_lame[
'raw'][
'vbr_method']][$thisfile_mpeg_audio_lame[
'raw'][
'noise_shaping']][$thisfile_mpeg_audio_lame[
'raw'][
'stereo_mode']][$thisfile_mpeg_audio_lame[
'ath_type']][$thisfile_mpeg_audio_lame[
'lowpass_frequency']])) {
239 $encoder_options = $KnownEncoderValues[$thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate']][$thisfile_mpeg_audio_lame[
'vbr_quality']][$thisfile_mpeg_audio_lame[
'raw'][
'vbr_method']][$thisfile_mpeg_audio_lame[
'raw'][
'noise_shaping']][$thisfile_mpeg_audio_lame[
'raw'][
'stereo_mode']][$thisfile_mpeg_audio_lame[
'ath_type']][$thisfile_mpeg_audio_lame[
'lowpass_frequency']];
241 } elseif (isset($KnownEncoderValues[
'**'][$thisfile_mpeg_audio_lame[
'vbr_quality']][$thisfile_mpeg_audio_lame[
'raw'][
'vbr_method']][$thisfile_mpeg_audio_lame[
'raw'][
'noise_shaping']][$thisfile_mpeg_audio_lame[
'raw'][
'stereo_mode']][$thisfile_mpeg_audio_lame[
'ath_type']][$thisfile_mpeg_audio_lame[
'lowpass_frequency']])) {
243 $encoder_options = $KnownEncoderValues[
'**'][$thisfile_mpeg_audio_lame[
'vbr_quality']][$thisfile_mpeg_audio_lame[
'raw'][
'vbr_method']][$thisfile_mpeg_audio_lame[
'raw'][
'noise_shaping']][$thisfile_mpeg_audio_lame[
'raw'][
'stereo_mode']][$thisfile_mpeg_audio_lame[
'ath_type']][$thisfile_mpeg_audio_lame[
'lowpass_frequency']];
245 } elseif ($ThisFileInfo[
'audio'][
'bitrate_mode'] ==
'vbr') {
251 $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame[
'vbr_quality'] / 10);
252 $LAME_q_value = 100 - $thisfile_mpeg_audio_lame[
'vbr_quality'] - ($LAME_V_value * 10);
253 $encoder_options =
'-V'.$LAME_V_value.
' -q'.$LAME_q_value;
255 } elseif ($ThisFileInfo[
'audio'][
'bitrate_mode'] ==
'cbr') {
257 $encoder_options = strtoupper($ThisFileInfo[
'audio'][
'bitrate_mode']).ceil($ThisFileInfo[
'audio'][
'bitrate'] / 1000);
261 $encoder_options = strtoupper($ThisFileInfo[
'audio'][
'bitrate_mode']);
265 } elseif (!empty($thisfile_mpeg_audio_lame[
'bitrate_abr'])) {
267 $encoder_options =
'ABR'.$thisfile_mpeg_audio_lame[
'bitrate_abr'];
269 } elseif (!empty($ThisFileInfo[
'audio'][
'bitrate'])) {
271 if ($ThisFileInfo[
'audio'][
'bitrate_mode'] ==
'cbr') {
272 $encoder_options = strtoupper($ThisFileInfo[
'audio'][
'bitrate_mode']).ceil($ThisFileInfo[
'audio'][
'bitrate'] / 1000);
274 $encoder_options = strtoupper($ThisFileInfo[
'audio'][
'bitrate_mode']);
278 if (!empty($thisfile_mpeg_audio_lame[
'bitrate_min'])) {
279 $encoder_options .=
' -b'.$thisfile_mpeg_audio_lame[
'bitrate_min'];
282 if (@$thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_prev'] || @$thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_next']) {
283 $encoder_options .=
' --nogap';
286 if (!empty($thisfile_mpeg_audio_lame[
'lowpass_frequency'])) {
287 $ExplodedOptions = explode(
' ', $encoder_options, 4);
288 if ($ExplodedOptions[0] ==
'--r3mix') {
289 $ExplodedOptions[1] =
'r3mix';
291 switch ($ExplodedOptions[0]) {
295 if ($ExplodedOptions[1] ==
'fast') {
296 $ExplodedOptions[1] .=
' '.$ExplodedOptions[2];
298 switch ($ExplodedOptions[1]) {
304 case 'fast portable':
306 case 'fast standard':
310 static $ExpectedLowpass = array(
311 'insane|20500' => 20500,
312 'insane|20600' => 20600,
313 'medium|18000' => 18000,
314 'fast medium|18000' => 18000,
315 'extreme|19500' => 19500,
316 'extreme|19600' => 19600,
317 'fast extreme|19500' => 19500,
318 'fast extreme|19600' => 19600,
319 'standard|19000' => 19000,
320 'fast standard|19000' => 19000,
321 'r3mix|19500' => 19500,
322 'r3mix|19600' => 19600,
323 'r3mix|18000' => 18000,
325 if (!isset($ExpectedLowpass[$ExplodedOptions[1].
'|'.$thisfile_mpeg_audio_lame[
'lowpass_frequency']]) && ($thisfile_mpeg_audio_lame[
'lowpass_frequency'] < 22050) && (round($thisfile_mpeg_audio_lame[
'lowpass_frequency'] / 1000) < round($thisfile_mpeg_audio[
'sample_rate'] / 2000))) {
326 $encoder_options .=
' --lowpass '.$thisfile_mpeg_audio_lame[
'lowpass_frequency'];
337 if (isset($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq'])) {
338 if (($thisfile_mpeg_audio[
'sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq'] != 1)) {
339 $encoder_options .=
' --resample 44100';
340 } elseif (($thisfile_mpeg_audio[
'sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq'] != 2)) {
341 $encoder_options .=
' --resample 48000';
342 } elseif ($thisfile_mpeg_audio[
'sample_rate'] < 44100) {
343 switch ($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq']) {
350 $ExplodedOptions = explode(
' ', $encoder_options, 4);
351 switch ($ExplodedOptions[0]) {
354 switch ($ExplodedOptions[1]) {
361 $encoder_options .=
' --resample '.$thisfile_mpeg_audio[
'sample_rate'];
365 static $ExpectedResampledRate = array(
366 'phon+/lw/mw-eu/sw|16000' => 16000,
367 'mw-us|24000' => 24000,
368 'mw-us|32000' => 32000,
369 'mw-us|16000' => 16000,
370 'phone|16000' => 16000,
371 'phone|11025' => 11025,
372 'radio|32000' => 32000,
373 'fm/radio|32000' => 32000,
375 'voice|32000' => 32000);
376 if (!isset($ExpectedResampledRate[$ExplodedOptions[1].
'|'.$thisfile_mpeg_audio[
'sample_rate']])) {
377 $encoder_options .=
' --resample '.$thisfile_mpeg_audio[
'sample_rate'];
385 $encoder_options .=
' --resample '.$thisfile_mpeg_audio[
'sample_rate'];
392 if (empty($encoder_options) && !empty($ThisFileInfo[
'audio'][
'bitrate']) && !empty($ThisFileInfo[
'audio'][
'bitrate_mode'])) {
394 $encoder_options = strtoupper($ThisFileInfo[
'audio'][
'bitrate_mode']);
397 return $encoder_options;
401 function decodeMPEGaudioHeader($fd, $offset, &$ThisFileInfo, $recursivesearch=
true, $ScanAsCBR=
false, $FastMPEGheaderScan=
false) {
403 static $MPEGaudioVersionLookup;
404 static $MPEGaudioLayerLookup;
405 static $MPEGaudioBitrateLookup;
406 static $MPEGaudioFrequencyLookup;
407 static $MPEGaudioChannelModeLookup;
408 static $MPEGaudioModeExtensionLookup;
409 static $MPEGaudioEmphasisLookup;
410 if (empty($MPEGaudioVersionLookup)) {
420 if ($offset >= $ThisFileInfo[
'avdataend']) {
421 $ThisFileInfo[
'error'][] =
'end of file encounter looking for MPEG synch';
424 fseek($fd, $offset, SEEK_SET);
426 $headerstring = fread($fd, 226);
434 $head4 = substr($headerstring, 0, 4);
436 static $MPEGaudioHeaderDecodeCache = array();
437 if (isset($MPEGaudioHeaderDecodeCache[$head4])) {
438 $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
441 $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
444 static $MPEGaudioHeaderValidCache = array();
447 if (!isset($MPEGaudioHeaderValidCache[$head4])) {
453 if (!isset($ThisFileInfo[
'mpeg'][
'audio'])) {
454 $ThisFileInfo[
'mpeg'][
'audio'] = array();
456 $thisfile_mpeg_audio = &$ThisFileInfo[
'mpeg'][
'audio'];
459 if ($MPEGaudioHeaderValidCache[$head4]) {
460 $thisfile_mpeg_audio[
'raw'] = $MPEGheaderRawArray;
462 $ThisFileInfo[
'error'][] =
'Invalid MPEG audio header at offset '.$offset;
466 if (!$FastMPEGheaderScan) {
468 $thisfile_mpeg_audio[
'version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio[
'raw'][
'version']];
469 $thisfile_mpeg_audio[
'layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio[
'raw'][
'layer']];
471 $thisfile_mpeg_audio[
'channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio[
'raw'][
'channelmode']];
472 $thisfile_mpeg_audio[
'channels'] = (($thisfile_mpeg_audio[
'channelmode'] ==
'mono') ? 1 : 2);
473 $thisfile_mpeg_audio[
'sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio[
'version']][$thisfile_mpeg_audio[
'raw'][
'sample_rate']];
474 $thisfile_mpeg_audio[
'protection'] = !$thisfile_mpeg_audio[
'raw'][
'protection'];
475 $thisfile_mpeg_audio[
'private'] = (bool) $thisfile_mpeg_audio[
'raw'][
'private'];
476 $thisfile_mpeg_audio[
'modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio[
'layer']][$thisfile_mpeg_audio[
'raw'][
'modeextension']];
477 $thisfile_mpeg_audio[
'copyright'] = (bool) $thisfile_mpeg_audio[
'raw'][
'copyright'];
478 $thisfile_mpeg_audio[
'original'] = (bool) $thisfile_mpeg_audio[
'raw'][
'original'];
479 $thisfile_mpeg_audio[
'emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio[
'raw'][
'emphasis']];
481 $ThisFileInfo[
'audio'][
'channels'] = $thisfile_mpeg_audio[
'channels'];
482 $ThisFileInfo[
'audio'][
'sample_rate'] = $thisfile_mpeg_audio[
'sample_rate'];
484 if ($thisfile_mpeg_audio[
'protection']) {
490 if ($thisfile_mpeg_audio[
'raw'][
'bitrate'] == 15) {
492 $ThisFileInfo[
'warning'][] =
'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';
493 $thisfile_mpeg_audio[
'raw'][
'bitrate'] = 0;
495 $thisfile_mpeg_audio[
'padding'] = (bool) $thisfile_mpeg_audio[
'raw'][
'padding'];
496 $thisfile_mpeg_audio[
'bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio[
'version']][$thisfile_mpeg_audio[
'layer']][$thisfile_mpeg_audio[
'raw'][
'bitrate']];
498 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') && ($offset == $ThisFileInfo[
'avdataoffset'])) {
501 $recursivesearch =
false;
505 if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio[
'layer'] ==
'2')) {
507 $ThisFileInfo[
'audio'][
'dataformat'] =
'mp2';
508 switch ($thisfile_mpeg_audio[
'channelmode']) {
511 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') || ($thisfile_mpeg_audio[
'bitrate'] <= 192000)) {
514 $ThisFileInfo[
'error'][] = $thisfile_mpeg_audio[
'bitrate'].
'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio[
'channelmode'].
'.';
522 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') || ($thisfile_mpeg_audio[
'bitrate'] == 64000) || ($thisfile_mpeg_audio[
'bitrate'] >= 96000)) {
525 $ThisFileInfo[
'error'][] = intval(round($thisfile_mpeg_audio[
'bitrate'] / 1000)).
'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio[
'channelmode'].
'.';
535 if ($ThisFileInfo[
'audio'][
'sample_rate'] > 0) {
536 $thisfile_mpeg_audio[
'framelength'] =
getid3_mp3::MPEGaudioFrameLength($thisfile_mpeg_audio[
'bitrate'], $thisfile_mpeg_audio[
'version'], $thisfile_mpeg_audio[
'layer'], (
int) $thisfile_mpeg_audio[
'padding'], $ThisFileInfo[
'audio'][
'sample_rate']);
539 $nextframetestoffset = $offset + 1;
540 if ($thisfile_mpeg_audio[
'bitrate'] !=
'free') {
542 $ThisFileInfo[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'bitrate'];
544 if (isset($thisfile_mpeg_audio[
'framelength'])) {
545 $nextframetestoffset = $offset + $thisfile_mpeg_audio[
'framelength'];
547 $ThisFileInfo[
'error'][] =
'Frame at offset('.$offset.
') is has an invalid frame length.';
553 $ExpectedNumberOfAudioBytes = 0;
558 if (substr($headerstring, 4 + 32, 4) ==
'VBRI') {
562 $thisfile_mpeg_audio[
'bitrate_mode'] =
'vbr';
563 $thisfile_mpeg_audio[
'VBR_method'] =
'Fraunhofer';
564 $ThisFileInfo[
'audio'][
'codec'] =
'Fraunhofer';
566 $SideInfoData = substr($headerstring, 4 + 2, 32);
568 $FraunhoferVBROffset = 36;
570 $thisfile_mpeg_audio[
'VBR_encoder_version'] =
getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2));
571 $thisfile_mpeg_audio[
'VBR_encoder_delay'] =
getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2));
575 $thisfile_mpeg_audio[
'VBR_seek_offsets'] =
getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2));
577 $thisfile_mpeg_audio[
'VBR_entry_bytes'] =
getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 22, 2));
578 $thisfile_mpeg_audio[
'VBR_entry_frames'] =
getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2));
580 $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio[
'VBR_bytes'];
582 $previousbyteoffset = $offset;
583 for ($i = 0; $i < $thisfile_mpeg_audio[
'VBR_seek_offsets']; $i++) {
584 $Fraunhofer_OffsetN =
getid3_lib::BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, $thisfile_mpeg_audio[
'VBR_entry_bytes']));
585 $FraunhoferVBROffset += $thisfile_mpeg_audio[
'VBR_entry_bytes'];
586 $thisfile_mpeg_audio[
'VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio[
'VBR_seek_scale']);
587 $thisfile_mpeg_audio[
'VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio[
'VBR_seek_scale']) + $previousbyteoffset;
588 $previousbyteoffset += $Fraunhofer_OffsetN;
598 $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4);
600 if ((substr($headerstring, $VBRidOffset, strlen(
'Xing')) ==
'Xing') || (substr($headerstring, $VBRidOffset, strlen(
'Info')) ==
'Info')) {
627 $thisfile_mpeg_audio[
'bitrate_mode'] =
'vbr';
628 $thisfile_mpeg_audio[
'VBR_method'] =
'Xing';
636 $thisfile_mpeg_audio[
'xing_flags'][
'frames'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000001);
637 $thisfile_mpeg_audio[
'xing_flags'][
'bytes'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000002);
638 $thisfile_mpeg_audio[
'xing_flags'][
'toc'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000004);
639 $thisfile_mpeg_audio[
'xing_flags'][
'vbr_scale'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000008);
641 if ($thisfile_mpeg_audio[
'xing_flags'][
'frames']) {
645 if ($thisfile_mpeg_audio[
'xing_flags'][
'bytes']) {
650 if (!empty($thisfile_mpeg_audio[
'VBR_frames']) && !empty($thisfile_mpeg_audio[
'VBR_bytes'])) {
652 $framelengthfloat = $thisfile_mpeg_audio[
'VBR_bytes'] / $thisfile_mpeg_audio[
'VBR_frames'];
654 if ($thisfile_mpeg_audio[
'layer'] ==
'1') {
657 $ThisFileInfo[
'audio'][
'bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio[
'sample_rate'] * (2 / $ThisFileInfo[
'audio'][
'channels']) / 12;
661 $ThisFileInfo[
'audio'][
'bitrate'] = $framelengthfloat * $thisfile_mpeg_audio[
'sample_rate'] * (2 / $ThisFileInfo[
'audio'][
'channels']) / 144;
663 $thisfile_mpeg_audio[
'framelength'] = floor($framelengthfloat);
666 if ($thisfile_mpeg_audio[
'xing_flags'][
'toc']) {
667 $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100);
668 for ($i = 0; $i < 100; $i++) {
669 $thisfile_mpeg_audio[
'toc'][$i] = ord($LAMEtocData{$i});
672 if ($thisfile_mpeg_audio[
'xing_flags'][
'vbr_scale']) {
678 if (substr($headerstring, $VBRidOffset + 120, 4) ==
'LAME') {
681 $thisfile_mpeg_audio[
'LAME'] = array();
682 $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio[
'LAME'];
685 $thisfile_mpeg_audio_lame[
'long_version'] = substr($headerstring, $VBRidOffset + 120, 20);
686 $thisfile_mpeg_audio_lame[
'short_version'] = substr($thisfile_mpeg_audio_lame[
'long_version'], 0, 9);
688 if ($thisfile_mpeg_audio_lame[
'short_version'] >=
'LAME3.90') {
691 unset($thisfile_mpeg_audio_lame[
'long_version']);
699 $LAMEtagOffsetContant = $VBRidOffset - 0x24;
702 $thisfile_mpeg_audio_lame[
'RGAD'] = array(
'track'=>array(),
'album'=>array());
703 $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame[
'RGAD'];
704 $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD[
'track'];
705 $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD[
'album'];
706 $thisfile_mpeg_audio_lame[
'raw'] = array();
707 $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame[
'raw'];
712 unset($thisfile_mpeg_audio[
'VBR_scale']);
713 $thisfile_mpeg_audio_lame[
'vbr_quality'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1));
716 $thisfile_mpeg_audio_lame[
'short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9);
721 $thisfile_mpeg_audio_lame[
'tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4;
722 $thisfile_mpeg_audio_lame_raw[
'vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F;
724 $thisfile_mpeg_audio[
'bitrate_mode'] = substr($thisfile_mpeg_audio_lame[
'vbr_method'], 0, 3);
727 $thisfile_mpeg_audio_lame[
'lowpass_frequency'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;
732 if ($thisfile_mpeg_audio_lame[
'short_version'] >=
'LAME3.94b') {
735 $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'] = (float) ((
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608);
741 if ($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'] == 0) {
742 unset($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude']);
747 $thisfile_mpeg_audio_lame_raw[
'RGAD_track'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2));
748 $thisfile_mpeg_audio_lame_raw[
'RGAD_album'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2));
751 if ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] != 0) {
753 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'name'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0xE000) >> 13;
754 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'originator'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x1C00) >> 10;
755 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'sign_bit'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x0200) >> 9;
756 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'gain_adjust'] = $thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x01FF;
757 $thisfile_mpeg_audio_lame_RGAD_track[
'name'] =
getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'name']);
759 $thisfile_mpeg_audio_lame_RGAD_track[
'gain_db'] =
getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'sign_bit']);
761 if (!empty($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'])) {
762 $ThisFileInfo[
'replay_gain'][
'track'][
'peak'] = $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'];
764 $ThisFileInfo[
'replay_gain'][
'track'][
'originator'] = $thisfile_mpeg_audio_lame_RGAD_track[
'originator'];
765 $ThisFileInfo[
'replay_gain'][
'track'][
'adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track[
'gain_db'];
767 unset($thisfile_mpeg_audio_lame_RGAD[
'track']);
769 if ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] != 0) {
771 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'name'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0xE000) >> 13;
772 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'originator'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x1C00) >> 10;
773 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'sign_bit'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x0200) >> 9;
774 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'gain_adjust'] = $thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x01FF;
775 $thisfile_mpeg_audio_lame_RGAD_album[
'name'] =
getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'name']);
777 $thisfile_mpeg_audio_lame_RGAD_album[
'gain_db'] =
getid3_lib::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'gain_adjust'], $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'sign_bit']);
779 if (!empty($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'])) {
780 $ThisFileInfo[
'replay_gain'][
'album'][
'peak'] = $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'];
782 $ThisFileInfo[
'replay_gain'][
'album'][
'originator'] = $thisfile_mpeg_audio_lame_RGAD_album[
'originator'];
783 $ThisFileInfo[
'replay_gain'][
'album'][
'adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album[
'gain_db'];
785 unset($thisfile_mpeg_audio_lame_RGAD[
'album']);
787 if (empty($thisfile_mpeg_audio_lame_RGAD)) {
788 unset($thisfile_mpeg_audio_lame[
'RGAD']);
794 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10);
795 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20);
796 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40);
797 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80);
798 $thisfile_mpeg_audio_lame[
'ath_type'] = $EncodingFlagsATHtype & 0x0F;
801 $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1));
802 if ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 2) {
803 $thisfile_mpeg_audio_lame[
'bitrate_abr'] = $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'];
804 } elseif ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 1) {
806 } elseif ($thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'] > 0) {
807 $thisfile_mpeg_audio_lame[
'bitrate_min'] = $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'];
812 $thisfile_mpeg_audio_lame[
'encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12;
813 $thisfile_mpeg_audio_lame[
'end_padding'] = $EncoderDelays & 0x000FFF;
817 $thisfile_mpeg_audio_lame_raw[
'noise_shaping'] = ($MiscByte & 0x03);
818 $thisfile_mpeg_audio_lame_raw[
'stereo_mode'] = ($MiscByte & 0x1C) >> 2;
819 $thisfile_mpeg_audio_lame_raw[
'not_optimal_quality'] = ($MiscByte & 0x20) >> 5;
820 $thisfile_mpeg_audio_lame_raw[
'source_sample_freq'] = ($MiscByte & 0xC0) >> 6;
821 $thisfile_mpeg_audio_lame[
'noise_shaping'] = $thisfile_mpeg_audio_lame_raw[
'noise_shaping'];
823 $thisfile_mpeg_audio_lame[
'not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw[
'not_optimal_quality'];
827 $thisfile_mpeg_audio_lame_raw[
'mp3_gain'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1),
false,
true);
829 $thisfile_mpeg_audio_lame[
'mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame[
'mp3_gain_db'] / 6));
834 $thisfile_mpeg_audio_lame_raw[
'surround_info'] = ($PresetSurroundBytes & 0x3800);
836 $thisfile_mpeg_audio_lame[
'preset_used_id'] = ($PresetSurroundBytes & 0x07FF);
838 if (!empty($thisfile_mpeg_audio_lame[
'preset_used_id']) && empty($thisfile_mpeg_audio_lame[
'preset_used'])) {
839 $ThisFileInfo[
'warning'][] =
'Unknown LAME preset used ('.$thisfile_mpeg_audio_lame[
'preset_used_id'].
') - please report to info@getid3.org';
841 if (($thisfile_mpeg_audio_lame[
'short_version'] ==
'LAME3.90.') && !empty($thisfile_mpeg_audio_lame[
'preset_used_id'])) {
843 $thisfile_mpeg_audio_lame[
'short_version'] =
'LAME3.90.3';
847 $thisfile_mpeg_audio_lame[
'audio_bytes'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4));
848 $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame[
'audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame[
'audio_bytes'] : $thisfile_mpeg_audio[
'VBR_bytes']);
851 $thisfile_mpeg_audio_lame[
'music_crc'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2));
854 $thisfile_mpeg_audio_lame[
'lame_tag_crc'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2));
858 if ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 1) {
860 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
862 $ThisFileInfo[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'bitrate'];
875 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
876 if ($recursivesearch) {
877 $thisfile_mpeg_audio[
'bitrate_mode'] =
'vbr';
879 $recursivesearch =
false;
880 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
882 if ($thisfile_mpeg_audio[
'bitrate_mode'] ==
'vbr') {
883 $ThisFileInfo[
'warning'][] =
'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.';
891 if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != ($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']))) {
892 if ($ExpectedNumberOfAudioBytes > ($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset'])) {
893 if (($ExpectedNumberOfAudioBytes - ($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset'])) == 1) {
894 $ThisFileInfo[
'warning'][] =
'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)';
896 $ThisFileInfo[
'warning'][] =
'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.
' bytes of audio data, only found '.($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']).
' (short by '.($ExpectedNumberOfAudioBytes - ($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset'])).
' bytes)';
899 if ((($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) {
905 $ThisFileInfo[
'avdataend']--;
911 $ThisFileInfo[
'warning'][] =
'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.
' bytes of audio data, found '.($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']).
' ('.(($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']) - $ExpectedNumberOfAudioBytes).
' bytes too many)';
916 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') && empty($ThisFileInfo[
'audio'][
'bitrate'])) {
917 if (($offset == $ThisFileInfo[
'avdataoffset']) && empty($thisfile_mpeg_audio[
'VBR_frames'])) {
919 if ($framebytelength > 0) {
920 $thisfile_mpeg_audio[
'framelength'] = $framebytelength;
921 if ($thisfile_mpeg_audio[
'layer'] ==
'1') {
923 $ThisFileInfo[
'audio'][
'bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio[
'padding'])) * $thisfile_mpeg_audio[
'sample_rate']) / 12;
926 $ThisFileInfo[
'audio'][
'bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio[
'padding'])) * $thisfile_mpeg_audio[
'sample_rate']) / 144;
929 $ThisFileInfo[
'error'][] =
'Error calculating frame length of free-format MP3 without Xing/LAME header';
934 if (!empty($thisfile_mpeg_audio[
'VBR_frames'])) {
935 switch ($thisfile_mpeg_audio[
'bitrate_mode']) {
938 if (($thisfile_mpeg_audio[
'version'] ==
'1') && ($thisfile_mpeg_audio[
'layer'] == 1)) {
939 $thisfile_mpeg_audio[
'VBR_bitrate'] = (($thisfile_mpeg_audio[
'VBR_bytes'] / $thisfile_mpeg_audio[
'VBR_frames']) * 8) * ($ThisFileInfo[
'audio'][
'sample_rate'] / 384);
940 } elseif ((($thisfile_mpeg_audio[
'version'] ==
'2') || ($thisfile_mpeg_audio[
'version'] ==
'2.5')) && ($thisfile_mpeg_audio[
'layer'] == 3)) {
941 $thisfile_mpeg_audio[
'VBR_bitrate'] = (($thisfile_mpeg_audio[
'VBR_bytes'] / $thisfile_mpeg_audio[
'VBR_frames']) * 8) * ($ThisFileInfo[
'audio'][
'sample_rate'] / 576);
943 $thisfile_mpeg_audio[
'VBR_bitrate'] = (($thisfile_mpeg_audio[
'VBR_bytes'] / $thisfile_mpeg_audio[
'VBR_frames']) * 8) * ($ThisFileInfo[
'audio'][
'sample_rate'] / 1152);
945 if ($thisfile_mpeg_audio[
'VBR_bitrate'] > 0) {
946 $ThisFileInfo[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'VBR_bitrate'];
947 $thisfile_mpeg_audio[
'bitrate'] = $thisfile_mpeg_audio[
'VBR_bitrate'];
956 if ($recursivesearch) {
1073 if (($nextframetestoffset + 4) >= $ThisFileInfo[
'avdataend']) {
1078 $nextframetestarray = array(
'error'=>
'',
'warning'=>
'',
'avdataend'=>$ThisFileInfo[
'avdataend'],
'avdataoffset'=>$ThisFileInfo[
'avdataoffset']);
1083 if (!isset($nextframetestarray[
'mpeg'][
'audio'][
'bitrate']) || !isset($ThisFileInfo[
'mpeg'][
'audio'][
'bitrate']) || ($nextframetestarray[
'mpeg'][
'audio'][
'bitrate'] != $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate'])) {
1090 if (isset($nextframetestarray[
'mpeg'][
'audio'][
'framelength']) && ($nextframetestarray[
'mpeg'][
'audio'][
'framelength'] > 0)) {
1091 $nextframetestoffset += $nextframetestarray[
'mpeg'][
'audio'][
'framelength'];
1093 $ThisFileInfo[
'error'][] =
'Frame at offset ('.$offset.
') is has an invalid frame length.';
1100 $ThisFileInfo[
'error'][] =
'Frame at offset ('.$offset.
') is valid, but the next one at ('.$nextframetestoffset.
') is not.';
1109 fseek($fd, $offset, SEEK_SET);
1110 $MPEGaudioData = fread($fd, 32768);
1112 $SyncPattern1 = substr($MPEGaudioData, 0, 4);
1114 $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) | 0x02).$SyncPattern1{3};
1115 if ($SyncPattern2 === $SyncPattern1) {
1116 $SyncPattern2 = $SyncPattern1{0}.$SyncPattern1{1}.chr(ord($SyncPattern1{2}) & 0xFD).$SyncPattern1{3};
1119 $framelength =
false;
1120 $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4);
1121 $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4);
1122 if ($framelength1 > 4) {
1123 $framelength = $framelength1;
1125 if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1126 $framelength = $framelength2;
1128 if (!$framelength) {
1131 $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3), 4);
1132 $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3), 4);
1134 if ($framelength1 > 4) {
1135 $framelength = $framelength1;
1137 if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1138 $framelength = $framelength2;
1140 if (!$framelength) {
1141 $ThisFileInfo[
'error'][] =
'Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).
' or '.
getid3_lib::PrintHexBytes($SyncPattern2).
') after offset '.$offset;
1144 $ThisFileInfo[
'warning'][] =
'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)';
1145 $ThisFileInfo[
'audio'][
'codec'] =
'LAME';
1146 $ThisFileInfo[
'audio'][
'encoder'] =
'LAME3.88';
1147 $SyncPattern1 = substr($SyncPattern1, 0, 3);
1148 $SyncPattern2 = substr($SyncPattern2, 0, 3);
1154 $ActualFrameLengthValues = array();
1155 $nextoffset = $offset + $framelength;
1156 while ($nextoffset < ($ThisFileInfo[
'avdataend'] - 6)) {
1157 fseek($fd, $nextoffset - 1, SEEK_SET);
1158 $NextSyncPattern = fread($fd, 6);
1159 if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 1, strlen($SyncPattern2)) == $SyncPattern2)) {
1161 $ActualFrameLengthValues[] = $framelength;
1162 } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 0, strlen($SyncPattern2)) == $SyncPattern2)) {
1164 $ActualFrameLengthValues[] = ($framelength - 1);
1166 } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern, 2, strlen($SyncPattern2)) == $SyncPattern2)) {
1168 $ActualFrameLengthValues[] = ($framelength + 1);
1171 $ThisFileInfo[
'error'][] =
'Did not find expected free-format sync pattern at offset '.$nextoffset;
1174 $nextoffset += $framelength;
1176 if (count($ActualFrameLengthValues) > 0) {
1177 $framelength = intval(round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues)));
1180 return $framelength;
1185 $MPEGaudioHeaderDecodeCache = array();
1186 $MPEGaudioHeaderValidCache = array();
1187 $MPEGaudioHeaderLengthCache = array();
1195 $LongMPEGversionLookup = array();
1196 $LongMPEGlayerLookup = array();
1197 $LongMPEGbitrateLookup = array();
1198 $LongMPEGpaddingLookup = array();
1199 $LongMPEGfrequencyLookup = array();
1201 $Distribution[
'bitrate'] = array();
1202 $Distribution[
'frequency'] = array();
1203 $Distribution[
'layer'] = array();
1204 $Distribution[
'version'] = array();
1205 $Distribution[
'padding'] = array();
1207 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
1209 $previousvalidframe = $ThisFileInfo[
'avdataoffset'];
1210 while (ftell($fd) < $ThisFileInfo[
'avdataend']) {
1212 $head4 = fread($fd, 4);
1213 if (strlen($head4) < 4) {
1216 if ($head4{0} !=
"\xFF") {
1217 for ($i = 1; $i < 4; $i++) {
1218 if ($head4{$i} ==
"\xFF") {
1219 fseek($fd, $i - 4, SEEK_CUR);
1225 if (!isset($MPEGaudioHeaderDecodeCache[$head4])) {
1228 if (!isset($MPEGaudioHeaderValidCache[$head4])) {
1231 if ($MPEGaudioHeaderValidCache[$head4]) {
1233 if (!isset($MPEGaudioHeaderLengthCache[$head4])) {
1234 $LongMPEGversionLookup[$head4] = $MPEGaudioVersionLookup[$MPEGaudioHeaderDecodeCache[$head4][
'version']];
1235 $LongMPEGlayerLookup[$head4] = $MPEGaudioLayerLookup[$MPEGaudioHeaderDecodeCache[$head4][
'layer']];
1236 $LongMPEGbitrateLookup[$head4] = $MPEGaudioBitrateLookup[$LongMPEGversionLookup[$head4]][$LongMPEGlayerLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4][
'bitrate']];
1237 $LongMPEGpaddingLookup[$head4] = (bool) $MPEGaudioHeaderDecodeCache[$head4][
'padding'];
1238 $LongMPEGfrequencyLookup[$head4] = $MPEGaudioFrequencyLookup[$LongMPEGversionLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4][
'sample_rate']];
1240 $LongMPEGbitrateLookup[$head4],
1241 $LongMPEGversionLookup[$head4],
1242 $LongMPEGlayerLookup[$head4],
1243 $LongMPEGpaddingLookup[$head4],
1244 $LongMPEGfrequencyLookup[$head4]);
1246 if ($MPEGaudioHeaderLengthCache[$head4] > 4) {
1247 $WhereWeWere = ftell($fd);
1248 fseek($fd, $MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR);
1249 $next4 = fread($fd, 4);
1250 if ($next4{0} ==
"\xFF") {
1251 if (!isset($MPEGaudioHeaderDecodeCache[$next4])) {
1254 if (!isset($MPEGaudioHeaderValidCache[$next4])) {
1257 if ($MPEGaudioHeaderValidCache[$next4]) {
1258 fseek($fd, -4, SEEK_CUR);
1260 @$Distribution[
'bitrate'][$LongMPEGbitrateLookup[$head4]]++;
1261 @$Distribution[
'layer'][$LongMPEGlayerLookup[$head4]]++;
1262 @$Distribution[
'version'][$LongMPEGversionLookup[$head4]]++;
1263 @$Distribution[
'padding'][intval($LongMPEGpaddingLookup[$head4])]++;
1264 @$Distribution[
'frequency'][$LongMPEGfrequencyLookup[$head4]]++;
1269 fseek($fd, $WhereWeWere - 3, SEEK_SET);
1274 foreach ($Distribution as $key => $value) {
1275 ksort($Distribution[$key], SORT_NUMERIC);
1277 ksort($Distribution[
'version'], SORT_STRING);
1278 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] = $Distribution[
'bitrate'];
1279 $ThisFileInfo[
'mpeg'][
'audio'][
'frequency_distribution'] = $Distribution[
'frequency'];
1280 $ThisFileInfo[
'mpeg'][
'audio'][
'layer_distribution'] = $Distribution[
'layer'];
1281 $ThisFileInfo[
'mpeg'][
'audio'][
'version_distribution'] = $Distribution[
'version'];
1282 $ThisFileInfo[
'mpeg'][
'audio'][
'padding_distribution'] = $Distribution[
'padding'];
1283 if (count($Distribution[
'version']) > 1) {
1284 $ThisFileInfo[
'error'][] =
'Corrupt file - more than one MPEG version detected';
1286 if (count($Distribution[
'layer']) > 1) {
1287 $ThisFileInfo[
'error'][] =
'Corrupt file - more than one MPEG layer detected';
1289 if (count($Distribution[
'frequency']) > 1) {
1290 $ThisFileInfo[
'error'][] =
'Corrupt file - more than one MPEG sample rate detected';
1295 foreach ($Distribution[
'bitrate'] as $bitratevalue => $bitratecount) {
1296 if ($bitratevalue !=
'free') {
1297 $bittotal += ($bitratevalue * $bitratecount);
1300 $ThisFileInfo[
'mpeg'][
'audio'][
'frame_count'] = array_sum($Distribution[
'bitrate']);
1301 if ($ThisFileInfo[
'mpeg'][
'audio'][
'frame_count'] == 0) {
1302 $ThisFileInfo[
'error'][] =
'no MPEG audio frames found';
1305 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate'] = ($bittotal / $ThisFileInfo[
'mpeg'][
'audio'][
'frame_count']);
1306 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode'] = ((count($Distribution[
'bitrate']) > 0) ?
'vbr' :
'cbr');
1307 $ThisFileInfo[
'mpeg'][
'audio'][
'sample_rate'] =
getid3_lib::array_max($Distribution[
'frequency'],
true);
1309 $ThisFileInfo[
'audio'][
'bitrate'] = $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate'];
1310 $ThisFileInfo[
'audio'][
'bitrate_mode'] = $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode'];
1311 $ThisFileInfo[
'audio'][
'sample_rate'] = $ThisFileInfo[
'mpeg'][
'audio'][
'sample_rate'];
1312 $ThisFileInfo[
'audio'][
'dataformat'] =
'mp'.getid3_lib::array_max($Distribution[
'layer'],
true);
1313 $ThisFileInfo[
'fileformat'] = $ThisFileInfo[
'audio'][
'dataformat'];
1322 fseek($fd, $avdataoffset, SEEK_SET);
1324 $SynchSeekOffset = 0;
1326 static $MPEGaudioVersionLookup;
1327 static $MPEGaudioLayerLookup;
1328 static $MPEGaudioBitrateLookup;
1329 if (empty($MPEGaudioVersionLookup)) {
1339 if (($SynchSeekOffset > $header_len) && (($avdataoffset + $SynchSeekOffset) < $ThisFileInfo[
'avdataend']) && !feof($fd)) {
1341 if ($SynchSeekOffset > 131072) {
1343 $ThisFileInfo[
'error'][] =
'could not find valid MPEG audio synch within the first 128k bytes';
1344 if (isset($ThisFileInfo[
'audio'][
'bitrate'])) {
1345 unset($ThisFileInfo[
'audio'][
'bitrate']);
1347 if (isset($ThisFileInfo[
'mpeg'][
'audio'])) {
1348 unset($ThisFileInfo[
'mpeg'][
'audio']);
1350 if (empty($ThisFileInfo[
'mpeg'])) {
1351 unset($ThisFileInfo[
'mpeg']);
1362 $ThisFileInfo[
'error'][] =
'could not find valid MPEG audio synch before end of file';
1363 if (isset($ThisFileInfo[
'audio'][
'bitrate'])) {
1364 unset($ThisFileInfo[
'audio'][
'bitrate']);
1366 if (isset($ThisFileInfo[
'mpeg'][
'audio'])) {
1367 unset($ThisFileInfo[
'mpeg'][
'audio']);
1369 if (isset($ThisFileInfo[
'mpeg']) && (!is_array($ThisFileInfo[
'mpeg']) || (count($ThisFileInfo[
'mpeg']) == 0))) {
1370 unset($ThisFileInfo[
'mpeg']);
1377 if (($SynchSeekOffset + 1) >= strlen($header)) {
1378 $ThisFileInfo[
'error'][] =
'could not find valid MPEG synch before end of file';
1382 if (($header{$SynchSeekOffset} ==
"\xFF") && ($header{($SynchSeekOffset + 1)} >
"\xE0")) {
1384 if (!isset($FirstFrameThisfileInfo) && !isset($ThisFileInfo[
'mpeg'][
'audio'])) {
1385 $FirstFrameThisfileInfo = $ThisFileInfo;
1386 $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset;
1390 unset($FirstFrameThisfileInfo);
1394 $dummy = $ThisFileInfo;
1396 $ThisFileInfo = $dummy;
1397 $ThisFileInfo[
'avdataoffset'] = $avdataoffset + $SynchSeekOffset;
1398 switch ($ThisFileInfo[
'fileformat']) {
1403 $ThisFileInfo[
'fileformat'] =
'mp3';
1404 $ThisFileInfo[
'audio'][
'dataformat'] =
'mp3';
1407 if (isset($FirstFrameThisfileInfo[
'mpeg'][
'audio'][
'bitrate_mode']) && ($FirstFrameThisfileInfo[
'mpeg'][
'audio'][
'bitrate_mode'] ==
'vbr')) {
1408 if (!(abs($ThisFileInfo[
'audio'][
'bitrate'] - $FirstFrameThisfileInfo[
'audio'][
'bitrate']) <= 1)) {
1411 $ThisFileInfo = $FirstFrameThisfileInfo;
1412 $ThisFileInfo[
'avdataoffset'] = $FirstFrameAVDataOffset;
1413 $ThisFileInfo[
'fileformat'] =
'mp3';
1414 $ThisFileInfo[
'audio'][
'dataformat'] =
'mp3';
1415 $dummy = $ThisFileInfo;
1416 unset($dummy[
'mpeg'][
'audio']);
1417 $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo[
'mpeg'][
'audio'][
'framelength'];
1418 $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset;
1421 $ThisFileInfo = $dummy;
1422 $ThisFileInfo[
'avdataoffset'] = $GarbageOffsetEnd;
1423 $ThisFileInfo[
'warning'][] =
'apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.
' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).
' bytes between '.$GarbageOffsetStart.
' and '.$GarbageOffsetEnd.
'), but did find valid CBR stream starting at '.$GarbageOffsetEnd;
1427 $ThisFileInfo[
'warning'][] =
'using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.
' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).
' bytes between '.$GarbageOffsetStart.
' and '.$GarbageOffsetEnd.
')';
1432 if (isset($ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode']) && ($ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode'] ==
'vbr') && !isset($ThisFileInfo[
'mpeg'][
'audio'][
'VBR_method'])) {
1434 $BitrateHistogram =
true;
1437 if ($BitrateHistogram) {
1439 $ThisFileInfo[
'mpeg'][
'audio'][
'stereo_distribution'] = array(
'stereo'=>0,
'joint stereo'=>0,
'dual channel'=>0,
'mono'=>0);
1440 $ThisFileInfo[
'mpeg'][
'audio'][
'version_distribution'] = array(
'1'=>0,
'2'=>0,
'2.5'=>0);
1442 if ($ThisFileInfo[
'mpeg'][
'audio'][
'version'] ==
'1') {
1443 if ($ThisFileInfo[
'mpeg'][
'audio'][
'layer'] == 3) {
1444 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] = array(
'free'=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0);
1445 } elseif ($ThisFileInfo[
'mpeg'][
'audio'][
'layer'] == 2) {
1446 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] = array(
'free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 320000=>0, 384000=>0);
1447 } elseif ($ThisFileInfo[
'mpeg'][
'audio'][
'layer'] == 1) {
1448 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] = array(
'free'=>0, 32000=>0, 64000=>0, 96000=>0, 128000=>0, 160000=>0, 192000=>0, 224000=>0, 256000=>0, 288000=>0, 320000=>0, 352000=>0, 384000=>0, 416000=>0, 448000=>0);
1450 } elseif ($ThisFileInfo[
'mpeg'][
'audio'][
'layer'] == 1) {
1451 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] = array(
'free'=>0, 32000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0, 176000=>0, 192000=>0, 224000=>0, 256000=>0);
1453 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] = array(
'free'=>0, 8000=>0, 16000=>0, 24000=>0, 32000=>0, 40000=>0, 48000=>0, 56000=>0, 64000=>0, 80000=>0, 96000=>0, 112000=>0, 128000=>0, 144000=>0, 160000=>0);
1456 $dummy = array(
'error'=>$ThisFileInfo[
'error'],
'warning'=>$ThisFileInfo[
'warning'],
'avdataend'=>$ThisFileInfo[
'avdataend'],
'avdataoffset'=>$ThisFileInfo[
'avdataoffset']);
1457 $synchstartoffset = $ThisFileInfo[
'avdataoffset'];
1460 $SynchErrorsFound = 0;
1463 $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy[
'mpeg'][
'audio'][
'raw'][
'version']]][$MPEGaudioLayerLookup[$dummy[
'mpeg'][
'audio'][
'raw'][
'layer']]][$dummy[
'mpeg'][
'audio'][
'raw'][
'bitrate']];
1465 if (empty($dummy[
'mpeg'][
'audio'][
'framelength'])) {
1466 $SynchErrorsFound++;
1468 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'][$thisframebitrate]++;
1469 $ThisFileInfo[
'mpeg'][
'audio'][
'stereo_distribution'][$dummy[
'mpeg'][
'audio'][
'channelmode']]++;
1470 $ThisFileInfo[
'mpeg'][
'audio'][
'version_distribution'][$dummy[
'mpeg'][
'audio'][
'version']]++;
1472 $synchstartoffset += $dummy[
'mpeg'][
'audio'][
'framelength'];
1475 if ($SynchErrorsFound > 0) {
1476 $ThisFileInfo[
'warning'][] =
'Found '.$SynchErrorsFound.
' synch errors in histogram analysis';
1482 foreach ($ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] as $bitratevalue => $bitratecount) {
1483 $framecounter += $bitratecount;
1484 if ($bitratevalue !=
'free') {
1485 $bittotal += ($bitratevalue * $bitratecount);
1488 if ($framecounter == 0) {
1489 $ThisFileInfo[
'error'][] =
'Corrupt MP3 file: framecounter == zero';
1492 $ThisFileInfo[
'mpeg'][
'audio'][
'frame_count'] = $framecounter;
1493 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate'] = ($bittotal / $framecounter);
1495 $ThisFileInfo[
'audio'][
'bitrate'] = $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate'];
1499 $distinct_bitrates = 0;
1500 foreach ($ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_distribution'] as $bitrate_value => $bitrate_count) {
1501 if ($bitrate_count > 0) {
1502 $distinct_bitrates++;
1505 if ($distinct_bitrates > 1) {
1506 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode'] =
'vbr';
1508 $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode'] =
'cbr';
1510 $ThisFileInfo[
'audio'][
'bitrate_mode'] = $ThisFileInfo[
'mpeg'][
'audio'][
'bitrate_mode'];
1519 if (($avdataoffset + $SynchSeekOffset) >= $ThisFileInfo[
'avdataend']) {
1522 if (empty($ThisFileInfo[
'mpeg'][
'audio'])) {
1524 $ThisFileInfo[
'error'][] =
'could not find valid MPEG synch before end of file';
1525 if (isset($ThisFileInfo[
'audio'][
'bitrate'])) {
1526 unset($ThisFileInfo[
'audio'][
'bitrate']);
1528 if (isset($ThisFileInfo[
'mpeg'][
'audio'])) {
1529 unset($ThisFileInfo[
'mpeg'][
'audio']);
1531 if (isset($ThisFileInfo[
'mpeg']) && (!is_array($ThisFileInfo[
'mpeg']) || empty($ThisFileInfo[
'mpeg']))) {
1532 unset($ThisFileInfo[
'mpeg']);
1541 $ThisFileInfo[
'audio'][
'channels'] = $ThisFileInfo[
'mpeg'][
'audio'][
'channels'];
1542 $ThisFileInfo[
'audio'][
'channelmode'] = $ThisFileInfo[
'mpeg'][
'audio'][
'channelmode'];
1543 $ThisFileInfo[
'audio'][
'sample_rate'] = $ThisFileInfo[
'mpeg'][
'audio'][
'sample_rate'];
1549 static $MPEGaudioVersion = array(
'2.5',
false,
'2',
'1');
1550 return $MPEGaudioVersion;
1554 static $MPEGaudioLayer = array(
false, 3, 2, 1);
1555 return $MPEGaudioLayer;
1559 static $MPEGaudioBitrate;
1560 if (empty($MPEGaudioBitrate)) {
1561 $MPEGaudioBitrate = array (
1562 '1' => array (1 => array(
'free', 32000, 64000, 96000, 128000, 160000, 192000, 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000),
1563 2 => array(
'free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000),
1564 3 => array(
'free', 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000)
1567 '2' => array (1 => array(
'free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 176000, 192000, 224000, 256000),
1568 2 => array(
'free', 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000),
1571 $MPEGaudioBitrate[
'2'][3] = $MPEGaudioBitrate[
'2'][2];
1572 $MPEGaudioBitrate[
'2.5'] = $MPEGaudioBitrate[
'2'];
1574 return $MPEGaudioBitrate;
1578 static $MPEGaudioFrequency;
1579 if (empty($MPEGaudioFrequency)) {
1580 $MPEGaudioFrequency = array (
1581 '1' => array(44100, 48000, 32000),
1582 '2' => array(22050, 24000, 16000),
1583 '2.5' => array(11025, 12000, 8000)
1586 return $MPEGaudioFrequency;
1590 static $MPEGaudioChannelMode = array(
'stereo',
'joint stereo',
'dual channel',
'mono');
1591 return $MPEGaudioChannelMode;
1595 static $MPEGaudioModeExtension;
1596 if (empty($MPEGaudioModeExtension)) {
1597 $MPEGaudioModeExtension = array (
1598 1 => array(
'4-31',
'8-31',
'12-31',
'16-31'),
1599 2 => array(
'4-31',
'8-31',
'12-31',
'16-31'),
1600 3 => array(
'',
'IS',
'MS',
'IS+MS')
1603 return $MPEGaudioModeExtension;
1607 static $MPEGaudioEmphasis = array(
'none',
'50/15ms',
false,
'CCIT J.17');
1608 return $MPEGaudioEmphasis;
1616 if (($rawarray[
'synch'] & 0x0FFE) != 0x0FFE) {
1620 static $MPEGaudioVersionLookup;
1621 static $MPEGaudioLayerLookup;
1622 static $MPEGaudioBitrateLookup;
1623 static $MPEGaudioFrequencyLookup;
1624 static $MPEGaudioChannelModeLookup;
1625 static $MPEGaudioModeExtensionLookup;
1626 static $MPEGaudioEmphasisLookup;
1627 if (empty($MPEGaudioVersionLookup)) {
1637 if (isset($MPEGaudioVersionLookup[$rawarray[
'version']])) {
1638 $decodedVersion = $MPEGaudioVersionLookup[$rawarray[
'version']];
1640 echo ($echoerrors ?
"\n".
'invalid Version ('.$rawarray[
'version'].
')' :
'');
1643 if (isset($MPEGaudioLayerLookup[$rawarray[
'layer']])) {
1644 $decodedLayer = $MPEGaudioLayerLookup[$rawarray[
'layer']];
1646 echo ($echoerrors ?
"\n".
'invalid Layer ('.$rawarray[
'layer'].
')' :
'');
1649 if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray[
'bitrate']])) {
1650 echo ($echoerrors ?
"\n".
'invalid Bitrate ('.$rawarray[
'bitrate'].
')' :
'');
1651 if ($rawarray[
'bitrate'] == 15) {
1654 if (!$allowBitrate15) {
1661 if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray[
'sample_rate']])) {
1662 echo ($echoerrors ?
"\n".
'invalid Frequency ('.$rawarray[
'sample_rate'].
')' :
'');
1665 if (!isset($MPEGaudioChannelModeLookup[$rawarray[
'channelmode']])) {
1666 echo ($echoerrors ?
"\n".
'invalid ChannelMode ('.$rawarray[
'channelmode'].
')' :
'');
1669 if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray[
'modeextension']])) {
1670 echo ($echoerrors ?
"\n".
'invalid Mode Extension ('.$rawarray[
'modeextension'].
')' :
'');
1673 if (!isset($MPEGaudioEmphasisLookup[$rawarray[
'emphasis']])) {
1674 echo ($echoerrors ?
"\n".
'invalid Emphasis ('.$rawarray[
'emphasis'].
')' :
'');
1703 if (strlen($Header4Bytes) != 4) {
1708 $MPEGrawHeader[
'version'] = (ord($Header4Bytes{1}) & 0x18) >> 3;
1709 $MPEGrawHeader[
'layer'] = (ord($Header4Bytes{1}) & 0x06) >> 1;
1710 $MPEGrawHeader[
'protection'] = (ord($Header4Bytes{1}) & 0x01);
1711 $MPEGrawHeader[
'bitrate'] = (ord($Header4Bytes{2}) & 0xF0) >> 4;
1712 $MPEGrawHeader[
'sample_rate'] = (ord($Header4Bytes{2}) & 0x0C) >> 2;
1713 $MPEGrawHeader[
'padding'] = (ord($Header4Bytes{2}) & 0x02) >> 1;
1714 $MPEGrawHeader[
'private'] = (ord($Header4Bytes{2}) & 0x01);
1715 $MPEGrawHeader[
'channelmode'] = (ord($Header4Bytes{3}) & 0xC0) >> 6;
1716 $MPEGrawHeader[
'modeextension'] = (ord($Header4Bytes{3}) & 0x30) >> 4;
1717 $MPEGrawHeader[
'copyright'] = (ord($Header4Bytes{3}) & 0x08) >> 3;
1718 $MPEGrawHeader[
'original'] = (ord($Header4Bytes{3}) & 0x04) >> 2;
1719 $MPEGrawHeader[
'emphasis'] = (ord($Header4Bytes{3}) & 0x03);
1721 return $MPEGrawHeader;
1725 static $AudioFrameLengthCache = array();
1727 if (!isset($AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate])) {
1728 $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] =
false;
1729 if ($bitrate !=
'free') {
1731 if ($version ==
'1') {
1733 if ($layer ==
'1') {
1736 $FrameLengthCoefficient = 48;
1742 $FrameLengthCoefficient = 144;
1749 if ($layer ==
'1') {
1752 $FrameLengthCoefficient = 24;
1755 } elseif ($layer ==
'2') {
1758 $FrameLengthCoefficient = 144;
1764 $FrameLengthCoefficient = 72;
1772 if ($samplerate > 0) {
1773 $NewFramelength = ($FrameLengthCoefficient * $bitrate) / $samplerate;
1774 $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength;
1776 $NewFramelength += $SlotLength;
1778 $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate] = (int) $NewFramelength;
1782 return $AudioFrameLengthCache[$bitrate][$version][$layer][$padding][$samplerate];
1786 static $StandardBitrates = array(320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000);
1787 static $BitrateTable = array(0=>
'-');
1788 $roundbitrate = intval(round($bitrate, -3));
1789 if (!isset($BitrateTable[$roundbitrate])) {
1790 if ($roundbitrate > 320000) {
1791 $BitrateTable[$roundbitrate] = round($bitrate, -4);
1793 $LastBitrate = 320000;
1794 foreach ($StandardBitrates as $StandardBitrate) {
1795 $BitrateTable[$roundbitrate] = $StandardBitrate;
1796 if ($roundbitrate >= $StandardBitrate - (($LastBitrate - $StandardBitrate) / 2)) {
1799 $LastBitrate = $StandardBitrate;
1803 return $BitrateTable[$roundbitrate];
1807 static $XingVBRidOffsetCache = array();
1808 if (empty($XingVBRidOffset)) {
1809 $XingVBRidOffset = array (
1810 '1' => array (
'mono' => 0x15,
1812 'joint stereo' => 0x24,
1813 'dual channel' => 0x24
1816 '2' => array (
'mono' => 0x0D,
1818 'joint stereo' => 0x15,
1819 'dual channel' => 0x15
1822 '2.5' => array (
'mono' => 0x15,
1824 'joint stereo' => 0x15,
1825 'dual channel' => 0x15
1829 return $XingVBRidOffset[$version][$channelmode];
1833 static $LAMEvbrMethodLookup = array(
1837 0x03 =>
'vbr-old / vbr-rh',
1838 0x04 =>
'vbr-new / vbr-mtrh',
1840 0x06 =>
'Full VBR Method 4',
1841 0x08 =>
'constant bitrate 2 pass',
1842 0x09 =>
'abr 2 pass',
1845 return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] :
'');
1849 static $LAMEmiscStereoModeLookup = array(
1853 3 =>
'joint stereo',
1854 4 =>
'forced stereo',
1856 6 =>
'intensity stereo',
1859 return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] :
'');
1863 static $LAMEmiscSourceSampleFrequencyLookup = array(
1869 return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] :
'');
1873 static $LAMEsurroundInfoLookup = array(
1874 0 =>
'no surround info',
1875 1 =>
'DPL encoding',
1876 2 =>
'DPL2 encoding',
1877 3 =>
'Ambisonic encoding'
1879 return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] :
'reserved');
1884 if ($LAMEtag[
'preset_used_id'] == 0) {
1889 $LAMEpresetUsedLookup = array();
1892 for ($i = 8; $i <= 320; $i++) {
1893 switch ($LAMEtag[
'vbr_method']) {
1895 $LAMEpresetUsedLookup[$i] =
'--alt-preset '.$LAMEtag[
'vbr_method'].
' '.$i;
1899 $LAMEpresetUsedLookup[$i] =
'--alt-preset '.$i;
1907 $LAMEpresetUsedLookup[1000] =
'--r3mix';
1908 $LAMEpresetUsedLookup[1001] =
'--alt-preset standard';
1909 $LAMEpresetUsedLookup[1002] =
'--alt-preset extreme';
1910 $LAMEpresetUsedLookup[1003] =
'--alt-preset insane';
1911 $LAMEpresetUsedLookup[1004] =
'--alt-preset fast standard';
1912 $LAMEpresetUsedLookup[1005] =
'--alt-preset fast extreme';
1913 $LAMEpresetUsedLookup[1006] =
'--alt-preset medium';
1914 $LAMEpresetUsedLookup[1007] =
'--alt-preset fast medium';
1917 $LAMEpresetUsedLookup[1010] =
'--preset portable';
1918 $LAMEpresetUsedLookup[1015] =
'--preset radio';
1920 $LAMEpresetUsedLookup[320] =
'--preset insane';
1921 $LAMEpresetUsedLookup[410] =
'-V9';
1922 $LAMEpresetUsedLookup[420] =
'-V8';
1923 $LAMEpresetUsedLookup[440] =
'-V6';
1924 $LAMEpresetUsedLookup[430] =
'--preset radio';
1925 $LAMEpresetUsedLookup[450] =
'--preset '.(($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'').
'portable';
1926 $LAMEpresetUsedLookup[460] =
'--preset '.(($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'').
'medium';
1927 $LAMEpresetUsedLookup[470] =
'--r3mix';
1928 $LAMEpresetUsedLookup[480] =
'--preset '.(($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'').
'standard';
1929 $LAMEpresetUsedLookup[490] =
'-V1';
1930 $LAMEpresetUsedLookup[500] =
'--preset '.(($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'').
'extreme';
1932 return (isset($LAMEpresetUsedLookup[$LAMEtag[
'preset_used_id']]) ? $LAMEpresetUsedLookup[$LAMEtag[
'preset_used_id']] :
'new/unknown preset: '.$LAMEtag[
'preset_used_id'].
' - report to info@getid3.org');