54 $info = &$this->getid3->info;
56 $initialOffset =
$info[
'avdataoffset'];
59 if ($this->allow_bruteforce) {
60 $info[
'error'][] =
'Rescanning file in BruteForce mode';
65 if (isset(
$info[
'mpeg'][
'audio'][
'bitrate_mode'])) {
66 $info[
'audio'][
'bitrate_mode'] = strtolower(
$info[
'mpeg'][
'audio'][
'bitrate_mode']);
69 if (((isset(
$info[
'id3v2'][
'headerlength']) && (
$info[
'avdataoffset'] >
$info[
'id3v2'][
'headerlength'])) || (!isset(
$info[
'id3v2']) && (
$info[
'avdataoffset'] > 0) && (
$info[
'avdataoffset'] != $initialOffset)))) {
71 $synchoffsetwarning =
'Unknown data before synch ';
72 if (isset(
$info[
'id3v2'][
'headerlength'])) {
73 $synchoffsetwarning .=
'(ID3v2 header ends at ' .
$info[
'id3v2'][
'headerlength'] .
', then ' . (
$info[
'avdataoffset'] -
$info[
'id3v2'][
'headerlength']) .
' bytes garbage, ';
74 } elseif ($initialOffset > 0) {
75 $synchoffsetwarning .=
'(should be at ' . $initialOffset .
', ';
77 $synchoffsetwarning .=
'(should be at beginning of file, ';
79 $synchoffsetwarning .=
'synch detected at ' .
$info[
'avdataoffset'] .
')';
80 if (isset(
$info[
'audio'][
'bitrate_mode']) && (
$info[
'audio'][
'bitrate_mode'] ==
'cbr')) {
82 if (!empty(
$info[
'id3v2'][
'headerlength']) && ((
$info[
'avdataoffset'] -
$info[
'id3v2'][
'headerlength']) ==
$info[
'mpeg'][
'audio'][
'framelength'])) {
84 $synchoffsetwarning .=
'. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.';
85 $info[
'audio'][
'codec'] =
'LAME';
86 $CurrentDataLAMEversionString =
'LAME3.';
87 } elseif (empty(
$info[
'id3v2'][
'headerlength']) && (
$info[
'avdataoffset'] ==
$info[
'mpeg'][
'audio'][
'framelength'])) {
89 $synchoffsetwarning .=
'. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.';
90 $info[
'audio'][
'codec'] =
'LAME';
91 $CurrentDataLAMEversionString =
'LAME3.';
94 $info[
'warning'][] = $synchoffsetwarning;
97 if (isset(
$info[
'mpeg'][
'audio'][
'LAME'])) {
98 $info[
'audio'][
'codec'] =
'LAME';
99 if (!empty(
$info[
'mpeg'][
'audio'][
'LAME'][
'long_version'])) {
100 $info[
'audio'][
'encoder'] = rtrim(
$info[
'mpeg'][
'audio'][
'LAME'][
'long_version'],
102 } elseif (!empty(
$info[
'mpeg'][
'audio'][
'LAME'][
'short_version'])) {
103 $info[
'audio'][
'encoder'] = rtrim(
$info[
'mpeg'][
'audio'][
'LAME'][
'short_version'],
108 $CurrentDataLAMEversionString = (!empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : (isset(
$info[
'audio'][
'encoder']) ?
$info[
'audio'][
'encoder'] :
''));
109 if (!empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString,
110 0, 6) ==
'LAME3.') && !preg_match(
'[0-9\)]',
111 substr($CurrentDataLAMEversionString,
117 $PossiblyLongerLAMEversion_FrameLength = 1441;
120 $PossibleLAMEversionStringOffset =
$info[
'avdataend'] - $PossiblyLongerLAMEversion_FrameLength;
121 fseek($this->getid3->fp, $PossibleLAMEversionStringOffset);
122 $PossiblyLongerLAMEversion_Data =
fread($this->getid3->fp,
123 $PossiblyLongerLAMEversion_FrameLength);
124 switch (substr($CurrentDataLAMEversionString, -1)) {
129 $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString,
133 if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data,
134 $CurrentDataLAMEversionString)) !==
false) {
135 if (substr($PossiblyLongerLAMEversion_String, 0,
136 strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString) {
137 $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String,
139 strspn($PossiblyLongerLAMEversion_String,
140 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)'));
141 if (empty(
$info[
'audio'][
'encoder']) || (strlen($PossiblyLongerLAMEversion_NewString) > strlen(
$info[
'audio'][
'encoder']))) {
142 $info[
'audio'][
'encoder'] = $PossiblyLongerLAMEversion_NewString;
147 if (!empty(
$info[
'audio'][
'encoder'])) {
148 $info[
'audio'][
'encoder'] = rtrim(
$info[
'audio'][
'encoder'],
"\x00 ");
151 switch (isset(
$info[
'mpeg'][
'audio'][
'layer']) ?
$info[
'mpeg'][
'audio'][
'layer'] :
'') {
154 $info[
'audio'][
'dataformat'] =
'mp' . $info[
'mpeg'][
'audio'][
'layer'];
157 if (isset($info[
'fileformat']) && ($info[
'fileformat'] ==
'mp3')) {
158 switch ($info[
'audio'][
'dataformat']) {
162 $info[
'fileformat'] = $info[
'audio'][
'dataformat'];
166 $info[
'warning'][] =
'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "' . $info[
'audio'][
'dataformat'] .
'"';
171 if (empty($info[
'fileformat'])) {
172 unset($info[
'fileformat']);
173 unset($info[
'audio'][
'bitrate_mode']);
174 unset($info[
'avdataoffset']);
175 unset($info[
'avdataend']);
180 $info[
'mime_type'] =
'audio/mpeg';
181 $info[
'audio'][
'lossless'] =
false;
184 if (!isset($info[
'playtime_seconds']) && isset($info[
'audio'][
'bitrate']) && ($info[
'audio'][
'bitrate'] > 0)) {
185 $info[
'playtime_seconds'] = ($info[
'avdataend'] - $info[
'avdataoffset']) * 8 / $info[
'audio'][
'bitrate'];
204 $info = &$this->getid3->info;
205 if (!empty(
$info[
'mpeg'][
'audio'])) {
206 $thisfile_mpeg_audio = &
$info[
'mpeg'][
'audio'];
207 if (!empty($thisfile_mpeg_audio[
'LAME'])) {
208 $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio[
'LAME'];
212 $encoder_options =
'';
213 static $NamedPresetBitrates =
array(16, 24, 40, 56, 112, 128, 160, 192, 256);
215 if (isset($thisfile_mpeg_audio[
'VBR_method']) && ($thisfile_mpeg_audio[
'VBR_method'] ==
'Fraunhofer') && !empty($thisfile_mpeg_audio[
'VBR_quality'])) {
217 $encoder_options =
'VBR q' . $thisfile_mpeg_audio[
'VBR_quality'];
218 } elseif (!empty($thisfile_mpeg_audio_lame[
'preset_used']) && (!in_array($thisfile_mpeg_audio_lame[
'preset_used_id'],
219 $NamedPresetBitrates))) {
221 $encoder_options = $thisfile_mpeg_audio_lame[
'preset_used'];
222 } elseif (!empty($thisfile_mpeg_audio_lame[
'vbr_quality'])) {
224 static $KnownEncoderValues =
array();
225 if (empty($KnownEncoderValues)) {
228 $KnownEncoderValues[0xFF][58][1][1][3][2][20500] =
'--alt-preset insane';
229 $KnownEncoderValues[0xFF][58][1][1][3][2][20600] =
'--alt-preset insane';
230 $KnownEncoderValues[0xFF][57][1][1][3][4][20500] =
'--alt-preset insane';
231 $KnownEncoderValues[
'**'][78][3][2][3][2][19500] =
'--alt-preset extreme';
232 $KnownEncoderValues[
'**'][78][3][2][3][2][19600] =
'--alt-preset extreme';
233 $KnownEncoderValues[
'**'][78][3][1][3][2][19600] =
'--alt-preset extreme';
234 $KnownEncoderValues[
'**'][78][4][2][3][2][19500] =
'--alt-preset fast extreme';
235 $KnownEncoderValues[
'**'][78][4][2][3][2][19600] =
'--alt-preset fast extreme';
236 $KnownEncoderValues[
'**'][78][3][2][3][4][19000] =
'--alt-preset standard';
237 $KnownEncoderValues[
'**'][78][3][1][3][4][19000] =
'--alt-preset standard';
238 $KnownEncoderValues[
'**'][78][4][2][3][4][19000] =
'--alt-preset fast standard';
239 $KnownEncoderValues[
'**'][78][4][1][3][4][19000] =
'--alt-preset fast standard';
240 $KnownEncoderValues[
'**'][88][4][1][3][3][19500] =
'--r3mix';
241 $KnownEncoderValues[
'**'][88][4][1][3][3][19600] =
'--r3mix';
242 $KnownEncoderValues[
'**'][67][4][1][3][4][18000] =
'--r3mix';
243 $KnownEncoderValues[
'**'][68][3][2][3][4][18000] =
'--alt-preset medium';
244 $KnownEncoderValues[
'**'][68][4][2][3][4][18000] =
'--alt-preset fast medium';
246 $KnownEncoderValues[0xFF][99][1][1][1][2][0] =
'--preset studio';
247 $KnownEncoderValues[0xFF][58][2][1][3][2][20600] =
'--preset studio';
248 $KnownEncoderValues[0xFF][58][2][1][3][2][20500] =
'--preset studio';
249 $KnownEncoderValues[0xFF][57][2][1][3][4][20500] =
'--preset studio';
250 $KnownEncoderValues[0xC0][88][1][1][1][2][0] =
'--preset cd';
251 $KnownEncoderValues[0xC0][58][2][2][3][2][19600] =
'--preset cd';
252 $KnownEncoderValues[0xC0][58][2][2][3][2][19500] =
'--preset cd';
253 $KnownEncoderValues[0xC0][57][2][1][3][4][19500] =
'--preset cd';
254 $KnownEncoderValues[0xA0][78][1][1][3][2][18000] =
'--preset hifi';
255 $KnownEncoderValues[0xA0][58][2][2][3][2][18000] =
'--preset hifi';
256 $KnownEncoderValues[0xA0][57][2][1][3][4][18000] =
'--preset hifi';
257 $KnownEncoderValues[0x80][67][1][1][3][2][18000] =
'--preset tape';
258 $KnownEncoderValues[0x80][67][1][1][3][2][15000] =
'--preset radio';
259 $KnownEncoderValues[0x70][67][1][1][3][2][15000] =
'--preset fm';
260 $KnownEncoderValues[0x70][58][2][2][3][2][16000] =
'--preset tape/radio/fm';
261 $KnownEncoderValues[0x70][57][2][1][3][4][16000] =
'--preset tape/radio/fm';
262 $KnownEncoderValues[0x38][58][2][2][0][2][10000] =
'--preset voice';
263 $KnownEncoderValues[0x38][57][2][1][0][4][15000] =
'--preset voice';
264 $KnownEncoderValues[0x38][57][2][1][0][4][16000] =
'--preset voice';
265 $KnownEncoderValues[0x28][65][1][1][0][2][7500] =
'--preset mw-us';
266 $KnownEncoderValues[0x28][65][1][1][0][2][7600] =
'--preset mw-us';
267 $KnownEncoderValues[0x28][58][2][2][0][2][7000] =
'--preset mw-us';
268 $KnownEncoderValues[0x28][57][2][1][0][4][10500] =
'--preset mw-us';
269 $KnownEncoderValues[0x28][57][2][1][0][4][11200] =
'--preset mw-us';
270 $KnownEncoderValues[0x28][57][2][1][0][4][8800] =
'--preset mw-us';
271 $KnownEncoderValues[0x18][58][2][2][0][2][4000] =
'--preset phon+/lw/mw-eu/sw';
272 $KnownEncoderValues[0x18][58][2][2][0][2][3900] =
'--preset phon+/lw/mw-eu/sw';
273 $KnownEncoderValues[0x18][57][2][1][0][4][5900] =
'--preset phon+/lw/mw-eu/sw';
274 $KnownEncoderValues[0x18][57][2][1][0][4][6200] =
'--preset phon+/lw/mw-eu/sw';
275 $KnownEncoderValues[0x18][57][2][1][0][4][3200] =
'--preset phon+/lw/mw-eu/sw';
276 $KnownEncoderValues[0x10][58][2][2][0][2][3800] =
'--preset phone';
277 $KnownEncoderValues[0x10][58][2][2][0][2][3700] =
'--preset phone';
278 $KnownEncoderValues[0x10][57][2][1][0][4][5600] =
'--preset phone';
281 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']])) {
283 $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']];
284 } 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']])) {
286 $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']];
287 } elseif (
$info[
'audio'][
'bitrate_mode'] ==
'vbr') {
292 $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame[
'vbr_quality'] / 10);
293 $LAME_q_value = 100 - $thisfile_mpeg_audio_lame[
'vbr_quality'] - ($LAME_V_value * 10);
294 $encoder_options =
'-V' . $LAME_V_value .
' -q' . $LAME_q_value;
295 } elseif (
$info[
'audio'][
'bitrate_mode'] ==
'cbr') {
297 $encoder_options = strtoupper(
$info[
'audio'][
'bitrate_mode']) . ceil(
$info[
'audio'][
'bitrate'] / 1000);
300 $encoder_options = strtoupper(
$info[
'audio'][
'bitrate_mode']);
302 } elseif (!empty($thisfile_mpeg_audio_lame[
'bitrate_abr'])) {
304 $encoder_options =
'ABR' . $thisfile_mpeg_audio_lame[
'bitrate_abr'];
305 } elseif (!empty(
$info[
'audio'][
'bitrate'])) {
307 if (
$info[
'audio'][
'bitrate_mode'] ==
'cbr') {
308 $encoder_options = strtoupper(
$info[
'audio'][
'bitrate_mode']) . ceil(
$info[
'audio'][
'bitrate'] / 1000);
310 $encoder_options = strtoupper(
$info[
'audio'][
'bitrate_mode']);
313 if (!empty($thisfile_mpeg_audio_lame[
'bitrate_min'])) {
314 $encoder_options .=
' -b' . $thisfile_mpeg_audio_lame[
'bitrate_min'];
317 if (!empty($thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_prev']) || !empty($thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_next'])) {
318 $encoder_options .=
' --nogap';
321 if (!empty($thisfile_mpeg_audio_lame[
'lowpass_frequency'])) {
322 $ExplodedOptions = explode(
' ', $encoder_options, 4);
323 if ($ExplodedOptions[0] ==
'--r3mix') {
324 $ExplodedOptions[1] =
'r3mix';
326 switch ($ExplodedOptions[0]) {
330 if ($ExplodedOptions[1] ==
'fast') {
331 $ExplodedOptions[1] .=
' ' . $ExplodedOptions[2];
333 switch ($ExplodedOptions[1]) {
339 case 'fast portable':
341 case 'fast standard':
345 static $ExpectedLowpass =
array(
346 'insane|20500' => 20500,
347 'insane|20600' => 20600,
348 'medium|18000' => 18000,
349 'fast medium|18000' => 18000,
350 'extreme|19500' => 19500,
351 'extreme|19600' => 19600,
352 'fast extreme|19500' => 19500,
353 'fast extreme|19600' => 19600,
354 'standard|19000' => 19000,
355 'fast standard|19000' => 19000,
356 'r3mix|19500' => 19500,
357 'r3mix|19600' => 19600,
358 'r3mix|18000' => 18000,
360 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))) {
361 $encoder_options .=
' --lowpass ' . $thisfile_mpeg_audio_lame[
'lowpass_frequency'];
372 if (isset($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq'])) {
373 if (($thisfile_mpeg_audio[
'sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq'] != 1)) {
374 $encoder_options .=
' --resample 44100';
375 } elseif (($thisfile_mpeg_audio[
'sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq'] != 2)) {
376 $encoder_options .=
' --resample 48000';
377 } elseif ($thisfile_mpeg_audio[
'sample_rate'] < 44100) {
378 switch ($thisfile_mpeg_audio_lame[
'raw'][
'source_sample_freq']) {
385 $ExplodedOptions = explode(
' ', $encoder_options, 4);
386 switch ($ExplodedOptions[0]) {
389 switch ($ExplodedOptions[1]) {
396 $encoder_options .=
' --resample ' . $thisfile_mpeg_audio[
'sample_rate'];
400 static $ExpectedResampledRate =
array(
401 'phon+/lw/mw-eu/sw|16000' => 16000,
402 'mw-us|24000' => 24000,
403 'mw-us|32000' => 32000,
404 'mw-us|16000' => 16000,
405 'phone|16000' => 16000,
406 'phone|11025' => 11025,
407 'radio|32000' => 32000,
408 'fm/radio|32000' => 32000,
410 'voice|32000' => 32000);
411 if (!isset($ExpectedResampledRate[$ExplodedOptions[1] .
'|' . $thisfile_mpeg_audio[
'sample_rate']])) {
412 $encoder_options .=
' --resample ' . $thisfile_mpeg_audio[
'sample_rate'];
420 $encoder_options .=
' --resample ' . $thisfile_mpeg_audio[
'sample_rate'];
427 if (empty($encoder_options) && !empty(
$info[
'audio'][
'bitrate']) && !empty(
$info[
'audio'][
'bitrate_mode'])) {
429 $encoder_options = strtoupper(
$info[
'audio'][
'bitrate_mode']);
432 return $encoder_options;
454 $recursivesearch =
true,
456 $FastMPEGheaderScan =
false)
458 static $MPEGaudioVersionLookup;
459 static $MPEGaudioLayerLookup;
460 static $MPEGaudioBitrateLookup;
461 static $MPEGaudioFrequencyLookup;
462 static $MPEGaudioChannelModeLookup;
463 static $MPEGaudioModeExtensionLookup;
464 static $MPEGaudioEmphasisLookup;
465 if (empty($MPEGaudioVersionLookup)) {
466 $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
467 $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
468 $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
469 $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray();
470 $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray();
471 $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();
472 $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray();
475 if (
fseek($this->getid3->fp, $offset, SEEK_SET) != 0) {
476 $info[
'error'][] =
'decodeMPEGaudioHeader() failed to seek to next offset at ' . $offset;
481 $headerstring =
fread($this->getid3->fp, 226);
488 $head4 = substr($headerstring, 0, 4);
490 static $MPEGaudioHeaderDecodeCache =
array();
491 if (isset($MPEGaudioHeaderDecodeCache[$head4])) {
492 $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
494 $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4);
495 $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
498 static $MPEGaudioHeaderValidCache =
array();
499 if (!isset($MPEGaudioHeaderValidCache[$head4])) {
501 $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray,
507 if (!isset(
$info[
'mpeg'][
'audio'])) {
510 $thisfile_mpeg_audio = &
$info[
'mpeg'][
'audio'];
512 if ($MPEGaudioHeaderValidCache[$head4]) {
513 $thisfile_mpeg_audio[
'raw'] = $MPEGheaderRawArray;
520 if (!$FastMPEGheaderScan) {
521 $thisfile_mpeg_audio[
'version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio[
'raw'][
'version']];
522 $thisfile_mpeg_audio[
'layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio[
'raw'][
'layer']];
524 $thisfile_mpeg_audio[
'channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio[
'raw'][
'channelmode']];
525 $thisfile_mpeg_audio[
'channels'] = (($thisfile_mpeg_audio[
'channelmode'] ==
'mono') ? 1 : 2);
526 $thisfile_mpeg_audio[
'sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio[
'version']][$thisfile_mpeg_audio[
'raw'][
'sample_rate']];
527 $thisfile_mpeg_audio[
'protection'] = !$thisfile_mpeg_audio[
'raw'][
'protection'];
528 $thisfile_mpeg_audio[
'private'] = (bool) $thisfile_mpeg_audio[
'raw'][
'private'];
529 $thisfile_mpeg_audio[
'modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio[
'layer']][$thisfile_mpeg_audio[
'raw'][
'modeextension']];
530 $thisfile_mpeg_audio[
'copyright'] = (bool) $thisfile_mpeg_audio[
'raw'][
'copyright'];
531 $thisfile_mpeg_audio[
'original'] = (bool) $thisfile_mpeg_audio[
'raw'][
'original'];
532 $thisfile_mpeg_audio[
'emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio[
'raw'][
'emphasis']];
534 $info[
'audio'][
'channels'] = $thisfile_mpeg_audio[
'channels'];
535 $info[
'audio'][
'sample_rate'] = $thisfile_mpeg_audio[
'sample_rate'];
537 if ($thisfile_mpeg_audio[
'protection']) {
544 if ($thisfile_mpeg_audio[
'raw'][
'bitrate'] == 15) {
546 $info[
'warning'][] =
'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';
547 $thisfile_mpeg_audio[
'raw'][
'bitrate'] = 0;
549 $thisfile_mpeg_audio[
'padding'] = (bool) $thisfile_mpeg_audio[
'raw'][
'padding'];
550 $thisfile_mpeg_audio[
'bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio[
'version']][$thisfile_mpeg_audio[
'layer']][$thisfile_mpeg_audio[
'raw'][
'bitrate']];
552 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') && ($offset ==
$info[
'avdataoffset'])) {
555 $recursivesearch =
false;
559 if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio[
'layer'] ==
'2')) {
561 $info[
'audio'][
'dataformat'] =
'mp2';
562 switch ($thisfile_mpeg_audio[
'channelmode']) {
565 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') || ($thisfile_mpeg_audio[
'bitrate'] <= 192000)) {
568 $info[
'error'][] = $thisfile_mpeg_audio[
'bitrate'] .
'kbps not allowed in Layer 2, ' . $thisfile_mpeg_audio[
'channelmode'] .
'.';
577 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') || ($thisfile_mpeg_audio[
'bitrate'] == 64000) || ($thisfile_mpeg_audio[
'bitrate'] >= 96000)) {
580 $info[
'error'][] = intval(round($thisfile_mpeg_audio[
'bitrate'] / 1000)) .
'kbps not allowed in Layer 2, ' . $thisfile_mpeg_audio[
'channelmode'] .
'.';
588 if (
$info[
'audio'][
'sample_rate'] > 0) {
589 $thisfile_mpeg_audio[
'framelength'] = self::MPEGaudioFrameLength($thisfile_mpeg_audio[
'bitrate'],
590 $thisfile_mpeg_audio[
'version'],
591 $thisfile_mpeg_audio[
'layer'],
592 (
int) $thisfile_mpeg_audio[
'padding'],
593 $info[
'audio'][
'sample_rate']);
596 $nextframetestoffset = $offset + 1;
597 if ($thisfile_mpeg_audio[
'bitrate'] !=
'free') {
599 $info[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'bitrate'];
601 if (isset($thisfile_mpeg_audio[
'framelength'])) {
602 $nextframetestoffset = $offset + $thisfile_mpeg_audio[
'framelength'];
604 $info[
'error'][] =
'Frame at offset(' . $offset .
') is has an invalid frame length.';
610 $ExpectedNumberOfAudioBytes = 0;
615 if (substr($headerstring, 4 + 32, 4) ==
'VBRI') {
619 $thisfile_mpeg_audio[
'bitrate_mode'] =
'vbr';
620 $thisfile_mpeg_audio[
'VBR_method'] =
'Fraunhofer';
621 $info[
'audio'][
'codec'] =
'Fraunhofer';
623 $SideInfoData = substr($headerstring, 4 + 2, 32);
625 $FraunhoferVBROffset = 36;
628 $FraunhoferVBROffset + 4,
631 $FraunhoferVBROffset + 6,
634 $FraunhoferVBROffset + 8,
637 $FraunhoferVBROffset + 10,
640 $FraunhoferVBROffset + 14,
643 $FraunhoferVBROffset + 18,
646 $FraunhoferVBROffset + 20,
649 $FraunhoferVBROffset + 22,
652 $FraunhoferVBROffset + 24,
655 $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio[
'VBR_bytes'];
657 $previousbyteoffset = $offset;
658 for ($i = 0; $i < $thisfile_mpeg_audio[
'VBR_seek_offsets']; $i++) {
660 $FraunhoferVBROffset,
661 $thisfile_mpeg_audio[
'VBR_entry_bytes']));
662 $FraunhoferVBROffset += $thisfile_mpeg_audio[
'VBR_entry_bytes'];
663 $thisfile_mpeg_audio[
'VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio[
'VBR_seek_scale']);
664 $thisfile_mpeg_audio[
'VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio[
'VBR_seek_scale']) + $previousbyteoffset;
665 $previousbyteoffset += $Fraunhofer_OffsetN;
672 $VBRidOffset = self::XingVBRidOffset($thisfile_mpeg_audio[
'version'],
673 $thisfile_mpeg_audio[
'channelmode']);
674 $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4);
676 if ((substr($headerstring, $VBRidOffset, strlen(
'Xing')) ==
'Xing') || (substr($headerstring,
678 strlen(
'Info')) ==
'Info')) {
702 $thisfile_mpeg_audio[
'bitrate_mode'] =
'vbr';
703 $thisfile_mpeg_audio[
'VBR_method'] =
'Xing';
713 $thisfile_mpeg_audio[
'xing_flags'][
'frames'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000001);
714 $thisfile_mpeg_audio[
'xing_flags'][
'bytes'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000002);
715 $thisfile_mpeg_audio[
'xing_flags'][
'toc'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000004);
716 $thisfile_mpeg_audio[
'xing_flags'][
'vbr_scale'] = (bool) ($thisfile_mpeg_audio[
'xing_flags_raw'] & 0x00000008);
718 if ($thisfile_mpeg_audio[
'xing_flags'][
'frames']) {
724 if ($thisfile_mpeg_audio[
'xing_flags'][
'bytes']) {
731 if (!empty($thisfile_mpeg_audio[
'VBR_frames']) && !empty($thisfile_mpeg_audio[
'VBR_bytes'])) {
733 $framelengthfloat = $thisfile_mpeg_audio[
'VBR_bytes'] / $thisfile_mpeg_audio[
'VBR_frames'];
735 if ($thisfile_mpeg_audio[
'layer'] ==
'1') {
738 $info[
'audio'][
'bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio[
'sample_rate'] * (2 /
$info[
'audio'][
'channels']) / 12;
742 $info[
'audio'][
'bitrate'] = $framelengthfloat * $thisfile_mpeg_audio[
'sample_rate'] * (2 /
$info[
'audio'][
'channels']) / 144;
744 $thisfile_mpeg_audio[
'framelength'] = floor($framelengthfloat);
747 if ($thisfile_mpeg_audio[
'xing_flags'][
'toc']) {
748 $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100);
749 for ($i = 0; $i < 100; $i++) {
750 $thisfile_mpeg_audio[
'toc'][$i] = ord($LAMEtocData{$i});
753 if ($thisfile_mpeg_audio[
'xing_flags'][
'vbr_scale']) {
761 if (substr($headerstring, $VBRidOffset + 120, 4) ==
'LAME') {
764 $thisfile_mpeg_audio[
'LAME'] =
array();
765 $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio[
'LAME'];
768 $thisfile_mpeg_audio_lame[
'long_version'] = substr($headerstring,
771 $thisfile_mpeg_audio_lame[
'short_version'] = substr($thisfile_mpeg_audio_lame[
'long_version'],
774 if ($thisfile_mpeg_audio_lame[
'short_version'] >=
'LAME3.90') {
777 unset($thisfile_mpeg_audio_lame[
'long_version']);
784 $LAMEtagOffsetContant = $VBRidOffset - 0x24;
787 $thisfile_mpeg_audio_lame[
'RGAD'] =
array(
'track' =>
array(),
'album' =>
array());
788 $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame[
'RGAD'];
789 $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD[
'track'];
790 $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD[
'album'];
791 $thisfile_mpeg_audio_lame[
'raw'] =
array();
792 $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame[
'raw'];
797 unset($thisfile_mpeg_audio[
'VBR_scale']);
799 $LAMEtagOffsetContant + 0x9B,
803 $thisfile_mpeg_audio_lame[
'short_version'] = substr($headerstring,
804 $LAMEtagOffsetContant + 0x9C,
809 $LAMEtagOffsetContant + 0xA5,
812 $thisfile_mpeg_audio_lame[
'tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4;
813 $thisfile_mpeg_audio_lame_raw[
'vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F;
814 $thisfile_mpeg_audio_lame[
'vbr_method'] = self::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw[
'vbr_method']);
815 $thisfile_mpeg_audio[
'bitrate_mode'] = substr($thisfile_mpeg_audio_lame[
'vbr_method'],
819 $LAMEtagOffsetContant + 0xA6,
825 if ($thisfile_mpeg_audio_lame[
'short_version'] >=
'LAME3.94b') {
828 $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'] = (float) ((
Helper::BigEndian2Int(substr($headerstring,
829 $LAMEtagOffsetContant + 0xA7,
835 $LAMEtagOffsetContant + 0xA7,
838 if ($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'] == 0) {
839 unset($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude']);
841 $thisfile_mpeg_audio_lame_RGAD[
'peak_db'] =
Helper::RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude']);
845 $LAMEtagOffsetContant + 0xAB,
848 $LAMEtagOffsetContant + 0xAD,
852 if ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] != 0) {
854 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'name'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0xE000) >> 13;
855 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'originator'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x1C00) >> 10;
856 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'sign_bit'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x0200) >> 9;
857 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'gain_adjust'] = $thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x01FF;
858 $thisfile_mpeg_audio_lame_RGAD_track[
'name'] =
Helper::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'name']);
859 $thisfile_mpeg_audio_lame_RGAD_track[
'originator'] =
Helper::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'originator']);
860 $thisfile_mpeg_audio_lame_RGAD_track[
'gain_db'] =
Helper::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'gain_adjust'],
861 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'sign_bit']);
863 if (!empty($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'])) {
864 $info[
'replay_gain'][
'track'][
'peak'] = $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'];
866 $info[
'replay_gain'][
'track'][
'originator'] = $thisfile_mpeg_audio_lame_RGAD_track[
'originator'];
867 $info[
'replay_gain'][
'track'][
'adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track[
'gain_db'];
869 unset($thisfile_mpeg_audio_lame_RGAD[
'track']);
871 if ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] != 0) {
873 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'name'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0xE000) >> 13;
874 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'originator'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x1C00) >> 10;
875 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'sign_bit'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x0200) >> 9;
876 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'gain_adjust'] = $thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x01FF;
877 $thisfile_mpeg_audio_lame_RGAD_album[
'name'] =
Helper::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'name']);
878 $thisfile_mpeg_audio_lame_RGAD_album[
'originator'] =
Helper::RGADoriginatorLookup($thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'originator']);
879 $thisfile_mpeg_audio_lame_RGAD_album[
'gain_db'] =
Helper::RGADadjustmentLookup($thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'gain_adjust'],
880 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'sign_bit']);
882 if (!empty($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'])) {
883 $info[
'replay_gain'][
'album'][
'peak'] = $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'];
885 $info[
'replay_gain'][
'album'][
'originator'] = $thisfile_mpeg_audio_lame_RGAD_album[
'originator'];
886 $info[
'replay_gain'][
'album'][
'adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album[
'gain_db'];
888 unset($thisfile_mpeg_audio_lame_RGAD[
'album']);
890 if (empty($thisfile_mpeg_audio_lame_RGAD)) {
891 unset($thisfile_mpeg_audio_lame[
'RGAD']);
897 $LAMEtagOffsetContant + 0xAF,
899 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10);
900 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20);
901 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40);
902 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80);
903 $thisfile_mpeg_audio_lame[
'ath_type'] = $EncodingFlagsATHtype & 0x0F;
906 $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'] =
Helper::BigEndian2Int(substr($headerstring,
907 $LAMEtagOffsetContant + 0xB0,
909 if ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 2) {
910 $thisfile_mpeg_audio_lame[
'bitrate_abr'] = $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'];
911 } elseif ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 1) {
913 } elseif ($thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'] > 0) {
914 $thisfile_mpeg_audio_lame[
'bitrate_min'] = $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'];
919 $LAMEtagOffsetContant + 0xB1,
921 $thisfile_mpeg_audio_lame[
'encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12;
922 $thisfile_mpeg_audio_lame[
'end_padding'] = $EncoderDelays & 0x000FFF;
926 $LAMEtagOffsetContant + 0xB4,
928 $thisfile_mpeg_audio_lame_raw[
'noise_shaping'] = ($MiscByte & 0x03);
929 $thisfile_mpeg_audio_lame_raw[
'stereo_mode'] = ($MiscByte & 0x1C) >> 2;
930 $thisfile_mpeg_audio_lame_raw[
'not_optimal_quality'] = ($MiscByte & 0x20) >> 5;
931 $thisfile_mpeg_audio_lame_raw[
'source_sample_freq'] = ($MiscByte & 0xC0) >> 6;
932 $thisfile_mpeg_audio_lame[
'noise_shaping'] = $thisfile_mpeg_audio_lame_raw[
'noise_shaping'];
933 $thisfile_mpeg_audio_lame[
'stereo_mode'] = self::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw[
'stereo_mode']);
934 $thisfile_mpeg_audio_lame[
'not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw[
'not_optimal_quality'];
935 $thisfile_mpeg_audio_lame[
'source_sample_freq'] = self::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw[
'source_sample_freq']);
939 $LAMEtagOffsetContant + 0xB5,
943 $thisfile_mpeg_audio_lame[
'mp3_gain_db'] = (
Helper::RGADamplitude2dB(2) / 4) * $thisfile_mpeg_audio_lame_raw[
'mp3_gain'];
944 $thisfile_mpeg_audio_lame[
'mp3_gain_factor'] = pow(2,
945 ($thisfile_mpeg_audio_lame[
'mp3_gain_db'] / 6));
949 $LAMEtagOffsetContant + 0xB6,
952 $thisfile_mpeg_audio_lame_raw[
'surround_info'] = ($PresetSurroundBytes & 0x3800);
953 $thisfile_mpeg_audio_lame[
'surround_info'] = self::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw[
'surround_info']);
954 $thisfile_mpeg_audio_lame[
'preset_used_id'] = ($PresetSurroundBytes & 0x07FF);
955 $thisfile_mpeg_audio_lame[
'preset_used'] = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame);
956 if (!empty($thisfile_mpeg_audio_lame[
'preset_used_id']) && empty($thisfile_mpeg_audio_lame[
'preset_used'])) {
957 $info[
'warning'][] =
'Unknown LAME preset used (' . $thisfile_mpeg_audio_lame[
'preset_used_id'] .
') - please report to info@getid3.org';
959 if (($thisfile_mpeg_audio_lame[
'short_version'] ==
'LAME3.90.') && !empty($thisfile_mpeg_audio_lame[
'preset_used_id'])) {
961 $thisfile_mpeg_audio_lame[
'short_version'] =
'LAME3.90.3';
966 $LAMEtagOffsetContant + 0xB8,
968 $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame[
'audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame[
'audio_bytes'] : $thisfile_mpeg_audio[
'VBR_bytes']);
972 $LAMEtagOffsetContant + 0xBC,
977 $LAMEtagOffsetContant + 0xBE,
982 if ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 1) {
984 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
985 $thisfile_mpeg_audio[
'bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio[
'bitrate']);
986 $info[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'bitrate'];
996 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
997 if ($recursivesearch) {
998 $thisfile_mpeg_audio[
'bitrate_mode'] =
'vbr';
1000 $nextframetestoffset,
true)) {
1001 $recursivesearch =
false;
1002 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
1004 if ($thisfile_mpeg_audio[
'bitrate_mode'] ==
'vbr') {
1005 $info[
'warning'][] =
'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.';
1011 if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != (
$info[
'avdataend'] -
$info[
'avdataoffset']))) {
1012 if ($ExpectedNumberOfAudioBytes > (
$info[
'avdataend'] -
$info[
'avdataoffset'])) {
1013 if (isset(
$info[
'fileformat']) && (
$info[
'fileformat'] ==
'riff')) {
1015 } elseif (($ExpectedNumberOfAudioBytes - (
$info[
'avdataend'] -
$info[
'avdataoffset'])) == 1) {
1016 $info[
'warning'][] =
'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)';
1018 $info[
'warning'][] =
'Probable truncated file: expecting ' . $ExpectedNumberOfAudioBytes .
' bytes of audio data, only found ' . (
$info[
'avdataend'] -
$info[
'avdataoffset']) .
' (short by ' . ($ExpectedNumberOfAudioBytes - (
$info[
'avdataend'] -
$info[
'avdataoffset'])) .
' bytes)';
1021 if (((
$info[
'avdataend'] -
$info[
'avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) {
1027 $info[
'avdataend']--;
1033 $info[
'warning'][] =
'Too much data in file: expecting ' . $ExpectedNumberOfAudioBytes .
' bytes of audio data, found ' . (
$info[
'avdataend'] -
$info[
'avdataoffset']) .
' (' . ((
$info[
'avdataend'] -
$info[
'avdataoffset']) - $ExpectedNumberOfAudioBytes) .
' bytes too many)';
1038 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') && empty(
$info[
'audio'][
'bitrate'])) {
1039 if (($offset ==
$info[
'avdataoffset']) && empty($thisfile_mpeg_audio[
'VBR_frames'])) {
1041 if ($framebytelength > 0) {
1042 $thisfile_mpeg_audio[
'framelength'] = $framebytelength;
1043 if ($thisfile_mpeg_audio[
'layer'] ==
'1') {
1045 $info[
'audio'][
'bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio[
'padding'])) * $thisfile_mpeg_audio[
'sample_rate']) / 12;
1048 $info[
'audio'][
'bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio[
'padding'])) * $thisfile_mpeg_audio[
'sample_rate']) / 144;
1051 $info[
'error'][] =
'Error calculating frame length of free-format MP3 without Xing/LAME header';
1056 if (isset($thisfile_mpeg_audio[
'VBR_frames']) ? $thisfile_mpeg_audio[
'VBR_frames'] :
'') {
1057 switch ($thisfile_mpeg_audio[
'bitrate_mode']) {
1060 $bytes_per_frame = 1152;
1061 if (($thisfile_mpeg_audio[
'version'] ==
'1') && ($thisfile_mpeg_audio[
'layer'] == 1)) {
1062 $bytes_per_frame = 384;
1063 } elseif ((($thisfile_mpeg_audio[
'version'] ==
'2') || ($thisfile_mpeg_audio[
'version'] ==
'2.5')) && ($thisfile_mpeg_audio[
'layer'] == 3)) {
1064 $bytes_per_frame = 576;
1066 $thisfile_mpeg_audio[
'VBR_bitrate'] = (isset($thisfile_mpeg_audio[
'VBR_bytes']) ? (($thisfile_mpeg_audio[
'VBR_bytes'] / $thisfile_mpeg_audio[
'VBR_frames']) * 8) * (
$info[
'audio'][
'sample_rate'] / $bytes_per_frame) : 0);
1067 if ($thisfile_mpeg_audio[
'VBR_bitrate'] > 0) {
1068 $info[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'VBR_bitrate'];
1069 $thisfile_mpeg_audio[
'bitrate'] = $thisfile_mpeg_audio[
'VBR_bitrate'];
1078 if ($recursivesearch) {
1201 $info = &$this->getid3->info;
1202 $firstframetestarray =
array(
'error' =>
'',
'warning' =>
'',
'avdataend' =>
$info[
'avdataend'],
'avdataoffset' =>
$info[
'avdataoffset']);
1205 for ($i = 0; $i < self::GETID3_MP3_VALID_CHECK_FRAMES; $i++) {
1207 if (($nextframetestoffset + 4) >=
$info[
'avdataend']) {
1212 $nextframetestarray =
array(
'error' =>
'',
'warning' =>
'',
'avdataend' =>
$info[
'avdataend'],
'avdataoffset' =>
$info[
'avdataoffset']);
1214 $nextframetestarray,
false)) {
1217 if (!isset($nextframetestarray[
'mpeg'][
'audio'][
'bitrate']) || !isset($firstframetestarray[
'mpeg'][
'audio'][
'bitrate']) || ($nextframetestarray[
'mpeg'][
'audio'][
'bitrate'] != $firstframetestarray[
'mpeg'][
'audio'][
'bitrate'])) {
1223 if (isset($nextframetestarray[
'mpeg'][
'audio'][
'framelength']) && ($nextframetestarray[
'mpeg'][
'audio'][
'framelength'] > 0)) {
1224 $nextframetestoffset += $nextframetestarray[
'mpeg'][
'audio'][
'framelength'];
1226 $info[
'error'][] =
'Frame at offset (' . $offset .
') is has an invalid frame length.';
1230 } elseif (!empty($firstframetestarray[
'mpeg'][
'audio'][
'framelength']) && (($nextframetestoffset + $firstframetestarray[
'mpeg'][
'audio'][
'framelength']) >
$info[
'avdataend'])) {
1237 $info[
'warning'][] =
'Frame at offset (' . $offset .
') is valid, but the next one at (' . $nextframetestoffset .
') is not.';
1254 $info = &$this->getid3->info;
1256 fseek($this->getid3->fp, $offset, SEEK_SET);
1257 $MPEGaudioData =
fread($this->getid3->fp, 32768);
1259 $SyncPattern1 = substr($MPEGaudioData, 0, 4);
1261 $SyncPattern2 = $SyncPattern1{0} . $SyncPattern1{1} . chr(ord($SyncPattern1{2}) | 0x02) . $SyncPattern1{3};
1262 if ($SyncPattern2 === $SyncPattern1) {
1263 $SyncPattern2 = $SyncPattern1{0} . $SyncPattern1{1} . chr(ord($SyncPattern1{2}) & 0xFD) . $SyncPattern1{3};
1266 $framelength =
false;
1267 $framelength1 = strpos($MPEGaudioData, $SyncPattern1, 4);
1268 $framelength2 = strpos($MPEGaudioData, $SyncPattern2, 4);
1269 if ($framelength1 > 4) {
1270 $framelength = $framelength1;
1272 if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1273 $framelength = $framelength2;
1275 if (!$framelength) {
1278 $framelength1 = strpos($MPEGaudioData, substr($SyncPattern1, 0, 3),
1280 $framelength2 = strpos($MPEGaudioData, substr($SyncPattern2, 0, 3),
1283 if ($framelength1 > 4) {
1284 $framelength = $framelength1;
1286 if (($framelength2 > 4) && ($framelength2 < $framelength1)) {
1287 $framelength = $framelength2;
1289 if (!$framelength) {
1294 $info[
'warning'][] =
'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)';
1295 $info[
'audio'][
'codec'] =
'LAME';
1296 $info[
'audio'][
'encoder'] =
'LAME3.88';
1297 $SyncPattern1 = substr($SyncPattern1, 0, 3);
1298 $SyncPattern2 = substr($SyncPattern2, 0, 3);
1304 $ActualFrameLengthValues =
array();
1305 $nextoffset = $offset + $framelength;
1306 while ($nextoffset < (
$info[
'avdataend'] - 6)) {
1307 fseek($this->getid3->fp, $nextoffset - 1, SEEK_SET);
1308 $NextSyncPattern =
fread($this->getid3->fp, 6);
1309 if ((substr($NextSyncPattern, 1, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern,
1311 strlen($SyncPattern2)) == $SyncPattern2)) {
1313 $ActualFrameLengthValues[] = $framelength;
1314 } elseif ((substr($NextSyncPattern, 0, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern,
1316 strlen($SyncPattern2)) == $SyncPattern2)) {
1318 $ActualFrameLengthValues[] = ($framelength - 1);
1320 } elseif ((substr($NextSyncPattern, 2, strlen($SyncPattern1)) == $SyncPattern1) || (substr($NextSyncPattern,
1322 strlen($SyncPattern2)) == $SyncPattern2)) {
1324 $ActualFrameLengthValues[] = ($framelength + 1);
1327 $info[
'error'][] =
'Did not find expected free-format sync pattern at offset ' . $nextoffset;
1331 $nextoffset += $framelength;
1333 if (count($ActualFrameLengthValues) > 0) {
1334 $framelength = intval(round(array_sum($ActualFrameLengthValues) / count($ActualFrameLengthValues)));
1338 return $framelength;
1347 $MPEGaudioHeaderDecodeCache =
array();
1348 $MPEGaudioHeaderValidCache =
array();
1349 $MPEGaudioHeaderLengthCache =
array();
1350 $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
1351 $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
1352 $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
1353 $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray();
1354 $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray();
1355 $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();
1356 $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray();
1357 $LongMPEGversionLookup =
array();
1358 $LongMPEGlayerLookup =
array();
1359 $LongMPEGbitrateLookup =
array();
1360 $LongMPEGpaddingLookup =
array();
1361 $LongMPEGfrequencyLookup =
array();
1362 $Distribution[
'bitrate'] =
array();
1363 $Distribution[
'frequency'] =
array();
1364 $Distribution[
'layer'] =
array();
1365 $Distribution[
'version'] =
array();
1366 $Distribution[
'padding'] =
array();
1368 $info = &$this->getid3->info;
1369 fseek($this->getid3->fp,
$info[
'avdataoffset'], SEEK_SET);
1371 $max_frames_scan = 5000;
1372 $frames_scanned = 0;
1374 $previousvalidframe =
$info[
'avdataoffset'];
1375 while (
ftell($this->getid3->fp) <
$info[
'avdataend']) {
1377 $head4 =
fread($this->getid3->fp, 4);
1378 if (strlen($head4) < 4) {
1381 if ($head4{0} !=
"\xFF") {
1382 for ($i = 1; $i < 4; $i++) {
1383 if ($head4{$i} ==
"\xFF") {
1384 fseek($this->getid3->fp, $i - 4, SEEK_CUR);
1390 if (!isset($MPEGaudioHeaderDecodeCache[$head4])) {
1391 $MPEGaudioHeaderDecodeCache[$head4] = self::MPEGaudioHeaderDecode($head4);
1393 if (!isset($MPEGaudioHeaderValidCache[$head4])) {
1394 $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$head4],
1398 if ($MPEGaudioHeaderValidCache[$head4]) {
1400 if (!isset($MPEGaudioHeaderLengthCache[$head4])) {
1401 $LongMPEGversionLookup[$head4] = $MPEGaudioVersionLookup[$MPEGaudioHeaderDecodeCache[$head4][
'version']];
1402 $LongMPEGlayerLookup[$head4] = $MPEGaudioLayerLookup[$MPEGaudioHeaderDecodeCache[$head4][
'layer']];
1403 $LongMPEGbitrateLookup[$head4] = $MPEGaudioBitrateLookup[$LongMPEGversionLookup[$head4]][$LongMPEGlayerLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4][
'bitrate']];
1404 $LongMPEGpaddingLookup[$head4] = (bool) $MPEGaudioHeaderDecodeCache[$head4][
'padding'];
1405 $LongMPEGfrequencyLookup[$head4] = $MPEGaudioFrequencyLookup[$LongMPEGversionLookup[$head4]][$MPEGaudioHeaderDecodeCache[$head4][
'sample_rate']];
1406 $MPEGaudioHeaderLengthCache[$head4] = self::MPEGaudioFrameLength(
1407 $LongMPEGbitrateLookup[$head4],
1408 $LongMPEGversionLookup[$head4],
1409 $LongMPEGlayerLookup[$head4],
1410 $LongMPEGpaddingLookup[$head4],
1411 $LongMPEGfrequencyLookup[$head4]);
1413 if ($MPEGaudioHeaderLengthCache[$head4] > 4) {
1414 $WhereWeWere =
ftell($this->getid3->fp);
1415 fseek($this->getid3->fp,
1416 $MPEGaudioHeaderLengthCache[$head4] - 4, SEEK_CUR);
1417 $next4 =
fread($this->getid3->fp, 4);
1418 if ($next4{0} ==
"\xFF") {
1419 if (!isset($MPEGaudioHeaderDecodeCache[$next4])) {
1420 $MPEGaudioHeaderDecodeCache[$next4] = self::MPEGaudioHeaderDecode($next4);
1422 if (!isset($MPEGaudioHeaderValidCache[$next4])) {
1423 $MPEGaudioHeaderValidCache[$next4] = self::MPEGaudioHeaderValid($MPEGaudioHeaderDecodeCache[$next4],
1427 if ($MPEGaudioHeaderValidCache[$next4]) {
1428 fseek($this->getid3->fp, -4, SEEK_CUR);
1430 Helper::safe_inc($Distribution[
'bitrate'][$LongMPEGbitrateLookup[$head4]]);
1432 Helper::safe_inc($Distribution[
'version'][$LongMPEGversionLookup[$head4]]);
1433 Helper::safe_inc($Distribution[
'padding'][intval($LongMPEGpaddingLookup[$head4])]);
1434 Helper::safe_inc($Distribution[
'frequency'][$LongMPEGfrequencyLookup[$head4]]);
1435 if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) {
1436 $pct_data_scanned = (
ftell($this->getid3->fp) -
$info[
'avdataoffset']) / (
$info[
'avdataend'] -
$info[
'avdataoffset']);
1437 $info[
'warning'][] =
'too many MPEG audio frames to scan, only scanned first ' . $max_frames_scan .
' frames (' . number_format($pct_data_scanned * 100,
1438 1) .
'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
1439 foreach ($Distribution as $key1 => $value1) {
1440 foreach ($value1 as $key2 => $value2) {
1441 $Distribution[$key1][$key2] = round($value2 / $pct_data_scanned);
1450 fseek($this->getid3->fp, $WhereWeWere - 3, SEEK_SET);
1454 foreach ($Distribution as $key => $value) {
1455 ksort($Distribution[$key], SORT_NUMERIC);
1457 ksort($Distribution[
'version'], SORT_STRING);
1458 $info[
'mpeg'][
'audio'][
'bitrate_distribution'] = $Distribution[
'bitrate'];
1459 $info[
'mpeg'][
'audio'][
'frequency_distribution'] = $Distribution[
'frequency'];
1460 $info[
'mpeg'][
'audio'][
'layer_distribution'] = $Distribution[
'layer'];
1461 $info[
'mpeg'][
'audio'][
'version_distribution'] = $Distribution[
'version'];
1462 $info[
'mpeg'][
'audio'][
'padding_distribution'] = $Distribution[
'padding'];
1463 if (count($Distribution[
'version']) > 1) {
1464 $info[
'error'][] =
'Corrupt file - more than one MPEG version detected';
1466 if (count($Distribution[
'layer']) > 1) {
1467 $info[
'error'][] =
'Corrupt file - more than one MPEG layer detected';
1469 if (count($Distribution[
'frequency']) > 1) {
1470 $info[
'error'][] =
'Corrupt file - more than one MPEG sample rate detected';
1475 foreach ($Distribution[
'bitrate'] as $bitratevalue => $bitratecount) {
1476 if ($bitratevalue !=
'free') {
1477 $bittotal += ($bitratevalue * $bitratecount);
1480 $info[
'mpeg'][
'audio'][
'frame_count'] = array_sum($Distribution[
'bitrate']);
1481 if (
$info[
'mpeg'][
'audio'][
'frame_count'] == 0) {
1482 $info[
'error'][] =
'no MPEG audio frames found';
1486 $info[
'mpeg'][
'audio'][
'bitrate'] = ($bittotal /
$info[
'mpeg'][
'audio'][
'frame_count']);
1487 $info[
'mpeg'][
'audio'][
'bitrate_mode'] = ((count($Distribution[
'bitrate']) > 0) ?
'vbr' :
'cbr');
1491 $info[
'audio'][
'bitrate'] =
$info[
'mpeg'][
'audio'][
'bitrate'];
1492 $info[
'audio'][
'bitrate_mode'] =
$info[
'mpeg'][
'audio'][
'bitrate_mode'];
1493 $info[
'audio'][
'sample_rate'] =
$info[
'mpeg'][
'audio'][
'sample_rate'];
1496 $info[
'fileformat'] =
$info[
'audio'][
'dataformat'];
1514 $info = &$this->getid3->info;
1516 static $MPEGaudioVersionLookup;
1517 static $MPEGaudioLayerLookup;
1518 static $MPEGaudioBitrateLookup;
1519 if (empty($MPEGaudioVersionLookup)) {
1520 $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
1521 $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
1522 $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
1525 fseek($this->getid3->fp, $avdataoffset, SEEK_SET);
1526 $sync_seek_buffer_size = min(128 * 1024,
1527 $info[
'avdataend'] - $avdataoffset);
1528 if ($sync_seek_buffer_size <= 0) {
1529 $info[
'error'][] =
'Invalid $sync_seek_buffer_size at offset ' . $avdataoffset;
1533 $header =
fread($this->getid3->fp, $sync_seek_buffer_size);
1534 $sync_seek_buffer_size = strlen(
$header);
1535 $SynchSeekOffset = 0;
1536 while ($SynchSeekOffset < $sync_seek_buffer_size) {
1537 if ((($avdataoffset + $SynchSeekOffset) <
$info[
'avdataend']) && !
feof($this->getid3->fp)) {
1539 if ($SynchSeekOffset > $sync_seek_buffer_size) {
1541 $info[
'error'][] =
'Could not find valid MPEG audio synch within the first ' . round($sync_seek_buffer_size / 1024) .
'kB';
1542 if (isset(
$info[
'audio'][
'bitrate'])) {
1543 unset(
$info[
'audio'][
'bitrate']);
1545 if (isset(
$info[
'mpeg'][
'audio'])) {
1546 unset(
$info[
'mpeg'][
'audio']);
1548 if (empty(
$info[
'mpeg'])) {
1549 unset(
$info[
'mpeg']);
1553 } elseif (
feof($this->getid3->fp)) {
1555 $info[
'error'][] =
'Could not find valid MPEG audio synch before end of file';
1556 if (isset(
$info[
'audio'][
'bitrate'])) {
1557 unset(
$info[
'audio'][
'bitrate']);
1559 if (isset(
$info[
'mpeg'][
'audio'])) {
1560 unset(
$info[
'mpeg'][
'audio']);
1562 if (isset(
$info[
'mpeg']) && (!is_array(
$info[
'mpeg']) || (count(
$info[
'mpeg']) == 0))) {
1563 unset(
$info[
'mpeg']);
1570 if (($SynchSeekOffset + 1) >= strlen(
$header)) {
1571 $info[
'error'][] =
'Could not find valid MPEG synch before end of file';
1576 if ((
$header{$SynchSeekOffset} ==
"\xFF") && (
$header{($SynchSeekOffset + 1)} >
"\xE0")) {
1577 if (!isset($FirstFrameThisfileInfo) && !isset(
$info[
'mpeg'][
'audio'])) {
1578 $FirstFrameThisfileInfo =
$info;
1579 $FirstFrameAVDataOffset = $avdataoffset + $SynchSeekOffset;
1581 $FirstFrameThisfileInfo,
1585 unset($FirstFrameThisfileInfo);
1593 $info[
'avdataoffset'] = $avdataoffset + $SynchSeekOffset;
1594 switch (isset(
$info[
'fileformat']) ?
$info[
'fileformat'] :
'') {
1599 $info[
'fileformat'] =
'mp3';
1600 $info[
'audio'][
'dataformat'] =
'mp3';
1603 if (isset($FirstFrameThisfileInfo[
'mpeg'][
'audio'][
'bitrate_mode']) && ($FirstFrameThisfileInfo[
'mpeg'][
'audio'][
'bitrate_mode'] ==
'vbr')) {
1604 if (!(abs($info[
'audio'][
'bitrate'] - $FirstFrameThisfileInfo[
'audio'][
'bitrate']) <= 1)) {
1607 $info = $FirstFrameThisfileInfo;
1608 $info[
'avdataoffset'] = $FirstFrameAVDataOffset;
1609 $info[
'fileformat'] =
'mp3';
1610 $info[
'audio'][
'dataformat'] =
'mp3';
1612 unset($dummy[
'mpeg'][
'audio']);
1613 $GarbageOffsetStart = $FirstFrameAVDataOffset + $FirstFrameThisfileInfo[
'mpeg'][
'audio'][
'framelength'];
1614 $GarbageOffsetEnd = $avdataoffset + $SynchSeekOffset;
1616 $dummy,
true,
true)) {
1618 $info[
'avdataoffset'] = $GarbageOffsetEnd;
1619 $info[
'warning'][] =
'apparently-valid VBR header not used because could not find ' . self::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;
1621 $info[
'warning'][] =
'using data from VBR header even though could not find ' . self::GETID3_MP3_VALID_CHECK_FRAMES .
' consecutive MPEG-audio frames immediately after VBR header (garbage data for ' . ($GarbageOffsetEnd - $GarbageOffsetStart) .
' bytes between ' . $GarbageOffsetStart .
' and ' . $GarbageOffsetEnd .
')';
1625 if (isset($info[
'mpeg'][
'audio'][
'bitrate_mode']) && ($info[
'mpeg'][
'audio'][
'bitrate_mode'] ==
'vbr') && !isset($info[
'mpeg'][
'audio'][
'VBR_method'])) {
1627 $BitrateHistogram =
true;
1630 if ($BitrateHistogram) {
1632 $info[
'mpeg'][
'audio'][
'stereo_distribution'] =
array(
'stereo' => 0,
'joint stereo' => 0,
'dual channel' => 0,
'mono' => 0);
1633 $info[
'mpeg'][
'audio'][
'version_distribution'] =
array(
'1' => 0,
'2' => 0,
'2.5' => 0);
1635 if ($info[
'mpeg'][
'audio'][
'version'] ==
'1') {
1636 if ($info[
'mpeg'][
'audio'][
'layer'] == 3) {
1637 $info[
'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);
1638 } elseif ($info[
'mpeg'][
'audio'][
'layer'] == 2) {
1639 $info[
'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);
1640 } elseif ($info[
'mpeg'][
'audio'][
'layer'] == 1) {
1641 $info[
'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);
1643 } elseif ($info[
'mpeg'][
'audio'][
'layer'] == 1) {
1644 $info[
'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);
1646 $info[
'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);
1649 $dummy =
array(
'error' => $info[
'error'],
'warning' => $info[
'warning'],
'avdataend' => $info[
'avdataend'],
'avdataoffset' => $info[
'avdataoffset']);
1650 $synchstartoffset = $info[
'avdataoffset'];
1651 fseek($this->getid3->fp, $info[
'avdataoffset'], SEEK_SET);
1654 $max_frames_scan = 50000;
1655 $max_scan_segments = 10;
1659 $SynchErrorsFound = 0;
1660 $frames_scanned = 0;
1661 $this_scan_segment = 0;
1662 $frames_scan_per_segment = ceil($max_frames_scan / $max_scan_segments);
1663 $pct_data_scanned = 0;
1664 for ($current_segment = 0;
1665 $current_segment < $max_scan_segments;
1666 $current_segment++) {
1667 $frames_scanned_this_segment = 0;
1668 if (
ftell($this->getid3->fp) >= $info[
'avdataend']) {
1671 $scan_start_offset[$current_segment] = max(
ftell($this->getid3->fp),
1672 $info[
'avdataoffset'] + round($current_segment * (($info[
'avdataend'] - $info[
'avdataoffset']) / $max_scan_segments)));
1673 if ($current_segment > 0) {
1674 fseek($this->getid3->fp,
1675 $scan_start_offset[$current_segment],
1677 $buffer_4k =
fread($this->getid3->fp, 4096);
1678 for ($j = 0; $j < (strlen($buffer_4k) - 4); $j++) {
1679 if (($buffer_4k{$j} ==
"\xFF") && ($buffer_4k{($j + 1)} >
"\xE0")) {
1685 $calculated_next_offset = $scan_start_offset[$current_segment] + $j + $dummy[
'mpeg'][
'audio'][
'framelength'];
1691 $scan_start_offset[$current_segment] += $j;
1698 $synchstartoffset = $scan_start_offset[$current_segment];
1701 false, $FastMode)) {
1703 $thisframebitrate = $MPEGaudioBitrateLookup[$MPEGaudioVersionLookup[$dummy[
'mpeg'][
'audio'][
'raw'][
'version']]][$MPEGaudioLayerLookup[$dummy[
'mpeg'][
'audio'][
'raw'][
'layer']]][$dummy[
'mpeg'][
'audio'][
'raw'][
'bitrate']];
1705 if (empty($dummy[
'mpeg'][
'audio'][
'framelength'])) {
1706 $SynchErrorsFound++;
1707 $synchstartoffset++;
1709 Helper::safe_inc($info[
'mpeg'][
'audio'][
'bitrate_distribution'][$thisframebitrate]);
1710 Helper::safe_inc($info[
'mpeg'][
'audio'][
'stereo_distribution'][$dummy[
'mpeg'][
'audio'][
'channelmode']]);
1711 Helper::safe_inc($info[
'mpeg'][
'audio'][
'version_distribution'][$dummy[
'mpeg'][
'audio'][
'version']]);
1712 $synchstartoffset += $dummy[
'mpeg'][
'audio'][
'framelength'];
1715 if ($frames_scan_per_segment && (++$frames_scanned_this_segment >= $frames_scan_per_segment)) {
1716 $this_pct_scanned = (
ftell($this->getid3->fp) - $scan_start_offset[$current_segment]) / ($info[
'avdataend'] - $info[
'avdataoffset']);
1717 if (($current_segment == 0) && (($this_pct_scanned * $max_scan_segments) >= 1)) {
1719 $max_scan_segments = 1;
1720 $frames_scan_per_segment = $max_frames_scan;
1722 $pct_data_scanned += $this_pct_scanned;
1728 if ($pct_data_scanned > 0) {
1729 $info[
'warning'][] =
'too many MPEG audio frames to scan, only scanned ' . $frames_scanned .
' frames in ' . $max_scan_segments .
' segments (' . number_format($pct_data_scanned * 100,
1730 1) .
'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
1731 foreach ($info[
'mpeg'][
'audio'] as $key1 => $value1) {
1732 if (!preg_match(
'#_distribution$#i', $key1)) {
1735 foreach ($value1 as $key2 => $value2) {
1736 $info[
'mpeg'][
'audio'][$key1][$key2] = round($value2 / $pct_data_scanned);
1741 if ($SynchErrorsFound > 0) {
1742 $info[
'warning'][] =
'Found ' . $SynchErrorsFound .
' synch errors in histogram analysis';
1748 foreach ($info[
'mpeg'][
'audio'][
'bitrate_distribution'] as $bitratevalue => $bitratecount) {
1749 $framecounter += $bitratecount;
1750 if ($bitratevalue !=
'free') {
1751 $bittotal += ($bitratevalue * $bitratecount);
1754 if ($framecounter == 0) {
1755 $info[
'error'][] =
'Corrupt MP3 file: framecounter == zero';
1760 $info[
'mpeg'][
'audio'][
'bitrate'] = ($bittotal / $framecounter);
1762 $info[
'audio'][
'bitrate'] = $info[
'mpeg'][
'audio'][
'bitrate'];
1766 $distinct_bitrates = 0;
1767 foreach ($info[
'mpeg'][
'audio'][
'bitrate_distribution'] as $bitrate_value => $bitrate_count) {
1768 if ($bitrate_count > 0) {
1769 $distinct_bitrates++;
1772 if ($distinct_bitrates > 1) {
1773 $info[
'mpeg'][
'audio'][
'bitrate_mode'] =
'vbr';
1775 $info[
'mpeg'][
'audio'][
'bitrate_mode'] =
'cbr';
1777 $info[
'audio'][
'bitrate_mode'] = $info[
'mpeg'][
'audio'][
'bitrate_mode'];
1785 if (($avdataoffset + $SynchSeekOffset) >=
$info[
'avdataend']) {
1788 if (empty(
$info[
'mpeg'][
'audio'])) {
1790 $info[
'error'][] =
'could not find valid MPEG synch before end of file';
1791 if (isset(
$info[
'audio'][
'bitrate'])) {
1792 unset(
$info[
'audio'][
'bitrate']);
1794 if (isset(
$info[
'mpeg'][
'audio'])) {
1795 unset(
$info[
'mpeg'][
'audio']);
1797 if (isset(
$info[
'mpeg']) && (!is_array(
$info[
'mpeg']) || empty(
$info[
'mpeg']))) {
1798 unset(
$info[
'mpeg']);
1806 $info[
'audio'][
'channels'] =
$info[
'mpeg'][
'audio'][
'channels'];
1807 $info[
'audio'][
'channelmode'] =
$info[
'mpeg'][
'audio'][
'channelmode'];
1808 $info[
'audio'][
'sample_rate'] =
$info[
'mpeg'][
'audio'][
'sample_rate'];
1820 static $MPEGaudioVersion =
array(
'2.5',
false,
'2',
'1');
1822 return $MPEGaudioVersion;
1832 static $MPEGaudioLayer =
array(
false, 3, 2, 1);
1834 return $MPEGaudioLayer;
1844 static $MPEGaudioBitrate;
1845 if (empty($MPEGaudioBitrate)) {
1846 $MPEGaudioBitrate =
array(
1847 '1' =>
array(1 =>
array(
'free', 32000, 64000, 96000, 128000, 160000, 192000, 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000),
1848 2 =>
array(
'free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000),
1849 3 =>
array(
'free', 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000)
1851 '2' =>
array(1 =>
array(
'free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 176000, 192000, 224000, 256000),
1852 2 =>
array(
'free', 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000),
1855 $MPEGaudioBitrate[
'2'][3] = $MPEGaudioBitrate[
'2'][2];
1856 $MPEGaudioBitrate[
'2.5'] = $MPEGaudioBitrate[
'2'];
1859 return $MPEGaudioBitrate;
1869 static $MPEGaudioFrequency;
1870 if (empty($MPEGaudioFrequency)) {
1871 $MPEGaudioFrequency =
array(
1872 '1' =>
array(44100, 48000, 32000),
1873 '2' =>
array(22050, 24000, 16000),
1874 '2.5' =>
array(11025, 12000, 8000)
1878 return $MPEGaudioFrequency;
1888 static $MPEGaudioChannelMode =
array(
'stereo',
'joint stereo',
'dual channel',
'mono');
1890 return $MPEGaudioChannelMode;
1900 static $MPEGaudioModeExtension;
1901 if (empty($MPEGaudioModeExtension)) {
1902 $MPEGaudioModeExtension =
array(
1903 1 =>
array(
'4-31',
'8-31',
'12-31',
'16-31'),
1904 2 =>
array(
'4-31',
'8-31',
'12-31',
'16-31'),
1905 3 =>
array(
'',
'IS',
'MS',
'IS+MS')
1909 return $MPEGaudioModeExtension;
1919 static $MPEGaudioEmphasis =
array(
'none',
'50/15ms',
false,
'CCIT J.17');
1921 return $MPEGaudioEmphasis;
1931 $allowBitrate15 =
false)
1933 return self::MPEGaudioHeaderValid(self::MPEGaudioHeaderDecode($head4),
1953 $allowBitrate15 =
false)
1955 if (($rawarray[
'synch'] & 0x0FFE) != 0x0FFE) {
1959 static $MPEGaudioVersionLookup;
1960 static $MPEGaudioLayerLookup;
1961 static $MPEGaudioBitrateLookup;
1962 static $MPEGaudioFrequencyLookup;
1963 static $MPEGaudioChannelModeLookup;
1964 static $MPEGaudioModeExtensionLookup;
1965 static $MPEGaudioEmphasisLookup;
1966 if (empty($MPEGaudioVersionLookup)) {
1967 $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
1968 $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
1969 $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
1970 $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray();
1971 $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray();
1972 $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();
1973 $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray();
1976 if (isset($MPEGaudioVersionLookup[$rawarray[
'version']])) {
1977 $decodedVersion = $MPEGaudioVersionLookup[$rawarray[
'version']];
1979 echo ($echoerrors ?
"\n" .
'invalid Version (' . $rawarray[
'version'] .
')' :
'');
1983 if (isset($MPEGaudioLayerLookup[$rawarray[
'layer']])) {
1984 $decodedLayer = $MPEGaudioLayerLookup[$rawarray[
'layer']];
1986 echo ($echoerrors ?
"\n" .
'invalid Layer (' . $rawarray[
'layer'] .
')' :
'');
1990 if (!isset($MPEGaudioBitrateLookup[$decodedVersion][$decodedLayer][$rawarray[
'bitrate']])) {
1991 echo ($echoerrors ?
"\n" .
'invalid Bitrate (' . $rawarray[
'bitrate'] .
')' :
'');
1992 if ($rawarray[
'bitrate'] == 15) {
1995 if (!$allowBitrate15) {
2002 if (!isset($MPEGaudioFrequencyLookup[$decodedVersion][$rawarray[
'sample_rate']])) {
2003 echo ($echoerrors ?
"\n" .
'invalid Frequency (' . $rawarray[
'sample_rate'] .
')' :
'');
2007 if (!isset($MPEGaudioChannelModeLookup[$rawarray[
'channelmode']])) {
2008 echo ($echoerrors ?
"\n" .
'invalid ChannelMode (' . $rawarray[
'channelmode'] .
')' :
'');
2012 if (!isset($MPEGaudioModeExtensionLookup[$decodedLayer][$rawarray[
'modeextension']])) {
2013 echo ($echoerrors ?
"\n" .
'invalid Mode Extension (' . $rawarray[
'modeextension'] .
')' :
'');
2017 if (!isset($MPEGaudioEmphasisLookup[$rawarray[
'emphasis']])) {
2018 echo ($echoerrors ?
"\n" .
'invalid Emphasis (' . $rawarray[
'emphasis'] .
')' :
'');
2053 if (strlen($Header4Bytes) != 4) {
2058 0, 2)) & 0xFFE0) >> 4;
2059 $MPEGrawHeader[
'version'] = (ord($Header4Bytes{1}) & 0x18) >> 3;
2060 $MPEGrawHeader[
'layer'] = (ord($Header4Bytes{1}) & 0x06) >> 1;
2061 $MPEGrawHeader[
'protection'] = (ord($Header4Bytes{1}) & 0x01);
2062 $MPEGrawHeader[
'bitrate'] = (ord($Header4Bytes{2}) & 0xF0) >> 4;
2063 $MPEGrawHeader[
'sample_rate'] = (ord($Header4Bytes{2}) & 0x0C) >> 2;
2064 $MPEGrawHeader[
'padding'] = (ord($Header4Bytes{2}) & 0x02) >> 1;
2065 $MPEGrawHeader[
'private'] = (ord($Header4Bytes{2}) & 0x01);
2066 $MPEGrawHeader[
'channelmode'] = (ord($Header4Bytes{3}) & 0xC0) >> 6;
2067 $MPEGrawHeader[
'modeextension'] = (ord($Header4Bytes{3}) & 0x30) >> 4;
2068 $MPEGrawHeader[
'copyright'] = (ord($Header4Bytes{3}) & 0x08) >> 3;
2069 $MPEGrawHeader[
'original'] = (ord($Header4Bytes{3}) & 0x04) >> 2;
2070 $MPEGrawHeader[
'emphasis'] = (ord($Header4Bytes{3}) & 0x03);
2072 return $MPEGrawHeader;
2086 $padding, &$samplerate)
2088 static $AudioFrameLengthCache =
array();
2090 if (!isset($AudioFrameLengthCache[$bitrate][
$version][$layer][$padding][$samplerate])) {
2091 $AudioFrameLengthCache[$bitrate][
$version][$layer][$padding][$samplerate] =
false;
2092 if ($bitrate !=
'free') {
2096 if ($layer ==
'1') {
2099 $FrameLengthCoefficient = 48;
2103 $FrameLengthCoefficient = 144;
2107 if ($layer ==
'1') {
2110 $FrameLengthCoefficient = 24;
2112 } elseif ($layer ==
'2') {
2115 $FrameLengthCoefficient = 144;
2119 $FrameLengthCoefficient = 72;
2125 if ($samplerate > 0) {
2126 $NewFramelength = ($FrameLengthCoefficient * $bitrate) / $samplerate;
2127 $NewFramelength = floor($NewFramelength / $SlotLength) * $SlotLength;
2129 $NewFramelength += $SlotLength;
2131 $AudioFrameLengthCache[$bitrate][
$version][$layer][$padding][$samplerate] = (int) $NewFramelength;
2136 return $AudioFrameLengthCache[$bitrate][
$version][$layer][$padding][$samplerate];
2148 static $standard_bit_rates =
array(320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000);
2149 static $bit_rate_table =
array(0 =>
'-');
2150 $round_bit_rate = intval(round($bit_rate, -3));
2151 if (!isset($bit_rate_table[$round_bit_rate])) {
2152 if ($round_bit_rate > max($standard_bit_rates)) {
2153 $bit_rate_table[$round_bit_rate] = round($bit_rate,
2154 2 - strlen($bit_rate));
2156 $bit_rate_table[$round_bit_rate] = max($standard_bit_rates);
2157 foreach ($standard_bit_rates as $standard_bit_rate) {
2158 if ($round_bit_rate >= $standard_bit_rate + (($bit_rate_table[$round_bit_rate] - $standard_bit_rate) / 2)) {
2161 $bit_rate_table[$round_bit_rate] = $standard_bit_rate;
2166 return $bit_rate_table[$round_bit_rate];
2178 static $XingVBRidOffsetCache =
array();
2179 if (empty($XingVBRidOffset)) {
2180 $XingVBRidOffset =
array(
2181 '1' =>
array(
'mono' => 0x15,
2183 'joint stereo' => 0x24,
2184 'dual channel' => 0x24
2186 '2' =>
array(
'mono' => 0x0D,
2188 'joint stereo' => 0x15,
2189 'dual channel' => 0x15
2191 '2.5' =>
array(
'mono' => 0x15,
2193 'joint stereo' => 0x15,
2194 'dual channel' => 0x15
2199 return $XingVBRidOffset[
$version][$channelmode];
2210 static $LAMEvbrMethodLookup =
array(
2214 0x03 =>
'vbr-old / vbr-rh',
2215 0x04 =>
'vbr-new / vbr-mtrh',
2217 0x06 =>
'vbr (full vbr method 4)',
2218 0x08 =>
'cbr (constant bitrate 2 pass)',
2219 0x09 =>
'abr (2 pass)',
2223 return (isset($LAMEvbrMethodLookup[$VBRmethodID]) ? $LAMEvbrMethodLookup[$VBRmethodID] :
'');
2234 static $LAMEmiscStereoModeLookup =
array(
2238 3 =>
'joint stereo',
2239 4 =>
'forced stereo',
2241 6 =>
'intensity stereo',
2245 return (isset($LAMEmiscStereoModeLookup[$StereoModeID]) ? $LAMEmiscStereoModeLookup[$StereoModeID] :
'');
2256 static $LAMEmiscSourceSampleFrequencyLookup =
array(
2263 return (isset($LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID]) ? $LAMEmiscSourceSampleFrequencyLookup[$SourceSampleFrequencyID] :
'');
2274 static $LAMEsurroundInfoLookup =
array(
2275 0 =>
'no surround info',
2276 1 =>
'DPL encoding',
2277 2 =>
'DPL2 encoding',
2278 3 =>
'Ambisonic encoding' 2281 return (isset($LAMEsurroundInfoLookup[$SurroundInfoID]) ? $LAMEsurroundInfoLookup[$SurroundInfoID] :
'reserved');
2292 if ($LAMEtag[
'preset_used_id'] == 0) {
2297 $LAMEpresetUsedLookup =
array();
2300 for ($i = 8; $i <= 320; $i++) {
2301 switch ($LAMEtag[
'vbr_method']) {
2303 $LAMEpresetUsedLookup[$i] =
'--alt-preset ' . $LAMEtag[
'vbr_method'] .
' ' . $i;
2307 $LAMEpresetUsedLookup[$i] =
'--alt-preset ' . $i;
2314 $LAMEpresetUsedLookup[1000] =
'--r3mix';
2315 $LAMEpresetUsedLookup[1001] =
'--alt-preset standard';
2316 $LAMEpresetUsedLookup[1002] =
'--alt-preset extreme';
2317 $LAMEpresetUsedLookup[1003] =
'--alt-preset insane';
2318 $LAMEpresetUsedLookup[1004] =
'--alt-preset fast standard';
2319 $LAMEpresetUsedLookup[1005] =
'--alt-preset fast extreme';
2320 $LAMEpresetUsedLookup[1006] =
'--alt-preset medium';
2321 $LAMEpresetUsedLookup[1007] =
'--alt-preset fast medium';
2324 $LAMEpresetUsedLookup[1010] =
'--preset portable';
2325 $LAMEpresetUsedLookup[1015] =
'--preset radio';
2327 $LAMEpresetUsedLookup[320] =
'--preset insane';
2328 $LAMEpresetUsedLookup[410] =
'-V9';
2329 $LAMEpresetUsedLookup[420] =
'-V8';
2330 $LAMEpresetUsedLookup[440] =
'-V6';
2331 $LAMEpresetUsedLookup[430] =
'--preset radio';
2332 $LAMEpresetUsedLookup[450] =
'--preset ' . (($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'') .
'portable';
2333 $LAMEpresetUsedLookup[460] =
'--preset ' . (($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'') .
'medium';
2334 $LAMEpresetUsedLookup[470] =
'--r3mix';
2335 $LAMEpresetUsedLookup[480] =
'--preset ' . (($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'') .
'standard';
2336 $LAMEpresetUsedLookup[490] =
'-V1';
2337 $LAMEpresetUsedLookup[500] =
'--preset ' . (($LAMEtag[
'raw'][
'vbr_method'] == 4) ?
'fast ' :
'') .
'extreme';
2339 return (isset($LAMEpresetUsedLookup[$LAMEtag[
'preset_used_id']]) ? $LAMEpresetUsedLookup[$LAMEtag[
'preset_used_id']] :
'new/unknown preset: ' . $LAMEtag[
'preset_used_id'] .
' - report to info@getid3.org');
FreeFormatFrameLength($offset, $deepscan=false)
static MPEGaudioFrameLength(&$bitrate, &$version, &$layer, $padding, &$samplerate)
array $AudioFrameLengthCache
static MPEGaudioEmphasisArray()
array $MPEGaudioEmphasis
static MPEGaudioHeaderValid($rawarray, $echoerrors=false, $allowBitrate15=false)
type $MPEGaudioVersionLookup type $MPEGaudioLayerLookup type $MPEGaudioBitrateLookup type $MPEGaud...
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
decodeMPEGaudioHeader($offset, &$info, $recursivesearch=true, $ScanAsCBR=false, $FastMPEGheaderScan=false)
type $MPEGaudioVersionLookup type $MPEGaudioLayerLookup type $MPEGaudioBitrateLookup type $MPEGaud...
static LAMEsurroundInfoLookup($SurroundInfoID)
array $LAMEsurroundInfoLookup
GetId3() by James Heinrich info@getid3.org //.
static MPEGaudioBitrateArray()
type $MPEGaudioBitrate
static XingVBRidOffset($version, $channelmode)
array $XingVBRidOffsetCache
static RGADamplitude2dB($amplitude)
GuessEncoderOptions()
array $NamedPresetBitrates array $KnownEncoderValues array $ExpectedLowpass array $ExpectedResampl...
static MPEGaudioLayerArray()
array $MPEGaudioLayer
static MPEGaudioHeaderDecode($Header4Bytes)
static MPEGaudioVersionArray()
array $MPEGaudioVersion
static MPEGaudioFrequencyArray()
array $MPEGaudioFrequency
static LAMEmiscStereoModeLookup($StereoModeID)
array $LAMEmiscStereoModeLookup
fseek($bytes, $whence=SEEK_SET)
getOnlyMPEGaudioInfo($avdataoffset, $BitrateHistogram=false)
type $MPEGaudioVersionLookup type $MPEGaudioLayerLookup type $MPEGaudioBitrateLookup ...
static ClosestStandardMP3Bitrate($bit_rate)
array $standard_bit_rates array $bit_rate_table
static LAMEpresetUsedLookup($LAMEtag)
static MPEGaudioModeExtensionArray()
array $MPEGaudioModeExtension
static MPEGaudioChannelModeArray()
array $MPEGaudioChannelMode
GetId3() by James Heinrich info@getid3.org //.
static RGADadjustmentLookup($rawadjustment, $signbit)
getOnlyMPEGaudioInfoBruteForce()
static RGADnameLookup($namecode)
array $RGADname
static CastAsInt($floatnum)
Create styles array
The data for the language used.
static RGADoriginatorLookup($originatorcode)
array $RGADoriginator
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
static MPEGaudioHeaderBytesValid($head4, $allowBitrate15=false)
static safe_inc(&$variable, $increment=1)
static LAMEvbrMethodLookup($VBRmethodID)
array $LAMEvbrMethodLookup
static LAMEmiscSourceSampleFrequencyLookup($SourceSampleFrequencyID)
array $LAMEmiscSourceSampleFrequencyLookup
RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR)
static array_max($arraydata, $returnkey=false)
static LittleEndian2Float($byteword)
const GETID3_MP3_VALID_CHECK_FRAMES