getid3_dts

The WordPress Core getid3 dts class.

Defined (1)

The class is defined in the following location(s).

/wp-includes/ID3/module.audio.dts.php  
  1. class getid3_dts extends getid3_handler 
  2. /** 
  3. * Default DTS syncword used in native .cpt or .dts formats 
  4. */ 
  5. const syncword = "\x7F\xFE\x80\x01"; 
  6.  
  7. private $readBinDataOffset = 0; 
  8.  
  9. /** 
  10. * Possible syncwords indicating bitstream encoding 
  11. */ 
  12. public static $syncwords = array( 
  13. 0 => "\x7F\xFE\x80\x01", // raw big-endian 
  14. 1 => "\xFE\x7F\x01\x80", // raw little-endian 
  15. 2 => "\x1F\xFF\xE8\x00", // 14-bit big-endian 
  16. 3 => "\xFF\x1F\x00\xE8"); // 14-bit little-endian 
  17.  
  18. public function Analyze() { 
  19. $info = &$this->getid3->info; 
  20. $info['fileformat'] = 'dts'; 
  21.  
  22. $this->fseek($info['avdataoffset']); 
  23. $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 
  24.  
  25. // check syncword 
  26. $sync = substr($DTSheader, 0, 4); 
  27. if (($encoding = array_search($sync, self::$syncwords)) !== false) { 
  28.  
  29. $info['dts']['raw']['magic'] = $sync; 
  30. $this->readBinDataOffset = 32; 
  31.  
  32. } elseif ($this->isDependencyFor('matroska')) { 
  33.  
  34. // Matroska contains DTS without syncword encoded as raw big-endian format 
  35. $encoding = 0; 
  36. $this->readBinDataOffset = 0; 
  37.  
  38. } else { 
  39.  
  40. unset($info['fileformat']); 
  41. return $this->error('Expecting "'.implode('| ', array_map('getid3_lib::PrintHexBytes', self::$syncwords)).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($sync).'"'); 
  42.  
  43.  
  44. // decode header 
  45. $fhBS = ''; 
  46. for ($word_offset = 0; $word_offset <= strlen($DTSheader); $word_offset += 2) { 
  47. switch ($encoding) { 
  48. case 0: // raw big-endian 
  49. $fhBS .= getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ); 
  50. break; 
  51. case 1: // raw little-endian 
  52. $fhBS .= getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))); 
  53. break; 
  54. case 2: // 14-bit big-endian 
  55. $fhBS .= substr(getid3_lib::BigEndian2Bin( substr($DTSheader, $word_offset, 2) ), 2, 14); 
  56. break; 
  57. case 3: // 14-bit little-endian 
  58. $fhBS .= substr(getid3_lib::BigEndian2Bin(strrev(substr($DTSheader, $word_offset, 2))), 2, 14); 
  59. break; 
  60.  
  61. $info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, 1); 
  62. $info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, 5); 
  63. $info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, 1); 
  64. $info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, 7); 
  65. $info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, 14); 
  66. $info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, 6); 
  67. $info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, 4); 
  68. $info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, 5); 
  69. $info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, 1); 
  70. $info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, 1); 
  71. $info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, 1); 
  72. $info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, 1); 
  73. $info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, 1); 
  74. $info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, 3); 
  75. $info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, 1); 
  76. $info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, 1); 
  77. $info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, 2); 
  78. $info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, 1); 
  79. if ($info['dts']['flags']['crc_present']) { 
  80. $info['dts']['raw']['crc16'] = $this->readBinData($fhBS, 16); 
  81. $info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, 1); 
  82. $info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, 4); 
  83. $info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, 2); 
  84. $info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, 2); 
  85. $info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, 1); 
  86. $info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, 1); 
  87. $info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, 1); 
  88. $info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, 4); 
  89.  
  90.  
  91. $info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']); 
  92. $info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']); 
  93. $info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']); 
  94. $info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']); 
  95. $info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false); 
  96. $info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr'); 
  97. $info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']); 
  98. $info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']); 
  99.  
  100. $info['audio']['dataformat'] = 'dts'; 
  101. $info['audio']['lossless'] = $info['dts']['flags']['lossless']; 
  102. $info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode']; 
  103. $info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample']; 
  104. $info['audio']['sample_rate'] = $info['dts']['sample_rate']; 
  105. $info['audio']['channels'] = $info['dts']['channels']; 
  106. $info['audio']['bitrate'] = $info['dts']['bitrate']; 
  107. if (isset($info['avdataend']) && !empty($info['dts']['bitrate']) && is_numeric($info['dts']['bitrate'])) { 
  108. $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8); 
  109. if (($encoding == 2) || ($encoding == 3)) { 
  110. // 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 
  111. $info['playtime_seconds'] *= (14 / 16); 
  112. return true; 
  113.  
  114. private function readBinData($bin, $length) { 
  115. $data = substr($bin, $this->readBinDataOffset, $length); 
  116. $this->readBinDataOffset += $length; 
  117.  
  118. return bindec($data); 
  119.  
  120. public static function bitrateLookup($index) { 
  121. static $lookup = array( 
  122. 0 => 32000,  
  123. 1 => 56000,  
  124. 2 => 64000,  
  125. 3 => 96000,  
  126. 4 => 112000,  
  127. 5 => 128000,  
  128. 6 => 192000,  
  129. 7 => 224000,  
  130. 8 => 256000,  
  131. 9 => 320000,  
  132. 10 => 384000,  
  133. 11 => 448000,  
  134. 12 => 512000,  
  135. 13 => 576000,  
  136. 14 => 640000,  
  137. 15 => 768000,  
  138. 16 => 960000,  
  139. 17 => 1024000,  
  140. 18 => 1152000,  
  141. 19 => 1280000,  
  142. 20 => 1344000,  
  143. 21 => 1408000,  
  144. 22 => 1411200,  
  145. 23 => 1472000,  
  146. 24 => 1536000,  
  147. 25 => 1920000,  
  148. 26 => 2048000,  
  149. 27 => 3072000,  
  150. 28 => 3840000,  
  151. 29 => 'open',  
  152. 30 => 'variable',  
  153. 31 => 'lossless',  
  154. ); 
  155. return (isset($lookup[$index]) ? $lookup[$index] : false); 
  156.  
  157. public static function sampleRateLookup($index) { 
  158. static $lookup = array( 
  159. 0 => 'invalid',  
  160. 1 => 8000,  
  161. 2 => 16000,  
  162. 3 => 32000,  
  163. 4 => 'invalid',  
  164. 5 => 'invalid',  
  165. 6 => 11025,  
  166. 7 => 22050,  
  167. 8 => 44100,  
  168. 9 => 'invalid',  
  169. 10 => 'invalid',  
  170. 11 => 12000,  
  171. 12 => 24000,  
  172. 13 => 48000,  
  173. 14 => 'invalid',  
  174. 15 => 'invalid',  
  175. ); 
  176. return (isset($lookup[$index]) ? $lookup[$index] : false); 
  177.  
  178. public static function bitPerSampleLookup($index) { 
  179. static $lookup = array( 
  180. 0 => 16,  
  181. 1 => 20,  
  182. 2 => 24,  
  183. 3 => 24,  
  184. ); 
  185. return (isset($lookup[$index]) ? $lookup[$index] : false); 
  186.  
  187. public static function numChannelsLookup($index) { 
  188. switch ($index) { 
  189. case 0: 
  190. return 1; 
  191. break; 
  192. case 1: 
  193. case 2: 
  194. case 3: 
  195. case 4: 
  196. return 2; 
  197. break; 
  198. case 5: 
  199. case 6: 
  200. return 3; 
  201. break; 
  202. case 7: 
  203. case 8: 
  204. return 4; 
  205. break; 
  206. case 9: 
  207. return 5; 
  208. break; 
  209. case 10: 
  210. case 11: 
  211. case 12: 
  212. return 6; 
  213. break; 
  214. case 13: 
  215. return 7; 
  216. break; 
  217. case 14: 
  218. case 15: 
  219. return 8; 
  220. break; 
  221. return false; 
  222.  
  223. public static function channelArrangementLookup($index) { 
  224. static $lookup = array( 
  225. 0 => 'A',  
  226. 1 => 'A + B (dual mono)',  
  227. 2 => 'L + R (stereo)',  
  228. 3 => '(L+R) + (L-R) (sum-difference)',  
  229. 4 => 'LT + RT (left and right total)',  
  230. 5 => 'C + L + R',  
  231. 6 => 'L + R + S',  
  232. 7 => 'C + L + R + S',  
  233. 8 => 'L + R + SL + SR',  
  234. 9 => 'C + L + R + SL + SR',  
  235. 10 => 'CL + CR + L + R + SL + SR',  
  236. 11 => 'C + L + R+ LR + RR + OV',  
  237. 12 => 'CF + CR + LF + RF + LR + RR',  
  238. 13 => 'CL + C + CR + L + R + SL + SR',  
  239. 14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2',  
  240. 15 => 'CL + C+ CR + L + R + SL + S + SR',  
  241. ); 
  242. return (isset($lookup[$index]) ? $lookup[$index] : 'user-defined'); 
  243.  
  244. public static function dialogNormalization($index, $version) { 
  245. switch ($version) { 
  246. case 7: 
  247. return 0 - $index; 
  248. break; 
  249. case 6: 
  250. return 0 - 16 - $index; 
  251. break; 
  252. return false; 
  253.