49 $info = &$this->getid3->info;
53 $thisfile_ac3 = &
$info[
'ac3'];
54 $thisfile_ac3_raw = &$thisfile_ac3[
'raw'];
55 $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw[
'bsi'];
59 $info[
'fileformat'] =
'ac3';
80 $this->AC3header[
'syncinfo'] = $this->
fread(5);
84 if (strpos($this->AC3header[
'syncinfo'], $magic) === 0) {
85 $thisfile_ac3_raw[
'synchinfo'][
'synchword'] = $magic;
94 $this->
fseek(-2, SEEK_CUR);
97 $info[
'audio'][
'dataformat'] =
'ac3';
98 $info[
'audio'][
'bitrate_mode'] =
'cbr';
99 $info[
'audio'][
'lossless'] =
false;
101 $thisfile_ac3_raw[
'synchinfo'][
'crc1'] =
Helper::LittleEndian2Int(substr($this->AC3header[
'syncinfo'], $offset, 2));
103 $thisfile_ac3_raw[
'synchinfo'][
'fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6;
104 $thisfile_ac3_raw[
'synchinfo'][
'frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F);
106 $thisfile_ac3[
'sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw[
'synchinfo'][
'fscod']);
107 if ($thisfile_ac3_raw[
'synchinfo'][
'fscod'] <= 3) {
108 $info[
'audio'][
'sample_rate'] = $thisfile_ac3[
'sample_rate'];
111 $thisfile_ac3[
'frame_length'] = self::frameSizeLookup($thisfile_ac3_raw[
'synchinfo'][
'frmsizecod'], $thisfile_ac3_raw[
'synchinfo'][
'fscod']);
112 $thisfile_ac3[
'bitrate'] = self::bitrateLookup($thisfile_ac3_raw[
'synchinfo'][
'frmsizecod']);
113 $info[
'audio'][
'bitrate'] = $thisfile_ac3[
'bitrate'];
119 if ($thisfile_ac3_raw_bsi[
'bsid'] > 8) {
123 $this->
error(
'Bit stream identification is version '.$thisfile_ac3_raw_bsi[
'bsid'].
', but GetId3Core() only understands up to version 8');
132 $thisfile_ac3[
'service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi[
'bsmod'], $thisfile_ac3_raw_bsi[
'acmod']);
133 $ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi[
'acmod']);
134 foreach ($ac3_coding_mode as $key => $value) {
135 $thisfile_ac3[$key] = $value;
137 switch ($thisfile_ac3_raw_bsi[
'acmod']) {
140 $info[
'audio'][
'channelmode'] =
'mono';
144 $info[
'audio'][
'channelmode'] =
'stereo';
147 $info[
'audio'][
'channelmode'] =
'surround';
150 $info[
'audio'][
'channels'] = $thisfile_ac3[
'num_channels'];
152 if ($thisfile_ac3_raw_bsi[
'acmod'] & 0x01) {
155 $thisfile_ac3[
'center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi[
'cmixlev']);
158 if ($thisfile_ac3_raw_bsi[
'acmod'] & 0x04) {
160 $thisfile_ac3_raw_bsi[
'surmixlev'] = $this->
readHeaderBSI(2);
161 $thisfile_ac3[
'surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi[
'surmixlev']);
164 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0x02) {
167 $thisfile_ac3[
'dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi[
'dsurmod']);
170 $thisfile_ac3_raw_bsi[
'lfeon'] = (bool) $this->
readHeaderBSI(1);
171 $thisfile_ac3[
'lfe_enabled'] = $thisfile_ac3_raw_bsi[
'lfeon'];
172 if ($thisfile_ac3_raw_bsi[
'lfeon']) {
174 $info[
'audio'][
'channels'] .=
'.1';
177 $thisfile_ac3[
'channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi[
'acmod'], $thisfile_ac3_raw_bsi[
'lfeon']);
182 $thisfile_ac3[
'dialogue_normalization'] =
'-'.$thisfile_ac3_raw_bsi[
'dialnorm'].
'dB';
184 $thisfile_ac3_raw_bsi[
'compre_flag'] = (bool) $this->
readHeaderBSI(1);
185 if ($thisfile_ac3_raw_bsi[
'compre_flag']) {
187 $thisfile_ac3[
'heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi[
'compr']);
190 $thisfile_ac3_raw_bsi[
'langcode_flag'] = (bool) $this->
readHeaderBSI(1);
191 if ($thisfile_ac3_raw_bsi[
'langcode_flag']) {
195 $thisfile_ac3_raw_bsi[
'audprodie'] = (bool) $this->
readHeaderBSI(1);
196 if ($thisfile_ac3_raw_bsi[
'audprodie']) {
200 $thisfile_ac3[
'mixing_level'] = (80 + $thisfile_ac3_raw_bsi[
'mixlevel']).
'dB';
201 $thisfile_ac3[
'room_type'] = self::roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp']);
204 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0x00) {
211 $thisfile_ac3_raw_bsi[
'dialnorm2'] = $this->
readHeaderBSI(5);
212 $thisfile_ac3[
'dialogue_normalization2'] =
'-'.$thisfile_ac3_raw_bsi[
'dialnorm2'].
'dB';
214 $thisfile_ac3_raw_bsi[
'compre_flag2'] = (bool) $this->
readHeaderBSI(1);
215 if ($thisfile_ac3_raw_bsi[
'compre_flag2']) {
217 $thisfile_ac3[
'heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi[
'compr2']);
220 $thisfile_ac3_raw_bsi[
'langcode_flag2'] = (bool) $this->
readHeaderBSI(1);
221 if ($thisfile_ac3_raw_bsi[
'langcode_flag2']) {
225 $thisfile_ac3_raw_bsi[
'audprodie2'] = (bool) $this->
readHeaderBSI(1);
226 if ($thisfile_ac3_raw_bsi[
'audprodie2']) {
227 $thisfile_ac3_raw_bsi[
'mixlevel2'] = $this->
readHeaderBSI(5);
230 $thisfile_ac3[
'mixing_level2'] = (80 + $thisfile_ac3_raw_bsi[
'mixlevel2']).
'dB';
231 $thisfile_ac3[
'room_type2'] = self::roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp2']);
236 $thisfile_ac3_raw_bsi[
'copyright'] = (bool) $this->
readHeaderBSI(1);
238 $thisfile_ac3_raw_bsi[
'original'] = (bool) $this->
readHeaderBSI(1);
240 $thisfile_ac3_raw_bsi[
'timecode1_flag'] = (bool) $this->
readHeaderBSI(1);
241 if ($thisfile_ac3_raw_bsi[
'timecode1_flag']) {
242 $thisfile_ac3_raw_bsi[
'timecode1'] = $this->
readHeaderBSI(14);
245 $thisfile_ac3_raw_bsi[
'timecode2_flag'] = (bool) $this->
readHeaderBSI(1);
246 if ($thisfile_ac3_raw_bsi[
'timecode2_flag']) {
247 $thisfile_ac3_raw_bsi[
'timecode2'] = $this->
readHeaderBSI(14);
250 $thisfile_ac3_raw_bsi[
'addbsi_flag'] = (bool) $this->
readHeaderBSI(1);
251 if ($thisfile_ac3_raw_bsi[
'addbsi_flag']) {
252 $thisfile_ac3_raw_bsi[
'addbsi_length'] = $this->
readHeaderBSI(6);
256 $thisfile_ac3_raw_bsi[
'addbsi_data'] = substr($this->AC3header[
'bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi[
'addbsi_length'] * 8);
257 $this->BSIoffset += $thisfile_ac3_raw_bsi[
'addbsi_length'] * 8;
270 $data = substr($this->AC3header[
'bsi'], $this->BSIoffset, $length);
271 $this->BSIoffset += $length;
273 return bindec(
$data);
284 static $AC3sampleRateCodeLookup =
array(
291 return (isset($AC3sampleRateCodeLookup[$fscod]) ? $AC3sampleRateCodeLookup[$fscod] :
false);
303 static $AC3serviceTypeLookup =
array();
304 if (empty($AC3serviceTypeLookup)) {
305 for ($i = 0; $i <= 7; $i++) {
306 $AC3serviceTypeLookup[0][$i] =
'main audio service: complete main (CM)';
307 $AC3serviceTypeLookup[1][$i] =
'main audio service: music and effects (ME)';
308 $AC3serviceTypeLookup[2][$i] =
'associated service: visually impaired (VI)';
309 $AC3serviceTypeLookup[3][$i] =
'associated service: hearing impaired (HI)';
310 $AC3serviceTypeLookup[4][$i] =
'associated service: dialogue (D)';
311 $AC3serviceTypeLookup[5][$i] =
'associated service: commentary (C)';
312 $AC3serviceTypeLookup[6][$i] =
'associated service: emergency (E)';
315 $AC3serviceTypeLookup[7][1] =
'associated service: voice over (VO)';
316 for ($i = 2; $i <= 7; $i++) {
317 $AC3serviceTypeLookup[7][$i] =
'main audio service: karaoke';
321 return (isset($AC3serviceTypeLookup[$bsmod][$acmod]) ? $AC3serviceTypeLookup[$bsmod][$acmod] :
false);
332 static $AC3audioCodingModeLookup =
array();
333 if (empty($AC3audioCodingModeLookup)) {
335 $AC3audioCodingModeLookup =
array (
336 0 =>
array(
'channel_config'=>
'1+1',
'num_channels'=>2,
'channel_order'=>
'Ch1,Ch2'),
337 1 =>
array(
'channel_config'=>
'1/0',
'num_channels'=>1,
'channel_order'=>
'C'),
338 2 =>
array(
'channel_config'=>
'2/0',
'num_channels'=>2,
'channel_order'=>
'L,R'),
339 3 =>
array(
'channel_config'=>
'3/0',
'num_channels'=>3,
'channel_order'=>
'L,C,R'),
340 4 =>
array(
'channel_config'=>
'2/1',
'num_channels'=>3,
'channel_order'=>
'L,R,S'),
341 5 =>
array(
'channel_config'=>
'3/1',
'num_channels'=>4,
'channel_order'=>
'L,C,R,S'),
342 6 =>
array(
'channel_config'=>
'2/2',
'num_channels'=>4,
'channel_order'=>
'L,R,SL,SR'),
343 7 =>
array(
'channel_config'=>
'3/2',
'num_channels'=>5,
'channel_order'=>
'L,C,R,SL,SR')
347 return (isset($AC3audioCodingModeLookup[$acmod]) ? $AC3audioCodingModeLookup[$acmod] :
false);
358 static $AC3centerMixLevelLookup;
359 if (empty($AC3centerMixLevelLookup)) {
360 $AC3centerMixLevelLookup =
array(
361 0 => pow(2, -3.0 / 6),
362 1 => pow(2, -4.5 / 6),
363 2 => pow(2, -6.0 / 6),
368 return (isset($AC3centerMixLevelLookup[$cmixlev]) ? $AC3centerMixLevelLookup[$cmixlev] :
false);
379 static $AC3surroundMixLevelLookup;
380 if (empty($AC3surroundMixLevelLookup)) {
381 $AC3surroundMixLevelLookup =
array(
382 0 => pow(2, -3.0 / 6),
383 1 => pow(2, -6.0 / 6),
389 return (isset($AC3surroundMixLevelLookup[$surmixlev]) ? $AC3surroundMixLevelLookup[$surmixlev] :
false);
400 static $AC3dolbySurroundModeLookup =
array(
401 0 =>
'not indicated',
402 1 =>
'Not Dolby Surround encoded',
403 2 =>
'Dolby Surround encoded',
407 return (isset($AC3dolbySurroundModeLookup[$dsurmod]) ? $AC3dolbySurroundModeLookup[$dsurmod] :
false);
418 $AC3channelsEnabledLookup =
array(
419 'ch1'=>(
bool) ($acmod == 0),
420 'ch2'=>(
bool) ($acmod == 0),
421 'left'=>(
bool) ($acmod > 1),
422 'right'=>(
bool) ($acmod > 1),
423 'center'=>(
bool) ($acmod & 0x01),
424 'surround_mono'=>
false,
425 'surround_left'=>
false,
426 'surround_right'=>
false,
431 $AC3channelsEnabledLookup[
'surround_mono'] =
true;
435 $AC3channelsEnabledLookup[
'surround_left'] =
true;
436 $AC3channelsEnabledLookup[
'surround_right'] =
true;
440 return $AC3channelsEnabledLookup;
477 $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4,
'0', STR_PAD_LEFT);
478 if ($fourbit{0} ==
'1') {
479 $log_gain = -8 + bindec(substr($fourbit, 1));
481 $log_gain = bindec(substr($fourbit, 1));
490 $lin_gain = (16 + ($compre & 0x0F)) / 32;
495 return $log_gain - $lin_gain;
506 static $AC3roomTypeLookup =
array(
507 0 =>
'not indicated',
508 1 =>
'large room, X curve monitor',
509 2 =>
'small room, flat monitor',
513 return (isset($AC3roomTypeLookup[$roomtyp]) ? $AC3roomTypeLookup[$roomtyp] :
false);
525 $padding = (bool) ($frmsizecod % 2);
526 $framesizeid = floor($frmsizecod / 2);
528 static $AC3frameSizeLookup =
array();
529 if (empty($AC3frameSizeLookup)) {
530 $AC3frameSizeLookup =
array (
531 0 =>
array(128, 138, 192),
532 1 =>
array(40, 160, 174, 240),
533 2 =>
array(48, 192, 208, 288),
534 3 =>
array(56, 224, 242, 336),
535 4 =>
array(64, 256, 278, 384),
536 5 =>
array(80, 320, 348, 480),
537 6 =>
array(96, 384, 416, 576),
538 7 =>
array(112, 448, 486, 672),
539 8 =>
array(128, 512, 556, 768),
540 9 =>
array(160, 640, 696, 960),
541 10 =>
array(192, 768, 834, 1152),
542 11 =>
array(224, 896, 974, 1344),
543 12 =>
array(256, 1024, 1114, 1536),
544 13 =>
array(320, 1280, 1392, 1920),
545 14 =>
array(384, 1536, 1670, 2304),
546 15 =>
array(448, 1792, 1950, 2688),
547 16 =>
array(512, 2048, 2228, 3072),
548 17 =>
array(576, 2304, 2506, 3456),
549 18 =>
array(640, 2560, 2786, 3840)
552 if (($fscod == 1) && $padding) {
554 $AC3frameSizeLookup[$frmsizecod] += 2;
557 return (isset($AC3frameSizeLookup[$framesizeid][$fscod]) ? $AC3frameSizeLookup[$framesizeid][$fscod] :
false);
568 $framesizeid = floor($frmsizecod / 2);
570 static $AC3bitrateLookup =
array(
592 return (isset($AC3bitrateLookup[$framesizeid]) ? $AC3bitrateLookup[$framesizeid] :
false);
static BigEndian2Bin($byteword)
static dolbySurroundModeLookup($dsurmod)
array $AC3dolbySurroundModeLookup
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
GetId3() by James Heinrich info@getid3.org //.
static RGADamplitude2dB($amplitude)
static roomTypeLookup($roomtyp)
array $AC3roomTypeLookup
static serviceTypeLookup($bsmod, $acmod)
array $AC3serviceTypeLookup
static sampleRateCodeLookup($fscod)
array $AC3sampleRateCodeLookup
fseek($bytes, $whence=SEEK_SET)
static surroundMixLevelLookup($surmixlev)
type $AC3surroundMixLevelLookup
static channelsEnabledLookup($acmod, $lfeon)
static audioCodingModeLookup($acmod)
array $AC3audioCodingModeLookup
Create styles array
The data for the language used.
GetId3() by James Heinrich info@getid3.org //.
static centerMixLevelLookup($cmixlev)
type $AC3centerMixLevelLookup
static LittleEndian2Int($byteword, $signed=false)
static bitrateLookup($frmsizecod)
array $AC3bitrateLookup
static frameSizeLookup($frmsizecod, $fscod)
array $AC3frameSizeLookup
static heavyCompression($compre)