ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_ac3 Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_ac3:
+ Collaboration diagram for getid3_ac3:

Public Member Functions

 getid3_ac3 (&$fd, &$ThisFileInfo)
 
 AC3sampleRateCodeLookup ($fscod)
 
 AC3serviceTypeLookup ($bsmod, $acmod)
 
 AC3audioCodingModeLookup ($acmod)
 
 AC3centerMixLevelLookup ($cmixlev)
 
 AC3surroundMixLevelLookup ($surmixlev)
 
 AC3dolbySurroundModeLookup ($dsurmod)
 
 AC3channelsEnabledLookup ($acmod, $lfeon)
 
 AC3heavyCompression ($compre)
 
 AC3roomTypeLookup ($roomtyp)
 
 AC3frameSizeLookup ($frmsizecod, $fscod)
 
 AC3bitrateLookup ($frmsizecod)
 
 Analyze ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Static Public Member Functions

static sampleRateCodeLookup ($fscod)
 
static serviceTypeLookup ($bsmod, $acmod)
 
static audioCodingModeLookup ($acmod)
 
static centerMixLevelLookup ($cmixlev)
 
static surroundMixLevelLookup ($surmixlev)
 
static dolbySurroundModeLookup ($dsurmod)
 
static channelsEnabledLookup ($acmod, $lfeon)
 
static heavyCompression ($compre)
 
static roomTypeLookup ($roomtyp)
 
static frameSizeLookup ($frmsizecod, $fscod)
 
static bitrateLookup ($frmsizecod)
 

Data Fields

const syncword = "\x0B\x77"
 

Private Member Functions

 readHeaderBSI ($length)
 

Private Attributes

 $AC3header = array()
 
 $BSIoffset = 0
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.audio.ac3.php.

Member Function Documentation

◆ AC3audioCodingModeLookup()

getid3_ac3::AC3audioCodingModeLookup (   $acmod)

Definition at line 293 of file module.audio.ac3.php.

293 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3bitrateLookup()

getid3_ac3::AC3bitrateLookup (   $frmsizecod)

Definition at line 467 of file module.audio.ac3.php.

467 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3centerMixLevelLookup()

getid3_ac3::AC3centerMixLevelLookup (   $cmixlev)

Definition at line 311 of file module.audio.ac3.php.

311 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3channelsEnabledLookup()

getid3_ac3::AC3channelsEnabledLookup (   $acmod,
  $lfeon 
)

Definition at line 347 of file module.audio.ac3.php.

347 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3dolbySurroundModeLookup()

getid3_ac3::AC3dolbySurroundModeLookup (   $dsurmod)

Definition at line 337 of file module.audio.ac3.php.

337 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3frameSizeLookup()

getid3_ac3::AC3frameSizeLookup (   $frmsizecod,
  $fscod 
)

Definition at line 432 of file module.audio.ac3.php.

432 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3heavyCompression()

getid3_ac3::AC3heavyCompression (   $compre)

Definition at line 372 of file module.audio.ac3.php.

372 {
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 }
RGADamplitude2dB($amplitude)

References getid3_lib\RGADamplitude2dB().

Referenced by getid3_ac3().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AC3roomTypeLookup()

getid3_ac3::AC3roomTypeLookup (   $roomtyp)

Definition at line 422 of file module.audio.ac3.php.

422 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3sampleRateCodeLookup()

getid3_ac3::AC3sampleRateCodeLookup (   $fscod)

Definition at line 262 of file module.audio.ac3.php.

262 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3serviceTypeLookup()

getid3_ac3::AC3serviceTypeLookup (   $bsmod,
  $acmod 
)

Definition at line 272 of file module.audio.ac3.php.

272 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ AC3surroundMixLevelLookup()

getid3_ac3::AC3surroundMixLevelLookup (   $surmixlev)

Definition at line 324 of file module.audio.ac3.php.

324 {
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 }

Referenced by getid3_ac3().

+ Here is the caller graph for this function:

◆ Analyze()

getid3_ac3::Analyze ( )

AH

Reimplemented from getid3_handler.

Definition at line 25 of file module.audio.ac3.php.

25 {
26 $info = &$this->getid3->info;
27
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 }
static channelsEnabledLookup($acmod, $lfeon)
static heavyCompression($compre)
static surroundMixLevelLookup($surmixlev)
static sampleRateCodeLookup($fscod)
static audioCodingModeLookup($acmod)
static dolbySurroundModeLookup($dsurmod)
static serviceTypeLookup($bsmod, $acmod)
readHeaderBSI($length)
static roomTypeLookup($roomtyp)
static bitrateLookup($frmsizecod)
static frameSizeLookup($frmsizecod, $fscod)
static centerMixLevelLookup($cmixlev)
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
isDependencyFor($module)
Definition: getid3.php:1734
fread($bytes)
Definition: getid3.php:1685
error($text)
Definition: getid3.php:1738
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
BigEndian2Bin($byteword)
Definition: getid3.lib.php:271
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
$info
Definition: example_052.php:80

