/common/libraries/plugin/getid3/module.audio.mp3.php
PHP | 2377 lines | 1761 code | 308 blank | 308 comment | 354 complexity | 1454326416f5ae4e585d2b4e57f864bf MD5 | raw file
Possible License(s): GPL-3.0, MIT, GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /////////////////////////////////////////////////////////////////
- /// getID3() by James Heinrich <info@getid3.org> //
- // available at http://getid3.sourceforge.net //
- // or http://www.getid3.org //
- /////////////////////////////////////////////////////////////////
- // See readme.txt for more details //
- /////////////////////////////////////////////////////////////////
- // //
- // module.audio.mp3.php //
- // module for analyzing MP3 files //
- // dependencies: NONE //
- // ///
- /////////////////////////////////////////////////////////////////
-
-
- // number of frames to scan to determine if MPEG-audio sequence is valid
- // Lower this number to 5-20 for faster scanning
- // Increase this number to 50+ for most accurate detection of valid VBR/CBR
- // mpeg-audio streams
- define('GETID3_MP3_VALID_CHECK_FRAMES', 35);
-
- class getid3_mp3
- {
-
- var $allow_bruteforce = false; // forces getID3() to scan the file byte-by-byte and log all the valid audio frame headers - extremely slow, unrecommended, but may provide data from otherwise-unusuable files
-
-
- function __construct(&$fd, &$ThisFileInfo)
- {
-
- if (! $this->getOnlyMPEGaudioInfo($fd, $ThisFileInfo, $ThisFileInfo['avdataoffset']))
- {
- if ($this->allow_bruteforce)
- {
- $ThisFileInfo['error'][] = 'Rescanning file in BruteForce mode';
- $this->getOnlyMPEGaudioInfoBruteForce($fd, $ThisFileInfo);
- }
- }
-
- if (isset($ThisFileInfo['mpeg']['audio']['bitrate_mode']))
- {
- $ThisFileInfo['audio']['bitrate_mode'] = strtolower($ThisFileInfo['mpeg']['audio']['bitrate_mode']);
- }
-
- if (((isset($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] > $ThisFileInfo['id3v2']['headerlength'])) || (! isset($ThisFileInfo['id3v2']) && ($ThisFileInfo['avdataoffset'] > 0))))
- {
-
- $synchoffsetwarning = 'Unknown data before synch ';
- if (isset($ThisFileInfo['id3v2']['headerlength']))
- {
- $synchoffsetwarning .= '(ID3v2 header ends at ' . $ThisFileInfo['id3v2']['headerlength'] . ', then ' . ($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']) . ' bytes garbage, ';
- }
- else
- {
- $synchoffsetwarning .= '(should be at beginning of file, ';
- }
- $synchoffsetwarning .= 'synch detected at ' . $ThisFileInfo['avdataoffset'] . ')';
- if (@$ThisFileInfo['audio']['bitrate_mode'] == 'cbr')
- {
-
- if (! empty($ThisFileInfo['id3v2']['headerlength']) && (($ThisFileInfo['avdataoffset'] - $ThisFileInfo['id3v2']['headerlength']) == $ThisFileInfo['mpeg']['audio']['framelength']))
- {
-
- $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.';
- $ThisFileInfo['audio']['codec'] = 'LAME';
- $CurrentDataLAMEversionString = 'LAME3.';
-
- }
- elseif (empty($ThisFileInfo['id3v2']['headerlength']) && ($ThisFileInfo['avdataoffset'] == $ThisFileInfo['mpeg']['audio']['framelength']))
- {
-
- $synchoffsetwarning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.';
- $ThisFileInfo['audio']['codec'] = 'LAME';
- $CurrentDataLAMEversionString = 'LAME3.';
-
- }
-
- }
- $ThisFileInfo['warning'][] = $synchoffsetwarning;
-
- }
-
- if (isset($ThisFileInfo['mpeg']['audio']['LAME']))
- {
- $ThisFileInfo['audio']['codec'] = 'LAME';
- if (! empty($ThisFileInfo['mpeg']['audio']['LAME']['long_version']))
- {
- $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['long_version'], "\x00");
- }
- elseif (! empty($ThisFileInfo['mpeg']['audio']['LAME']['short_version']))
- {
- $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['mpeg']['audio']['LAME']['short_version'], "\x00");
- }
- }
-
- $CurrentDataLAMEversionString = (! empty($CurrentDataLAMEversionString) ? $CurrentDataLAMEversionString : @$ThisFileInfo['audio']['encoder']);
- if (! empty($CurrentDataLAMEversionString) && (substr($CurrentDataLAMEversionString, 0, 6) == 'LAME3.') && ! preg_match('[0-9\)]', substr($CurrentDataLAMEversionString, - 1)))
- {
- // a version number of LAME that does not end with a number like "LAME3.92"
- // or with a closing parenthesis like "LAME3.88 (alpha)"
- // or a version of LAME with the LAMEtag-not-filled-in-DLL-mode bug (3.90-3.92)
-
-
- // not sure what the actual last frame length will be, but will be less than or equal to 1441
- $PossiblyLongerLAMEversion_FrameLength = 1441;
-
- // Not sure what version of LAME this is - look in padding of last frame for longer version string
- $PossibleLAMEversionStringOffset = $ThisFileInfo['avdataend'] - $PossiblyLongerLAMEversion_FrameLength;
- fseek($fd, $PossibleLAMEversionStringOffset);
- $PossiblyLongerLAMEversion_Data = fread($fd, $PossiblyLongerLAMEversion_FrameLength);
- switch (substr($CurrentDataLAMEversionString, - 1))
- {
- case 'a' :
- case 'b' :
- // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example
- // need to trim off "a" to match longer string
- $CurrentDataLAMEversionString = substr($CurrentDataLAMEversionString, 0, - 1);
- break;
- }
- if (($PossiblyLongerLAMEversion_String = strstr($PossiblyLongerLAMEversion_Data, $CurrentDataLAMEversionString)) !== false)
- {
- if (substr($PossiblyLongerLAMEversion_String, 0, strlen($CurrentDataLAMEversionString)) == $CurrentDataLAMEversionString)
- {
- $PossiblyLongerLAMEversion_NewString = substr($PossiblyLongerLAMEversion_String, 0, strspn($PossiblyLongerLAMEversion_String, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)"
- if (strlen($PossiblyLongerLAMEversion_NewString) > strlen(@$ThisFileInfo['audio']['encoder']))
- {
- $ThisFileInfo['audio']['encoder'] = $PossiblyLongerLAMEversion_NewString;
- }
- }
- }
- }
- if (! empty($ThisFileInfo['audio']['encoder']))
- {
- $ThisFileInfo['audio']['encoder'] = rtrim($ThisFileInfo['audio']['encoder'], "\x00 ");
- }
-
- switch (@$ThisFileInfo['mpeg']['audio']['layer'])
- {
- case 1 :
- case 2 :
- $ThisFileInfo['audio']['dataformat'] = 'mp' . $ThisFileInfo['mpeg']['audio']['layer'];
- break;
- }
- if (@$ThisFileInfo['fileformat'] == 'mp3')
- {
- switch ($ThisFileInfo['audio']['dataformat'])
- {
- case 'mp1' :
- case 'mp2' :
- case 'mp3' :
- $ThisFileInfo['fileformat'] = $ThisFileInfo['audio']['dataformat'];
- break;
-
- default :
- $ThisFileInfo['warning'][] = 'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "' . $ThisFileInfo['audio']['dataformat'] . '"';
- break;
- }
- }
-
- if (empty($ThisFileInfo['fileformat']))
- {
- unset($ThisFileInfo['fileformat']);
- unset($ThisFileInfo['audio']['bitrate_mode']);
- unset($ThisFileInfo['avdataoffset']);
- unset($ThisFileInfo['avdataend']);
- return false;
- }
-
- $ThisFileInfo['mime_type'] = 'audio/mpeg';
- $ThisFileInfo['audio']['lossless'] = false;
-
- // Calculate playtime
- if (! isset($ThisFileInfo['playtime_seconds']) && isset($ThisFileInfo['audio']['bitrate']) && ($ThisFileInfo['audio']['bitrate'] > 0))
- {
- $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['audio']['bitrate'];
- }
-
- $ThisFileInfo['audio']['encoder_options'] = $this->GuessEncoderOptions($ThisFileInfo);
-
- return true;
- }
-
- function GuessEncoderOptions(&$ThisFileInfo)
- {
- // shortcuts
- if (! empty($ThisFileInfo['mpeg']['audio']))
- {
- $thisfile_mpeg_audio = &$ThisFileInfo['mpeg']['audio'];
- if (! empty($thisfile_mpeg_audio['LAME']))
- {
- $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
- }
- }
-
- $encoder_options = '';
- static $NamedPresetBitrates = array(16, 24, 40, 56, 112, 128, 160, 192, 256);
-
- if ((@$thisfile_mpeg_audio['VBR_method'] == 'Fraunhofer') && ! empty($thisfile_mpeg_audio['VBR_quality']))
- {
-
- $encoder_options = 'VBR q' . $thisfile_mpeg_audio['VBR_quality'];
-
- }
- elseif (! empty($thisfile_mpeg_audio_lame['preset_used']) && (! in_array($thisfile_mpeg_audio_lame['preset_used_id'], $NamedPresetBitrates)))
- {
-
- $encoder_options = $thisfile_mpeg_audio_lame['preset_used'];
-
- }
- elseif (! empty($thisfile_mpeg_audio_lame['vbr_quality']))
- {
-
- static $KnownEncoderValues = array();
- if (empty($KnownEncoderValues))
- {
-
- //$KnownEncoderValues[abrbitrate_minbitrate][vbr_quality][raw_vbr_method][raw_noise_shaping][raw_stereo_mode][ath_type][lowpass_frequency] = 'preset name';
- $KnownEncoderValues[0xFF][58][1][1][3][2][20500] = '--alt-preset insane'; // 3.90, 3.90.1, 3.92
- $KnownEncoderValues[0xFF][58][1][1][3][2][20600] = '--alt-preset insane'; // 3.90.2, 3.90.3, 3.91
- $KnownEncoderValues[0xFF][57][1][1][3][4][20500] = '--alt-preset insane'; // 3.94, 3.95
- $KnownEncoderValues['**'][78][3][2][3][2][19500] = '--alt-preset extreme'; // 3.90, 3.90.1, 3.92
- $KnownEncoderValues['**'][78][3][2][3][2][19600] = '--alt-preset extreme'; // 3.90.2, 3.91
- $KnownEncoderValues['**'][78][3][1][3][2][19600] = '--alt-preset extreme'; // 3.90.3
- $KnownEncoderValues['**'][78][4][2][3][2][19500] = '--alt-preset fast extreme'; // 3.90, 3.90.1, 3.92
- $KnownEncoderValues['**'][78][4][2][3][2][19600] = '--alt-preset fast extreme'; // 3.90.2, 3.90.3, 3.91
- $KnownEncoderValues['**'][78][3][2][3][4][19000] = '--alt-preset standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues['**'][78][3][1][3][4][19000] = '--alt-preset standard'; // 3.90.3
- $KnownEncoderValues['**'][78][4][2][3][4][19000] = '--alt-preset fast standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues['**'][78][4][1][3][4][19000] = '--alt-preset fast standard'; // 3.90.3
- $KnownEncoderValues['**'][88][4][1][3][3][19500] = '--r3mix'; // 3.90, 3.90.1, 3.92
- $KnownEncoderValues['**'][88][4][1][3][3][19600] = '--r3mix'; // 3.90.2, 3.90.3, 3.91
- $KnownEncoderValues['**'][67][4][1][3][4][18000] = '--r3mix'; // 3.94, 3.95
- $KnownEncoderValues['**'][68][3][2][3][4][18000] = '--alt-preset medium'; // 3.90.3
- $KnownEncoderValues['**'][68][4][2][3][4][18000] = '--alt-preset fast medium'; // 3.90.3
-
-
- $KnownEncoderValues[0xFF][99][1][1][1][2][0] = '--preset studio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues[0xFF][58][2][1][3][2][20600] = '--preset studio'; // 3.90.3, 3.93.1
- $KnownEncoderValues[0xFF][58][2][1][3][2][20500] = '--preset studio'; // 3.93
- $KnownEncoderValues[0xFF][57][2][1][3][4][20500] = '--preset studio'; // 3.94, 3.95
- $KnownEncoderValues[0xC0][88][1][1][1][2][0] = '--preset cd'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues[0xC0][58][2][2][3][2][19600] = '--preset cd'; // 3.90.3, 3.93.1
- $KnownEncoderValues[0xC0][58][2][2][3][2][19500] = '--preset cd'; // 3.93
- $KnownEncoderValues[0xC0][57][2][1][3][4][19500] = '--preset cd'; // 3.94, 3.95
- $KnownEncoderValues[0xA0][78][1][1][3][2][18000] = '--preset hifi'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues[0xA0][58][2][2][3][2][18000] = '--preset hifi'; // 3.90.3, 3.93, 3.93.1
- $KnownEncoderValues[0xA0][57][2][1][3][4][18000] = '--preset hifi'; // 3.94, 3.95
- $KnownEncoderValues[0x80][67][1][1][3][2][18000] = '--preset tape'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues[0x80][67][1][1][3][2][15000] = '--preset radio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues[0x70][67][1][1][3][2][15000] = '--preset fm'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
- $KnownEncoderValues[0x70][58][2][2][3][2][16000] = '--preset tape/radio/fm'; // 3.90.3, 3.93, 3.93.1
- $KnownEncoderValues[0x70][57][2][1][3][4][16000] = '--preset tape/radio/fm'; // 3.94, 3.95
- $KnownEncoderValues[0x38][58][2][2][0][2][10000] = '--preset voice'; // 3.90.3, 3.93, 3.93.1
- $KnownEncoderValues[0x38][57][2][1][0][4][15000] = '--preset voice'; // 3.94, 3.95
- $KnownEncoderValues[0x38][57][2][1][0][4][16000] = '--preset voice'; // 3.94a14
- $KnownEncoderValues[0x28][65][1][1][0][2][7500] = '--preset mw-us'; // 3.90, 3.90.1, 3.92
- $KnownEncoderValues[0x28][65][1][1][0][2][7600] = '--preset mw-us'; // 3.90.2, 3.91
- $KnownEncoderValues[0x28][58][2][2][0][2][7000] = '--preset mw-us'; // 3.90.3, 3.93, 3.93.1
- $KnownEncoderValues[0x28][57][2][1][0][4][10500] = '--preset mw-us'; // 3.94, 3.95
- $KnownEncoderValues[0x28][57][2][1][0][4][11200] = '--preset mw-us'; // 3.94a14
- $KnownEncoderValues[0x28][57][2][1][0][4][8800] = '--preset mw-us'; // 3.94a15
- $KnownEncoderValues[0x18][58][2][2][0][2][4000] = '--preset phon+/lw/mw-eu/sw'; // 3.90.3, 3.93.1
- $KnownEncoderValues[0x18][58][2][2][0][2][3900] = '--preset phon+/lw/mw-eu/sw'; // 3.93
- $KnownEncoderValues[0x18][57][2][1][0][4][5900] = '--preset phon+/lw/mw-eu/sw'; // 3.94, 3.95
- $KnownEncoderValues[0x18][57][2][1][0][4][6200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a14
- $KnownEncoderValues[0x18][57][2][1][0][4][3200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a15
- $KnownEncoderValues[0x10][58][2][2][0][2][3800] = '--preset phone'; // 3.90.3, 3.93.1
- $KnownEncoderValues[0x10][58][2][2][0][2][3700] = '--preset phone'; // 3.93
- $KnownEncoderValues[0x10][57][2][1][0][4][5600] = '--preset phone'; // 3.94, 3.95
- }
-
- 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']]))
- {
-
- $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']];
-
- }
- 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']]))
- {
-
- $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']];
-
- }
- elseif ($ThisFileInfo['audio']['bitrate_mode'] == 'vbr')
- {
-
- // http://gabriel.mp3-tech.org/mp3infotag.html
- // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h
-
-
- $LAME_V_value = 10 - ceil($thisfile_mpeg_audio_lame['vbr_quality'] / 10);
- $LAME_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($LAME_V_value * 10);
- $encoder_options = '-V' . $LAME_V_value . ' -q' . $LAME_q_value;
-
- }
- elseif ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr')
- {
-
- $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']) . ceil($ThisFileInfo['audio']['bitrate'] / 1000);
-
- }
- else
- {
-
- $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']);
-
- }
-
- }
- elseif (! empty($thisfile_mpeg_audio_lame['bitrate_abr']))
- {
-
- $encoder_options = 'ABR' . $thisfile_mpeg_audio_lame['bitrate_abr'];
-
- }
- elseif (! empty($ThisFileInfo['audio']['bitrate']))
- {
-
- if ($ThisFileInfo['audio']['bitrate_mode'] == 'cbr')
- {
- $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']) . ceil($ThisFileInfo['audio']['bitrate'] / 1000);
- }
- else
- {
- $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']);
- }
-
- }
- if (! empty($thisfile_mpeg_audio_lame['bitrate_min']))
- {
- $encoder_options .= ' -b' . $thisfile_mpeg_audio_lame['bitrate_min'];
- }
-
- if (@$thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] || @$thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'])
- {
- $encoder_options .= ' --nogap';
- }
-
- if (! empty($thisfile_mpeg_audio_lame['lowpass_frequency']))
- {
- $ExplodedOptions = explode(' ', $encoder_options, 4);
- if ($ExplodedOptions[0] == '--r3mix')
- {
- $ExplodedOptions[1] = 'r3mix';
- }
- switch ($ExplodedOptions[0])
- {
- case '--preset' :
- case '--alt-preset' :
- case '--r3mix' :
- if ($ExplodedOptions[1] == 'fast')
- {
- $ExplodedOptions[1] .= ' ' . $ExplodedOptions[2];
- }
- switch ($ExplodedOptions[1])
- {
- case 'portable' :
- case 'medium' :
- case 'standard' :
- case 'extreme' :
- case 'insane' :
- case 'fast portable' :
- case 'fast medium' :
- case 'fast standard' :
- case 'fast extreme' :
- case 'fast insane' :
- case 'r3mix' :
- static $ExpectedLowpass = array('insane|20500' => 20500, 'insane|20600' => 20600, // 3.90.2, 3.90.3, 3.91
- 'medium|18000' => 18000,
- 'fast medium|18000' => 18000, 'extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
- 'extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
- 'fast extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
- 'fast extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
- 'standard|19000' => 19000,
- 'fast standard|19000' => 19000, 'r3mix|19500' => 19500, // 3.90, 3.90.1, 3.92
- 'r3mix|19600' => 19600, // 3.90.2, 3.90.3, 3.91
- 'r3mix|18000' => 18000)// 3.94, 3.95
- ;
- 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)))
- {
- $encoder_options .= ' --lowpass ' . $thisfile_mpeg_audio_lame['lowpass_frequency'];
- }
- break;
-
- default :
- break;
- }
- break;
- }
- }
-
- if (isset($thisfile_mpeg_audio_lame['raw']['source_sample_freq']))
- {
- if (($thisfile_mpeg_audio['sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 1))
- {
- $encoder_options .= ' --resample 44100';
- }
- elseif (($thisfile_mpeg_audio['sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 2))
- {
- $encoder_options .= ' --resample 48000';
- }
- elseif ($thisfile_mpeg_audio['sample_rate'] < 44100)
- {
- switch ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'])
- {
- case 0 : // <= 32000
- // may or may not be same as source frequency - ignore
- break;
- case 1 : // 44100
- case 2 : // 48000
- case 3 : // 48000+
- $ExplodedOptions = explode(' ', $encoder_options, 4);
- switch ($ExplodedOptions[0])
- {
- case '--preset' :
- case '--alt-preset' :
- switch ($ExplodedOptions[1])
- {
- case 'fast' :
- case 'portable' :
- case 'medium' :
- case 'standard' :
- case 'extreme' :
- case 'insane' :
- $encoder_options .= ' --resample ' . $thisfile_mpeg_audio['sample_rate'];
- break;
-
- default :
- static $ExpectedResampledRate = array('phon+/lw/mw-eu/sw|16000' => 16000,
- 'mw-us|24000' => 24000, // 3.95
- 'mw-us|32000' => 32000, // 3.93
- 'mw-us|16000' => 16000, // 3.92
- 'phone|16000' => 16000,
- 'phone|11025' => 11025, // 3.94a15
- 'radio|32000' => 32000, // 3.94a15
- 'fm/radio|32000' => 32000, // 3.92
- 'fm|32000' => 32000, // 3.90
- 'voice|32000' => 32000);
- if (! isset($ExpectedResampledRate[$ExplodedOptions[1] . '|' . $thisfile_mpeg_audio['sample_rate']]))
- {
- $encoder_options .= ' --resample ' . $thisfile_mpeg_audio['sample_rate'];
- }
- break;
- }
- break;
-
- case '--r3mix' :
- default :
- $encoder_options .= ' --resample ' . $thisfile_mpeg_audio['sample_rate'];
- break;
- }
- break;
- }
- }
- }
- if (empty($encoder_options) && ! empty($ThisFileInfo['audio']['bitrate']) && ! empty($ThisFileInfo['audio']['bitrate_mode']))
- {
- //$encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']).ceil($ThisFileInfo['audio']['bitrate'] / 1000);
- $encoder_options = strtoupper($ThisFileInfo['audio']['bitrate_mode']);
- }
-
- return $encoder_options;
- }
-
- function decodeMPEGaudioHeader($fd, $offset, &$ThisFileInfo, $recursivesearch = true, $ScanAsCBR = false, $FastMPEGheaderScan = false)
- {
-
- static $MPEGaudioVersionLookup;
- static $MPEGaudioLayerLookup;
- static $MPEGaudioBitrateLookup;
- static $MPEGaudioFrequencyLookup;
- static $MPEGaudioChannelModeLookup;
- static $MPEGaudioModeExtensionLookup;
- static $MPEGaudioEmphasisLookup;
- if (empty($MPEGaudioVersionLookup))
- {
- $MPEGaudioVersionLookup = getid3_mp3 :: MPEGaudioVersionArray();
- $MPEGaudioLayerLookup = getid3_mp3 :: MPEGaudioLayerArray();
- $MPEGaudioBitrateLookup = getid3_mp3 :: MPEGaudioBitrateArray();
- $MPEGaudioFrequencyLookup = getid3_mp3 :: MPEGaudioFrequencyArray();
- $MPEGaudioChannelModeLookup = getid3_mp3 :: MPEGaudioChannelModeArray();
- $MPEGaudioModeExtensionLookup = getid3_mp3 :: MPEGaudioModeExtensionArray();
- $MPEGaudioEmphasisLookup = getid3_mp3 :: MPEGaudioEmphasisArray();
- }
-
- if ($offset >= $ThisFileInfo['avdataend'])
- {
- $ThisFileInfo['error'][] = 'end of file encounter looking for MPEG synch';
- return false;
- }
- fseek($fd, $offset, SEEK_SET);
- //$headerstring = fread($fd, 1441); // worst-case max length = 32kHz @ 320kbps layer 3 = 1441 bytes/frame
- $headerstring = fread($fd, 226); // LAME header at offset 36 + 190 bytes of Xing/LAME data
-
-
- // MP3 audio frame structure:
- // $aa $aa $aa $aa [$bb $bb] $cc...
- // where $aa..$aa is the four-byte mpeg-audio header (below)
- // $bb $bb is the optional 2-byte CRC
- // and $cc... is the audio data
-
-
- $head4 = substr($headerstring, 0, 4);
-
- static $MPEGaudioHeaderDecodeCache = array();
- if (isset($MPEGaudioHeaderDecodeCache[$head4]))
- {
- $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
- }
- else
- {
- $MPEGheaderRawArray = getid3_mp3 :: MPEGaudioHeaderDecode($head4);
- $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
- }
-
- static $MPEGaudioHeaderValidCache = array();
-
- // Not in cache
- if (! isset($MPEGaudioHeaderValidCache[$head4]))
- {
- //$MPEGaudioHeaderValidCache[$head4] = getid3_mp3::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true); // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)
- $MPEGaudioHeaderValidCache[$head4] = getid3_mp3 :: MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);
- }
-
- // shortcut
- if (! isset($ThisFileInfo['mpeg']['audio']))
- {
- $ThisFileInfo['mpeg']['audio'] = array();
- }
- $thisfile_mpeg_audio = &$ThisFileInfo['mpeg']['audio'];
-
- if ($MPEGaudioHeaderValidCache[$head4])
- {
- $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray;
- }
- else
- {
- $ThisFileInfo['error'][] = 'Invalid MPEG audio header at offset ' . $offset;
- return false;
- }
-
- if (! $FastMPEGheaderScan)
- {
-
- $thisfile_mpeg_audio['version'] = $MPEGaudioVersionLookup[$thisfile_mpeg_audio['raw']['version']];
- $thisfile_mpeg_audio['layer'] = $MPEGaudioLayerLookup[$thisfile_mpeg_audio['raw']['layer']];
-
- $thisfile_mpeg_audio['channelmode'] = $MPEGaudioChannelModeLookup[$thisfile_mpeg_audio['raw']['channelmode']];
- $thisfile_mpeg_audio['channels'] = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2);
- $thisfile_mpeg_audio['sample_rate'] = $MPEGaudioFrequencyLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']];
- $thisfile_mpeg_audio['protection'] = ! $thisfile_mpeg_audio['raw']['protection'];
- $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private'];
- $thisfile_mpeg_audio['modeextension'] = $MPEGaudioModeExtensionLookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']];
- $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright'];
- $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original'];
- $thisfile_mpeg_audio['emphasis'] = $MPEGaudioEmphasisLookup[$thisfile_mpeg_audio['raw']['emphasis']];
-
- $ThisFileInfo['audio']['channels'] = $thisfile_mpeg_audio['channels'];
- $ThisFileInfo['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate'];
-
- if ($thisfile_mpeg_audio['protection'])
- {
- $thisfile_mpeg_audio['crc'] = getid3_lib :: BigEndian2Int(substr($headerstring, 4, 2));
- }
-
- }
-
- if ($thisfile_mpeg_audio['raw']['bitrate'] == 15)
- {
- // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0
- $ThisFileInfo['warning'][] = 'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';
- $thisfile_mpeg_audio['raw']['bitrate'] = 0;
- }
- $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding'];
- $thisfile_mpeg_audio['bitrate'] = $MPEGaudioBitrateLookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']];
-
- if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $ThisFileInfo['avdataoffset']))
- {
- // only skip multiple frame check if free-format bitstream found at beginning of file
- // otherwise is quite possibly simply corrupted data
- $recursivesearch = false;
- }
-
- // For Layer 2 there are some combinations of bitrate and mode which are not allowed.
- if (! $FastMPEGheaderScan && ($thisfile_mpeg_audio['layer'] == '2'))
- {
-
- $ThisFileInfo['audio']['dataformat'] = 'mp2';
- switch ($thisfile_mpeg_audio['channelmode'])
- {
-
- case 'mono' :
- if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000))
- {
- // these are ok
- }
- else
- {
- $ThisFileInfo['error'][] = $thisfile_mpeg_audio['bitrate'] . 'kbps not allowed in Layer 2, ' . $thisfile_mpeg_audio['channelmode'] . '.';
- return false;
- }
- break;
-
- case 'stereo' :
- case 'joint stereo' :
- case 'dual channel' :
- if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000))
- {
- // these are ok
- }
- else
- {
- $ThisFileInfo['error'][] = intval(round($thisfile_mpeg_audio['bitrate'] / 1000)) . 'kbps not allowed in Layer 2, ' . $thisfile_mpeg_audio['channelmode'] . '.';
- return false;
- }
- break;
-
- }
-
- }
-
- if ($ThisFileInfo['audio']['sample_rate'] > 0)
- {
- $thisfile_mpeg_audio['framelength'] = getid3_mp3 :: MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $ThisFileInfo['audio']['sample_rate']);
- }
-
- $nextframetestoffset = $offset + 1;
- if ($thisfile_mpeg_audio['bitrate'] != 'free')
- {
-
- $ThisFileInfo['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
-
- if (isset($thisfile_mpeg_audio['framelength']))
- {
- $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength'];
- }
- else
- {
- $ThisFileInfo['error'][] = 'Frame at offset(' . $offset . ') is has an invalid frame length.';
- return false;
- }
-
- }
-
- $ExpectedNumberOfAudioBytes = 0;
-
- ////////////////////////////////////////////////////////////////////////////////////
- // Variable-bitrate headers
-
-
- if (substr($headerstring, 4 + 32, 4) == 'VBRI')
- {
- // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36)
- // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html
-
-
- $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
- $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer';
- $ThisFileInfo['audio']['codec'] = 'Fraunhofer';
-
- $SideInfoData = substr($headerstring, 4 + 2, 32);
-
- $FraunhoferVBROffset = 36;
-
- $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 4, 2)); // VbriVersion
- $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 6, 2)); // VbriDelay
- $thisfile_mpeg_audio['VBR_quality'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 8, 2)); // VbriQuality
- $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 10, 4)); // VbriStreamBytes
- $thisfile_mpeg_audio['VBR_frames'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 14, 4)); // VbriStreamFrames
- $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 18, 2)); // VbriTableSize
- $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 20, 2)); // VbriTableScale
- $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 22, 2)); // VbriEntryBytes
- $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset + 24, 2)); // VbriEntryFrames
-
-
- $ExpectedNumberOfAudioBytes = $thisfile_mpeg_audio['VBR_bytes'];
-
- $previousbyteoffset = $offset;
- for($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i ++)
- {
- $Fraunhofer_OffsetN = getid3_lib :: BigEndian2Int(substr($headerstring, $FraunhoferVBROffset, $thisfile_mpeg_audio['VBR_entry_bytes']));
- $FraunhoferVBROffset += $thisfile_mpeg_audio['VBR_entry_bytes'];
- $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']);
- $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = ($Fraunhofer_OffsetN * $thisfile_mpeg_audio['VBR_seek_scale']) + $previousbyteoffset;
- $previousbyteoffset += $Fraunhofer_OffsetN;
- }
-
- }
- else
- {
-
- // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36)
- // depending on MPEG layer and number of channels
-
-
- $VBRidOffset = getid3_mp3 :: XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']);
- $SideInfoData = substr($headerstring, 4 + 2, $VBRidOffset - 4);
-
- if ((substr($headerstring, $VBRidOffset, strlen('Xing')) == 'Xing') || (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Info'))
- {
- // 'Xing' is traditional Xing VBR frame
- // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.)
- // 'Info' *can* legally be used to specify a VBR file as well, however.
-
-
- // http://www.multiweb.cz/twoinches/MP3inside.htm
- //00..03 = "Xing" or "Info"
- //04..07 = Flags:
- // 0x01 Frames Flag set if value for number of frames in file is stored
- // 0x02 Bytes Flag set if value for filesize in bytes is stored
- // 0x04 TOC Flag set if values for TOC are stored
- // 0x08 VBR Scale Flag set if values for VBR scale is stored
- //08..11 Frames: Number of frames in file (including the first Xing/Info one)
- //12..15 Bytes: File length in Bytes
- //16..115 TOC (Table of Contents):
- // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file.
- // Each Byte has a value according this formula:
- // (TOC[i] / 256) * fileLenInBytes
- // So if song lasts eg. 240 sec. and you want to jump to 60. sec. (and file is 5 000 000 Bytes length) you can use:
- // TOC[(60/240)*100] = TOC[25]
- // and corresponding Byte in file is then approximately at:
- // (TOC[25]/256) * 5000000
- //116..119 VBR Scale
-
-
- // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME
- // if (substr($headerstring, $VBRidOffset, strlen('Info')) == 'Xing') {
- $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
- $thisfile_mpeg_audio['VBR_method'] = 'Xing';
- // } else {
- // $ScanAsCBR = true;
- // $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
- // }
-
-
- $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib :: BigEndian2Int(substr($headerstring, $VBRidOffset + 4, 4));
-
- $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000001);
- $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000002);
- $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000004);
- $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000008);
-
- if ($thisfile_mpeg_audio['xing_flags']['frames'])
- {
- $thisfile_mpeg_audio['VBR_frames'] = getid3_lib :: BigEndian2Int(substr($headerstring, $VBRidOffset + 8, 4));
-
- //$thisfile_mpeg_audio['VBR_frames']--; // don't count header Xing/Info frame
- }
- if ($thisfile_mpeg_audio['xing_flags']['bytes'])
- {
- $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib :: BigEndian2Int(substr($headerstring, $VBRidOffset + 12, 4));
- }
-
- //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
- if (! empty($thisfile_mpeg_audio['VBR_frames']) && ! empty($thisfile_mpeg_audio['VBR_bytes']))
- {
-
- $framelengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'];
-
- if ($thisfile_mpeg_audio['layer'] == '1')
- {
- // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
- //$ThisFileInfo['audio']['bitrate'] = ((($framelengthfloat / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12;
- $ThisFileInfo['audio']['bitrate'] = ($framelengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $ThisFileInfo['audio']['channels']) / 12;
- }
- else
- {
- // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
- //$ThisFileInfo['audio']['bitrate'] = (($framelengthfloat - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
- $ThisFileInfo['audio']['bitrate'] = $framelengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $ThisFileInfo['audio']['channels']) / 144;
- }
- $thisfile_mpeg_audio['framelength'] = floor($framelengthfloat);
- }
-
- if ($thisfile_mpeg_audio['xing_flags']['toc'])
- {
- $LAMEtocData = substr($headerstring, $VBRidOffset + 16, 100);
- for($i = 0; $i < 100; $i ++)
- {
- $thisfile_mpeg_audio['toc'][$i] = ord($LAMEtocData{$i});
- }
- }
- if ($thisfile_mpeg_audio['xing_flags']['vbr_scale'])
- {
- $thisfile_mpeg_audio['VBR_scale'] = getid3_lib :: BigEndian2Int(substr($headerstring, $VBRidOffset + 116, 4));
- }
-
- // http://gabriel.mp3-tech.org/mp3infotag.html
- if (substr($headerstring, $VBRidOffset + 120, 4) == 'LAME')
- {
-
- // shortcut
- $thisfile_mpeg_audio['LAME'] = array();
- $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
-
- $thisfile_mpeg_audio_lame['long_version'] = substr($headerstring, $VBRidOffset + 120, 20);
- $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9);
-
- if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90')
- {
-
- // extra 11 chars are not part of version string when LAMEtag present
- unset($thisfile_mpeg_audio_lame['long_version']);
-
- // It the LAME tag was only introduced in LAME v3.90
- // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933
-
-
- // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html
- // are assuming a 'Xing' identifier offset of 0x24, which is the case for
- // MPEG-1 non-mono, but not for other combinations
- $LAMEtagOffsetContant = $VBRidOffset - 0x24;
-
- // shortcuts
- $thisfile_mpeg_audio_lame['RGAD'] = array('track' => array(),
- 'album' => array());
- $thisfile_mpeg_audio_lame_RGAD = &$thisfile_mpeg_audio_lame['RGAD'];
- $thisfile_mpeg_audio_lame_RGAD_track = &$thisfile_mpeg_audio_lame_RGAD['track'];
- $thisfile_mpeg_audio_lame_RGAD_album = &$thisfile_mpeg_audio_lame_RGAD['album'];
- $thisfile_mpeg_audio_lame['raw'] = array();
- $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw'];
-
- // byte $9B VBR Quality
- // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications.
- // Actually overwrites original Xing bytes
- unset($thisfile_mpeg_audio['VBR_scale']);
- $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib :: BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0x9B, 1));
-
- // bytes $9C-$A4 Encoder short VersionString
- $thisfile_mpeg_audio_lame['short_version'] = substr($headerstring, $LAMEtagOffsetContant + 0x9C, 9);
-
- // byte $A5 Info Tag revision + VBR method
- $LAMEtagRevisionVBRmethod = getid3_lib :: BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA5, 1));
-
- $thisfile_mpeg_audio_lame['tag_revision'] = ($LAMEtagRevisionVBRmethod & 0xF0) >> 4;
- $thisfile_mpeg_audio_lame_raw['vbr_method'] = $LAMEtagRevisionVBRmethod & 0x0F;
- $thisfile_mpeg_audio_lame['vbr_method'] = getid3_mp3 :: LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']);
- $thisfile_mpeg_audio['bitrate_mode'] = substr($thisfile_mpeg_audio_lame['vbr_method'], 0, 3); // usually either 'cbr' or 'vbr', but truncates 'vbr-old / vbr-rh' to 'vbr'
-
-
- // byte $A6 Lowpass filter value
- $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib :: BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA6, 1)) * 100;
-
- // bytes $A7-$AE Replay Gain
- // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
- // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude"
- if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b')
- {
- // LAME 3.94a16 and later - 9.23 fixed point
- // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375
- $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = (float) ((getid3_lib :: BigEndian2Int(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4))) / 8388608);
- }
- else
- {
- // LAME 3.94a15 and earlier - 32-bit floating point
- // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15
- $thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] = getid3_lib :: LittleEndian2Float(substr($headerstring, $LAMEtagOffsetContant + 0xA7, 4));
- }
- if ($thisfile_mpeg_audio_lame_RGAD['peak_amplitude'] == 0)
- {
- unset($thisfile_mpeg_audio_lame_RGAD['peak_amplitude']);
- }
- else
- {
- $thisfile_mpeg_audio_lame_RGAD['peak_db'] = getid3_lib :: RGADamplitude2dB($thisfile_mpeg_audio_lame_RGAD['peak_a…
Large files files are truncated, but you can click here to view the full file