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