source: extensions/charlies_content/getid3/getid3/module.audio.dts.php @ 3544

Last change on this file since 3544 was 3544, checked in by vdigital, 15 years ago

Change: getid3 upgraded to -> 1.7.9

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1<?php
2/////////////////////////////////////////////////////////////////
3/// getID3() by James Heinrich <info@getid3.org>               //
4//  available at http://getid3.sourceforge.net                 //
5//            or http://www.getid3.org                         //
6/////////////////////////////////////////////////////////////////
7// See readme.txt for more details                             //
8/////////////////////////////////////////////////////////////////
9//                                                             //
10// module.audio.dts.php                                        //
11// module for analyzing DTS Audio files                        //
12// dependencies: NONE                                          //
13//                                                             //
14/////////////////////////////////////////////////////////////////
15
16
17class getid3_dts
18{
19
20    function getid3_dts(&$fd, &$ThisFileInfo) {
21        // Specs taken from "DTS Coherent Acoustics;Core and Extensions,  ETSI TS 102 114 V1.2.1 (2002-12)"
22        // (http://pda.etsi.org/pda/queryform.asp)
23        // With thanks to Gambit <macteam@users.sourceforge.net> http://mac.sourceforge.net/atl/
24
25        $ThisFileInfo['fileformat'] = 'dts';
26
27        fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
28        $DTSheader = fread($fd, 16);
29
30        $ThisFileInfo['dts']['raw']['magic'] = getid3_lib::BigEndian2Int(substr($DTSheader,  0,  4));
31        if ($ThisFileInfo['dts']['raw']['magic'] != 0x7FFE8001) {
32            $ThisFileInfo['error'][] = 'Expecting "0x7FFE8001" at offset '.$ThisFileInfo['avdataoffset'].', found "0x'.str_pad(strtoupper(dechex($ThisFileInfo['dts']['raw']['magic'])), 8, '0', STR_PAD_LEFT).'"';
33            unset($ThisFileInfo['fileformat']);
34            unset($ThisFileInfo['dts']);
35            return false;
36        }
37
38        $fhBS = getid3_lib::BigEndian2Bin(substr($DTSheader,  4,  12));
39        $bsOffset = 0;
40        $ThisFileInfo['dts']['raw']['frame_type']             =        bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
41        $ThisFileInfo['dts']['raw']['deficit_samples']        =        bindec(substr($fhBS, $bsOffset,  5)); $bsOffset +=  5;
42        $ThisFileInfo['dts']['flags']['crc_present']          = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
43        $ThisFileInfo['dts']['raw']['pcm_sample_blocks']      =        bindec(substr($fhBS, $bsOffset,  7)); $bsOffset +=  7;
44        $ThisFileInfo['dts']['raw']['frame_byte_size']        =        bindec(substr($fhBS, $bsOffset, 14)); $bsOffset += 14;
45        $ThisFileInfo['dts']['raw']['channel_arrangement']    =        bindec(substr($fhBS, $bsOffset,  6)); $bsOffset +=  6;
46        $ThisFileInfo['dts']['raw']['sample_frequency']       =        bindec(substr($fhBS, $bsOffset,  4)); $bsOffset +=  4;
47        $ThisFileInfo['dts']['raw']['bitrate']                =        bindec(substr($fhBS, $bsOffset,  5)); $bsOffset +=  5;
48        $ThisFileInfo['dts']['flags']['embedded_downmix']     = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
49        $ThisFileInfo['dts']['flags']['dynamicrange']         = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
50        $ThisFileInfo['dts']['flags']['timestamp']            = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
51        $ThisFileInfo['dts']['flags']['auxdata']              = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
52        $ThisFileInfo['dts']['flags']['hdcd']                 = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
53        $ThisFileInfo['dts']['raw']['extension_audio']        =        bindec(substr($fhBS, $bsOffset,  3)); $bsOffset +=  3;
54        $ThisFileInfo['dts']['flags']['extended_coding']      = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
55        $ThisFileInfo['dts']['flags']['audio_sync_insertion'] = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
56        $ThisFileInfo['dts']['raw']['lfe_effects']            =        bindec(substr($fhBS, $bsOffset,  2)); $bsOffset +=  2;
57        $ThisFileInfo['dts']['flags']['predictor_history']    = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
58        if ($ThisFileInfo['dts']['flags']['crc_present']) {
59            $ThisFileInfo['dts']['raw']['crc16']              =        bindec(substr($fhBS, $bsOffset, 16)); $bsOffset += 16;
60        }
61        $ThisFileInfo['dts']['flags']['mri_perfect_reconst']  = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
62        $ThisFileInfo['dts']['raw']['encoder_soft_version']   =        bindec(substr($fhBS, $bsOffset,  4)); $bsOffset +=  4;
63        $ThisFileInfo['dts']['raw']['copy_history']           =        bindec(substr($fhBS, $bsOffset,  2)); $bsOffset +=  2;
64        $ThisFileInfo['dts']['raw']['bits_per_sample']        =        bindec(substr($fhBS, $bsOffset,  2)); $bsOffset +=  2;
65        $ThisFileInfo['dts']['flags']['surround_es']          = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
66        $ThisFileInfo['dts']['flags']['front_sum_diff']       = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
67        $ThisFileInfo['dts']['flags']['surround_sum_diff']    = (bool) bindec(substr($fhBS, $bsOffset,  1)); $bsOffset +=  1;
68        $ThisFileInfo['dts']['raw']['dialog_normalization']   =        bindec(substr($fhBS, $bsOffset,  4)); $bsOffset +=  4;
69
70
71        $ThisFileInfo['dts']['bitrate']              = $this->DTSbitrateLookup($ThisFileInfo['dts']['raw']['bitrate']);
72        $ThisFileInfo['dts']['bits_per_sample']      = $this->DTSbitPerSampleLookup($ThisFileInfo['dts']['raw']['bits_per_sample']);
73        $ThisFileInfo['dts']['sample_rate']          = $this->DTSsampleRateLookup($ThisFileInfo['dts']['raw']['sample_frequency']);
74        $ThisFileInfo['dts']['dialog_normalization'] = $this->DTSdialogNormalization($ThisFileInfo['dts']['raw']['dialog_normalization'], $ThisFileInfo['dts']['raw']['encoder_soft_version']);
75        $ThisFileInfo['dts']['flags']['lossless']    = (($ThisFileInfo['dts']['raw']['bitrate'] == 31) ? true  : false);
76        $ThisFileInfo['dts']['bitrate_mode']         = (($ThisFileInfo['dts']['raw']['bitrate'] == 30) ? 'vbr' : 'cbr');
77        $ThisFileInfo['dts']['channels']             = $this->DTSnumChannelsLookup($ThisFileInfo['dts']['raw']['channel_arrangement']);
78        $ThisFileInfo['dts']['channel_arrangement']  = $this->DTSchannelArrangementLookup($ThisFileInfo['dts']['raw']['channel_arrangement']);
79
80        $ThisFileInfo['audio']['dataformat']          = 'dts';
81        $ThisFileInfo['audio']['lossless']            = $ThisFileInfo['dts']['flags']['lossless'];
82        $ThisFileInfo['audio']['bitrate_mode']        = $ThisFileInfo['dts']['bitrate_mode'];
83        $ThisFileInfo['audio']['bits_per_sample']     = $ThisFileInfo['dts']['bits_per_sample'];
84        $ThisFileInfo['audio']['sample_rate']         = $ThisFileInfo['dts']['sample_rate'];
85        $ThisFileInfo['audio']['channels']            = $ThisFileInfo['dts']['channels'];
86        $ThisFileInfo['audio']['bitrate']             = $ThisFileInfo['dts']['bitrate'];
87        if (isset($ThisFileInfo['avdataend'])) {
88                $ThisFileInfo['playtime_seconds']         = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / ($ThisFileInfo['dts']['bitrate'] / 8);
89        }
90
91        return true;
92    }
93
94    function DTSbitrateLookup($index) {
95        $DTSbitrateLookup = array(
96            0  => 32000,
97            1  => 56000,
98            2  => 64000,
99            3  => 96000,
100            4  => 112000,
101            5  => 128000,
102            6  => 192000,
103            7  => 224000,
104            8  => 256000,
105            9  => 320000,
106            10 => 384000,
107            11 => 448000,
108            12 => 512000,
109            13 => 576000,
110            14 => 640000,
111            15 => 768000,
112            16 => 960000,
113            17 => 1024000,
114            18 => 1152000,
115            19 => 1280000,
116            20 => 1344000,
117            21 => 1408000,
118            22 => 1411200,
119            23 => 1472000,
120            24 => 1536000,
121            25 => 1920000,
122            26 => 2048000,
123            27 => 3072000,
124            28 => 3840000,
125            29 => 'open',
126            30 => 'variable',
127            31 => 'lossless'
128        );
129        return @$DTSbitrateLookup[$index];
130    }
131
132    function DTSsampleRateLookup($index) {
133        $DTSsampleRateLookup = array(
134            0  => 'invalid',
135            1  => 8000,
136            2  => 16000,
137            3  => 32000,
138            4  => 'invalid',
139            5  => 'invalid',
140            6  => 11025,
141            7  => 22050,
142            8  => 44100,
143            9  => 'invalid',
144            10 => 'invalid',
145            11 => 12000,
146            12 => 24000,
147            13 => 48000,
148            14 => 'invalid',
149            15 => 'invalid'
150        );
151        return @$DTSsampleRateLookup[$index];
152    }
153
154    function DTSbitPerSampleLookup($index) {
155        $DTSbitPerSampleLookup = array(
156            0  => 16,
157            1  => 20,
158            2  => 24,
159            3  => 24,
160        );
161        return @$DTSbitPerSampleLookup[$index];
162    }
163
164    function DTSnumChannelsLookup($index) {
165        switch ($index) {
166            case 0:
167                return 1;
168                break;
169            case 1:
170            case 2:
171            case 3:
172            case 4:
173                return 2;
174                break;
175            case 5:
176            case 6:
177                return 3;
178                break;
179            case 7:
180            case 8:
181                return 4;
182                break;
183            case 9:
184                return 5;
185                break;
186            case 10:
187            case 11:
188            case 12:
189                return 6;
190                break;
191            case 13:
192                return 7;
193                break;
194            case 14:
195            case 15:
196                return 8;
197                break;
198        }
199        return false;
200    }
201
202    function DTSchannelArrangementLookup($index) {
203        $DTSchannelArrangementLookup = array(
204            0  => 'A',
205            1  => 'A + B (dual mono)',
206            2  => 'L + R (stereo)',
207            3  => '(L+R) + (L-R) (sum-difference)',
208            4  => 'LT + RT (left and right total)',
209            5  => 'C + L + R',
210            6  => 'L + R + S',
211            7  => 'C + L + R + S',
212            8  => 'L + R + SL + SR',
213            9  => 'C + L + R + SL + SR',
214            10 => 'CL + CR + L + R + SL + SR',
215            11 => 'C + L + R+ LR + RR + OV',
216            12 => 'CF + CR + LF + RF + LR + RR',
217            13 => 'CL + C + CR + L + R + SL + SR',
218            14 => 'CL + CR + L + R + SL1 + SL2 + SR1 + SR2',
219            15 => 'CL + C+ CR + L + R + SL + S + SR',
220        );
221        return (@$DTSchannelArrangementLookup[$index] ? @$DTSchannelArrangementLookup[$index] : 'user-defined');
222    }
223
224    function DTSdialogNormalization($index, $version) {
225        switch ($version) {
226            case 7:
227                return 0 - $index;
228                break;
229            case 6:
230                return 0 - 16 - $index;
231                break;
232        }
233        return false;
234    }
235
236}
237
238
239?>
Note: See TracBrowser for help on using the repository browser.