Edit File by line
/home/barbar84/www/wp-inclu.../ID3
File: module.audio.dts.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/////////////////////////////////////////////////////////////////
[2] Fix | Delete
/// getID3() by James Heinrich <info@getid3.org> //
[3] Fix | Delete
// available at https://github.com/JamesHeinrich/getID3 //
[4] Fix | Delete
// or https://www.getid3.org //
[5] Fix | Delete
// or http://getid3.sourceforge.net //
[6] Fix | Delete
// see readme.txt for more details //
[7] Fix | Delete
/////////////////////////////////////////////////////////////////
[8] Fix | Delete
// //
[9] Fix | Delete
// module.audio.dts.php //
[10] Fix | Delete
// module for analyzing DTS Audio files //
[11] Fix | Delete
// dependencies: NONE //
[12] Fix | Delete
// //
[13] Fix | Delete
/////////////////////////////////////////////////////////////////
[14] Fix | Delete
[15] Fix | Delete
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
[16] Fix | Delete
exit;
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* @tutorial http://wiki.multimedia.cx/index.php?title=DTS
[21] Fix | Delete
*/
[22] Fix | Delete
class getid3_dts extends getid3_handler
[23] Fix | Delete
{
[24] Fix | Delete
/**
[25] Fix | Delete
* Default DTS syncword used in native .cpt or .dts formats.
[26] Fix | Delete
*/
[27] Fix | Delete
const syncword = "\x7F\xFE\x80\x01";
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* @var int
[31] Fix | Delete
*/
[32] Fix | Delete
private $readBinDataOffset = 0;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Possible syncwords indicating bitstream encoding.
[36] Fix | Delete
*/
[37] Fix | Delete
public static $syncwords = array(
[38] Fix | Delete
0 => "\x7F\xFE\x80\x01", // raw big-endian
[39] Fix | Delete
1 => "\xFE\x7F\x01\x80", // raw little-endian
[40] Fix | Delete
2 => "\x1F\xFF\xE8\x00", // 14-bit big-endian
[41] Fix | Delete
3 => "\xFF\x1F\x00\xE8"); // 14-bit little-endian
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* @return bool
[45] Fix | Delete
*/
[46] Fix | Delete
public function Analyze() {
[47] Fix | Delete
$info = &$this->getid3->info;
[48] Fix | Delete
$info['fileformat'] = 'dts';
[49] Fix | Delete
[50] Fix | Delete
$this->fseek($info['avdataoffset']);
[51] Fix | Delete
$DTSheader = $this->fread(20); // we only need 2 words magic + 6 words frame header, but these words may be normal 16-bit words OR 14-bit words with 2 highest bits set to zero, so 8 words can be either 8*16/8 = 16 bytes OR 8*16*(16/14)/8 = 18.3 bytes
[52] Fix | Delete
[53] Fix | Delete
// check syncword
[54] Fix | Delete
$sync = substr($DTSheader, 0, 4);
[55] Fix | Delete
if (($encoding = array_search($sync, self::$syncwords)) !== false) {
[56] Fix | Delete
[57] Fix | Delete
$info['dts']['raw']['magic'] = $sync;
[58] Fix | Delete
$this->readBinDataOffset = 32;
[59] Fix | Delete
[60] Fix | Delete
} elseif ($this->isDependencyFor('matroska')) {
[61] Fix | Delete
[62] Fix | Delete
// Matroska contains DTS without syncword encoded as raw big-endian format
[63] Fix | Delete
$encoding = 0;
[64] Fix | Delete
$this->readBinDataOffset = 0;
[65] Fix | Delete
[66] Fix | Delete
} else {
[67] Fix | Delete
[68] Fix | Delete
unset($info['fileformat']);
[69] Fix | Delete
return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"');
[70] Fix | Delete
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
// decode header
[74] Fix | Delete
$fhBS = '';
[75] Fix | Delete
for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) {
[76] Fix | Delete
switch ($encoding) {
[77] Fix | Delete
case 0: // raw big-endian
[78] Fix | Delete
$fhBS .= getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) );
[79] Fix | Delete
break;
[80] Fix | Delete
case 1: // raw little-endian
[81] Fix | Delete
$fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2)));
[82] Fix | Delete
break;
[83] Fix | Delete
case 2: // 14-bit big-endian
[84] Fix | Delete
$fhBS .= substr(getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ), 2, 14);
[85] Fix | Delete
break;
[86] Fix | Delete
case 3: // 14-bit little-endian
[87] Fix | Delete
$fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14);
[88] Fix | Delete
break;
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
$info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1);
[93] Fix | Delete
$info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5);
[94] Fix | Delete
$info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1);
[95] Fix | Delete
$info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7);
[96] Fix | Delete
$info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14);
[97] Fix | Delete
$info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6);
[98] Fix | Delete
$info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4);
[99] Fix | Delete
$info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5);
[100] Fix | Delete
$info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1);
[101] Fix | Delete
$info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1);
[102] Fix | Delete
$info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1);
[103] Fix | Delete
$info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1);
[104] Fix | Delete
$info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1);
[105] Fix | Delete
$info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3);
[106] Fix | Delete
$info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1);
[107] Fix | Delete
$info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1);
[108] Fix | Delete
$info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2);
[109] Fix | Delete
$info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1);
[110] Fix | Delete
if ($info['dts']['flags']['crc_present']) {
[111] Fix | Delete
$info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16);
[112] Fix | Delete
}
[113] Fix | Delete
$info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1);
[114] Fix | Delete
$info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4);
[115] Fix | Delete
$info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2);
[116] Fix | Delete
$info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2);
[117] Fix | Delete
$info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1);
[118] Fix | Delete
$info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
[119] Fix | Delete
$info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1);
[120] Fix | Delete
$info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4);
[121] Fix | Delete
[122] Fix | Delete
[123] Fix | Delete
$info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']);
[124] Fix | Delete
$info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']);
[125] Fix | Delete
$info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']);
[126] Fix | Delete
$info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']);
[127] Fix | Delete
$info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false);
[128] Fix | Delete
$info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr');
[129] Fix | Delete
$info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']);
[130] Fix | Delete
$info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']);
[131] Fix | Delete
[132] Fix | Delete
$info['audio']['dataformat'] = 'dts';
[133] Fix | Delete
$info['audio']['lossless'] = $info['dts']['flags']['lossless'];
[134] Fix | Delete
$info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode'];
[135] Fix | Delete
$info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample'];
[136] Fix | Delete
$info['audio']['sample_rate'] = $info['dts']['sample_rate'];
[137] Fix | Delete
$info['audio']['channels'] = $info['dts']['channels'];
[138] Fix | Delete
$info['audio']['bitrate'] = $info['dts']['bitrate'];
[139] Fix | Delete
if (isset($info['avdataend']) && !empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) {
[140] Fix | Delete
$info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8);
[141] Fix | Delete
if (($encoding == 2) || ($encoding == 3)) {
[142] Fix | Delete
// 14-bit data packed into 16-bit words, so the playtime is wrong because only (14/16) of the bytes in the data portion of the file are used at the specified bitrate
[143] Fix | Delete
$info['playtime_seconds'] *= (14 / 16);
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
return true;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* @param string $bin
[151] Fix | Delete
* @param int $length
[152] Fix | Delete
*
[153] Fix | Delete
* @return int
[154] Fix | Delete
*/
[155] Fix | Delete
private function readBinData($bin, $length) {
[156] Fix | Delete
$data = substr($bin, $this->readBinDataOffset, $length);
[157] Fix | Delete
$this->readBinDataOffset += $length;
[158] Fix | Delete
[159] Fix | Delete
return bindec($data);
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* @param int $index
[164] Fix | Delete
*
[165] Fix | Delete
* @return int|string|false
[166] Fix | Delete
*/
[167] Fix | Delete
public static function bitrateLookup($index) {
[168] Fix | Delete
static $lookup = array(
[169] Fix | Delete
0 => 32000,
[170] Fix | Delete
1 => 56000,
[171] Fix | Delete
2 => 64000,
[172] Fix | Delete
3 => 96000,
[173] Fix | Delete
4 => 112000,
[174] Fix | Delete
5 => 128000,
[175] Fix | Delete
6 => 192000,
[176] Fix | Delete
7 => 224000,
[177] Fix | Delete
8 => 256000,
[178] Fix | Delete
9 => 320000,
[179] Fix | Delete
10 => 384000,
[180] Fix | Delete
11 => 448000,
[181] Fix | Delete
12 => 512000,
[182] Fix | Delete
13 => 576000,
[183] Fix | Delete
14 => 640000,
[184] Fix | Delete
15 => 768000,
[185] Fix | Delete
16 => 960000,
[186] Fix | Delete
17 => 1024000,
[187] Fix | Delete
18 => 1152000,
[188] Fix | Delete
19 => 1280000,
[189] Fix | Delete
20 => 1344000,
[190] Fix | Delete
21 => 1408000,
[191] Fix | Delete
22 => 1411200,
[192] Fix | Delete
23 => 1472000,
[193] Fix | Delete
24 => 1536000,
[194] Fix | Delete
25 => 1920000,
[195] Fix | Delete
26 => 2048000,
[196] Fix | Delete
27 => 3072000,
[197] Fix | Delete
28 => 3840000,
[198] Fix | Delete
29 => 'open',
[199] Fix | Delete
30 => 'variable',
[200] Fix | Delete
31 => 'lossless',
[201] Fix | Delete
);
[202] Fix | Delete
return (isset($lookup[$index]) ? $lookup[$index] : false);
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* @param int $index
[207] Fix | Delete
*
[208] Fix | Delete
* @return int|string|false
[209] Fix | Delete
*/
[210] Fix | Delete
public static function sampleRateLookup($index) {
[211] Fix | Delete
static $lookup = array(
[212] Fix | Delete
0 => 'invalid',
[213] Fix | Delete
1 => 8000,
[214] Fix | Delete
2 => 16000,
[215] Fix | Delete
3 => 32000,
[216] Fix | Delete
4 => 'invalid',
[217] Fix | Delete
5 => 'invalid',
[218] Fix | Delete
6 => 11025,
[219] Fix | Delete
7 => 22050,
[220] Fix | Delete
8 => 44100,
[221] Fix | Delete
9 => 'invalid',
[222] Fix | Delete
10 => 'invalid',
[223] Fix | Delete
11 => 12000,
[224] Fix | Delete
12 => 24000,
[225] Fix | Delete
13 => 48000,
[226] Fix | Delete
14 => 'invalid',
[227] Fix | Delete
15 => 'invalid',
[228] Fix | Delete
);
[229] Fix | Delete
return (isset($lookup[$index]) ? $lookup[$index] : false);
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* @param int $index
[234] Fix | Delete
*
[235] Fix | Delete
* @return int|false
[236] Fix | Delete
*/
[237] Fix | Delete
public static function bitPerSampleLookup($index) {
[238] Fix | Delete
static $lookup = array(
[239] Fix | Delete
0 => 16,
[240] Fix | Delete
1 => 20,
[241] Fix | Delete
2 => 24,
[242] Fix | Delete
3 => 24,
[243] Fix | Delete
);
[244] Fix | Delete
return (isset($lookup[$index]) ? $lookup[$index] : false);
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* @param int $index
[249] Fix | Delete
*
[250] Fix | Delete
* @return int|false
[251] Fix | Delete
*/
[252] Fix | Delete
public static function numChannelsLookup($index) {
[253] Fix | Delete
switch ($index) {
[254] Fix | Delete
case 0:
[255] Fix | Delete
return 1;
[256] Fix | Delete
case 1:
[257] Fix | Delete
case 2:
[258] Fix | Delete
case 3:
[259] Fix | Delete
case 4:
[260] Fix | Delete
return 2;
[261] Fix | Delete
case 5:
[262] Fix | Delete
case 6:
[263] Fix | Delete
return 3;
[264] Fix | Delete
case 7:
[265] Fix | Delete
case 8:
[266] Fix | Delete
return 4;
[267] Fix | Delete
case 9:
[268] Fix | Delete
return 5;
[269] Fix | Delete
case 10:
[270] Fix | Delete
case 11:
[271] Fix | Delete
case 12:
[272] Fix | Delete
return 6;
[273] Fix | Delete
case 13:
[274] Fix | Delete
return 7;
[275] Fix | Delete
case 14:
[276] Fix | Delete
case 15:
[277] Fix | Delete
return 8;
[278] Fix | Delete
}
[279] Fix | Delete
return false;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* @param int $index
[284] Fix | Delete
*
[285] Fix | Delete
* @return string
[286] Fix | Delete
*/
[287] Fix | Delete
public static function channelArrangementLookup($index) {
[288] Fix | Delete
static $lookup = array(
[289] Fix | Delete
0 => 'A',
[290] Fix | Delete
1 => 'A + B (dual mono)',
[291] Fix | Delete
2 => 'L + R (stereo)',
[292] Fix | Delete
3 => '(L+R) + (L-R) (sum-difference)',
[293] Fix | Delete
4 => 'LT + RT (left and right total)',
[294] Fix | Delete
5 => 'C + L + R',
[295] Fix | Delete
6 => 'L + R + S',
[296] Fix | Delete
7 => 'C + L + R + S',
[297] Fix | Delete
8 => 'L + R + SL + SR',
[298] Fix | Delete
9 => 'C + L + R + SL + SR',
[299] Fix | Delete
10 => 'CL + CR + L + R + SL + SR',
[300] Fix | Delete
11 => 'C + L + R+ LR + RR + OV',
[301] Fix | Delete
12 => 'CF + CR + LF + RF + LR + RR',
[302] Fix | Delete
13 => 'CL + C + CR + L + R + SL + SR',
[303] Fix | Delete
14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2',
[304] Fix | Delete
15 => 'CL + C+ CR + L + R + SL + S + SR',
[305] Fix | Delete
);
[306] Fix | Delete
return (isset($lookup[$index]) ? $lookup[$index] : 'user-defined');
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* @param int $index
[311] Fix | Delete
* @param int $version
[312] Fix | Delete
*
[313] Fix | Delete
* @return int|false
[314] Fix | Delete
*/
[315] Fix | Delete
public static function dialogNormalization($index, $version) {
[316] Fix | Delete
switch ($version) {
[317] Fix | Delete
case 7:
[318] Fix | Delete
return 0 - $index;
[319] Fix | Delete
case 6:
[320] Fix | Delete
return 0 - 16 - $index;
[321] Fix | Delete
}
[322] Fix | Delete
return false;
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function