annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.mp3.php @ 28:118cb614cf18 judyates tip

judy bio.
author Robert McIntyre <rlm@mit.edu>
date Tue, 29 Dec 2015 16:26:18 -0800
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.audio.mp3.php |
rlm@3 18 // | Module for analyzing MPEG Audio Layer 1,2,3 files. |
rlm@3 19 // | dependencies: none |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio.mp3.php,v 1.10 2006/11/16 22:57:57 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_mp3 extends getid3_handler
rlm@3 27 {
rlm@3 28 // Number of frames to scan to determine if MPEG-audio sequence is valid.
rlm@3 29 // Lower this number to 5-20 for faster scanning
rlm@3 30 // Increase this number to 50+ for most accurate detection of valid VBR/CBR mpeg-audio streams
rlm@3 31 const VALID_CHECK_FRAMES = 35;
rlm@3 32
rlm@3 33
rlm@3 34 public function Analyze() {
rlm@3 35
rlm@3 36 $this->getAllMPEGInfo($this->getid3->fp, $this->getid3->info);
rlm@3 37
rlm@3 38 return true;
rlm@3 39 }
rlm@3 40
rlm@3 41
rlm@3 42 public function AnalyzeMPEGaudioInfo() {
rlm@3 43
rlm@3 44 $this->getOnlyMPEGaudioInfo($this->getid3->fp, $this->getid3->info, $this->getid3->info['avdataoffset'], false);
rlm@3 45 }
rlm@3 46
rlm@3 47
rlm@3 48 public function getAllMPEGInfo(&$fd, &$info) {
rlm@3 49
rlm@3 50 $this->getOnlyMPEGaudioInfo($fd, $info, 0 + $info['avdataoffset']);
rlm@3 51
rlm@3 52 if (isset($info['mpeg']['audio']['bitrate_mode'])) {
rlm@3 53 $info['audio']['bitrate_mode'] = strtolower($info['mpeg']['audio']['bitrate_mode']);
rlm@3 54 }
rlm@3 55
rlm@3 56 if (((isset($info['id3v2']['headerlength']) && ($info['avdataoffset'] > $info['id3v2']['headerlength'])) || (!isset($info['id3v2']) && ($info['avdataoffset'] > 0)))) {
rlm@3 57
rlm@3 58 $synch_offset_warning = 'Unknown data before synch ';
rlm@3 59 if (isset($info['id3v2']['headerlength'])) {
rlm@3 60 $synch_offset_warning .= '(ID3v2 header ends at '.$info['id3v2']['headerlength'].', then '.($info['avdataoffset'] - $info['id3v2']['headerlength']).' bytes garbage, ';
rlm@3 61 } else {
rlm@3 62 $synch_offset_warning .= '(should be at beginning of file, ';
rlm@3 63 }
rlm@3 64 $synch_offset_warning .= 'synch detected at '.$info['avdataoffset'].')';
rlm@3 65 if ($info['audio']['bitrate_mode'] == 'cbr') {
rlm@3 66
rlm@3 67 if (!empty($info['id3v2']['headerlength']) && (($info['avdataoffset'] - $info['id3v2']['headerlength']) == $info['mpeg']['audio']['framelength'])) {
rlm@3 68
rlm@3 69 $synch_offset_warning .= '. This is a known problem with some versions of LAME (3.90-3.92) DLL in CBR mode.';
rlm@3 70 $info['audio']['codec'] = 'LAME';
rlm@3 71 $current_data_lame_version_string = 'LAME3.';
rlm@3 72
rlm@3 73 } elseif (empty($info['id3v2']['headerlength']) && ($info['avdataoffset'] == $info['mpeg']['audio']['framelength'])) {
rlm@3 74
rlm@3 75 $synch_offset_warning .= '. This is a known problem with some versions of LAME (3.90 - 3.92) DLL in CBR mode.';
rlm@3 76 $info['audio']['codec'] = 'LAME';
rlm@3 77 $current_data_lame_version_string = 'LAME3.';
rlm@3 78
rlm@3 79 }
rlm@3 80
rlm@3 81 }
rlm@3 82 $this->getid3->warning($synch_offset_warning);
rlm@3 83
rlm@3 84 }
rlm@3 85
rlm@3 86 if (isset($info['mpeg']['audio']['LAME'])) {
rlm@3 87 $info['audio']['codec'] = 'LAME';
rlm@3 88 if (!empty($info['mpeg']['audio']['LAME']['long_version'])) {
rlm@3 89 $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['long_version'], "\x00");
rlm@3 90 } elseif (!empty($info['mpeg']['audio']['LAME']['short_version'])) {
rlm@3 91 $info['audio']['encoder'] = rtrim($info['mpeg']['audio']['LAME']['short_version'], "\x00");
rlm@3 92 }
rlm@3 93 }
rlm@3 94
rlm@3 95 $current_data_lame_version_string = (!empty($current_data_lame_version_string) ? $current_data_lame_version_string : @$info['audio']['encoder']);
rlm@3 96 if (!empty($current_data_lame_version_string) && (substr($current_data_lame_version_string, 0, 6) == 'LAME3.') && !preg_match('[0-9\)]', substr($current_data_lame_version_string, -1))) {
rlm@3 97 // a version number of LAME that does not end with a number like "LAME3.92"
rlm@3 98 // or with a closing parenthesis like "LAME3.88 (alpha)"
rlm@3 99 // or a version of LAME with the LAMEtag-not-filled-in-DLL-mode bug (3.90-3.92)
rlm@3 100
rlm@3 101 // not sure what the actual last frame length will be, but will be less than or equal to 1441
rlm@3 102 $possibly_longer_lame_version_frame_length = 1441;
rlm@3 103
rlm@3 104 // Not sure what version of LAME this is - look in padding of last frame for longer version string
rlm@3 105 $possible_lame_version_string_offset = $info['avdataend'] - $possibly_longer_lame_version_frame_length;
rlm@3 106 fseek($fd, $possible_lame_version_string_offset);
rlm@3 107 $possibly_longer_lame_version_data = fread($fd, $possibly_longer_lame_version_frame_length);
rlm@3 108 switch (substr($current_data_lame_version_string, -1)) {
rlm@3 109 case 'a':
rlm@3 110 case 'b':
rlm@3 111 // "LAME3.94a" will have a longer version string of "LAME3.94 (alpha)" for example
rlm@3 112 // need to trim off "a" to match longer string
rlm@3 113 $current_data_lame_version_string = substr($current_data_lame_version_string, 0, -1);
rlm@3 114 break;
rlm@3 115 }
rlm@3 116 if (($possibly_longer_lame_version_string = strstr($possibly_longer_lame_version_data, $current_data_lame_version_string)) !== false) {
rlm@3 117 if (substr($possibly_longer_lame_version_string, 0, strlen($current_data_lame_version_string)) == $current_data_lame_version_string) {
rlm@3 118 $possibly_longer_lame_version_new_string = substr($possibly_longer_lame_version_string, 0, strspn($possibly_longer_lame_version_string, 'LAME0123456789., (abcdefghijklmnopqrstuvwxyzJFSOND)')); //"LAME3.90.3" "LAME3.87 (beta 1, Sep 27 2000)" "LAME3.88 (beta)"
rlm@3 119 if (strlen($possibly_longer_lame_version_new_string) > strlen(@$info['audio']['encoder'])) {
rlm@3 120 $info['audio']['encoder'] = $possibly_longer_lame_version_new_string;
rlm@3 121 }
rlm@3 122 }
rlm@3 123 }
rlm@3 124 }
rlm@3 125 if (!empty($info['audio']['encoder'])) {
rlm@3 126 $info['audio']['encoder'] = rtrim($info['audio']['encoder'], "\x00 ");
rlm@3 127 }
rlm@3 128
rlm@3 129 switch (@$info['mpeg']['audio']['layer']) {
rlm@3 130 case 1:
rlm@3 131 case 2:
rlm@3 132 $info['audio']['dataformat'] = 'mp'.$info['mpeg']['audio']['layer'];
rlm@3 133 break;
rlm@3 134 }
rlm@3 135 if (@$info['fileformat'] == 'mp3') {
rlm@3 136 switch ($info['audio']['dataformat']) {
rlm@3 137 case 'mp1':
rlm@3 138 case 'mp2':
rlm@3 139 case 'mp3':
rlm@3 140 $info['fileformat'] = $info['audio']['dataformat'];
rlm@3 141 break;
rlm@3 142
rlm@3 143 default:
rlm@3 144 $this->getid3->warning('Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"');
rlm@3 145 break;
rlm@3 146 }
rlm@3 147 }
rlm@3 148
rlm@3 149 $info['mime_type'] = 'audio/mpeg';
rlm@3 150 $info['audio']['lossless'] = false;
rlm@3 151
rlm@3 152 // Calculate playtime
rlm@3 153 if (!isset($info['playtime_seconds']) && isset($info['audio']['bitrate']) && ($info['audio']['bitrate'] > 0)) {
rlm@3 154 $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['audio']['bitrate'];
rlm@3 155 }
rlm@3 156
rlm@3 157 $info['audio']['encoder_options'] = getid3_mp3::GuessEncoderOptions($info);
rlm@3 158
rlm@3 159 return true;
rlm@3 160 }
rlm@3 161
rlm@3 162
rlm@3 163
rlm@3 164 public static function GuessEncoderOptions(&$info) {
rlm@3 165 // shortcuts
rlm@3 166 if (!empty($info['mpeg']['audio'])) {
rlm@3 167 $thisfile_mpeg_audio = &$info['mpeg']['audio'];
rlm@3 168 if (!empty($thisfile_mpeg_audio['LAME'])) {
rlm@3 169 $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
rlm@3 170 }
rlm@3 171 }
rlm@3 172
rlm@3 173 $encoder_options = '';
rlm@3 174 static $named_preset_bitrates = array (16, 24, 40, 56, 112, 128, 160, 192, 256);
rlm@3 175
rlm@3 176 if ((@$thisfile_mpeg_audio['VBR_method'] == 'Fraunhofer') && !empty($thisfile_mpeg_audio['VBR_quality'])) {
rlm@3 177
rlm@3 178 $encoder_options = 'VBR q'.$thisfile_mpeg_audio['VBR_quality'];
rlm@3 179
rlm@3 180 } elseif (!empty($thisfile_mpeg_audio_lame['preset_used']) && (!in_array($thisfile_mpeg_audio_lame['preset_used_id'], $named_preset_bitrates))) {
rlm@3 181
rlm@3 182 $encoder_options = $thisfile_mpeg_audio_lame['preset_used'];
rlm@3 183
rlm@3 184 } elseif (!empty($thisfile_mpeg_audio_lame['vbr_quality'])) {
rlm@3 185
rlm@3 186 static $known_encoder_values = array ();
rlm@3 187 if (empty($known_encoder_values)) {
rlm@3 188
rlm@3 189 //$known_encoder_values[abrbitrate_minbitrate][vbr_quality][raw_vbr_method][raw_noise_shaping][raw_stereo_mode][ath_type][lowpass_frequency] = 'preset name';
rlm@3 190 $known_encoder_values[0xFF][58][1][1][3][2][20500] = '--alt-preset insane'; // 3.90, 3.90.1, 3.92
rlm@3 191 $known_encoder_values[0xFF][58][1][1][3][2][20600] = '--alt-preset insane'; // 3.90.2, 3.90.3, 3.91
rlm@3 192 $known_encoder_values[0xFF][57][1][1][3][4][20500] = '--alt-preset insane'; // 3.94, 3.95
rlm@3 193 $known_encoder_values['**'][78][3][2][3][2][19500] = '--alt-preset extreme'; // 3.90, 3.90.1, 3.92
rlm@3 194 $known_encoder_values['**'][78][3][2][3][2][19600] = '--alt-preset extreme'; // 3.90.2, 3.91
rlm@3 195 $known_encoder_values['**'][78][3][1][3][2][19600] = '--alt-preset extreme'; // 3.90.3
rlm@3 196 $known_encoder_values['**'][78][4][2][3][2][19500] = '--alt-preset fast extreme'; // 3.90, 3.90.1, 3.92
rlm@3 197 $known_encoder_values['**'][78][4][2][3][2][19600] = '--alt-preset fast extreme'; // 3.90.2, 3.90.3, 3.91
rlm@3 198 $known_encoder_values['**'][78][3][2][3][4][19000] = '--alt-preset standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 199 $known_encoder_values['**'][78][3][1][3][4][19000] = '--alt-preset standard'; // 3.90.3
rlm@3 200 $known_encoder_values['**'][78][4][2][3][4][19000] = '--alt-preset fast standard'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 201 $known_encoder_values['**'][78][4][1][3][4][19000] = '--alt-preset fast standard'; // 3.90.3
rlm@3 202 $known_encoder_values['**'][88][4][1][3][3][19500] = '--r3mix'; // 3.90, 3.90.1, 3.92
rlm@3 203 $known_encoder_values['**'][88][4][1][3][3][19600] = '--r3mix'; // 3.90.2, 3.90.3, 3.91
rlm@3 204 $known_encoder_values['**'][67][4][1][3][4][18000] = '--r3mix'; // 3.94, 3.95
rlm@3 205 $known_encoder_values['**'][68][3][2][3][4][18000] = '--alt-preset medium'; // 3.90.3
rlm@3 206 $known_encoder_values['**'][68][4][2][3][4][18000] = '--alt-preset fast medium'; // 3.90.3
rlm@3 207
rlm@3 208 $known_encoder_values[0xFF][99][1][1][1][2][0] = '--preset studio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 209 $known_encoder_values[0xFF][58][2][1][3][2][20600] = '--preset studio'; // 3.90.3, 3.93.1
rlm@3 210 $known_encoder_values[0xFF][58][2][1][3][2][20500] = '--preset studio'; // 3.93
rlm@3 211 $known_encoder_values[0xFF][57][2][1][3][4][20500] = '--preset studio'; // 3.94, 3.95
rlm@3 212 $known_encoder_values[0xC0][88][1][1][1][2][0] = '--preset cd'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 213 $known_encoder_values[0xC0][58][2][2][3][2][19600] = '--preset cd'; // 3.90.3, 3.93.1
rlm@3 214 $known_encoder_values[0xC0][58][2][2][3][2][19500] = '--preset cd'; // 3.93
rlm@3 215 $known_encoder_values[0xC0][57][2][1][3][4][19500] = '--preset cd'; // 3.94, 3.95
rlm@3 216 $known_encoder_values[0xA0][78][1][1][3][2][18000] = '--preset hifi'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 217 $known_encoder_values[0xA0][58][2][2][3][2][18000] = '--preset hifi'; // 3.90.3, 3.93, 3.93.1
rlm@3 218 $known_encoder_values[0xA0][57][2][1][3][4][18000] = '--preset hifi'; // 3.94, 3.95
rlm@3 219 $known_encoder_values[0x80][67][1][1][3][2][18000] = '--preset tape'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 220 $known_encoder_values[0x80][67][1][1][3][2][15000] = '--preset radio'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 221 $known_encoder_values[0x70][67][1][1][3][2][15000] = '--preset fm'; // 3.90, 3.90.1, 3.90.2, 3.91, 3.92
rlm@3 222 $known_encoder_values[0x70][58][2][2][3][2][16000] = '--preset tape/radio/fm'; // 3.90.3, 3.93, 3.93.1
rlm@3 223 $known_encoder_values[0x70][57][2][1][3][4][16000] = '--preset tape/radio/fm'; // 3.94, 3.95
rlm@3 224 $known_encoder_values[0x38][58][2][2][0][2][10000] = '--preset voice'; // 3.90.3, 3.93, 3.93.1
rlm@3 225 $known_encoder_values[0x38][57][2][1][0][4][15000] = '--preset voice'; // 3.94, 3.95
rlm@3 226 $known_encoder_values[0x38][57][2][1][0][4][16000] = '--preset voice'; // 3.94a14
rlm@3 227 $known_encoder_values[0x28][65][1][1][0][2][7500] = '--preset mw-us'; // 3.90, 3.90.1, 3.92
rlm@3 228 $known_encoder_values[0x28][65][1][1][0][2][7600] = '--preset mw-us'; // 3.90.2, 3.91
rlm@3 229 $known_encoder_values[0x28][58][2][2][0][2][7000] = '--preset mw-us'; // 3.90.3, 3.93, 3.93.1
rlm@3 230 $known_encoder_values[0x28][57][2][1][0][4][10500] = '--preset mw-us'; // 3.94, 3.95
rlm@3 231 $known_encoder_values[0x28][57][2][1][0][4][11200] = '--preset mw-us'; // 3.94a14
rlm@3 232 $known_encoder_values[0x28][57][2][1][0][4][8800] = '--preset mw-us'; // 3.94a15
rlm@3 233 $known_encoder_values[0x18][58][2][2][0][2][4000] = '--preset phon+/lw/mw-eu/sw'; // 3.90.3, 3.93.1
rlm@3 234 $known_encoder_values[0x18][58][2][2][0][2][3900] = '--preset phon+/lw/mw-eu/sw'; // 3.93
rlm@3 235 $known_encoder_values[0x18][57][2][1][0][4][5900] = '--preset phon+/lw/mw-eu/sw'; // 3.94, 3.95
rlm@3 236 $known_encoder_values[0x18][57][2][1][0][4][6200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a14
rlm@3 237 $known_encoder_values[0x18][57][2][1][0][4][3200] = '--preset phon+/lw/mw-eu/sw'; // 3.94a15
rlm@3 238 $known_encoder_values[0x10][58][2][2][0][2][3800] = '--preset phone'; // 3.90.3, 3.93.1
rlm@3 239 $known_encoder_values[0x10][58][2][2][0][2][3700] = '--preset phone'; // 3.93
rlm@3 240 $known_encoder_values[0x10][57][2][1][0][4][5600] = '--preset phone'; // 3.94, 3.95
rlm@3 241 }
rlm@3 242
rlm@3 243 if (isset($known_encoder_values[$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']])) {
rlm@3 244
rlm@3 245 $encoder_options = $known_encoder_values[$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']];
rlm@3 246
rlm@3 247 } elseif (isset($known_encoder_values['**'][$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']])) {
rlm@3 248
rlm@3 249 $encoder_options = $known_encoder_values['**'][$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']];
rlm@3 250
rlm@3 251 } elseif ($info['audio']['bitrate_mode'] == 'vbr') {
rlm@3 252
rlm@3 253 // http://gabriel.mp3-tech.org/mp3infotag.html
rlm@3 254 // int Quality = (100 - 10 * gfp->VBR_q - gfp->quality)h
rlm@3 255
rlm@3 256
rlm@3 257 $lame_v_value = 10 - ceil($thisfile_mpeg_audio_lame['vbr_quality'] / 10);
rlm@3 258 $lame_q_value = 100 - $thisfile_mpeg_audio_lame['vbr_quality'] - ($lame_v_value * 10);
rlm@3 259 $encoder_options = '-V'.$lame_v_value.' -q'.$lame_q_value;
rlm@3 260
rlm@3 261 } elseif ($info['audio']['bitrate_mode'] == 'cbr') {
rlm@3 262
rlm@3 263 $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
rlm@3 264
rlm@3 265 } else {
rlm@3 266
rlm@3 267 $encoder_options = strtoupper($info['audio']['bitrate_mode']);
rlm@3 268
rlm@3 269 }
rlm@3 270
rlm@3 271 } elseif (!empty($thisfile_mpeg_audio_lame['bitrate_abr'])) {
rlm@3 272
rlm@3 273 $encoder_options = 'ABR'.$thisfile_mpeg_audio_lame['bitrate_abr'];
rlm@3 274
rlm@3 275 } elseif (!empty($info['audio']['bitrate'])) {
rlm@3 276
rlm@3 277 if ($info['audio']['bitrate_mode'] == 'cbr') {
rlm@3 278 $encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
rlm@3 279 } else {
rlm@3 280 $encoder_options = strtoupper($info['audio']['bitrate_mode']);
rlm@3 281 }
rlm@3 282
rlm@3 283 }
rlm@3 284 if (!empty($thisfile_mpeg_audio_lame['bitrate_min'])) {
rlm@3 285 $encoder_options .= ' -b'.$thisfile_mpeg_audio_lame['bitrate_min'];
rlm@3 286 }
rlm@3 287
rlm@3 288 if (@$thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] || @$thisfile_mpeg_audio_lame['encoding_flags']['nogap_next']) {
rlm@3 289 $encoder_options .= ' --nogap';
rlm@3 290 }
rlm@3 291
rlm@3 292 if (!empty($thisfile_mpeg_audio_lame['lowpass_frequency'])) {
rlm@3 293 $exploded_options = explode(' ', $encoder_options, 4);
rlm@3 294 if ($exploded_options[0] == '--r3mix') {
rlm@3 295 $exploded_options[1] = 'r3mix';
rlm@3 296 }
rlm@3 297 switch ($exploded_options[0]) {
rlm@3 298 case '--preset':
rlm@3 299 case '--alt-preset':
rlm@3 300 case '--r3mix':
rlm@3 301 if ($exploded_options[1] == 'fast') {
rlm@3 302 $exploded_options[1] .= ' '.$exploded_options[2];
rlm@3 303 }
rlm@3 304 switch ($exploded_options[1]) {
rlm@3 305 case 'portable':
rlm@3 306 case 'medium':
rlm@3 307 case 'standard':
rlm@3 308 case 'extreme':
rlm@3 309 case 'insane':
rlm@3 310 case 'fast portable':
rlm@3 311 case 'fast medium':
rlm@3 312 case 'fast standard':
rlm@3 313 case 'fast extreme':
rlm@3 314 case 'fast insane':
rlm@3 315 case 'r3mix':
rlm@3 316 static $expected_lowpass = array (
rlm@3 317 'insane|20500' => 20500,
rlm@3 318 'insane|20600' => 20600, // 3.90.2, 3.90.3, 3.91
rlm@3 319 'medium|18000' => 18000,
rlm@3 320 'fast medium|18000' => 18000,
rlm@3 321 'extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
rlm@3 322 'extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
rlm@3 323 'fast extreme|19500' => 19500, // 3.90, 3.90.1, 3.92, 3.95
rlm@3 324 'fast extreme|19600' => 19600, // 3.90.2, 3.90.3, 3.91, 3.93.1
rlm@3 325 'standard|19000' => 19000,
rlm@3 326 'fast standard|19000' => 19000,
rlm@3 327 'r3mix|19500' => 19500, // 3.90, 3.90.1, 3.92
rlm@3 328 'r3mix|19600' => 19600, // 3.90.2, 3.90.3, 3.91
rlm@3 329 'r3mix|18000' => 18000, // 3.94, 3.95
rlm@3 330 );
rlm@3 331 if (!isset($expected_lowpass[$exploded_options[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))) {
rlm@3 332 $encoder_options .= ' --lowpass '.$thisfile_mpeg_audio_lame['lowpass_frequency'];
rlm@3 333 }
rlm@3 334 break;
rlm@3 335
rlm@3 336 default:
rlm@3 337 break;
rlm@3 338 }
rlm@3 339 break;
rlm@3 340 }
rlm@3 341 }
rlm@3 342
rlm@3 343 if (isset($thisfile_mpeg_audio_lame['raw']['source_sample_freq'])) {
rlm@3 344 if (($thisfile_mpeg_audio['sample_rate'] == 44100) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 1)) {
rlm@3 345 $encoder_options .= ' --resample 44100';
rlm@3 346 } elseif (($thisfile_mpeg_audio['sample_rate'] == 48000) && ($thisfile_mpeg_audio_lame['raw']['source_sample_freq'] != 2)) {
rlm@3 347 $encoder_options .= ' --resample 48000';
rlm@3 348 } elseif ($thisfile_mpeg_audio['sample_rate'] < 44100) {
rlm@3 349 switch ($thisfile_mpeg_audio_lame['raw']['source_sample_freq']) {
rlm@3 350 case 0: // <= 32000
rlm@3 351 // may or may not be same as source frequency - ignore
rlm@3 352 break;
rlm@3 353 case 1: // 44100
rlm@3 354 case 2: // 48000
rlm@3 355 case 3: // 48000+
rlm@3 356 $exploded_options = explode(' ', $encoder_options, 4);
rlm@3 357 switch ($exploded_options[0]) {
rlm@3 358 case '--preset':
rlm@3 359 case '--alt-preset':
rlm@3 360 switch ($exploded_options[1]) {
rlm@3 361 case 'fast':
rlm@3 362 case 'portable':
rlm@3 363 case 'medium':
rlm@3 364 case 'standard':
rlm@3 365 case 'extreme':
rlm@3 366 case 'insane':
rlm@3 367 $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
rlm@3 368 break;
rlm@3 369
rlm@3 370 default:
rlm@3 371 static $expected_resampled_rate = array (
rlm@3 372 'phon+/lw/mw-eu/sw|16000' => 16000,
rlm@3 373 'mw-us|24000' => 24000, // 3.95
rlm@3 374 'mw-us|32000' => 32000, // 3.93
rlm@3 375 'mw-us|16000' => 16000, // 3.92
rlm@3 376 'phone|16000' => 16000,
rlm@3 377 'phone|11025' => 11025, // 3.94a15
rlm@3 378 'radio|32000' => 32000, // 3.94a15
rlm@3 379 'fm/radio|32000' => 32000, // 3.92
rlm@3 380 'fm|32000' => 32000, // 3.90
rlm@3 381 'voice|32000' => 32000);
rlm@3 382 if (!isset($expected_resampled_rate[$exploded_options[1].'|'.$thisfile_mpeg_audio['sample_rate']])) {
rlm@3 383 $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
rlm@3 384 }
rlm@3 385 break;
rlm@3 386 }
rlm@3 387 break;
rlm@3 388
rlm@3 389 case '--r3mix':
rlm@3 390 default:
rlm@3 391 $encoder_options .= ' --resample '.$thisfile_mpeg_audio['sample_rate'];
rlm@3 392 break;
rlm@3 393 }
rlm@3 394 break;
rlm@3 395 }
rlm@3 396 }
rlm@3 397 }
rlm@3 398 if (empty($encoder_options) && !empty($info['audio']['bitrate']) && !empty($info['audio']['bitrate_mode'])) {
rlm@3 399 //$encoder_options = strtoupper($info['audio']['bitrate_mode']).ceil($info['audio']['bitrate'] / 1000);
rlm@3 400 $encoder_options = strtoupper($info['audio']['bitrate_mode']);
rlm@3 401 }
rlm@3 402
rlm@3 403 return $encoder_options;
rlm@3 404 }
rlm@3 405
rlm@3 406
rlm@3 407
rlm@3 408 public function decodeMPEGaudioHeader($fd, $offset, &$info, $recursive_search=true, $scan_as_cbr=false, $fast_mpeg_header_scan=false) {
rlm@3 409
rlm@3 410 static $mpeg_audio_version_lookup;
rlm@3 411 static $mpeg_audio_layer_lookup;
rlm@3 412 static $mpeg_audio_bitrate_lookup;
rlm@3 413 static $mpeg_audio_frequency_lookup;
rlm@3 414 static $mpeg_audio_channel_mode_lookup;
rlm@3 415 static $mpeg_audio_mode_extension_lookup;
rlm@3 416 static $mpeg_audio_emphasis_lookup;
rlm@3 417 if (empty($mpeg_audio_version_lookup)) {
rlm@3 418 $mpeg_audio_version_lookup = getid3_mp3::MPEGaudioVersionarray();
rlm@3 419 $mpeg_audio_layer_lookup = getid3_mp3::MPEGaudioLayerarray();
rlm@3 420 $mpeg_audio_bitrate_lookup = getid3_mp3::MPEGaudioBitratearray();
rlm@3 421 $mpeg_audio_frequency_lookup = getid3_mp3::MPEGaudioFrequencyarray();
rlm@3 422 $mpeg_audio_channel_mode_lookup = getid3_mp3::MPEGaudioChannelModearray();
rlm@3 423 $mpeg_audio_mode_extension_lookup = getid3_mp3::MPEGaudioModeExtensionarray();
rlm@3 424 $mpeg_audio_emphasis_lookup = getid3_mp3::MPEGaudioEmphasisarray();
rlm@3 425 }
rlm@3 426
rlm@3 427 if ($offset >= $info['avdataend']) {
rlm@3 428
rlm@3 429 // non-fatal error: 'end of file encounter looking for MPEG synch'
rlm@3 430 return;
rlm@3 431
rlm@3 432 }
rlm@3 433 fseek($fd, $offset, SEEK_SET);
rlm@3 434 $header_string = fread($fd, 226); // LAME header at offset 36 + 190 bytes of Xing/LAME data
rlm@3 435
rlm@3 436 // MP3 audio frame structure:
rlm@3 437 // $aa $aa $aa $aa [$bb $bb] $cc...
rlm@3 438 // where $aa..$aa is the four-byte mpeg-audio header (below)
rlm@3 439 // $bb $bb is the optional 2-byte CRC
rlm@3 440 // and $cc... is the audio data
rlm@3 441
rlm@3 442 $head4 = substr($header_string, 0, 4);
rlm@3 443
rlm@3 444 if (isset($mpeg_audio_header_decode_cache[$head4])) {
rlm@3 445 $mpeg_header_raw_array= $mpeg_audio_header_decode_cache[$head4];
rlm@3 446 } else {
rlm@3 447 $mpeg_header_raw_array = getid3_mp3::MPEGaudioHeaderDecode($head4);
rlm@3 448 $mpeg_audio_header_decode_cache[$head4] = $mpeg_header_raw_array;
rlm@3 449 }
rlm@3 450
rlm@3 451 // Not in cache
rlm@3 452 if (!isset($mpeg_audio_header_valid_cache[$head4])) {
rlm@3 453 $mpeg_audio_header_valid_cache[$head4] = getid3_mp3::MPEGaudioHeaderValid($mpeg_header_raw_array, false, false);
rlm@3 454 }
rlm@3 455
rlm@3 456 // shortcut
rlm@3 457 if (!isset($info['mpeg']['audio'])) {
rlm@3 458 $info['mpeg']['audio'] = array ();
rlm@3 459 }
rlm@3 460 $thisfile_mpeg_audio = &$info['mpeg']['audio'];
rlm@3 461
rlm@3 462
rlm@3 463 if ($mpeg_audio_header_valid_cache[$head4]) {
rlm@3 464 $thisfile_mpeg_audio['raw'] = $mpeg_header_raw_array;
rlm@3 465 } else {
rlm@3 466
rlm@3 467 // non-fatal error: Invalid MPEG audio header at offset $offset
rlm@3 468 return;
rlm@3 469 }
rlm@3 470
rlm@3 471 if (!$fast_mpeg_header_scan) {
rlm@3 472
rlm@3 473 $thisfile_mpeg_audio['version'] = $mpeg_audio_version_lookup[$thisfile_mpeg_audio['raw']['version']];
rlm@3 474 $thisfile_mpeg_audio['layer'] = $mpeg_audio_layer_lookup[$thisfile_mpeg_audio['raw']['layer']];
rlm@3 475
rlm@3 476 $thisfile_mpeg_audio['channelmode'] = $mpeg_audio_channel_mode_lookup[$thisfile_mpeg_audio['raw']['channelmode']];
rlm@3 477 $thisfile_mpeg_audio['channels'] = (($thisfile_mpeg_audio['channelmode'] == 'mono') ? 1 : 2);
rlm@3 478 $thisfile_mpeg_audio['sample_rate'] = $mpeg_audio_frequency_lookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['raw']['sample_rate']];
rlm@3 479 $thisfile_mpeg_audio['protection'] = !$thisfile_mpeg_audio['raw']['protection'];
rlm@3 480 $thisfile_mpeg_audio['private'] = (bool) $thisfile_mpeg_audio['raw']['private'];
rlm@3 481 $thisfile_mpeg_audio['modeextension'] = $mpeg_audio_mode_extension_lookup[$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['modeextension']];
rlm@3 482 $thisfile_mpeg_audio['copyright'] = (bool) $thisfile_mpeg_audio['raw']['copyright'];
rlm@3 483 $thisfile_mpeg_audio['original'] = (bool) $thisfile_mpeg_audio['raw']['original'];
rlm@3 484 $thisfile_mpeg_audio['emphasis'] = $mpeg_audio_emphasis_lookup[$thisfile_mpeg_audio['raw']['emphasis']];
rlm@3 485
rlm@3 486 $info['audio']['channels'] = $thisfile_mpeg_audio['channels'];
rlm@3 487 $info['audio']['sample_rate'] = $thisfile_mpeg_audio['sample_rate'];
rlm@3 488
rlm@3 489 if ($thisfile_mpeg_audio['protection']) {
rlm@3 490 $thisfile_mpeg_audio['crc'] = getid3_lib::BigEndian2Int(substr($header_string, 4, 2));
rlm@3 491 }
rlm@3 492
rlm@3 493 }
rlm@3 494
rlm@3 495 if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) {
rlm@3 496 // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0
rlm@3 497 $this->getid3->warning('Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1');
rlm@3 498 $thisfile_mpeg_audio['raw']['bitrate'] = 0;
rlm@3 499 }
rlm@3 500 $thisfile_mpeg_audio['padding'] = (bool) $thisfile_mpeg_audio['raw']['padding'];
rlm@3 501 $thisfile_mpeg_audio['bitrate'] = $mpeg_audio_bitrate_lookup[$thisfile_mpeg_audio['version']][$thisfile_mpeg_audio['layer']][$thisfile_mpeg_audio['raw']['bitrate']];
rlm@3 502
rlm@3 503 if (($thisfile_mpeg_audio['bitrate'] == 'free') && ($offset == $info['avdataoffset'])) {
rlm@3 504 // only skip multiple frame check if free-format bitstream found at beginning of file
rlm@3 505 // otherwise is quite possibly simply corrupted data
rlm@3 506 $recursive_search = false;
rlm@3 507 }
rlm@3 508
rlm@3 509 // For Layer 2 there are some combinations of bitrate and mode which are not allowed.
rlm@3 510 if (!$fast_mpeg_header_scan && ($thisfile_mpeg_audio['layer'] == '2')) {
rlm@3 511
rlm@3 512 $info['audio']['dataformat'] = 'mp2';
rlm@3 513 switch ($thisfile_mpeg_audio['channelmode']) {
rlm@3 514
rlm@3 515 case 'mono':
rlm@3 516 if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] <= 192000)) {
rlm@3 517 // these are ok
rlm@3 518 } else {
rlm@3 519
rlm@3 520 // non-fatal error: bitrate not allowed in Layer 2/mono
rlm@3 521 return;
rlm@3 522 }
rlm@3 523 break;
rlm@3 524
rlm@3 525 case 'stereo':
rlm@3 526 case 'joint stereo':
rlm@3 527 case 'dual channel':
rlm@3 528 if (($thisfile_mpeg_audio['bitrate'] == 'free') || ($thisfile_mpeg_audio['bitrate'] == 64000) || ($thisfile_mpeg_audio['bitrate'] >= 96000)) {
rlm@3 529 // these are ok
rlm@3 530 } else {
rlm@3 531
rlm@3 532 // non-fatal error: bitrate not allowed in Layer 2/stereo/joint stereo/dual channel
rlm@3 533 return;
rlm@3 534 }
rlm@3 535 break;
rlm@3 536
rlm@3 537 }
rlm@3 538
rlm@3 539 }
rlm@3 540
rlm@3 541
rlm@3 542 if ($info['audio']['sample_rate'] > 0) {
rlm@3 543 $thisfile_mpeg_audio['framelength'] = getid3_mp3::MPEGaudioFrameLength($thisfile_mpeg_audio['bitrate'], $thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['layer'], (int) $thisfile_mpeg_audio['padding'], $info['audio']['sample_rate']);
rlm@3 544 }
rlm@3 545
rlm@3 546 $next_frame_test_offset = $offset + 1;
rlm@3 547 if ($thisfile_mpeg_audio['bitrate'] != 'free') {
rlm@3 548
rlm@3 549 $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
rlm@3 550
rlm@3 551 if (isset($thisfile_mpeg_audio['framelength'])) {
rlm@3 552 $next_frame_test_offset = $offset + $thisfile_mpeg_audio['framelength'];
rlm@3 553 } else {
rlm@3 554
rlm@3 555 // non-fatal error: Frame at offset('.$offset.') is has an invalid frame length.
rlm@3 556 return;
rlm@3 557 }
rlm@3 558
rlm@3 559 }
rlm@3 560
rlm@3 561 $expected_number_of_audio_bytes = 0;
rlm@3 562
rlm@3 563 ////////////////////////////////////////////////////////////////////////////////////
rlm@3 564 // Variable-bitrate headers
rlm@3 565
rlm@3 566 if (substr($header_string, 4 + 32, 4) == 'VBRI') {
rlm@3 567 // Fraunhofer VBR header is hardcoded 'VBRI' at offset 0x24 (36)
rlm@3 568 // specs taken from http://minnie.tuhs.org/pipermail/mp3encoder/2001-January/001800.html
rlm@3 569
rlm@3 570 $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
rlm@3 571 $thisfile_mpeg_audio['VBR_method'] = 'Fraunhofer';
rlm@3 572 $info['audio']['codec'] = 'Fraunhofer';
rlm@3 573
rlm@3 574 $side_info_data = substr($header_string, 4 + 2, 32);
rlm@3 575
rlm@3 576 $fraunhofer_vbr_offset = 36;
rlm@3 577
rlm@3 578 $thisfile_mpeg_audio['VBR_encoder_version'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 4, 2)); // VbriVersion
rlm@3 579 $thisfile_mpeg_audio['VBR_encoder_delay'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 6, 2)); // VbriDelay
rlm@3 580 $thisfile_mpeg_audio['VBR_quality'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 8, 2)); // VbriQuality
rlm@3 581 $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 10, 4)); // VbriStreamBytes
rlm@3 582 $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 14, 4)); // VbriStreamFrames
rlm@3 583 $thisfile_mpeg_audio['VBR_seek_offsets'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 18, 2)); // VbriTableSize
rlm@3 584 $thisfile_mpeg_audio['VBR_seek_scale'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 20, 2)); // VbriTableScale
rlm@3 585 $thisfile_mpeg_audio['VBR_entry_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 22, 2)); // VbriEntryBytes
rlm@3 586 $thisfile_mpeg_audio['VBR_entry_frames'] = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset + 24, 2)); // VbriEntryFrames
rlm@3 587
rlm@3 588 $expected_number_of_audio_bytes = $thisfile_mpeg_audio['VBR_bytes'];
rlm@3 589
rlm@3 590 $previous_byte_offset = $offset;
rlm@3 591 for ($i = 0; $i < $thisfile_mpeg_audio['VBR_seek_offsets']; $i++) {
rlm@3 592 $fraunhofer_offset_n = getid3_lib::BigEndian2Int(substr($header_string, $fraunhofer_vbr_offset, $thisfile_mpeg_audio['VBR_entry_bytes']));
rlm@3 593 $fraunhofer_vbr_offset += $thisfile_mpeg_audio['VBR_entry_bytes'];
rlm@3 594 $thisfile_mpeg_audio['VBR_offsets_relative'][$i] = ($fraunhofer_offset_n * $thisfile_mpeg_audio['VBR_seek_scale']);
rlm@3 595 $thisfile_mpeg_audio['VBR_offsets_absolute'][$i] = ($fraunhofer_offset_n * $thisfile_mpeg_audio['VBR_seek_scale']) + $previous_byte_offset;
rlm@3 596 $previous_byte_offset += $fraunhofer_offset_n;
rlm@3 597 }
rlm@3 598
rlm@3 599
rlm@3 600 } else {
rlm@3 601
rlm@3 602 // Xing VBR header is hardcoded 'Xing' at a offset 0x0D (13), 0x15 (21) or 0x24 (36)
rlm@3 603 // depending on MPEG layer and number of channels
rlm@3 604
rlm@3 605 $vbr_id_offset = getid3_mp3::XingVBRidOffset($thisfile_mpeg_audio['version'], $thisfile_mpeg_audio['channelmode']);
rlm@3 606 $side_info_data = substr($header_string, 4 + 2, $vbr_id_offset - 4);
rlm@3 607
rlm@3 608 if ((substr($header_string, $vbr_id_offset, strlen('Xing')) == 'Xing') || (substr($header_string, $vbr_id_offset, strlen('Info')) == 'Info')) {
rlm@3 609 // 'Xing' is traditional Xing VBR frame
rlm@3 610 // 'Info' is LAME-encoded CBR (This was done to avoid CBR files to be recognized as traditional Xing VBR files by some decoders.)
rlm@3 611 // 'Info' *can* legally be used to specify a VBR file as well, however.
rlm@3 612
rlm@3 613 // http://www.multiweb.cz/twoinches/MP3inside.htm
rlm@3 614 //00..03 = "Xing" or "Info"
rlm@3 615 //04..07 = Flags:
rlm@3 616 // 0x01 Frames Flag set if value for number of frames in file is stored
rlm@3 617 // 0x02 Bytes Flag set if value for filesize in bytes is stored
rlm@3 618 // 0x04 TOC Flag set if values for TOC are stored
rlm@3 619 // 0x08 VBR Scale Flag set if values for VBR scale is stored
rlm@3 620 //08..11 Frames: Number of frames in file (including the first Xing/Info one)
rlm@3 621 //12..15 Bytes: File length in Bytes
rlm@3 622 //16..115 TOC (Table of Contents):
rlm@3 623 // Contains of 100 indexes (one Byte length) for easier lookup in file. Approximately solves problem with moving inside file.
rlm@3 624 // Each Byte has a value according this formula:
rlm@3 625 // (TOC[i] / 256) * fileLenInBytes
rlm@3 626 // 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:
rlm@3 627 // TOC[(60/240)*100] = TOC[25]
rlm@3 628 // and corresponding Byte in file is then approximately at:
rlm@3 629 // (TOC[25]/256) * 5000000
rlm@3 630 //116..119 VBR Scale
rlm@3 631
rlm@3 632
rlm@3 633 // should be safe to leave this at 'vbr' and let it be overriden to 'cbr' if a CBR preset/mode is used by LAME
rlm@3 634 $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
rlm@3 635 $thisfile_mpeg_audio['VBR_method'] = 'Xing';
rlm@3 636
rlm@3 637 $thisfile_mpeg_audio['xing_flags_raw'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 4, 4));
rlm@3 638
rlm@3 639 $thisfile_mpeg_audio['xing_flags']['frames'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000001);
rlm@3 640 $thisfile_mpeg_audio['xing_flags']['bytes'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000002);
rlm@3 641 $thisfile_mpeg_audio['xing_flags']['toc'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000004);
rlm@3 642 $thisfile_mpeg_audio['xing_flags']['vbr_scale'] = (bool) ($thisfile_mpeg_audio['xing_flags_raw'] & 0x00000008);
rlm@3 643
rlm@3 644 if ($thisfile_mpeg_audio['xing_flags']['frames']) {
rlm@3 645 $thisfile_mpeg_audio['VBR_frames'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 8, 4));
rlm@3 646 }
rlm@3 647 if ($thisfile_mpeg_audio['xing_flags']['bytes']) {
rlm@3 648 $thisfile_mpeg_audio['VBR_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 12, 4));
rlm@3 649 }
rlm@3 650
rlm@3 651 if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
rlm@3 652
rlm@3 653 $frame_lengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'];
rlm@3 654
rlm@3 655 if ($thisfile_mpeg_audio['layer'] == '1') {
rlm@3 656 // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
rlm@3 657 $info['audio']['bitrate'] = ($frame_lengthfloat / 4) * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 12;
rlm@3 658 } else {
rlm@3 659 // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
rlm@3 660 $info['audio']['bitrate'] = $frame_lengthfloat * $thisfile_mpeg_audio['sample_rate'] * (2 / $info['audio']['channels']) / 144;
rlm@3 661 }
rlm@3 662 $thisfile_mpeg_audio['framelength'] = floor($frame_lengthfloat);
rlm@3 663 }
rlm@3 664
rlm@3 665 if ($thisfile_mpeg_audio['xing_flags']['toc']) {
rlm@3 666 $lame_toc_data = substr($header_string, $vbr_id_offset + 16, 100);
rlm@3 667 for ($i = 0; $i < 100; $i++) {
rlm@3 668 $thisfile_mpeg_audio['toc'][$i] = ord($lame_toc_data{$i});
rlm@3 669 }
rlm@3 670 }
rlm@3 671 if ($thisfile_mpeg_audio['xing_flags']['vbr_scale']) {
rlm@3 672 $thisfile_mpeg_audio['VBR_scale'] = getid3_lib::BigEndian2Int(substr($header_string, $vbr_id_offset + 116, 4));
rlm@3 673 }
rlm@3 674
rlm@3 675
rlm@3 676 // http://gabriel.mp3-tech.org/mp3infotag.html
rlm@3 677 if (substr($header_string, $vbr_id_offset + 120, 4) == 'LAME') {
rlm@3 678
rlm@3 679 // shortcut
rlm@3 680 $thisfile_mpeg_audio['LAME'] = array ();
rlm@3 681 $thisfile_mpeg_audio_lame = &$thisfile_mpeg_audio['LAME'];
rlm@3 682
rlm@3 683
rlm@3 684 $thisfile_mpeg_audio_lame['long_version'] = substr($header_string, $vbr_id_offset + 120, 20);
rlm@3 685 $thisfile_mpeg_audio_lame['short_version'] = substr($thisfile_mpeg_audio_lame['long_version'], 0, 9);
rlm@3 686
rlm@3 687 if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.90') {
rlm@3 688
rlm@3 689 // extra 11 chars are not part of version string when LAMEtag present
rlm@3 690 unset($thisfile_mpeg_audio_lame['long_version']);
rlm@3 691
rlm@3 692 // It the LAME tag was only introduced in LAME v3.90
rlm@3 693 // http://www.hydrogenaudio.org/?act=ST&f=15&t=9933
rlm@3 694
rlm@3 695 // Offsets of various bytes in http://gabriel.mp3-tech.org/mp3infotag.html
rlm@3 696 // are assuming a 'Xing' identifier offset of 0x24, which is the case for
rlm@3 697 // MPEG-1 non-mono, but not for other combinations
rlm@3 698 $lame_tag_offset_contant = $vbr_id_offset - 0x24;
rlm@3 699
rlm@3 700 // shortcuts
rlm@3 701 $thisfile_mpeg_audio_lame['RGAD'] = array ('track'=>array(), 'album'=>array());
rlm@3 702 $thisfile_mpeg_audio_lame_rgad = &$thisfile_mpeg_audio_lame['RGAD'];
rlm@3 703 $thisfile_mpeg_audio_lame_rgad_track = &$thisfile_mpeg_audio_lame_rgad['track'];
rlm@3 704 $thisfile_mpeg_audio_lame_rgad_album = &$thisfile_mpeg_audio_lame_rgad['album'];
rlm@3 705 $thisfile_mpeg_audio_lame['raw'] = array ();
rlm@3 706 $thisfile_mpeg_audio_lame_raw = &$thisfile_mpeg_audio_lame['raw'];
rlm@3 707
rlm@3 708 // byte $9B VBR Quality
rlm@3 709 // This field is there to indicate a quality level, although the scale was not precised in the original Xing specifications.
rlm@3 710 // Actually overwrites original Xing bytes
rlm@3 711 unset($thisfile_mpeg_audio['VBR_scale']);
rlm@3 712 $thisfile_mpeg_audio_lame['vbr_quality'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0x9B, 1));
rlm@3 713
rlm@3 714 // bytes $9C-$A4 Encoder short VersionString
rlm@3 715 $thisfile_mpeg_audio_lame['short_version'] = substr($header_string, $lame_tag_offset_contant + 0x9C, 9);
rlm@3 716
rlm@3 717 // byte $A5 Info Tag revision + VBR method
rlm@3 718 $lame_tagRevisionVBRmethod = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xA5, 1));
rlm@3 719
rlm@3 720 $thisfile_mpeg_audio_lame['tag_revision'] = ($lame_tagRevisionVBRmethod & 0xF0) >> 4;
rlm@3 721 $thisfile_mpeg_audio_lame_raw['vbr_method'] = $lame_tagRevisionVBRmethod & 0x0F;
rlm@3 722 $thisfile_mpeg_audio_lame['vbr_method'] = getid3_mp3::LAMEvbrMethodLookup($thisfile_mpeg_audio_lame_raw['vbr_method']);
rlm@3 723 $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'
rlm@3 724
rlm@3 725 // byte $A6 Lowpass filter value
rlm@3 726 $thisfile_mpeg_audio_lame['lowpass_frequency'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xA6, 1)) * 100;
rlm@3 727
rlm@3 728 // bytes $A7-$AE Replay Gain
rlm@3 729 // http://privatewww.essex.ac.uk/~djmrob/replaygain/rg_data_format.html
rlm@3 730 // bytes $A7-$AA : 32 bit floating point "Peak signal amplitude"
rlm@3 731 if ($thisfile_mpeg_audio_lame['short_version'] >= 'LAME3.94b') {
rlm@3 732 // LAME 3.94a16 and later - 9.23 fixed point
rlm@3 733 // ie 0x0059E2EE / (2^23) = 5890798 / 8388608 = 0.7022378444671630859375
rlm@3 734 $thisfile_mpeg_audio_lame_rgad['peak_amplitude'] = (float) ((getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xA7, 4))) / 8388608);
rlm@3 735 } else {
rlm@3 736 // LAME 3.94a15 and earlier - 32-bit floating point
rlm@3 737 // Actually 3.94a16 will fall in here too and be WRONG, but is hard to detect 3.94a16 vs 3.94a15
rlm@3 738 $thisfile_mpeg_audio_lame_rgad['peak_amplitude'] = getid3_lib::LittleEndian2Float(substr($header_string, $lame_tag_offset_contant + 0xA7, 4));
rlm@3 739 }
rlm@3 740 if ($thisfile_mpeg_audio_lame_rgad['peak_amplitude'] == 0) {
rlm@3 741 unset($thisfile_mpeg_audio_lame_rgad['peak_amplitude']);
rlm@3 742 } else {
rlm@3 743 $thisfile_mpeg_audio_lame_rgad['peak_db'] = 20 * log10($thisfile_mpeg_audio_lame_rgad['peak_amplitude']);
rlm@3 744 }
rlm@3 745
rlm@3 746 $thisfile_mpeg_audio_lame_raw['RGAD_track'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xAB, 2));
rlm@3 747 $thisfile_mpeg_audio_lame_raw['RGAD_album'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xAD, 2));
rlm@3 748
rlm@3 749
rlm@3 750 if ($thisfile_mpeg_audio_lame_raw['RGAD_track'] != 0) {
rlm@3 751
rlm@3 752 $thisfile_mpeg_audio_lame_rgad_track['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0xE000) >> 13;
rlm@3 753 $thisfile_mpeg_audio_lame_rgad_track['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x1C00) >> 10;
rlm@3 754 $thisfile_mpeg_audio_lame_rgad_track['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x0200) >> 9;
rlm@3 755 $thisfile_mpeg_audio_lame_rgad_track['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_track'] & 0x01FF;
rlm@3 756 $thisfile_mpeg_audio_lame_rgad_track['name'] = getid3_lib_replaygain::NameLookup($thisfile_mpeg_audio_lame_rgad_track['raw']['name']);
rlm@3 757 $thisfile_mpeg_audio_lame_rgad_track['originator'] = getid3_lib_replaygain::OriginatorLookup($thisfile_mpeg_audio_lame_rgad_track['raw']['originator']);
rlm@3 758 $thisfile_mpeg_audio_lame_rgad_track['gain_db'] = getid3_lib_replaygain::AdjustmentLookup($thisfile_mpeg_audio_lame_rgad_track['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_rgad_track['raw']['sign_bit']);
rlm@3 759
rlm@3 760 if (!empty($thisfile_mpeg_audio_lame_rgad['peak_amplitude'])) {
rlm@3 761 $info['replay_gain']['track']['peak'] = $thisfile_mpeg_audio_lame_rgad['peak_amplitude'];
rlm@3 762 }
rlm@3 763 $info['replay_gain']['track']['originator'] = $thisfile_mpeg_audio_lame_rgad_track['originator'];
rlm@3 764 $info['replay_gain']['track']['adjustment'] = $thisfile_mpeg_audio_lame_rgad_track['gain_db'];
rlm@3 765 } else {
rlm@3 766 unset($thisfile_mpeg_audio_lame_rgad['track']);
rlm@3 767 }
rlm@3 768 if ($thisfile_mpeg_audio_lame_raw['RGAD_album'] != 0) {
rlm@3 769
rlm@3 770 $thisfile_mpeg_audio_lame_rgad_album['raw']['name'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0xE000) >> 13;
rlm@3 771 $thisfile_mpeg_audio_lame_rgad_album['raw']['originator'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x1C00) >> 10;
rlm@3 772 $thisfile_mpeg_audio_lame_rgad_album['raw']['sign_bit'] = ($thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x0200) >> 9;
rlm@3 773 $thisfile_mpeg_audio_lame_rgad_album['raw']['gain_adjust'] = $thisfile_mpeg_audio_lame_raw['RGAD_album'] & 0x01FF;
rlm@3 774 $thisfile_mpeg_audio_lame_rgad_album['name'] = getid3_lib_replaygain::NameLookup($thisfile_mpeg_audio_lame_rgad_album['raw']['name']);
rlm@3 775 $thisfile_mpeg_audio_lame_rgad_album['originator'] = getid3_lib_replaygain::OriginatorLookup($thisfile_mpeg_audio_lame_rgad_album['raw']['originator']);
rlm@3 776 $thisfile_mpeg_audio_lame_rgad_album['gain_db'] = getid3_lib_replaygain::AdjustmentLookup($thisfile_mpeg_audio_lame_rgad_album['raw']['gain_adjust'], $thisfile_mpeg_audio_lame_rgad_album['raw']['sign_bit']);
rlm@3 777
rlm@3 778 if (!empty($thisfile_mpeg_audio_lame_rgad['peak_amplitude'])) {
rlm@3 779 $info['replay_gain']['album']['peak'] = $thisfile_mpeg_audio_lame_rgad['peak_amplitude'];
rlm@3 780 }
rlm@3 781 $info['replay_gain']['album']['originator'] = $thisfile_mpeg_audio_lame_rgad_album['originator'];
rlm@3 782 $info['replay_gain']['album']['adjustment'] = $thisfile_mpeg_audio_lame_rgad_album['gain_db'];
rlm@3 783 } else {
rlm@3 784 unset($thisfile_mpeg_audio_lame_rgad['album']);
rlm@3 785 }
rlm@3 786 if (empty($thisfile_mpeg_audio_lame_rgad)) {
rlm@3 787 unset($thisfile_mpeg_audio_lame['RGAD']);
rlm@3 788 }
rlm@3 789
rlm@3 790
rlm@3 791 // byte $AF Encoding flags + ATH Type
rlm@3 792 $encoding_flags_ath_type = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xAF, 1));
rlm@3 793 $thisfile_mpeg_audio_lame['encoding_flags']['nspsytune'] = (bool) ($encoding_flags_ath_type & 0x10);
rlm@3 794 $thisfile_mpeg_audio_lame['encoding_flags']['nssafejoint'] = (bool) ($encoding_flags_ath_type & 0x20);
rlm@3 795 $thisfile_mpeg_audio_lame['encoding_flags']['nogap_next'] = (bool) ($encoding_flags_ath_type & 0x40);
rlm@3 796 $thisfile_mpeg_audio_lame['encoding_flags']['nogap_prev'] = (bool) ($encoding_flags_ath_type & 0x80);
rlm@3 797 $thisfile_mpeg_audio_lame['ath_type'] = $encoding_flags_ath_type & 0x0F;
rlm@3 798
rlm@3 799 // byte $B0 if ABR {specified bitrate} else {minimal bitrate}
rlm@3 800 $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xB0, 1));
rlm@3 801 if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 2) { // Average BitRate (ABR)
rlm@3 802 $thisfile_mpeg_audio_lame['bitrate_abr'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'];
rlm@3 803 } elseif ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) { // Constant BitRate (CBR)
rlm@3 804 // ignore
rlm@3 805 } elseif ($thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'] > 0) { // Variable BitRate (VBR) - minimum bitrate
rlm@3 806 $thisfile_mpeg_audio_lame['bitrate_min'] = $thisfile_mpeg_audio_lame['raw']['abrbitrate_minbitrate'];
rlm@3 807 }
rlm@3 808
rlm@3 809 // bytes $B1-$B3 Encoder delays
rlm@3 810 $encoder_delays = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xB1, 3));
rlm@3 811 $thisfile_mpeg_audio_lame['encoder_delay'] = ($encoder_delays & 0xFFF000) >> 12;
rlm@3 812 $thisfile_mpeg_audio_lame['end_padding'] = $encoder_delays & 0x000FFF;
rlm@3 813
rlm@3 814 // byte $B4 Misc
rlm@3 815 $misc_byte = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xB4, 1));
rlm@3 816 $thisfile_mpeg_audio_lame_raw['noise_shaping'] = ($misc_byte & 0x03);
rlm@3 817 $thisfile_mpeg_audio_lame_raw['stereo_mode'] = ($misc_byte & 0x1C) >> 2;
rlm@3 818 $thisfile_mpeg_audio_lame_raw['not_optimal_quality'] = ($misc_byte & 0x20) >> 5;
rlm@3 819 $thisfile_mpeg_audio_lame_raw['source_sample_freq'] = ($misc_byte & 0xC0) >> 6;
rlm@3 820 $thisfile_mpeg_audio_lame['noise_shaping'] = $thisfile_mpeg_audio_lame_raw['noise_shaping'];
rlm@3 821 $thisfile_mpeg_audio_lame['stereo_mode'] = getid3_mp3::LAMEmiscStereoModeLookup($thisfile_mpeg_audio_lame_raw['stereo_mode']);
rlm@3 822 $thisfile_mpeg_audio_lame['not_optimal_quality'] = (bool) $thisfile_mpeg_audio_lame_raw['not_optimal_quality'];
rlm@3 823 $thisfile_mpeg_audio_lame['source_sample_freq'] = getid3_mp3::LAMEmiscSourceSampleFrequencyLookup($thisfile_mpeg_audio_lame_raw['source_sample_freq']);
rlm@3 824
rlm@3 825 // byte $B5 MP3 Gain
rlm@3 826 $thisfile_mpeg_audio_lame_raw['mp3_gain'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xB5, 1), false, true);
rlm@3 827 $thisfile_mpeg_audio_lame['mp3_gain_db'] = (20 * log10(2) / 4) * $thisfile_mpeg_audio_lame_raw['mp3_gain'];
rlm@3 828 $thisfile_mpeg_audio_lame['mp3_gain_factor'] = pow(2, ($thisfile_mpeg_audio_lame['mp3_gain_db'] / 6));
rlm@3 829
rlm@3 830 // bytes $B6-$B7 Preset and surround info
rlm@3 831 $PresetSurroundBytes = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xB6, 2));
rlm@3 832 // Reserved = ($PresetSurroundBytes & 0xC000);
rlm@3 833 $thisfile_mpeg_audio_lame_raw['surround_info'] = ($PresetSurroundBytes & 0x3800);
rlm@3 834 $thisfile_mpeg_audio_lame['surround_info'] = getid3_mp3::LAMEsurroundInfoLookup($thisfile_mpeg_audio_lame_raw['surround_info']);
rlm@3 835 $thisfile_mpeg_audio_lame['preset_used_id'] = ($PresetSurroundBytes & 0x07FF);
rlm@3 836 $thisfile_mpeg_audio_lame['preset_used'] = getid3_mp3::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame);
rlm@3 837 if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) {
rlm@3 838 $this->getid3->warning('Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org');
rlm@3 839 }
rlm@3 840 if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) {
rlm@3 841 // this may change if 3.90.4 ever comes out
rlm@3 842 $thisfile_mpeg_audio_lame['short_version'] = 'LAME3.90.3';
rlm@3 843 }
rlm@3 844
rlm@3 845 // bytes $B8-$BB MusicLength
rlm@3 846 $thisfile_mpeg_audio_lame['audio_bytes'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xB8, 4));
rlm@3 847 $expected_number_of_audio_bytes = (($thisfile_mpeg_audio_lame['audio_bytes'] > 0) ? $thisfile_mpeg_audio_lame['audio_bytes'] : $thisfile_mpeg_audio['VBR_bytes']);
rlm@3 848
rlm@3 849 // bytes $BC-$BD MusicCRC
rlm@3 850 $thisfile_mpeg_audio_lame['music_crc'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xBC, 2));
rlm@3 851
rlm@3 852 // bytes $BE-$BF CRC-16 of Info Tag
rlm@3 853 $thisfile_mpeg_audio_lame['lame_tag_crc'] = getid3_lib::BigEndian2Int(substr($header_string, $lame_tag_offset_contant + 0xBE, 2));
rlm@3 854
rlm@3 855
rlm@3 856 // LAME CBR
rlm@3 857 if ($thisfile_mpeg_audio_lame_raw['vbr_method'] == 1) {
rlm@3 858
rlm@3 859 $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
rlm@3 860 $thisfile_mpeg_audio['bitrate'] = getid3_mp3::ClosestStandardMP3Bitrate($thisfile_mpeg_audio['bitrate']);
rlm@3 861 $info['audio']['bitrate'] = $thisfile_mpeg_audio['bitrate'];
rlm@3 862
rlm@3 863 }
rlm@3 864
rlm@3 865 }
rlm@3 866 }
rlm@3 867
rlm@3 868 } else {
rlm@3 869
rlm@3 870 // not Fraunhofer or Xing VBR methods, most likely CBR (but could be VBR with no header)
rlm@3 871 $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
rlm@3 872 if ($recursive_search) {
rlm@3 873 $thisfile_mpeg_audio['bitrate_mode'] = 'vbr';
rlm@3 874 if (getid3_mp3::RecursiveFrameScanning($fd, $info, $offset, $next_frame_test_offset, true)) {
rlm@3 875 $recursive_search = false;
rlm@3 876 $thisfile_mpeg_audio['bitrate_mode'] = 'cbr';
rlm@3 877 }
rlm@3 878 if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') {
rlm@3 879 $this->getid3->warning('VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.');
rlm@3 880 }
rlm@3 881 }
rlm@3 882
rlm@3 883 }
rlm@3 884
rlm@3 885 }
rlm@3 886
rlm@3 887 if (($expected_number_of_audio_bytes > 0) && ($expected_number_of_audio_bytes != ($info['avdataend'] - $info['avdataoffset']))) {
rlm@3 888 if ($expected_number_of_audio_bytes > ($info['avdataend'] - $info['avdataoffset'])) {
rlm@3 889 if (($expected_number_of_audio_bytes - ($info['avdataend'] - $info['avdataoffset'])) == 1) {
rlm@3 890 $this->getid3->warning('Last byte of data truncated (this is a known bug in Meracl ID3 Tag Writer before v1.3.5)');
rlm@3 891 } else {
rlm@3 892 $this->getid3->warning('Probable truncated file: expecting '.$expected_number_of_audio_bytes.' bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' (short by '.($expected_number_of_audio_bytes - ($info['avdataend'] - $info['avdataoffset'])).' bytes)');
rlm@3 893 }
rlm@3 894 } else {
rlm@3 895 if ((($info['avdataend'] - $info['avdataoffset']) - $expected_number_of_audio_bytes) == 1) {
rlm@3 896 $info['avdataend']--;
rlm@3 897 } else {
rlm@3 898 $this->getid3->warning('Too much data in file: expecting '.$expected_number_of_audio_bytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $expected_number_of_audio_bytes).' bytes too many)');
rlm@3 899 }
rlm@3 900 }
rlm@3 901 }
rlm@3 902
rlm@3 903 if (($thisfile_mpeg_audio['bitrate'] == 'free') && empty($info['audio']['bitrate'])) {
rlm@3 904 if (($offset == $info['avdataoffset']) && empty($thisfile_mpeg_audio['VBR_frames'])) {
rlm@3 905 $frame_byte_length = getid3_mp3::FreeFormatFrameLength($fd, $offset, $info, true);
rlm@3 906 if ($frame_byte_length > 0) {
rlm@3 907 $thisfile_mpeg_audio['framelength'] = $frame_byte_length;
rlm@3 908 if ($thisfile_mpeg_audio['layer'] == '1') {
rlm@3 909 // BitRate = (((FrameLengthInBytes / 4) - Padding) * SampleRate) / 12
rlm@3 910 $info['audio']['bitrate'] = ((($frame_byte_length / 4) - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 12;
rlm@3 911 } else {
rlm@3 912 // Bitrate = ((FrameLengthInBytes - Padding) * SampleRate) / 144
rlm@3 913 $info['audio']['bitrate'] = (($frame_byte_length - intval($thisfile_mpeg_audio['padding'])) * $thisfile_mpeg_audio['sample_rate']) / 144;
rlm@3 914 }
rlm@3 915 } else {
rlm@3 916
rlm@3 917 // non-fatal error: Error calculating frame length of free-format MP3 without Xing/LAME header.
rlm@3 918 return;
rlm@3 919 }
rlm@3 920 }
rlm@3 921 }
rlm@3 922
rlm@3 923 if (@$thisfile_mpeg_audio['VBR_frames']) {
rlm@3 924 switch ($thisfile_mpeg_audio['bitrate_mode']) {
rlm@3 925 case 'vbr':
rlm@3 926 case 'abr':
rlm@3 927 if (($thisfile_mpeg_audio['version'] == '1') && ($thisfile_mpeg_audio['layer'] == 1)) {
rlm@3 928 $thisfile_mpeg_audio['VBR_bitrate'] = ((@$thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / 384);
rlm@3 929 } elseif ((($thisfile_mpeg_audio['version'] == '2') || ($thisfile_mpeg_audio['version'] == '2.5')) && ($thisfile_mpeg_audio['layer'] == 3)) {
rlm@3 930 $thisfile_mpeg_audio['VBR_bitrate'] = ((@$thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / 576);
rlm@3 931 } else {
rlm@3 932 $thisfile_mpeg_audio['VBR_bitrate'] = ((@$thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / 1152);
rlm@3 933 }
rlm@3 934 if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) {
rlm@3 935 $info['audio']['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate'];
rlm@3 936 $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion
rlm@3 937 }
rlm@3 938 break;
rlm@3 939 }
rlm@3 940 }
rlm@3 941
rlm@3 942 // End variable-bitrate headers
rlm@3 943 ////////////////////////////////////////////////////////////////////////////////////
rlm@3 944
rlm@3 945 if ($recursive_search) {
rlm@3 946
rlm@3 947 if (!getid3_mp3::RecursiveFrameScanning($fd, $info, $offset, $next_frame_test_offset, $scan_as_cbr)) {
rlm@3 948 return false;
rlm@3 949 }
rlm@3 950
rlm@3 951 }
rlm@3 952
rlm@3 953 return true;
rlm@3 954 }
rlm@3 955
rlm@3 956
rlm@3 957
rlm@3 958 public function RecursiveFrameScanning(&$fd, &$info, &$offset, &$next_frame_test_offset, $scan_as_cbr) {
rlm@3 959 for ($i = 0; $i < getid3_mp3::VALID_CHECK_FRAMES; $i++) {
rlm@3 960 // check next getid3_mp3::VALID_CHECK_FRAMES frames for validity, to make sure we haven't run across a false synch
rlm@3 961 if (($next_frame_test_offset + 4) >= $info['avdataend']) {
rlm@3 962 // end of file
rlm@3 963 return true;
rlm@3 964 }
rlm@3 965
rlm@3 966 $next_frame_test_array = array ('avdataend' => $info['avdataend'], 'avdataoffset' => $info['avdataoffset']);
rlm@3 967 if ($this->decodeMPEGaudioHeader($fd, $next_frame_test_offset, $next_frame_test_array, false)) {
rlm@3 968 if ($scan_as_cbr) {
rlm@3 969 // force CBR mode, used for trying to pick out invalid audio streams with
rlm@3 970 // valid(?) VBR headers, or VBR streams with no VBR header
rlm@3 971 if (!isset($next_frame_test_array['mpeg']['audio']['bitrate']) || !isset($info['mpeg']['audio']['bitrate']) || ($next_frame_test_array['mpeg']['audio']['bitrate'] != $info['mpeg']['audio']['bitrate'])) {
rlm@3 972 return false;
rlm@3 973 }
rlm@3 974 }
rlm@3 975
rlm@3 976
rlm@3 977 // next frame is OK, get ready to check the one after that
rlm@3 978 if (isset($next_frame_test_array['mpeg']['audio']['framelength']) && ($next_frame_test_array['mpeg']['audio']['framelength'] > 0)) {
rlm@3 979 $next_frame_test_offset += $next_frame_test_array['mpeg']['audio']['framelength'];
rlm@3 980 } else {
rlm@3 981
rlm@3 982 // non-fatal error: Frame at offset $offset has an invalid frame length.
rlm@3 983 return;
rlm@3 984 }
rlm@3 985
rlm@3 986 } else {
rlm@3 987
rlm@3 988 // non-fatal error: Next frame is not valid.
rlm@3 989 return;
rlm@3 990 }
rlm@3 991 }
rlm@3 992 return true;
rlm@3 993 }
rlm@3 994
rlm@3 995
rlm@3 996
rlm@3 997 public function FreeFormatFrameLength($fd, $offset, &$info, $deep_scan=false) {
rlm@3 998 fseek($fd, $offset, SEEK_SET);
rlm@3 999 $mpeg_audio_data = fread($fd, 32768);
rlm@3 1000
rlm@3 1001 $sync_pattern1 = substr($mpeg_audio_data, 0, 4);
rlm@3 1002 // may be different pattern due to padding
rlm@3 1003 $sync_pattern2 = $sync_pattern1{0}.$sync_pattern1{1}.chr(ord($sync_pattern1{2}) | 0x02).$sync_pattern1{3};
rlm@3 1004 if ($sync_pattern2 === $sync_pattern1) {
rlm@3 1005 $sync_pattern2 = $sync_pattern1{0}.$sync_pattern1{1}.chr(ord($sync_pattern1{2}) & 0xFD).$sync_pattern1{3};
rlm@3 1006 }
rlm@3 1007
rlm@3 1008 $frame_length = false;
rlm@3 1009 $frame_length1 = strpos($mpeg_audio_data, $sync_pattern1, 4);
rlm@3 1010 $frame_length2 = strpos($mpeg_audio_data, $sync_pattern2, 4);
rlm@3 1011 if ($frame_length1 > 4) {
rlm@3 1012 $frame_length = $frame_length1;
rlm@3 1013 }
rlm@3 1014 if (($frame_length2 > 4) && ($frame_length2 < $frame_length1)) {
rlm@3 1015 $frame_length = $frame_length2;
rlm@3 1016 }
rlm@3 1017 if (!$frame_length) {
rlm@3 1018
rlm@3 1019 // LAME 3.88 has a different value for modeextension on the first frame vs the rest
rlm@3 1020 $frame_length1 = strpos($mpeg_audio_data, substr($sync_pattern1, 0, 3), 4);
rlm@3 1021 $frame_length2 = strpos($mpeg_audio_data, substr($sync_pattern2, 0, 3), 4);
rlm@3 1022
rlm@3 1023 if ($frame_length1 > 4) {
rlm@3 1024 $frame_length = $frame_length1;
rlm@3 1025 }
rlm@3 1026 if (($frame_length2 > 4) && ($frame_length2 < $frame_length1)) {
rlm@3 1027 $frame_length = $frame_length2;
rlm@3 1028 }
rlm@3 1029 if (!$frame_length) {
rlm@3 1030 throw new getid3_exception('Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($sync_pattern1).' or '.getid3_lib::PrintHexBytes($sync_pattern2).') after offset '.$offset);
rlm@3 1031 } else {
rlm@3 1032 $this->getid3->warning('ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)');
rlm@3 1033 $info['audio']['codec'] = 'LAME';
rlm@3 1034 $info['audio']['encoder'] = 'LAME3.88';
rlm@3 1035 $sync_pattern1 = substr($sync_pattern1, 0, 3);
rlm@3 1036 $sync_pattern2 = substr($sync_pattern2, 0, 3);
rlm@3 1037 }
rlm@3 1038 }
rlm@3 1039
rlm@3 1040 if ($deep_scan) {
rlm@3 1041
rlm@3 1042 $actual_frame_length_values = array ();
rlm@3 1043 $next_offset = $offset + $frame_length;
rlm@3 1044 while ($next_offset < ($info['avdataend'] - 6)) {
rlm@3 1045 fseek($fd, $next_offset - 1, SEEK_SET);
rlm@3 1046 $NextSyncPattern = fread($fd, 6);
rlm@3 1047 if ((substr($NextSyncPattern, 1, strlen($sync_pattern1)) == $sync_pattern1) || (substr($NextSyncPattern, 1, strlen($sync_pattern2)) == $sync_pattern2)) {
rlm@3 1048 // good - found where expected
rlm@3 1049 $actual_frame_length_values[] = $frame_length;
rlm@3 1050 } elseif ((substr($NextSyncPattern, 0, strlen($sync_pattern1)) == $sync_pattern1) || (substr($NextSyncPattern, 0, strlen($sync_pattern2)) == $sync_pattern2)) {
rlm@3 1051 // ok - found one byte earlier than expected (last frame wasn't padded, first frame was)
rlm@3 1052 $actual_frame_length_values[] = ($frame_length - 1);
rlm@3 1053 $next_offset--;
rlm@3 1054 } elseif ((substr($NextSyncPattern, 2, strlen($sync_pattern1)) == $sync_pattern1) || (substr($NextSyncPattern, 2, strlen($sync_pattern2)) == $sync_pattern2)) {
rlm@3 1055 // ok - found one byte later than expected (last frame was padded, first frame wasn't)
rlm@3 1056 $actual_frame_length_values[] = ($frame_length + 1);
rlm@3 1057 $next_offset++;
rlm@3 1058 } else {
rlm@3 1059 throw new getid3_exception('Did not find expected free-format sync pattern at offset '.$next_offset);
rlm@3 1060 }
rlm@3 1061 $next_offset += $frame_length;
rlm@3 1062 }
rlm@3 1063 if (count($actual_frame_length_values) > 0) {
rlm@3 1064 $frame_length = intval(round(array_sum($actual_frame_length_values) / count($actual_frame_length_values)));
rlm@3 1065 }
rlm@3 1066 }
rlm@3 1067 return $frame_length;
rlm@3 1068 }
rlm@3 1069
rlm@3 1070
rlm@3 1071
rlm@3 1072 public function getOnlyMPEGaudioInfo($fd, &$info, $avdata_offset, $bit_rate_histogram=false) {
rlm@3 1073
rlm@3 1074 // looks for synch, decodes MPEG audio header
rlm@3 1075
rlm@3 1076 fseek($fd, $avdata_offset, SEEK_SET);
rlm@3 1077
rlm@3 1078 $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdata_offset);
rlm@3 1079 $header = fread($fd, $sync_seek_buffer_size);
rlm@3 1080 $sync_seek_buffer_size = strlen($header);
rlm@3 1081 $synch_seek_offset = 0;
rlm@3 1082
rlm@3 1083 static $mpeg_audio_version_lookup;
rlm@3 1084 static $mpeg_audio_layer_lookup;
rlm@3 1085 static $mpeg_audio_bitrate_lookup;
rlm@3 1086 if (empty($mpeg_audio_version_lookup)) {
rlm@3 1087 $mpeg_audio_version_lookup = getid3_mp3::MPEGaudioVersionarray();
rlm@3 1088 $mpeg_audio_layer_lookup = getid3_mp3::MPEGaudioLayerarray();
rlm@3 1089 $mpeg_audio_bitrate_lookup = getid3_mp3::MPEGaudioBitratearray();
rlm@3 1090
rlm@3 1091 }
rlm@3 1092
rlm@3 1093 while ($synch_seek_offset < $sync_seek_buffer_size) {
rlm@3 1094
rlm@3 1095 if ((($avdata_offset + $synch_seek_offset) < $info['avdataend']) && !feof($fd)) {
rlm@3 1096
rlm@3 1097 // if a synch's not found within the first 128k bytes, then give up
rlm@3 1098 if ($synch_seek_offset > $sync_seek_buffer_size) {
rlm@3 1099 throw new getid3_exception('Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB');
rlm@3 1100 }
rlm@3 1101
rlm@3 1102 if (feof($fd)) {
rlm@3 1103 throw new getid3_exception('Could not find valid MPEG audio synch before end of file');
rlm@3 1104 }
rlm@3 1105 }
rlm@3 1106
rlm@3 1107 if (($synch_seek_offset + 1) >= strlen($header)) {
rlm@3 1108 throw new getid3_exception('Could not find valid MPEG synch before end of file');
rlm@3 1109 }
rlm@3 1110
rlm@3 1111 if (($header{$synch_seek_offset} == "\xFF") && ($header{($synch_seek_offset + 1)} > "\xE0")) { // synch detected
rlm@3 1112
rlm@3 1113 if (!isset($first_frame_info) && !isset($info['mpeg']['audio'])) {
rlm@3 1114 $first_frame_info = $info;
rlm@3 1115 $first_frame_avdata_offset = $avdata_offset + $synch_seek_offset;
rlm@3 1116 if (!getid3_mp3::decodeMPEGaudioHeader($fd, $avdata_offset + $synch_seek_offset, $first_frame_info, false)) {
rlm@3 1117 // if this is the first valid MPEG-audio frame, save it in case it's a VBR header frame and there's
rlm@3 1118 // garbage between this frame and a valid sequence of MPEG-audio frames, to be restored below
rlm@3 1119 unset($first_frame_info);
rlm@3 1120 }
rlm@3 1121 }
rlm@3 1122
rlm@3 1123 $dummy = $info; // only overwrite real data if valid header found
rlm@3 1124 if (getid3_mp3::decodeMPEGaudioHeader($fd, $avdata_offset + $synch_seek_offset, $dummy, true)) {
rlm@3 1125 $info = $dummy;
rlm@3 1126 $info['avdataoffset'] = $avdata_offset + $synch_seek_offset;
rlm@3 1127
rlm@3 1128 switch (@$info['fileformat']) {
rlm@3 1129 case '':
rlm@3 1130 case 'mp3':
rlm@3 1131 $info['fileformat'] = 'mp3';
rlm@3 1132 $info['audio']['dataformat'] = 'mp3';
rlm@3 1133 break;
rlm@3 1134 }
rlm@3 1135 if (isset($first_frame_info['mpeg']['audio']['bitrate_mode']) && ($first_frame_info['mpeg']['audio']['bitrate_mode'] == 'vbr')) {
rlm@3 1136 if (!(abs($info['audio']['bitrate'] - $first_frame_info['audio']['bitrate']) <= 1)) {
rlm@3 1137 // If there is garbage data between a valid VBR header frame and a sequence
rlm@3 1138 // of valid MPEG-audio frames the VBR data is no longer discarded.
rlm@3 1139 $info = $first_frame_info;
rlm@3 1140 $info['avdataoffset'] = $first_frame_avdata_offset;
rlm@3 1141 $info['fileformat'] = 'mp3';
rlm@3 1142 $info['audio']['dataformat'] = 'mp3';
rlm@3 1143 $dummy = $info;
rlm@3 1144 unset($dummy['mpeg']['audio']);
rlm@3 1145 $GarbageOffsetStart = $first_frame_avdata_offset + $first_frame_info['mpeg']['audio']['framelength'];
rlm@3 1146 $GarbageOffsetEnd = $avdata_offset + $synch_seek_offset;
rlm@3 1147 if (getid3_mp3::decodeMPEGaudioHeader($fd, $GarbageOffsetEnd, $dummy, true, true)) {
rlm@3 1148
rlm@3 1149 $info = $dummy;
rlm@3 1150 $info['avdataoffset'] = $GarbageOffsetEnd;
rlm@3 1151 $this->getid3->warning('apparently-valid VBR header not used because could not find '.getid3_mp3::VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd);
rlm@3 1152
rlm@3 1153 } else {
rlm@3 1154
rlm@3 1155 $this->getid3->warning('using data from VBR header even though could not find '.getid3_mp3::VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')');
rlm@3 1156
rlm@3 1157 }
rlm@3 1158 }
rlm@3 1159 }
rlm@3 1160 if (isset($info['mpeg']['audio']['bitrate_mode']) && ($info['mpeg']['audio']['bitrate_mode'] == 'vbr') && !isset($info['mpeg']['audio']['VBR_method'])) {
rlm@3 1161 // VBR file with no VBR header
rlm@3 1162 $bit_rate_histogram = true;
rlm@3 1163 }
rlm@3 1164
rlm@3 1165 if ($bit_rate_histogram) {
rlm@3 1166
rlm@3 1167 $info['mpeg']['audio']['stereo_distribution'] = array ('stereo'=>0, 'joint stereo'=>0, 'dual channel'=>0, 'mono'=>0);
rlm@3 1168 $info['mpeg']['audio']['version_distribution'] = array ('1'=>0, '2'=>0, '2.5'=>0);
rlm@3 1169
rlm@3 1170 if ($info['mpeg']['audio']['version'] == '1') {
rlm@3 1171 if ($info['mpeg']['audio']['layer'] == 3) {
rlm@3 1172 $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);
rlm@3 1173 } elseif ($info['mpeg']['audio']['layer'] == 2) {
rlm@3 1174 $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);
rlm@3 1175 } elseif ($info['mpeg']['audio']['layer'] == 1) {
rlm@3 1176 $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);
rlm@3 1177 }
rlm@3 1178 } elseif ($info['mpeg']['audio']['layer'] == 1) {
rlm@3 1179 $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);
rlm@3 1180 } else {
rlm@3 1181 $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);
rlm@3 1182 }
rlm@3 1183
rlm@3 1184 $dummy = array ('avdataend' => $info['avdataend'], 'avdataoffset' => $info['avdataoffset']);
rlm@3 1185 $synch_start_offset = $info['avdataoffset'];
rlm@3 1186
rlm@3 1187 $fast_mode = false;
rlm@3 1188 $synch_errors_found = 0;
rlm@3 1189 while ($this->decodeMPEGaudioHeader($fd, $synch_start_offset, $dummy, false, false, $fast_mode)) {
rlm@3 1190 $fast_mode = true;
rlm@3 1191 $thisframebitrate = $mpeg_audio_bitrate_lookup[$mpeg_audio_version_lookup[$dummy['mpeg']['audio']['raw']['version']]][$mpeg_audio_layer_lookup[$dummy['mpeg']['audio']['raw']['layer']]][$dummy['mpeg']['audio']['raw']['bitrate']];
rlm@3 1192
rlm@3 1193 if (empty($dummy['mpeg']['audio']['framelength'])) {
rlm@3 1194 $synch_errors_found++;
rlm@3 1195 }
rlm@3 1196 else {
rlm@3 1197 @$info['mpeg']['audio']['bitrate_distribution'][$thisframebitrate]++;
rlm@3 1198 @$info['mpeg']['audio']['stereo_distribution'][$dummy['mpeg']['audio']['channelmode']]++;
rlm@3 1199 @$info['mpeg']['audio']['version_distribution'][$dummy['mpeg']['audio']['version']]++;
rlm@3 1200
rlm@3 1201 $synch_start_offset += $dummy['mpeg']['audio']['framelength'];
rlm@3 1202 }
rlm@3 1203 }
rlm@3 1204 if ($synch_errors_found > 0) {
rlm@3 1205 $this->getid3->warning('Found '.$synch_errors_found.' synch errors in histogram analysis');
rlm@3 1206 }
rlm@3 1207
rlm@3 1208 $bit_total = 0;
rlm@3 1209 $frame_counter = 0;
rlm@3 1210 foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bit_rate_value => $bit_rate_count) {
rlm@3 1211 $frame_counter += $bit_rate_count;
rlm@3 1212 if ($bit_rate_value != 'free') {
rlm@3 1213 $bit_total += ($bit_rate_value * $bit_rate_count);
rlm@3 1214 }
rlm@3 1215 }
rlm@3 1216 if ($frame_counter == 0) {
rlm@3 1217 throw new getid3_exception('Corrupt MP3 file: framecounter == zero');
rlm@3 1218 }
rlm@3 1219 $info['mpeg']['audio']['frame_count'] = $frame_counter;
rlm@3 1220 $info['mpeg']['audio']['bitrate'] = ($bit_total / $frame_counter);
rlm@3 1221
rlm@3 1222 $info['audio']['bitrate'] = $info['mpeg']['audio']['bitrate'];
rlm@3 1223
rlm@3 1224
rlm@3 1225 // Definitively set VBR vs CBR, even if the Xing/LAME/VBRI header says differently
rlm@3 1226 $distinct_bit_rates = 0;
rlm@3 1227 foreach ($info['mpeg']['audio']['bitrate_distribution'] as $bit_rate_value => $bit_rate_count) {
rlm@3 1228 if ($bit_rate_count > 0) {
rlm@3 1229 $distinct_bit_rates++;
rlm@3 1230 }
rlm@3 1231 }
rlm@3 1232 if ($distinct_bit_rates > 1) {
rlm@3 1233 $info['mpeg']['audio']['bitrate_mode'] = 'vbr';
rlm@3 1234 } else {
rlm@3 1235 $info['mpeg']['audio']['bitrate_mode'] = 'cbr';
rlm@3 1236 }
rlm@3 1237 $info['audio']['bitrate_mode'] = $info['mpeg']['audio']['bitrate_mode'];
rlm@3 1238
rlm@3 1239 }
rlm@3 1240
rlm@3 1241 break; // exit while()
rlm@3 1242 }
rlm@3 1243 }
rlm@3 1244
rlm@3 1245 $synch_seek_offset++;
rlm@3 1246 if (($avdata_offset + $synch_seek_offset) >= $info['avdataend']) {
rlm@3 1247 // end of file/data
rlm@3 1248
rlm@3 1249 if (empty($info['mpeg']['audio'])) {
rlm@3 1250
rlm@3 1251 throw new getid3_exception('could not find valid MPEG synch before end of file');
rlm@3 1252 }
rlm@3 1253 break;
rlm@3 1254 }
rlm@3 1255
rlm@3 1256 }
rlm@3 1257
rlm@3 1258 $info['audio']['channels'] = $info['mpeg']['audio']['channels'];
rlm@3 1259 $info['audio']['channelmode'] = $info['mpeg']['audio']['channelmode'];
rlm@3 1260 $info['audio']['sample_rate'] = $info['mpeg']['audio']['sample_rate'];
rlm@3 1261 return true;
rlm@3 1262 }
rlm@3 1263
rlm@3 1264
rlm@3 1265
rlm@3 1266 public static function MPEGaudioVersionarray() {
rlm@3 1267
rlm@3 1268 static $array = array ('2.5', false, '2', '1');
rlm@3 1269 return $array;
rlm@3 1270 }
rlm@3 1271
rlm@3 1272
rlm@3 1273
rlm@3 1274 public static function MPEGaudioLayerarray() {
rlm@3 1275
rlm@3 1276 static $array = array (false, 3, 2, 1);
rlm@3 1277 return $array;
rlm@3 1278 }
rlm@3 1279
rlm@3 1280
rlm@3 1281
rlm@3 1282 public static function MPEGaudioBitratearray() {
rlm@3 1283
rlm@3 1284 static $array;
rlm@3 1285 if (empty($array)) {
rlm@3 1286 $array = array (
rlm@3 1287 '1' => array (1 => array ('free', 32000, 64000, 96000, 128000, 160000, 192000, 224000, 256000, 288000, 320000, 352000, 384000, 416000, 448000),
rlm@3 1288 2 => array ('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000, 384000),
rlm@3 1289 3 => array ('free', 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000)
rlm@3 1290 ),
rlm@3 1291
rlm@3 1292 '2' => array (1 => array ('free', 32000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000, 176000, 192000, 224000, 256000),
rlm@3 1293 2 => array ('free', 8000, 16000, 24000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 144000, 160000),
rlm@3 1294 )
rlm@3 1295 );
rlm@3 1296 $array['2'][3] = $array['2'][2];
rlm@3 1297 $array['2.5'] = $array['2'];
rlm@3 1298 }
rlm@3 1299 return $array;
rlm@3 1300 }
rlm@3 1301
rlm@3 1302
rlm@3 1303
rlm@3 1304 public static function MPEGaudioFrequencyarray() {
rlm@3 1305
rlm@3 1306 static $array = array (
rlm@3 1307 '1' => array (44100, 48000, 32000),
rlm@3 1308 '2' => array (22050, 24000, 16000),
rlm@3 1309 '2.5' => array (11025, 12000, 8000)
rlm@3 1310 );
rlm@3 1311 return $array;
rlm@3 1312 }
rlm@3 1313
rlm@3 1314
rlm@3 1315
rlm@3 1316 public static function MPEGaudioChannelModearray() {
rlm@3 1317
rlm@3 1318 static $array = array ('stereo', 'joint stereo', 'dual channel', 'mono');
rlm@3 1319 return $array;
rlm@3 1320 }
rlm@3 1321
rlm@3 1322
rlm@3 1323
rlm@3 1324 public static function MPEGaudioModeExtensionarray() {
rlm@3 1325
rlm@3 1326 static $array = array (
rlm@3 1327 1 => array ('4-31', '8-31', '12-31', '16-31'),
rlm@3 1328 2 => array ('4-31', '8-31', '12-31', '16-31'),
rlm@3 1329 3 => array ('', 'IS', 'MS', 'IS+MS')
rlm@3 1330 );
rlm@3 1331 return $array;
rlm@3 1332 }
rlm@3 1333
rlm@3 1334
rlm@3 1335
rlm@3 1336 public static function MPEGaudioEmphasisarray() {
rlm@3 1337
rlm@3 1338 static $array = array ('none', '50/15ms', false, 'CCIT J.17');
rlm@3 1339 return $array;
rlm@3 1340 }
rlm@3 1341
rlm@3 1342
rlm@3 1343
rlm@3 1344 public static function MPEGaudioHeaderBytesValid($head4, $allow_bitrate_15=false) {
rlm@3 1345
rlm@3 1346 return getid3_mp3::MPEGaudioHeaderValid(getid3_mp3::MPEGaudioHeaderDecode($head4), false, $allow_bitrate_15);
rlm@3 1347 }
rlm@3 1348
rlm@3 1349
rlm@3 1350
rlm@3 1351 public static function MPEGaudioHeaderValid($raw_array, $echo_errors=false, $allow_bitrate_15=false) {
rlm@3 1352
rlm@3 1353 if (($raw_array['synch'] & 0x0FFE) != 0x0FFE) {
rlm@3 1354 return false;
rlm@3 1355 }
rlm@3 1356
rlm@3 1357 static $mpeg_audio_version_lookup;
rlm@3 1358 static $mpeg_audio_layer_lookup;
rlm@3 1359 static $mpeg_audio_bitrate_lookup;
rlm@3 1360 static $mpeg_audio_frequency_lookup;
rlm@3 1361 static $mpeg_audio_channel_mode_lookup;
rlm@3 1362 static $mpeg_audio_mode_extension_lookup;
rlm@3 1363 static $mpeg_audio_emphasis_lookup;
rlm@3 1364 if (empty($mpeg_audio_version_lookup)) {
rlm@3 1365 $mpeg_audio_version_lookup = getid3_mp3::MPEGaudioVersionarray();
rlm@3 1366 $mpeg_audio_layer_lookup = getid3_mp3::MPEGaudioLayerarray();
rlm@3 1367 $mpeg_audio_bitrate_lookup = getid3_mp3::MPEGaudioBitratearray();
rlm@3 1368 $mpeg_audio_frequency_lookup = getid3_mp3::MPEGaudioFrequencyarray();
rlm@3 1369 $mpeg_audio_channel_mode_lookup = getid3_mp3::MPEGaudioChannelModearray();
rlm@3 1370 $mpeg_audio_mode_extension_lookup = getid3_mp3::MPEGaudioModeExtensionarray();
rlm@3 1371 $mpeg_audio_emphasis_lookup = getid3_mp3::MPEGaudioEmphasisarray();
rlm@3 1372 }
rlm@3 1373
rlm@3 1374 if (isset($mpeg_audio_version_lookup[$raw_array['version']])) {
rlm@3 1375 $decodedVersion = $mpeg_audio_version_lookup[$raw_array['version']];
rlm@3 1376 } else {
rlm@3 1377 echo ($echo_errors ? "\n".'invalid Version ('.$raw_array['version'].')' : '');
rlm@3 1378 return false;
rlm@3 1379 }
rlm@3 1380 if (isset($mpeg_audio_layer_lookup[$raw_array['layer']])) {
rlm@3 1381 $decodedLayer = $mpeg_audio_layer_lookup[$raw_array['layer']];
rlm@3 1382 } else {
rlm@3 1383 echo ($echo_errors ? "\n".'invalid Layer ('.$raw_array['layer'].')' : '');
rlm@3 1384 return false;
rlm@3 1385 }
rlm@3 1386 if (!isset($mpeg_audio_bitrate_lookup[$decodedVersion][$decodedLayer][$raw_array['bitrate']])) {
rlm@3 1387 echo ($echo_errors ? "\n".'invalid Bitrate ('.$raw_array['bitrate'].')' : '');
rlm@3 1388 if ($raw_array['bitrate'] == 15) {
rlm@3 1389 // known issue in LAME 3.90 - 3.93.1 where free-format has bitrate ID of 15 instead of 0
rlm@3 1390 // let it go through here otherwise file will not be identified
rlm@3 1391 if (!$allow_bitrate_15) {
rlm@3 1392 return false;
rlm@3 1393 }
rlm@3 1394 } else {
rlm@3 1395 return false;
rlm@3 1396 }
rlm@3 1397 }
rlm@3 1398 if (!isset($mpeg_audio_frequency_lookup[$decodedVersion][$raw_array['sample_rate']])) {
rlm@3 1399 echo ($echo_errors ? "\n".'invalid Frequency ('.$raw_array['sample_rate'].')' : '');
rlm@3 1400 return false;
rlm@3 1401 }
rlm@3 1402 if (!isset($mpeg_audio_channel_mode_lookup[$raw_array['channelmode']])) {
rlm@3 1403 echo ($echo_errors ? "\n".'invalid ChannelMode ('.$raw_array['channelmode'].')' : '');
rlm@3 1404 return false;
rlm@3 1405 }
rlm@3 1406 if (!isset($mpeg_audio_mode_extension_lookup[$decodedLayer][$raw_array['modeextension']])) {
rlm@3 1407 echo ($echo_errors ? "\n".'invalid Mode Extension ('.$raw_array['modeextension'].')' : '');
rlm@3 1408 return false;
rlm@3 1409 }
rlm@3 1410 if (!isset($mpeg_audio_emphasis_lookup[$raw_array['emphasis']])) {
rlm@3 1411 echo ($echo_errors ? "\n".'invalid Emphasis ('.$raw_array['emphasis'].')' : '');
rlm@3 1412 return false;
rlm@3 1413 }
rlm@3 1414 // These are just either set or not set, you can't mess that up :)
rlm@3 1415 // $raw_array['protection'];
rlm@3 1416 // $raw_array['padding'];
rlm@3 1417 // $raw_array['private'];
rlm@3 1418 // $raw_array['copyright'];
rlm@3 1419 // $raw_array['original'];
rlm@3 1420
rlm@3 1421 return true;
rlm@3 1422 }
rlm@3 1423
rlm@3 1424
rlm@3 1425
rlm@3 1426 public static function MPEGaudioHeaderDecode($header_four_bytes) {
rlm@3 1427 // AAAA AAAA AAAB BCCD EEEE FFGH IIJJ KLMM
rlm@3 1428 // A - Frame sync (all bits set)
rlm@3 1429 // B - MPEG Audio version ID
rlm@3 1430 // C - Layer description
rlm@3 1431 // D - Protection bit
rlm@3 1432 // E - Bitrate index
rlm@3 1433 // F - Sampling rate frequency index
rlm@3 1434 // G - Padding bit
rlm@3 1435 // H - Private bit
rlm@3 1436 // I - Channel Mode
rlm@3 1437 // J - Mode extension (Only if Joint stereo)
rlm@3 1438 // K - Copyright
rlm@3 1439 // L - Original
rlm@3 1440 // M - Emphasis
rlm@3 1441
rlm@3 1442 if (strlen($header_four_bytes) != 4) {
rlm@3 1443 return false;
rlm@3 1444 }
rlm@3 1445
rlm@3 1446 $mpeg_raw_header['synch'] = (getid3_lib::BigEndian2Int(substr($header_four_bytes, 0, 2)) & 0xFFE0) >> 4;
rlm@3 1447 $mpeg_raw_header['version'] = (ord($header_four_bytes{1}) & 0x18) >> 3; // BB
rlm@3 1448 $mpeg_raw_header['layer'] = (ord($header_four_bytes{1}) & 0x06) >> 1; // CC
rlm@3 1449 $mpeg_raw_header['protection'] = (ord($header_four_bytes{1}) & 0x01); // D
rlm@3 1450 $mpeg_raw_header['bitrate'] = (ord($header_four_bytes{2}) & 0xF0) >> 4; // EEEE
rlm@3 1451 $mpeg_raw_header['sample_rate'] = (ord($header_four_bytes{2}) & 0x0C) >> 2; // FF
rlm@3 1452 $mpeg_raw_header['padding'] = (ord($header_four_bytes{2}) & 0x02) >> 1; // G
rlm@3 1453 $mpeg_raw_header['private'] = (ord($header_four_bytes{2}) & 0x01); // H
rlm@3 1454 $mpeg_raw_header['channelmode'] = (ord($header_four_bytes{3}) & 0xC0) >> 6; // II
rlm@3 1455 $mpeg_raw_header['modeextension'] = (ord($header_four_bytes{3}) & 0x30) >> 4; // JJ
rlm@3 1456 $mpeg_raw_header['copyright'] = (ord($header_four_bytes{3}) & 0x08) >> 3; // K
rlm@3 1457 $mpeg_raw_header['original'] = (ord($header_four_bytes{3}) & 0x04) >> 2; // L
rlm@3 1458 $mpeg_raw_header['emphasis'] = (ord($header_four_bytes{3}) & 0x03); // MM
rlm@3 1459
rlm@3 1460 return $mpeg_raw_header;
rlm@3 1461 }
rlm@3 1462
rlm@3 1463
rlm@3 1464
rlm@3 1465 public static function MPEGaudioFrameLength(&$bit_rate, &$version, &$layer, $padding, &$sample_rate) {
rlm@3 1466
rlm@3 1467 if (!isset($cache[$bit_rate][$version][$layer][$padding][$sample_rate])) {
rlm@3 1468 $cache[$bit_rate][$version][$layer][$padding][$sample_rate] = false;
rlm@3 1469 if ($bit_rate != 'free') {
rlm@3 1470
rlm@3 1471 if ($version == '1') {
rlm@3 1472
rlm@3 1473 if ($layer == '1') {
rlm@3 1474
rlm@3 1475 // For Layer I slot is 32 bits long
rlm@3 1476 $frame_length_coefficient = 48;
rlm@3 1477 $slot_length = 4;
rlm@3 1478
rlm@3 1479 } else { // Layer 2 / 3
rlm@3 1480
rlm@3 1481 // for Layer 2 and Layer 3 slot is 8 bits long.
rlm@3 1482 $frame_length_coefficient = 144;
rlm@3 1483 $slot_length = 1;
rlm@3 1484
rlm@3 1485 }
rlm@3 1486
rlm@3 1487 } else { // MPEG-2 / MPEG-2.5
rlm@3 1488
rlm@3 1489 if ($layer == '1') {
rlm@3 1490
rlm@3 1491 // For Layer I slot is 32 bits long
rlm@3 1492 $frame_length_coefficient = 24;
rlm@3 1493 $slot_length = 4;
rlm@3 1494
rlm@3 1495 } elseif ($layer == '2') {
rlm@3 1496
rlm@3 1497 // for Layer 2 and Layer 3 slot is 8 bits long.
rlm@3 1498 $frame_length_coefficient = 144;
rlm@3 1499 $slot_length = 1;
rlm@3 1500
rlm@3 1501 } else { // layer 3
rlm@3 1502
rlm@3 1503 // for Layer 2 and Layer 3 slot is 8 bits long.
rlm@3 1504 $frame_length_coefficient = 72;
rlm@3 1505 $slot_length = 1;
rlm@3 1506
rlm@3 1507 }
rlm@3 1508
rlm@3 1509 }
rlm@3 1510
rlm@3 1511 // FrameLengthInBytes = ((Coefficient * BitRate) / SampleRate) + Padding
rlm@3 1512 if ($sample_rate > 0) {
rlm@3 1513 $new_frame_length = ($frame_length_coefficient * $bit_rate) / $sample_rate;
rlm@3 1514 $new_frame_length = floor($new_frame_length / $slot_length) * $slot_length; // round to next-lower multiple of SlotLength (1 byte for Layer 2/3, 4 bytes for Layer I)
rlm@3 1515 if ($padding) {
rlm@3 1516 $new_frame_length += $slot_length;
rlm@3 1517 }
rlm@3 1518 $cache[$bit_rate][$version][$layer][$padding][$sample_rate] = (int) $new_frame_length;
rlm@3 1519 }
rlm@3 1520 }
rlm@3 1521 }
rlm@3 1522 return $cache[$bit_rate][$version][$layer][$padding][$sample_rate];
rlm@3 1523 }
rlm@3 1524
rlm@3 1525
rlm@3 1526
rlm@3 1527 public static function ClosestStandardMP3Bitrate($bit_rate) {
rlm@3 1528
rlm@3 1529 static $standard_bit_rates = array (320000, 256000, 224000, 192000, 160000, 128000, 112000, 96000, 80000, 64000, 56000, 48000, 40000, 32000, 24000, 16000, 8000);
rlm@3 1530 static $bit_rate_table = array (0=>'-');
rlm@3 1531 $round_bit_rate = intval(round($bit_rate, -3));
rlm@3 1532 if (!isset($bit_rate_table[$round_bit_rate])) {
rlm@3 1533 if ($round_bit_rate > 320000) {
rlm@3 1534 $bit_rate_table[$round_bit_rate] = round($bit_rate, -4);
rlm@3 1535 } else {
rlm@3 1536 $last_bit_rate = 320000;
rlm@3 1537 foreach ($standard_bit_rates as $standard_bit_rate) {
rlm@3 1538 $bit_rate_table[$round_bit_rate] = $standard_bit_rate;
rlm@3 1539 if ($round_bit_rate >= $standard_bit_rate - (($last_bit_rate - $standard_bit_rate) / 2)) {
rlm@3 1540 break;
rlm@3 1541 }
rlm@3 1542 $last_bit_rate = $standard_bit_rate;
rlm@3 1543 }
rlm@3 1544 }
rlm@3 1545 }
rlm@3 1546 return $bit_rate_table[$round_bit_rate];
rlm@3 1547 }
rlm@3 1548
rlm@3 1549
rlm@3 1550
rlm@3 1551 public static function XingVBRidOffset($version, $channel_mode) {
rlm@3 1552
rlm@3 1553 static $lookup = array (
rlm@3 1554 '1' => array ('mono' => 0x15, // 4 + 17 = 21
rlm@3 1555 'stereo' => 0x24, // 4 + 32 = 36
rlm@3 1556 'joint stereo' => 0x24,
rlm@3 1557 'dual channel' => 0x24
rlm@3 1558 ),
rlm@3 1559
rlm@3 1560 '2' => array ('mono' => 0x0D, // 4 + 9 = 13
rlm@3 1561 'stereo' => 0x15, // 4 + 17 = 21
rlm@3 1562 'joint stereo' => 0x15,
rlm@3 1563 'dual channel' => 0x15
rlm@3 1564 ),
rlm@3 1565
rlm@3 1566 '2.5' => array ('mono' => 0x15,
rlm@3 1567 'stereo' => 0x15,
rlm@3 1568 'joint stereo' => 0x15,
rlm@3 1569 'dual channel' => 0x15
rlm@3 1570 )
rlm@3 1571 );
rlm@3 1572
rlm@3 1573 return $lookup[$version][$channel_mode];
rlm@3 1574 }
rlm@3 1575
rlm@3 1576
rlm@3 1577
rlm@3 1578 public static function LAMEvbrMethodLookup($vbr_method_id) {
rlm@3 1579
rlm@3 1580 static $lookup = array (
rlm@3 1581 0x00 => 'unknown',
rlm@3 1582 0x01 => 'cbr',
rlm@3 1583 0x02 => 'abr',
rlm@3 1584 0x03 => 'vbr-old / vbr-rh',
rlm@3 1585 0x04 => 'vbr-new / vbr-mtrh',
rlm@3 1586 0x05 => 'vbr-mt',
rlm@3 1587 0x06 => 'Full VBR Method 4',
rlm@3 1588 0x08 => 'constant bitrate 2 pass',
rlm@3 1589 0x09 => 'abr 2 pass',
rlm@3 1590 0x0F => 'reserved'
rlm@3 1591 );
rlm@3 1592 return (isset($lookup[$vbr_method_id]) ? $lookup[$vbr_method_id] : '');
rlm@3 1593 }
rlm@3 1594
rlm@3 1595
rlm@3 1596
rlm@3 1597 public static function LAMEmiscStereoModeLookup($stereo_mode_id) {
rlm@3 1598
rlm@3 1599 static $lookup = array (
rlm@3 1600 0 => 'mono',
rlm@3 1601 1 => 'stereo',
rlm@3 1602 2 => 'dual mono',
rlm@3 1603 3 => 'joint stereo',
rlm@3 1604 4 => 'forced stereo',
rlm@3 1605 5 => 'auto',
rlm@3 1606 6 => 'intensity stereo',
rlm@3 1607 7 => 'other'
rlm@3 1608 );
rlm@3 1609 return (isset($lookup[$stereo_mode_id]) ? $lookup[$stereo_mode_id] : '');
rlm@3 1610 }
rlm@3 1611
rlm@3 1612
rlm@3 1613
rlm@3 1614 public static function LAMEmiscSourceSampleFrequencyLookup($source_sample_frequency_id) {
rlm@3 1615
rlm@3 1616 static $lookup = array (
rlm@3 1617 0 => '<= 32 kHz',
rlm@3 1618 1 => '44.1 kHz',
rlm@3 1619 2 => '48 kHz',
rlm@3 1620 3 => '> 48kHz'
rlm@3 1621 );
rlm@3 1622 return (isset($lookup[$source_sample_frequency_id]) ? $lookup[$source_sample_frequency_id] : '');
rlm@3 1623 }
rlm@3 1624
rlm@3 1625
rlm@3 1626
rlm@3 1627 public static function LAMEsurroundInfoLookup($surround_info_id) {
rlm@3 1628
rlm@3 1629 static $lookup = array (
rlm@3 1630 0 => 'no surround info',
rlm@3 1631 1 => 'DPL encoding',
rlm@3 1632 2 => 'DPL2 encoding',
rlm@3 1633 3 => 'Ambisonic encoding'
rlm@3 1634 );
rlm@3 1635 return (isset($lookup[$surround_info_id]) ? $lookup[$surround_info_id] : 'reserved');
rlm@3 1636 }
rlm@3 1637
rlm@3 1638
rlm@3 1639
rlm@3 1640 public static function LAMEpresetUsedLookup($lame_tag) {
rlm@3 1641
rlm@3 1642 if ($lame_tag['preset_used_id'] == 0) {
rlm@3 1643 // no preset used (LAME >=3.93)
rlm@3 1644 // no preset recorded (LAME <3.93)
rlm@3 1645 return '';
rlm@3 1646 }
rlm@3 1647
rlm@3 1648 $lame_preset_used_lookup = array ();
rlm@3 1649
rlm@3 1650 for ($i = 8; $i <= 320; $i++) {
rlm@3 1651 switch ($lame_tag['vbr_method']) {
rlm@3 1652 case 'cbr':
rlm@3 1653 $lame_preset_used_lookup[$i] = '--alt-preset '.$lame_tag['vbr_method'].' '.$i;
rlm@3 1654 break;
rlm@3 1655 case 'abr':
rlm@3 1656 default: // other VBR modes shouldn't be here(?)
rlm@3 1657 $lame_preset_used_lookup[$i] = '--alt-preset '.$i;
rlm@3 1658 break;
rlm@3 1659 }
rlm@3 1660 }
rlm@3 1661
rlm@3 1662 // named old-style presets (studio, phone, voice, etc) are handled in GuessEncoderOptions()
rlm@3 1663
rlm@3 1664 // named alt-presets
rlm@3 1665 $lame_preset_used_lookup[1000] = '--r3mix';
rlm@3 1666 $lame_preset_used_lookup[1001] = '--alt-preset standard';
rlm@3 1667 $lame_preset_used_lookup[1002] = '--alt-preset extreme';
rlm@3 1668 $lame_preset_used_lookup[1003] = '--alt-preset insane';
rlm@3 1669 $lame_preset_used_lookup[1004] = '--alt-preset fast standard';
rlm@3 1670 $lame_preset_used_lookup[1005] = '--alt-preset fast extreme';
rlm@3 1671 $lame_preset_used_lookup[1006] = '--alt-preset medium';
rlm@3 1672 $lame_preset_used_lookup[1007] = '--alt-preset fast medium';
rlm@3 1673
rlm@3 1674 // LAME 3.94 additions/changes
rlm@3 1675 $lame_preset_used_lookup[1010] = '--preset portable'; // 3.94a15 Oct 21 2003
rlm@3 1676 $lame_preset_used_lookup[1015] = '--preset radio'; // 3.94a15 Oct 21 2003
rlm@3 1677
rlm@3 1678 $lame_preset_used_lookup[320] = '--preset insane'; // 3.94a15 Nov 12 2003
rlm@3 1679 $lame_preset_used_lookup[410] = '-V9';
rlm@3 1680 $lame_preset_used_lookup[420] = '-V8';
rlm@3 1681 $lame_preset_used_lookup[430] = '--preset radio'; // 3.94a15 Nov 12 2003
rlm@3 1682 $lame_preset_used_lookup[440] = '-V6';
rlm@3 1683 $lame_preset_used_lookup[450] = '--preset '.(($lame_tag['raw']['vbr_method'] == 4) ? 'fast ' : '').'portable'; // 3.94a15 Nov 12 2003
rlm@3 1684 $lame_preset_used_lookup[460] = '--preset '.(($lame_tag['raw']['vbr_method'] == 4) ? 'fast ' : '').'medium'; // 3.94a15 Nov 12 2003
rlm@3 1685 $lame_preset_used_lookup[470] = '--r3mix'; // 3.94b1 Dec 18 2003
rlm@3 1686 $lame_preset_used_lookup[480] = '--preset '.(($lame_tag['raw']['vbr_method'] == 4) ? 'fast ' : '').'standard'; // 3.94a15 Nov 12 2003
rlm@3 1687 $lame_preset_used_lookup[490] = '-V1';
rlm@3 1688 $lame_preset_used_lookup[500] = '--preset '.(($lame_tag['raw']['vbr_method'] == 4) ? 'fast ' : '').'extreme'; // 3.94a15 Nov 12 2003
rlm@3 1689
rlm@3 1690 return (isset($lame_preset_used_lookup[$lame_tag['preset_used_id']]) ? $lame_preset_used_lookup[$lame_tag['preset_used_id']] : 'new/unknown preset: '.$lame_tag['preset_used_id'].' - report to info@getid3.org');
rlm@3 1691 }
rlm@3 1692
rlm@3 1693
rlm@3 1694 }
rlm@3 1695
rlm@3 1696 ?>