ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Dts.php
Go to the documentation of this file.
1<?php
2
3namespace GetId3\Module\Audio;
4
7
10// available at http://getid3.sourceforge.net //
11// or http://www.getid3.org //
13// See readme.txt for more details //
15// //
16// module.audio.dts.php //
17// module for analyzing DTS Audio files //
18// dependencies: NONE //
19// //
21
29class Dts extends BaseHandler
30{
35 public function analyze()
36 {
37 $info = &$this->getid3->info;
38
39 // Specs taken from "DTS Coherent Acoustics;Core and Extensions, ETSI TS 102 114 V1.2.1 (2002-12)"
40 // (http://pda.etsi.org/pda/queryform.asp)
41 // With thanks to Gambit <macteam@users.sourceforge.net> http://mac.sourceforge.net/atl/
42
43 $info['fileformat'] = 'dts';
44
45 $this->fseek($info['avdataoffset']);
46 $DTSheader = $this->fread(16);
47
48 $magic = "\x7F\xFE\x80\x01";
49
50 if (strpos($DTSheader, $magic) === 0) {
51 $info['dts']['raw']['magic'] = $magic;
52 $offset = 4;
53 } else {
54 if (!$this->isDependencyFor('matroska')) {
55 unset($info['fileformat']);
56
57 return $this->error('Expecting "'.Helper::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.Helper::PrintHexBytes(substr($DTSheader, 0, 4)).'"');
58 }
59 $offset = 0;
60 }
61
62 $fhBS = Helper::BigEndian2Bin(substr($DTSheader, $offset, 12));
63 $bsOffset = 0;
64 $info['dts']['raw']['frame_type'] = $this->readBinData($fhBS, $bsOffset, 1);
65 $info['dts']['raw']['deficit_samples'] = $this->readBinData($fhBS, $bsOffset, 5);
66 $info['dts']['flags']['crc_present'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
67 $info['dts']['raw']['pcm_sample_blocks'] = $this->readBinData($fhBS, $bsOffset, 7);
68 $info['dts']['raw']['frame_byte_size'] = $this->readBinData($fhBS, $bsOffset, 14);
69 $info['dts']['raw']['channel_arrangement'] = $this->readBinData($fhBS, $bsOffset, 6);
70 $info['dts']['raw']['sample_frequency'] = $this->readBinData($fhBS, $bsOffset, 4);
71 $info['dts']['raw']['bitrate'] = $this->readBinData($fhBS, $bsOffset, 5);
72 $info['dts']['flags']['embedded_downmix'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
73 $info['dts']['flags']['dynamicrange'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
74 $info['dts']['flags']['timestamp'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
75 $info['dts']['flags']['auxdata'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
76 $info['dts']['flags']['hdcd'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
77 $info['dts']['raw']['extension_audio'] = $this->readBinData($fhBS, $bsOffset, 3);
78 $info['dts']['flags']['extended_coding'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
79 $info['dts']['flags']['audio_sync_insertion'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
80 $info['dts']['raw']['lfe_effects'] = $this->readBinData($fhBS, $bsOffset, 2);
81 $info['dts']['flags']['predictor_history'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
82 if ($info['dts']['flags']['crc_present']) {
83 $info['dts']['raw']['crc16'] = $this->readBinData($fhBS, $bsOffset, 16);
84 }
85 $info['dts']['flags']['mri_perfect_reconst'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
86 $info['dts']['raw']['encoder_soft_version'] = $this->readBinData($fhBS, $bsOffset, 4);
87 $info['dts']['raw']['copy_history'] = $this->readBinData($fhBS, $bsOffset, 2);
88 $info['dts']['raw']['bits_per_sample'] = $this->readBinData($fhBS, $bsOffset, 2);
89 $info['dts']['flags']['surround_es'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
90 $info['dts']['flags']['front_sum_diff'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
91 $info['dts']['flags']['surround_sum_diff'] = (bool) $this->readBinData($fhBS, $bsOffset, 1);
92 $info['dts']['raw']['dialog_normalization'] = $this->readBinData($fhBS, $bsOffset, 4);
93
94 $info['dts']['bitrate'] = self::bitrateLookup($info['dts']['raw']['bitrate']);
95 $info['dts']['bits_per_sample'] = self::bitPerSampleLookup($info['dts']['raw']['bits_per_sample']);
96 $info['dts']['sample_rate'] = self::sampleRateLookup($info['dts']['raw']['sample_frequency']);
97 $info['dts']['dialog_normalization'] = self::dialogNormalization($info['dts']['raw']['dialog_normalization'], $info['dts']['raw']['encoder_soft_version']);
98 $info['dts']['flags']['lossless'] = (($info['dts']['raw']['bitrate'] == 31) ? true : false);
99 $info['dts']['bitrate_mode'] = (($info['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr');
100 $info['dts']['channels'] = self::numChannelsLookup($info['dts']['raw']['channel_arrangement']);
101 $info['dts']['channel_arrangement'] = self::channelArrangementLookup($info['dts']['raw']['channel_arrangement']);
102
103 $info['audio']['dataformat'] = 'dts';
104 $info['audio']['lossless'] = $info['dts']['flags']['lossless'];
105 $info['audio']['bitrate_mode'] = $info['dts']['bitrate_mode'];
106 $info['audio']['bits_per_sample'] = $info['dts']['bits_per_sample'];
107 $info['audio']['sample_rate'] = $info['dts']['sample_rate'];
108 $info['audio']['channels'] = $info['dts']['channels'];
109 $info['audio']['bitrate'] = $info['dts']['bitrate'];
110 if (isset($info['avdataend'])) {
111 $info['playtime_seconds'] = ($info['avdataend'] - $info['avdataoffset']) / ($info['dts']['bitrate'] / 8);
112 }
113
114 return true;
115 }
116
124 private function readBinData($bin, &$offset, $length)
125 {
126 $data = substr($bin, $offset, $length);
127 $offset += $length;
128
129 return bindec($data);
130 }
131
137 private static function bitrateLookup($index)
138 {
139 $DTSbitrateLookup = array(
140 0 => 32000,
141 1 => 56000,
142 2 => 64000,
143 3 => 96000,
144 4 => 112000,
145 5 => 128000,
146 6 => 192000,
147 7 => 224000,
148 8 => 256000,
149 9 => 320000,
150 10 => 384000,
151 11 => 448000,
152 12 => 512000,
153 13 => 576000,
154 14 => 640000,
155 15 => 768000,
156 16 => 960000,
157 17 => 1024000,
158 18 => 1152000,
159 19 => 1280000,
160 20 => 1344000,
161 21 => 1408000,
162 22 => 1411200,
163 23 => 1472000,
164 24 => 1536000,
165 25 => 1920000,
166 26 => 2048000,
167 27 => 3072000,
168 28 => 3840000,
169 29 => 'open',
170 30 => 'variable',
171 31 => 'lossless'
172 );
173
174 return (isset($DTSbitrateLookup[$index]) ? $DTSbitrateLookup[$index] : false);
175 }
176
182 private static function sampleRateLookup($index)
183 {
184 $DTSsampleRateLookup = array(
185 0 => 'invalid',
186 1 => 8000,
187 2 => 16000,
188 3 => 32000,
189 4 => 'invalid',
190 5 => 'invalid',
191 6 => 11025,
192 7 => 22050,
193 8 => 44100,
194 9 => 'invalid',
195 10 => 'invalid',
196 11 => 12000,
197 12 => 24000,
198 13 => 48000,
199 14 => 'invalid',
200 15 => 'invalid'
201 );
202
203 return (isset($DTSsampleRateLookup[$index]) ? $DTSsampleRateLookup[$index] : false);
204 }
205
211 private static function bitPerSampleLookup($index)
212 {
213 $DTSbitPerSampleLookup = array(
214 0 => 16,
215 1 => 20,
216 2 => 24,
217 3 => 24,
218 );
219
220 return (isset($DTSbitPerSampleLookup[$index]) ? $DTSbitPerSampleLookup[$index] : false);
221 }
222
228 private static function numChannelsLookup($index)
229 {
230 switch ($index) {
231 case 0:
232 return 1;
233 break;
234 case 1:
235 case 2:
236 case 3:
237 case 4:
238 return 2;
239 break;
240 case 5:
241 case 6:
242 return 3;
243 break;
244 case 7:
245 case 8:
246 return 4;
247 break;
248 case 9:
249 return 5;
250 break;
251 case 10:
252 case 11:
253 case 12:
254 return 6;
255 break;
256 case 13:
257 return 7;
258 break;
259 case 14:
260 case 15:
261 return 8;
262 break;
263 }
264
265 return false;
266 }
267
273 private static function channelArrangementLookup($index)
274 {
275 $DTSchannelArrangementLookup = array(
276 0 => 'A',
277 1 => 'A + B (dual mono)',
278 2 => 'L + R (stereo)',
279 3 => '(L+R) + (L-R) (sum-difference)',
280 4 => 'LT + RT (left and right total)',
281 5 => 'C + L + R',
282 6 => 'L + R + S',
283 7 => 'C + L + R + S',
284 8 => 'L + R + SL + SR',
285 9 => 'C + L + R + SL + SR',
286 10 => 'CL + CR + L + R + SL + SR',
287 11 => 'C + L + R+ LR + RR + OV',
288 12 => 'CF + CR + LF + RF + LR + RR',
289 13 => 'CL + C + CR + L + R + SL + SR',
290 14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2',
291 15 => 'CL + C+ CR + L + R + SL + S + SR',
292 );
293
294 return (isset($DTSchannelArrangementLookup[$index]) ? $DTSchannelArrangementLookup[$index] : 'user-defined');
295 }
296
303 private static function dialogNormalization($index, $version)
304 {
305 switch ($version) {
306 case 7:
307 return 0 - $index;
308 break;
309 case 6:
310 return 0 - 16 - $index;
311 break;
312 }
313
314 return false;
315 }
316
317}
An exception for terminatinating execution or to throw for unit testing.
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:26
fseek($bytes, $whence=SEEK_SET)
GetId3() by James Heinrich info@getid3.org //.
Definition: Helper.php:27
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: Helper.php:36
static BigEndian2Bin($byteword)
Definition: Helper.php:423
GetId3() by James Heinrich info@getid3.org //.
Definition: Dts.php:30
static sampleRateLookup($index)
Definition: Dts.php:182
static bitPerSampleLookup($index)
Definition: Dts.php:211
static channelArrangementLookup($index)
Definition: Dts.php:273
readBinData($bin, &$offset, $length)
Definition: Dts.php:124
static numChannelsLookup($index)
Definition: Dts.php:228
static dialogNormalization($index, $version)
Definition: Dts.php:303
static bitrateLookup($index)
Definition: Dts.php:137
$info
Definition: example_052.php:80