409 static $MPEGaudioVersionLookup;
410 static $MPEGaudioLayerLookup;
411 static $MPEGaudioBitrateLookup;
412 static $MPEGaudioFrequencyLookup;
413 static $MPEGaudioChannelModeLookup;
414 static $MPEGaudioModeExtensionLookup;
415 static $MPEGaudioEmphasisLookup;
416 if (empty($MPEGaudioVersionLookup)) {
417 $MPEGaudioVersionLookup = self::MPEGaudioVersionArray();
418 $MPEGaudioLayerLookup = self::MPEGaudioLayerArray();
419 $MPEGaudioBitrateLookup = self::MPEGaudioBitrateArray();
420 $MPEGaudioFrequencyLookup = self::MPEGaudioFrequencyArray();
421 $MPEGaudioChannelModeLookup = self::MPEGaudioChannelModeArray();
422 $MPEGaudioModeExtensionLookup = self::MPEGaudioModeExtensionArray();
423 $MPEGaudioEmphasisLookup = self::MPEGaudioEmphasisArray();
426 if ($this->
fseek($offset) != 0) {
427 $this->
error(
'decodeMPEGaudioHeader() failed to seek to next offset at '.$offset);
431 $headerstring = $this->
fread(226);
439 $head4 = substr($headerstring, 0, 4);
440 static $MPEGaudioHeaderDecodeCache = array();
441 if (isset($MPEGaudioHeaderDecodeCache[$head4])) {
442 $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
444 $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4);
445 $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
448 static $MPEGaudioHeaderValidCache = array();
449 if (!isset($MPEGaudioHeaderValidCache[$head4])) {
451 $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray,
false,
false);
455 if (!isset(
$info[
'mpeg'][
'audio'])) {
456 $info[
'mpeg'][
'audio'] = array();
458 $thisfile_mpeg_audio = &
$info[
'mpeg'][
'audio'];
461 if ($MPEGaudioHeaderValidCache[$head4]) {
462 $thisfile_mpeg_audio[
'raw'] = $MPEGheaderRawArray;
468 if (!$FastMPEGheaderScan) {
469 $thisfile_mpeg_audio[
'version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio[
'raw'][
'version']];
470 $thisfile_mpeg_audio[
'layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio[
'raw'][
'layer']];
472 $thisfile_mpeg_audio[
'channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio[
'raw'][
'channelmode']];
473 $thisfile_mpeg_audio[
'channels'] = (($thisfile_mpeg_audio[
'channelmode'] ==
'mono') ? 1 : 2);
474 $thisfile_mpeg_audio[
'sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio[
'version']][$thisfile_mpeg_audio[
'raw'][
'sample_rate']];
475 $thisfile_mpeg_audio[
'protection'] = !$thisfile_mpeg_audio[
'raw'][
'protection'];
476 $thisfile_mpeg_audio[
'private'] = (bool) $thisfile_mpeg_audio[
'raw'][
'private'];
477 $thisfile_mpeg_audio[
'modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio[
'layer']][$thisfile_mpeg_audio[
'raw'][
'modeextension']];
478 $thisfile_mpeg_audio[
'copyright'] = (bool) $thisfile_mpeg_audio[
'raw'][
'copyright'];
479 $thisfile_mpeg_audio[
'original'] = (bool) $thisfile_mpeg_audio[
'raw'][
'original'];
480 $thisfile_mpeg_audio[
'emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio[
'raw'][
'emphasis']];
482 $info[
'audio'][
'channels'] = $thisfile_mpeg_audio[
'channels'];
483 $info[
'audio'][
'sample_rate'] = $thisfile_mpeg_audio[
'sample_rate'];
485 if ($thisfile_mpeg_audio[
'protection']) {
490 if ($thisfile_mpeg_audio[
'raw'][
'bitrate'] == 15) {
492 $this->
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 ==
$info[
'avdataoffset'])) {
501 $recursivesearch =
false;
505 if (!$FastMPEGheaderScan && ($thisfile_mpeg_audio[
'layer'] ==
'2')) {
507 $info[
'audio'][
'dataformat'] =
'mp2';
508 switch ($thisfile_mpeg_audio[
'channelmode']) {
511 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') || ($thisfile_mpeg_audio[
'bitrate'] <= 192000)) {
514 $this->
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 $this->
error(intval(round($thisfile_mpeg_audio[
'bitrate'] / 1000)).
'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio[
'channelmode'].
'.');
535 if (
$info[
'audio'][
'sample_rate'] > 0) {
536 $thisfile_mpeg_audio[
'framelength'] = self::MPEGaudioFrameLength($thisfile_mpeg_audio[
'bitrate'], $thisfile_mpeg_audio[
'version'], $thisfile_mpeg_audio[
'layer'], (
int) $thisfile_mpeg_audio[
'padding'],
$info[
'audio'][
'sample_rate']);
539 $nextframetestoffset = $offset + 1;
540 if ($thisfile_mpeg_audio[
'bitrate'] !=
'free') {
542 $info[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'bitrate'];
544 if (isset($thisfile_mpeg_audio[
'framelength'])) {
545 $nextframetestoffset = $offset + $thisfile_mpeg_audio[
'framelength'];
547 $this->
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 $info[
'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;
597 $VBRidOffset = self::XingVBRidOffset($thisfile_mpeg_audio[
'version'], $thisfile_mpeg_audio[
'channelmode']);
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']) {
651 if (!empty($thisfile_mpeg_audio[
'VBR_frames'])) {
653 if (!empty($thisfile_mpeg_audio[
'VBR_bytes'])) {
654 $used_filesize = $thisfile_mpeg_audio[
'VBR_bytes'];
655 } elseif (!empty(
$info[
'filesize'])) {
656 $used_filesize =
$info[
'filesize'];
657 $used_filesize -= intval(@
$info[
'id3v2'][
'headerlength']);
658 $used_filesize -= (isset(
$info[
'id3v1']) ? 128 : 0);
659 $used_filesize -= (isset(
$info[
'tag_offset_end']) ?
$info[
'tag_offset_end'] -
$info[
'tag_offset_start'] : 0);
660 $this->
warning(
'MP3.Xing header missing VBR_bytes, assuming MPEG audio portion of file is '.number_format($used_filesize).
' bytes');
663 $framelengthfloat = $used_filesize / $thisfile_mpeg_audio[
'VBR_frames'];
665 if ($thisfile_mpeg_audio[
'layer'] ==
'1') {
668 $info[
'audio'][
'bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio[
'sample_rate'] * (2 /
$info[
'audio'][
'channels']) / 12;
672 $info[
'audio'][
'bitrate'] = $framelengthfloat * $thisfile_mpeg_audio[
'sample_rate'] * (2 /
$info[
'audio'][
'channels']) / 144;
674 $thisfile_mpeg_audio[
'framelength'] = floor($framelengthfloat);
677 if ($thisfile_mpeg_audio[
'xing_flags'][
'toc']) {
678 $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100);
679 for (
$i = 0;
$i < 100;
$i++) {
680 $thisfile_mpeg_audio[
'toc'][
$i] = ord($LAMEtocData{
$i});
683 if ($thisfile_mpeg_audio[
'xing_flags'][
'vbr_scale']) {
689 if (substr($headerstring, $VBRidOffset + 120, 4) ==
'LAME') {
692 $thisfile_mpeg_audio[
'LAME'] = array();
693 $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio[
'LAME'];
696 $thisfile_mpeg_audio_lame[
'long_version'] = substr($headerstring, $VBRidOffset + 120, 20);
697 $thisfile_mpeg_audio_lame[
'short_version'] = substr($thisfile_mpeg_audio_lame[
'long_version'], 0, 9);
699 if ($thisfile_mpeg_audio_lame[
'short_version'] >=
'LAME3.90') {
702 unset($thisfile_mpeg_audio_lame[
'long_version']);
710 $LAMEtagOffsetContant = $VBRidOffset - 0x24;
713 $thisfile_mpeg_audio_lame[
'RGAD'] = array(
'track'=>array(),
'album'=>array());
714 $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame[
'RGAD'];
715 $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD[
'track'];
716 $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD[
'album'];
717 $thisfile_mpeg_audio_lame[
'raw'] = array();
718 $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame[
'raw'];
723 unset($thisfile_mpeg_audio[
'VBR_scale']);
724 $thisfile_mpeg_audio_lame[
'vbr_quality'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1));
727 $thisfile_mpeg_audio_lame[
'short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9);
732 $thisfile_mpeg_audio_lame[
'tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4;
733 $thisfile_mpeg_audio_lame_raw[
'vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F;
734 $thisfile_mpeg_audio_lame[
'vbr_method'] = self::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw[
'vbr_method']);
735 $thisfile_mpeg_audio[
'bitrate_mode'] = substr($thisfile_mpeg_audio_lame[
'vbr_method'], 0, 3);
738 $thisfile_mpeg_audio_lame[
'lowpass_frequency'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;
743 if ($thisfile_mpeg_audio_lame[
'short_version'] >=
'LAME3.94b') {
746 $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'] = (float) ((
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608);
752 if ($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'] == 0) {
753 unset($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude']);
758 $thisfile_mpeg_audio_lame_raw[
'RGAD_track'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAB, 2));
759 $thisfile_mpeg_audio_lame_raw[
'RGAD_album'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xAD, 2));
762 if ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] != 0) {
764 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'name'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0xE000) >> 13;
765 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'originator'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x1C00) >> 10;
766 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'sign_bit'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x0200) >> 9;
767 $thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'gain_adjust'] = $thisfile_mpeg_audio_lame_raw[
'RGAD_track'] & 0x01FF;
768 $thisfile_mpeg_audio_lame_RGAD_track[
'name'] =
getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_track[
'raw'][
'name']);
770 $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']);
772 if (!empty($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'])) {
773 $info[
'replay_gain'][
'track'][
'peak'] = $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'];
775 $info[
'replay_gain'][
'track'][
'originator'] = $thisfile_mpeg_audio_lame_RGAD_track[
'originator'];
776 $info[
'replay_gain'][
'track'][
'adjustment'] = $thisfile_mpeg_audio_lame_RGAD_track[
'gain_db'];
778 unset($thisfile_mpeg_audio_lame_RGAD[
'track']);
780 if ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] != 0) {
782 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'name'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0xE000) >> 13;
783 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'originator'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x1C00) >> 10;
784 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'sign_bit'] = ($thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x0200) >> 9;
785 $thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'gain_adjust'] = $thisfile_mpeg_audio_lame_raw[
'RGAD_album'] & 0x01FF;
786 $thisfile_mpeg_audio_lame_RGAD_album[
'name'] =
getid3_lib::RGADnameLookup($thisfile_mpeg_audio_lame_RGAD_album[
'raw'][
'name']);
788 $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']);
790 if (!empty($thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'])) {
791 $info[
'replay_gain'][
'album'][
'peak'] = $thisfile_mpeg_audio_lame_RGAD[
'peak_amplitude'];
793 $info[
'replay_gain'][
'album'][
'originator'] = $thisfile_mpeg_audio_lame_RGAD_album[
'originator'];
794 $info[
'replay_gain'][
'album'][
'adjustment'] = $thisfile_mpeg_audio_lame_RGAD_album[
'gain_db'];
796 unset($thisfile_mpeg_audio_lame_RGAD[
'album']);
798 if (empty($thisfile_mpeg_audio_lame_RGAD)) {
799 unset($thisfile_mpeg_audio_lame[
'RGAD']);
805 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nspsytune'] = (bool) ($EncodingFlagsATHtype & 0x10);
806 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nssafejoint'] = (bool) ($EncodingFlagsATHtype & 0x20);
807 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_next'] = (bool) ($EncodingFlagsATHtype & 0x40);
808 $thisfile_mpeg_audio_lame[
'encoding_flags'][
'nogap_prev'] = (bool) ($EncodingFlagsATHtype & 0x80);
809 $thisfile_mpeg_audio_lame[
'ath_type'] = $EncodingFlagsATHtype & 0x0F;
812 $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB0, 1));
813 if ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 2) {
814 $thisfile_mpeg_audio_lame[
'bitrate_abr'] = $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'];
815 } elseif ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 1) {
817 } elseif ($thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'] > 0) {
818 $thisfile_mpeg_audio_lame[
'bitrate_min'] = $thisfile_mpeg_audio_lame[
'raw'][
'abrbitrate_minbitrate'];
823 $thisfile_mpeg_audio_lame[
'encoder_delay'] = ($EncoderDelays & 0xFFF000) >> 12;
824 $thisfile_mpeg_audio_lame[
'end_padding'] = $EncoderDelays & 0x000FFF;
828 $thisfile_mpeg_audio_lame_raw[
'noise_shaping'] = ($MiscByte & 0x03);
829 $thisfile_mpeg_audio_lame_raw[
'stereo_mode'] = ($MiscByte & 0x1C) >> 2;
830 $thisfile_mpeg_audio_lame_raw[
'not_optimal_quality'] = ($MiscByte & 0x20) >> 5;
831 $thisfile_mpeg_audio_lame_raw[
'source_sample_freq'] = ($MiscByte & 0xC0) >> 6;
832 $thisfile_mpeg_audio_lame[
'noise_shaping'] = $thisfile_mpeg_audio_lame_raw[
'noise_shaping'];
833 $thisfile_mpeg_audio_lame[
'stereo_mode'] = self::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw[
'stereo_mode']);
834 $thisfile_mpeg_audio_lame[
'not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw[
'not_optimal_quality'];
835 $thisfile_mpeg_audio_lame[
'source_sample_freq'] = self::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw[
'source_sample_freq']);
838 $thisfile_mpeg_audio_lame_raw[
'mp3_gain'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB5, 1),
false,
true);
840 $thisfile_mpeg_audio_lame[
'mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame[
'mp3_gain_db'] / 6));
845 $thisfile_mpeg_audio_lame_raw[
'surround_info'] = ($PresetSurroundBytes & 0x3800);
846 $thisfile_mpeg_audio_lame[
'surround_info'] = self::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw[
'surround_info']);
847 $thisfile_mpeg_audio_lame[
'preset_used_id'] = ($PresetSurroundBytes & 0x07FF);
848 $thisfile_mpeg_audio_lame[
'preset_used'] = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame);
849 if (!empty($thisfile_mpeg_audio_lame[
'preset_used_id']) && empty($thisfile_mpeg_audio_lame[
'preset_used'])) {
850 $this->
warning(
'Unknown LAME preset used ('.$thisfile_mpeg_audio_lame[
'preset_used_id'].
') - please report to info@getid3.org');
852 if (($thisfile_mpeg_audio_lame[
'short_version'] ==
'LAME3.90.') && !empty($thisfile_mpeg_audio_lame[
'preset_used_id'])) {
854 $thisfile_mpeg_audio_lame[
'short_version'] =
'LAME3.90.3';
858 $thisfile_mpeg_audio_lame[
'audio_bytes'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xB8, 4));
859 $ExpectedNumberOfAudioBytes = (($thisfile_mpeg_audio_lame[
'audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame[
'audio_bytes'] : $thisfile_mpeg_audio[
'VBR_bytes']);
862 $thisfile_mpeg_audio_lame[
'music_crc'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBC, 2));
865 $thisfile_mpeg_audio_lame[
'lame_tag_crc'] =
getid3_lib::BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xBE, 2));
869 if ($thisfile_mpeg_audio_lame_raw[
'vbr_method'] == 1) {
871 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
872 $thisfile_mpeg_audio[
'bitrate'] = self::ClosestStandardMP3Bitrate($thisfile_mpeg_audio[
'bitrate']);
873 $info[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'bitrate'];
886 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
887 if ($recursivesearch) {
888 $thisfile_mpeg_audio[
'bitrate_mode'] =
'vbr';
890 $recursivesearch =
false;
891 $thisfile_mpeg_audio[
'bitrate_mode'] =
'cbr';
893 if ($thisfile_mpeg_audio[
'bitrate_mode'] ==
'vbr') {
894 $this->
warning(
'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.');
902 if (($ExpectedNumberOfAudioBytes > 0) && ($ExpectedNumberOfAudioBytes != (
$info[
'avdataend'] -
$info[
'avdataoffset']))) {
903 if ($ExpectedNumberOfAudioBytes > (
$info[
'avdataend'] -
$info[
'avdataoffset'])) {
907 elseif (($ExpectedNumberOfAudioBytes - (
$info[
'avdataend'] -
$info[
'avdataoffset'])) == 1) {
908 $this->
warning(
'Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)');
911 $this->
warning(
'Probable truncated file: expecting '.$ExpectedNumberOfAudioBytes.
' bytes of audio data, only found '.(
$info[
'avdataend'] -
$info[
'avdataoffset']).
' (short by '.($ExpectedNumberOfAudioBytes - (
$info[
'avdataend'] -
$info[
'avdataoffset'])).
' bytes)');
914 if (((
$info[
'avdataend'] -
$info[
'avdataoffset']) - $ExpectedNumberOfAudioBytes) == 1) {
920 $info[
'avdataend']--;
926 $this->
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)');
931 if (($thisfile_mpeg_audio[
'bitrate'] ==
'free') && empty(
$info[
'audio'][
'bitrate'])) {
932 if (($offset ==
$info[
'avdataoffset']) && empty($thisfile_mpeg_audio[
'VBR_frames'])) {
934 if ($framebytelength > 0) {
935 $thisfile_mpeg_audio[
'framelength'] = $framebytelength;
936 if ($thisfile_mpeg_audio[
'layer'] ==
'1') {
938 $info[
'audio'][
'bitrate'] = ((($framebytelength / 4) - intval($thisfile_mpeg_audio[
'padding'])) * $thisfile_mpeg_audio[
'sample_rate']) / 12;
941 $info[
'audio'][
'bitrate'] = (($framebytelength - intval($thisfile_mpeg_audio[
'padding'])) * $thisfile_mpeg_audio[
'sample_rate']) / 144;
944 $this->
error(
'Error calculating frame length of free-format MP3 without Xing/LAME header');
949 if (isset($thisfile_mpeg_audio[
'VBR_frames']) ? $thisfile_mpeg_audio[
'VBR_frames'] :
'') {
950 switch ($thisfile_mpeg_audio[
'bitrate_mode']) {
953 $bytes_per_frame = 1152;
954 if (($thisfile_mpeg_audio[
'version'] ==
'1') && ($thisfile_mpeg_audio[
'layer'] == 1)) {
955 $bytes_per_frame = 384;
956 } elseif ((($thisfile_mpeg_audio[
'version'] ==
'2') || ($thisfile_mpeg_audio[
'version'] ==
'2.5')) && ($thisfile_mpeg_audio[
'layer'] == 3)) {
957 $bytes_per_frame = 576;
959 $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);
960 if ($thisfile_mpeg_audio[
'VBR_bitrate'] > 0) {
961 $info[
'audio'][
'bitrate'] = $thisfile_mpeg_audio[
'VBR_bitrate'];
962 $thisfile_mpeg_audio[
'bitrate'] = $thisfile_mpeg_audio[
'VBR_bitrate'];
971 if ($recursivesearch) {
static RGADnameLookup($namecode)
static RGADoriginatorLookup($originatorcode)
static RGADamplitude2dB($amplitude)
FreeFormatFrameLength($offset, $deepscan=false)
static RGADadjustmentLookup($rawadjustment, $signbit)
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
static LittleEndian2Float($byteword)
fseek($bytes, $whence=SEEK_SET)
RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR)
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)