]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/ID3/module.audio.ac3.php
WordPress 4.1-scripts
[autoinstalls/wordpress.git] / wp-includes / ID3 / module.audio.ac3.php
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 //          also https://github.com/JamesHeinrich/getID3       //
7 /////////////////////////////////////////////////////////////////
8 // See readme.txt for more details                             //
9 /////////////////////////////////////////////////////////////////
10 //                                                             //
11 // module.audio.ac3.php                                        //
12 // module for analyzing AC-3 (aka Dolby Digital) audio files   //
13 // dependencies: NONE                                          //
14 //                                                            ///
15 /////////////////////////////////////////////////////////////////
16
17
18 class getid3_ac3 extends getid3_handler
19 {
20     private $AC3header = array();
21     private $BSIoffset = 0;
22
23     const syncword = "\x0B\x77";
24
25         public function Analyze() {
26                 $info = &$this->getid3->info;
27
28                 ///AH
29                 $info['ac3']['raw']['bsi'] = array();
30                 $thisfile_ac3              = &$info['ac3'];
31                 $thisfile_ac3_raw          = &$thisfile_ac3['raw'];
32                 $thisfile_ac3_raw_bsi      = &$thisfile_ac3_raw['bsi'];
33
34
35                 // http://www.atsc.org/standards/a_52a.pdf
36
37                 $info['fileformat'] = 'ac3';
38
39                 // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames
40                 // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256
41                 // new audio samples per channel. A synchronization information (SI) header at the beginning
42                 // of each frame contains information needed to acquire and maintain synchronization. A
43                 // bit stream information (BSI) header follows SI, and contains parameters describing the coded
44                 // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the
45                 // end of each frame is an error check field that includes a CRC word for error detection. An
46                 // additional CRC word is located in the SI header, the use of which, by a decoder, is optional.
47                 //
48                 // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC
49
50                 // syncinfo() {
51                 //       syncword    16
52                 //       crc1        16
53                 //       fscod        2
54                 //       frmsizecod   6
55                 // } /* end of syncinfo */
56
57                 $this->fseek($info['avdataoffset']);
58                 $this->AC3header['syncinfo'] = $this->fread(5);
59
60                 if (strpos($this->AC3header['syncinfo'], self::syncword) === 0) {
61                         $thisfile_ac3_raw['synchinfo']['synchword'] = self::syncword;
62                         $offset = 2;
63                 } else {
64                         if (!$this->isDependencyFor('matroska')) {
65                                 unset($info['fileformat'], $info['ac3']);
66                                 return $this->error('Expecting "'.getid3_lib::PrintHexBytes(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($this->AC3header['syncinfo'], 0, 2)).'"');
67                         }
68                         $offset = 0;
69                         $this->fseek(-2, SEEK_CUR);
70                 }
71
72                 $info['audio']['dataformat']   = 'ac3';
73                 $info['audio']['bitrate_mode'] = 'cbr';
74                 $info['audio']['lossless']     = false;
75
76                 $thisfile_ac3_raw['synchinfo']['crc1']       = getid3_lib::LittleEndian2Int(substr($this->AC3header['syncinfo'], $offset, 2));
77                 $ac3_synchinfo_fscod_frmsizecod              = getid3_lib::LittleEndian2Int(substr($this->AC3header['syncinfo'], ($offset + 2), 1));
78                 $thisfile_ac3_raw['synchinfo']['fscod']      = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6;
79                 $thisfile_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F);
80
81                 $thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw['synchinfo']['fscod']);
82                 if ($thisfile_ac3_raw['synchinfo']['fscod'] <= 3) {
83                         $info['audio']['sample_rate'] = $thisfile_ac3['sample_rate'];
84                 }
85
86                 $thisfile_ac3['frame_length'] = self::frameSizeLookup($thisfile_ac3_raw['synchinfo']['frmsizecod'], $thisfile_ac3_raw['synchinfo']['fscod']);
87                 $thisfile_ac3['bitrate']      = self::bitrateLookup($thisfile_ac3_raw['synchinfo']['frmsizecod']);
88                 $info['audio']['bitrate'] = $thisfile_ac3['bitrate'];
89
90                 $this->AC3header['bsi'] = getid3_lib::BigEndian2Bin($this->fread(15));
91                 $ac3_bsi_offset = 0;
92
93                 $thisfile_ac3_raw_bsi['bsid'] = $this->readHeaderBSI(5);
94                 if ($thisfile_ac3_raw_bsi['bsid'] > 8) {
95                         // Decoders which can decode version 8 will thus be able to decode version numbers less than 8.
96                         // If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used.
97                         // Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8.
98                         $this->error('Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8');
99                     unset($info['ac3']);
100                         return false;
101                 }
102
103                 $thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3);
104                 $thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3);
105
106                 $thisfile_ac3['service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']);
107                 $ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']);
108                 foreach($ac3_coding_mode as $key => $value) {
109                         $thisfile_ac3[$key] = $value;
110                 }
111                 switch ($thisfile_ac3_raw_bsi['acmod']) {
112                         case 0:
113                         case 1:
114                                 $info['audio']['channelmode'] = 'mono';
115                                 break;
116                         case 3:
117                         case 4:
118                                 $info['audio']['channelmode'] = 'stereo';
119                                 break;
120                         default:
121                                 $info['audio']['channelmode'] = 'surround';
122                                 break;
123                 }
124                 $info['audio']['channels'] = $thisfile_ac3['num_channels'];
125
126                 if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) {
127                         // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream.
128                         $thisfile_ac3_raw_bsi['cmixlev'] = $this->readHeaderBSI(2);
129                         $thisfile_ac3['center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']);
130                 }
131
132                 if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) {
133                         // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream.
134                         $thisfile_ac3_raw_bsi['surmixlev'] = $this->readHeaderBSI(2);
135                         $thisfile_ac3['surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']);
136                 }
137
138                 if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) {
139                         // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround.
140                         $thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2);
141                         $thisfile_ac3['dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']);
142                 }
143
144                 $thisfile_ac3_raw_bsi['lfeon'] = (bool) $this->readHeaderBSI(1);
145                 $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['lfeon'];
146                 if ($thisfile_ac3_raw_bsi['lfeon']) {
147                         //$info['audio']['channels']++;
148                         $info['audio']['channels'] .= '.1';
149                 }
150
151                 $thisfile_ac3['channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['lfeon']);
152
153                 // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31.
154                 // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent.
155                 $thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5);
156                 $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB';
157
158                 $thisfile_ac3_raw_bsi['compre_flag'] = (bool) $this->readHeaderBSI(1);
159                 if ($thisfile_ac3_raw_bsi['compre_flag']) {
160                         $thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8);
161                         $thisfile_ac3['heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr']);
162                 }
163
164                 $thisfile_ac3_raw_bsi['langcode_flag'] = (bool) $this->readHeaderBSI(1);
165                 if ($thisfile_ac3_raw_bsi['langcode_flag']) {
166                         $thisfile_ac3_raw_bsi['langcod'] = $this->readHeaderBSI(8);
167                 }
168
169                 $thisfile_ac3_raw_bsi['audprodie'] = (bool) $this->readHeaderBSI(1);
170                 if ($thisfile_ac3_raw_bsi['audprodie']) {
171                         $thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5);
172                         $thisfile_ac3_raw_bsi['roomtyp']  = $this->readHeaderBSI(2);
173
174                         $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB';
175                         $thisfile_ac3['room_type']    = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']);
176                 }
177
178                 if ($thisfile_ac3_raw_bsi['acmod'] == 0x00) {
179                         // If acmod is 0, then two completely independent program channels (dual mono)
180                         // are encoded into the bit stream, and are referenced as Ch1, Ch2. In this case,
181                         // a number of additional items are present in BSI or audblk to fully describe Ch2.
182
183                         // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31.
184                         // The value of 0 is reserved. The values of 1 to 31 are interpreted as -1 dB to -31 dB with respect to digital 100 percent.
185                         $thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5);
186                         $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB';
187
188                         $thisfile_ac3_raw_bsi['compre_flag2'] = (bool) $this->readHeaderBSI(1);
189                         if ($thisfile_ac3_raw_bsi['compre_flag2']) {
190                                 $thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8);
191                                 $thisfile_ac3['heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr2']);
192                         }
193
194                         $thisfile_ac3_raw_bsi['langcode_flag2'] = (bool) $this->readHeaderBSI(1);
195                         if ($thisfile_ac3_raw_bsi['langcode_flag2']) {
196                                 $thisfile_ac3_raw_bsi['langcod2'] = $this->readHeaderBSI(8);
197                         }
198
199                         $thisfile_ac3_raw_bsi['audprodie2'] = (bool) $this->readHeaderBSI(1);
200                         if ($thisfile_ac3_raw_bsi['audprodie2']) {
201                                 $thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5);
202                                 $thisfile_ac3_raw_bsi['roomtyp2']  = $this->readHeaderBSI(2);
203
204                                 $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB';
205                                 $thisfile_ac3['room_type2']    = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']);
206                         }
207
208                 }
209
210                 $thisfile_ac3_raw_bsi['copyright'] = (bool) $this->readHeaderBSI(1);
211
212                 $thisfile_ac3_raw_bsi['original']  = (bool) $this->readHeaderBSI(1);
213
214                 $thisfile_ac3_raw_bsi['timecode1_flag'] = (bool) $this->readHeaderBSI(1);
215                 if ($thisfile_ac3_raw_bsi['timecode1_flag']) {
216                         $thisfile_ac3_raw_bsi['timecode1'] = $this->readHeaderBSI(14);
217                 }
218
219                 $thisfile_ac3_raw_bsi['timecode2_flag'] = (bool) $this->readHeaderBSI(1);
220                 if ($thisfile_ac3_raw_bsi['timecode2_flag']) {
221                         $thisfile_ac3_raw_bsi['timecode2'] = $this->readHeaderBSI(14);
222                 }
223
224                 $thisfile_ac3_raw_bsi['addbsi_flag'] = (bool) $this->readHeaderBSI(1);
225                 if ($thisfile_ac3_raw_bsi['addbsi_flag']) {
226                         $thisfile_ac3_raw_bsi['addbsi_length'] = $this->readHeaderBSI(6);
227
228                         $this->AC3header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($thisfile_ac3_raw_bsi['addbsi_length']));
229
230                         $thisfile_ac3_raw_bsi['addbsi_data'] = substr($this->AC3header['bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8);
231                         $this->BSIoffset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8;
232                 }
233
234                 return true;
235         }
236
237         private function readHeaderBSI($length) {
238                 $data = substr($this->AC3header['bsi'], $this->BSIoffset, $length);
239                 $this->BSIoffset += $length;
240
241                 return bindec($data);
242         }
243
244         public static function sampleRateCodeLookup($fscod) {
245                 static $sampleRateCodeLookup = array(
246                         0 => 48000,
247                         1 => 44100,
248                         2 => 32000,
249                         3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute.
250                 );
251                 return (isset($sampleRateCodeLookup[$fscod]) ? $sampleRateCodeLookup[$fscod] : false);
252         }
253
254         public static function serviceTypeLookup($bsmod, $acmod) {
255                 static $serviceTypeLookup = array();
256                 if (empty($serviceTypeLookup)) {
257                         for ($i = 0; $i <= 7; $i++) {
258                                 $serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)';
259                                 $serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)';
260                                 $serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)';
261                                 $serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)';
262                                 $serviceTypeLookup[4][$i] = 'associated service: dialogue (D)';
263                                 $serviceTypeLookup[5][$i] = 'associated service: commentary (C)';
264                                 $serviceTypeLookup[6][$i] = 'associated service: emergency (E)';
265                         }
266
267                         $serviceTypeLookup[7][1]      = 'associated service: voice over (VO)';
268                         for ($i = 2; $i <= 7; $i++) {
269                                 $serviceTypeLookup[7][$i] = 'main audio service: karaoke';
270                         }
271                 }
272                 return (isset($serviceTypeLookup[$bsmod][$acmod]) ? $serviceTypeLookup[$bsmod][$acmod] : false);
273         }
274
275         public static function audioCodingModeLookup($acmod) {
276                 // array(channel configuration, # channels (not incl LFE), channel order)
277                 static $audioCodingModeLookup = array (
278                         0 => array('channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'),
279                         1 => array('channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'),
280                         2 => array('channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'),
281                         3 => array('channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'),
282                         4 => array('channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'),
283                         5 => array('channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'),
284                         6 => array('channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'),
285                         7 => array('channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR'),
286                 );
287                 return (isset($audioCodingModeLookup[$acmod]) ? $audioCodingModeLookup[$acmod] : false);
288         }
289
290         public static function centerMixLevelLookup($cmixlev) {
291                 static $centerMixLevelLookup;
292                 if (empty($centerMixLevelLookup)) {
293                         $centerMixLevelLookup = array(
294                                 0 => pow(2, -3.0 / 6), // 0.707 (-3.0 dB)
295                                 1 => pow(2, -4.5 / 6), // 0.595 (-4.5 dB)
296                                 2 => pow(2, -6.0 / 6), // 0.500 (-6.0 dB)
297                                 3 => 'reserved'
298                         );
299                 }
300                 return (isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] : false);
301         }
302
303         public static function surroundMixLevelLookup($surmixlev) {
304                 static $surroundMixLevelLookup;
305                 if (empty($surroundMixLevelLookup)) {
306                         $surroundMixLevelLookup = array(
307                                 0 => pow(2, -3.0 / 6),
308                                 1 => pow(2, -6.0 / 6),
309                                 2 => 0,
310                                 3 => 'reserved'
311                         );
312                 }
313                 return (isset($surroundMixLevelLookup[$surmixlev]) ? $surroundMixLevelLookup[$surmixlev] : false);
314         }
315
316         public static function dolbySurroundModeLookup($dsurmod) {
317                 static $dolbySurroundModeLookup = array(
318                         0 => 'not indicated',
319                         1 => 'Not Dolby Surround encoded',
320                         2 => 'Dolby Surround encoded',
321                         3 => 'reserved'
322                 );
323                 return (isset($dolbySurroundModeLookup[$dsurmod]) ? $dolbySurroundModeLookup[$dsurmod] : false);
324         }
325
326         public static function channelsEnabledLookup($acmod, $lfeon) {
327                 $lookup = array(
328                         'ch1'=>(bool) ($acmod == 0),
329                         'ch2'=>(bool) ($acmod == 0),
330                         'left'=>(bool) ($acmod > 1),
331                         'right'=>(bool) ($acmod > 1),
332                         'center'=>(bool) ($acmod & 0x01),
333                         'surround_mono'=>false,
334                         'surround_left'=>false,
335                         'surround_right'=>false,
336                         'lfe'=>$lfeon);
337                 switch ($acmod) {
338                         case 4:
339                         case 5:
340                                 $lookup['surround_mono']  = true;
341                                 break;
342                         case 6:
343                         case 7:
344                                 $lookup['surround_left']  = true;
345                                 $lookup['surround_right'] = true;
346                                 break;
347                 }
348                 return $lookup;
349         }
350
351         public static function heavyCompression($compre) {
352                 // The first four bits indicate gain changes in 6.02dB increments which can be
353                 // implemented with an arithmetic shift operation. The following four bits
354                 // indicate linear gain changes, and require a 5-bit multiply.
355                 // We will represent the two 4-bit fields of compr as follows:
356                 //   X0 X1 X2 X3 . Y4 Y5 Y6 Y7
357                 // The meaning of the X values is most simply described by considering X to represent a 4-bit
358                 // signed integer with values from -8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The
359                 // following table shows this in detail.
360
361                 // Meaning of 4 msb of compr
362                 //  7    +48.16 dB
363                 //  6    +42.14 dB
364                 //  5    +36.12 dB
365                 //  4    +30.10 dB
366                 //  3    +24.08 dB
367                 //  2    +18.06 dB
368                 //  1    +12.04 dB
369                 //  0     +6.02 dB
370                 // -1         0 dB
371                 // -2     -6.02 dB
372                 // -3    -12.04 dB
373                 // -4    -18.06 dB
374                 // -5    -24.08 dB
375                 // -6    -30.10 dB
376                 // -7    -36.12 dB
377                 // -8    -42.14 dB
378
379                 $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT);
380                 if ($fourbit{0} == '1') {
381                         $log_gain = -8 + bindec(substr($fourbit, 1));
382                 } else {
383                         $log_gain = bindec(substr($fourbit, 1));
384                 }
385                 $log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2);
386
387                 // The value of Y is a linear representation of a gain change of up to -6 dB. Y is considered to
388                 // be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can
389                 // represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain
390                 // changes from -0.28 dB to -6.02 dB.
391
392                 $lin_gain = (16 + ($compre & 0x0F)) / 32;
393
394                 // The combination of X and Y values allows compr to indicate gain changes from
395                 //  48.16 - 0.28 = +47.89 dB, to
396                 // -42.14 - 6.02 = -48.16 dB.
397
398                 return $log_gain - $lin_gain;
399         }
400
401         public static function roomTypeLookup($roomtyp) {
402                 static $roomTypeLookup = array(
403                         0 => 'not indicated',
404                         1 => 'large room, X curve monitor',
405                         2 => 'small room, flat monitor',
406                         3 => 'reserved'
407                 );
408                 return (isset($roomTypeLookup[$roomtyp]) ? $roomTypeLookup[$roomtyp] : false);
409         }
410
411         public static function frameSizeLookup($frmsizecod, $fscod) {
412                 $padding     = (bool) ($frmsizecod % 2);
413                 $framesizeid =   floor($frmsizecod / 2);
414
415                 static $frameSizeLookup = array();
416                 if (empty($frameSizeLookup)) {
417                         $frameSizeLookup = array (
418                                 0  => array(128, 138, 192),
419                                 1  => array(40, 160, 174, 240),
420                                 2  => array(48, 192, 208, 288),
421                                 3  => array(56, 224, 242, 336),
422                                 4  => array(64, 256, 278, 384),
423                                 5  => array(80, 320, 348, 480),
424                                 6  => array(96, 384, 416, 576),
425                                 7  => array(112, 448, 486, 672),
426                                 8  => array(128, 512, 556, 768),
427                                 9  => array(160, 640, 696, 960),
428                                 10 => array(192, 768, 834, 1152),
429                                 11 => array(224, 896, 974, 1344),
430                                 12 => array(256, 1024, 1114, 1536),
431                                 13 => array(320, 1280, 1392, 1920),
432                                 14 => array(384, 1536, 1670, 2304),
433                                 15 => array(448, 1792, 1950, 2688),
434                                 16 => array(512, 2048, 2228, 3072),
435                                 17 => array(576, 2304, 2506, 3456),
436                                 18 => array(640, 2560, 2786, 3840)
437                         );
438                 }
439                 if (($fscod == 1) && $padding) {
440                         // frame lengths are padded by 1 word (16 bits) at 44100
441                         $frameSizeLookup[$frmsizecod] += 2;
442                 }
443                 return (isset($frameSizeLookup[$framesizeid][$fscod]) ? $frameSizeLookup[$framesizeid][$fscod] : false);
444         }
445
446         public static function bitrateLookup($frmsizecod) {
447                 $framesizeid =   floor($frmsizecod / 2);
448
449                 static $bitrateLookup = array(
450                         0  => 32000,
451                         1  => 40000,
452                         2  => 48000,
453                         3  => 56000,
454                         4  => 64000,
455                         5  => 80000,
456                         6  => 96000,
457                         7  => 112000,
458                         8  => 128000,
459                         9  => 160000,
460                         10 => 192000,
461                         11 => 224000,
462                         12 => 256000,
463                         13 => 320000,
464                         14 => 384000,
465                         15 => 448000,
466                         16 => 512000,
467                         17 => 576000,
468                         18 => 640000
469                 );
470                 return (isset($bitrateLookup[$framesizeid]) ? $bitrateLookup[$framesizeid] : false);
471         }
472
473
474 }