References $info, audioCodingModeLookup(), getid3_lib\BigEndian2Bin(), bitrateLookup(), centerMixLevelLookup(), channelsEnabledLookup(), dolbySurroundModeLookup(), getid3_handler\error(), frameSizeLookup(), getid3_handler\fread(), getid3_handler\fseek(), heavyCompression(), getid3_handler\isDependencyFor(), getid3_lib\LittleEndian2Int(), getid3_lib\PrintHexBytes(), readHeaderBSI(), roomTypeLookup(), sampleRateCodeLookup(), serviceTypeLookup(), surroundMixLevelLookup(), and syncword.

+ Here is the call graph for this function:

◆ audioCodingModeLookup()

static getid3_ac3::audioCodingModeLookup (   $acmod)
static

Definition at line 275 of file module.audio.ac3.php.

275 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ bitrateLookup()

static getid3_ac3::bitrateLookup (   $frmsizecod)
static

Definition at line 446 of file module.audio.ac3.php.

446 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ centerMixLevelLookup()

static getid3_ac3::centerMixLevelLookup (   $cmixlev)
static

Definition at line 290 of file module.audio.ac3.php.

290 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ channelsEnabledLookup()

static getid3_ac3::channelsEnabledLookup (   $acmod,
  $lfeon 
)
static

Definition at line 326 of file module.audio.ac3.php.

326 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ dolbySurroundModeLookup()

static getid3_ac3::dolbySurroundModeLookup (   $dsurmod)
static

Definition at line 316 of file module.audio.ac3.php.

316 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ frameSizeLookup()

static getid3_ac3::frameSizeLookup (   $frmsizecod,
  $fscod 
)
static

Definition at line 411 of file module.audio.ac3.php.

411 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ getid3_ac3()

getid3_ac3::getid3_ac3 ( $fd,
$ThisFileInfo 
)

AH

Definition at line 20 of file module.audio.ac3.php.

20 {
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
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 }
AC3bitrateLookup($frmsizecod)
AC3roomTypeLookup($roomtyp)
AC3centerMixLevelLookup($cmixlev)
AC3sampleRateCodeLookup($fscod)
AC3audioCodingModeLookup($acmod)
AC3serviceTypeLookup($bsmod, $acmod)
AC3channelsEnabledLookup($acmod, $lfeon)
AC3surroundMixLevelLookup($surmixlev)
AC3heavyCompression($compre)
AC3frameSizeLookup($frmsizecod, $fscod)
AC3dolbySurroundModeLookup($dsurmod)

References $AC3header, AC3audioCodingModeLookup(), AC3bitrateLookup(), AC3centerMixLevelLookup(), AC3channelsEnabledLookup(), AC3dolbySurroundModeLookup(), AC3frameSizeLookup(), AC3heavyCompression(), AC3roomTypeLookup(), AC3sampleRateCodeLookup(), AC3serviceTypeLookup(), AC3surroundMixLevelLookup(), getid3_lib\BigEndian2Bin(), getid3_handler\fread(), getid3_handler\fseek(), and getid3_lib\LittleEndian2Int().

+ Here is the call graph for this function:

◆ heavyCompression()

static getid3_ac3::heavyCompression (   $compre)
static

Definition at line 351 of file module.audio.ac3.php.

351 {
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 }

References getid3_lib\RGADamplitude2dB().

Referenced by Analyze().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readHeaderBSI()

getid3_ac3::readHeaderBSI (   $length)
private

Definition at line 237 of file module.audio.ac3.php.

237 {
238 $data = substr($this->AC3header['bsi'], $this->BSIoffset, $length);
239 $this->BSIoffset += $length;
240
241 return bindec($data);
242 }
$data

References $data.

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ roomTypeLookup()

static getid3_ac3::roomTypeLookup (   $roomtyp)
static

Definition at line 401 of file module.audio.ac3.php.

401 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ sampleRateCodeLookup()

static getid3_ac3::sampleRateCodeLookup (   $fscod)
static

Definition at line 244 of file module.audio.ac3.php.

244 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ serviceTypeLookup()

static getid3_ac3::serviceTypeLookup (   $bsmod,
  $acmod 
)
static

Definition at line 254 of file module.audio.ac3.php.

254 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

◆ surroundMixLevelLookup()

static getid3_ac3::surroundMixLevelLookup (   $surmixlev)
static

Definition at line 303 of file module.audio.ac3.php.

303 {
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 }

Referenced by Analyze().

+ Here is the caller graph for this function:

Field Documentation

◆ $AC3header

getid3_ac3::$AC3header = array()
private

Definition at line 20 of file module.audio.ac3.php.

Referenced by getid3_ac3().

◆ $BSIoffset

getid3_ac3::$BSIoffset = 0
private

Definition at line 21 of file module.audio.ac3.php.

◆ syncword

const getid3_ac3::syncword = "\x0B\x77"

Definition at line 23 of file module.audio.ac3.php.

Referenced by Analyze(), and getid3_riff\ParseRIFF().


The documentation for this class was generated from the following files: