26 $info = &$this->getid3->info;
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'];
37 $info[
'fileformat'] =
'ac3';
58 $tempAC3header = $this->
fread(100);
62 unset($tempAC3header);
64 if ($this->AC3header[
'syncinfo'] !== self::syncword) {
67 return $this->
error(
'Expecting "'.dechex(self::syncword).
'" at offset '.
$info[
'avdataoffset'].
', found "'.dechex($this->AC3header[
'syncinfo']).
'"');
71 $info[
'audio'][
'dataformat'] =
'ac3';
72 $info[
'audio'][
'bitrate_mode'] =
'cbr';
73 $info[
'audio'][
'lossless'] =
false;
75 if ($thisfile_ac3_raw_bsi[
'bsid'] <= 8) {
79 $thisfile_ac3_raw_bsi[
'frmsizecod'] = $this->
readHeaderBSI(6);
80 if ($thisfile_ac3_raw_bsi[
'frmsizecod'] > 37) {
81 $this->
warning(
'Unexpected ac3.bsi.frmsizecod value: '.$thisfile_ac3_raw_bsi[
'frmsizecod'].
', bitrate not set correctly');
88 if ($thisfile_ac3_raw_bsi[
'acmod'] & 0x01) {
91 $thisfile_ac3[
'center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi[
'cmixlev']);
94 if ($thisfile_ac3_raw_bsi[
'acmod'] & 0x04) {
97 $thisfile_ac3[
'surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi[
'surmixlev']);
100 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0x02) {
103 $thisfile_ac3[
'dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi[
'dsurmod']);
106 $thisfile_ac3_raw_bsi[
'flags'][
'lfeon'] = (bool) $this->
readHeaderBSI(1);
112 $thisfile_ac3_raw_bsi[
'flags'][
'compr'] = (bool) $this->
readHeaderBSI(1);
113 if ($thisfile_ac3_raw_bsi[
'flags'][
'compr']) {
115 $thisfile_ac3[
'heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi[
'compr']);
118 $thisfile_ac3_raw_bsi[
'flags'][
'langcod'] = (bool) $this->
readHeaderBSI(1);
119 if ($thisfile_ac3_raw_bsi[
'flags'][
'langcod']) {
123 $thisfile_ac3_raw_bsi[
'flags'][
'audprodinfo'] = (bool) $this->
readHeaderBSI(1);
124 if ($thisfile_ac3_raw_bsi[
'flags'][
'audprodinfo']) {
128 $thisfile_ac3[
'mixing_level'] = (80 + $thisfile_ac3_raw_bsi[
'mixlevel']).
'dB';
129 $thisfile_ac3[
'room_type'] = self::roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp']);
133 $thisfile_ac3_raw_bsi[
'dialnorm2'] = $this->
readHeaderBSI(5);
134 $thisfile_ac3[
'dialogue_normalization2'] =
'-'.$thisfile_ac3_raw_bsi[
'dialnorm2'].
'dB';
136 $thisfile_ac3_raw_bsi[
'flags'][
'compr2'] = (bool) $this->
readHeaderBSI(1);
137 if ($thisfile_ac3_raw_bsi[
'flags'][
'compr2']) {
139 $thisfile_ac3[
'heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi[
'compr2']);
142 $thisfile_ac3_raw_bsi[
'flags'][
'langcod2'] = (bool) $this->
readHeaderBSI(1);
143 if ($thisfile_ac3_raw_bsi[
'flags'][
'langcod2']) {
147 $thisfile_ac3_raw_bsi[
'flags'][
'audprodinfo2'] = (bool) $this->
readHeaderBSI(1);
148 if ($thisfile_ac3_raw_bsi[
'flags'][
'audprodinfo2']) {
149 $thisfile_ac3_raw_bsi[
'mixlevel2'] = $this->
readHeaderBSI(5);
152 $thisfile_ac3[
'mixing_level2'] = (80 + $thisfile_ac3_raw_bsi[
'mixlevel2']).
'dB';
153 $thisfile_ac3[
'room_type2'] = self::roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp2']);
156 $thisfile_ac3_raw_bsi[
'copyright'] = (bool) $this->
readHeaderBSI(1);
158 $thisfile_ac3_raw_bsi[
'original'] = (bool) $this->
readHeaderBSI(1);
160 $thisfile_ac3_raw_bsi[
'flags'][
'timecod1'] = $this->
readHeaderBSI(2);
161 if ($thisfile_ac3_raw_bsi[
'flags'][
'timecod1'] & 0x01) {
162 $thisfile_ac3_raw_bsi[
'timecod1'] = $this->
readHeaderBSI(14);
163 $thisfile_ac3[
'timecode1'] = 0;
164 $thisfile_ac3[
'timecode1'] += (($thisfile_ac3_raw_bsi[
'timecod1'] & 0x3E00) >> 9) * 3600;
165 $thisfile_ac3[
'timecode1'] += (($thisfile_ac3_raw_bsi[
'timecod1'] & 0x01F8) >> 3) * 60;
166 $thisfile_ac3[
'timecode1'] += (($thisfile_ac3_raw_bsi[
'timecod1'] & 0x0003) >> 0) * 8;
168 if ($thisfile_ac3_raw_bsi[
'flags'][
'timecod1'] & 0x02) {
169 $thisfile_ac3_raw_bsi[
'timecod2'] = $this->
readHeaderBSI(14);
170 $thisfile_ac3[
'timecode2'] = 0;
171 $thisfile_ac3[
'timecode2'] += (($thisfile_ac3_raw_bsi[
'timecod2'] & 0x3800) >> 11) * 1;
172 $thisfile_ac3[
'timecode2'] += (($thisfile_ac3_raw_bsi[
'timecod2'] & 0x07C0) >> 6) * (1 / 30);
173 $thisfile_ac3[
'timecode2'] += (($thisfile_ac3_raw_bsi[
'timecod2'] & 0x003F) >> 0) * ((1 / 30) / 60);
176 $thisfile_ac3_raw_bsi[
'flags'][
'addbsi'] = (bool) $this->
readHeaderBSI(1);
177 if ($thisfile_ac3_raw_bsi[
'flags'][
'addbsi']) {
178 $thisfile_ac3_raw_bsi[
'addbsi_length'] = $this->
readHeaderBSI(6) + 1;
182 $thisfile_ac3_raw_bsi[
'addbsi_data'] = substr($this->AC3header[
'bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi[
'addbsi_length'] * 8);
183 $this->BSIoffset += $thisfile_ac3_raw_bsi[
'addbsi_length'] * 8;
187 } elseif ($thisfile_ac3_raw_bsi[
'bsid'] <= 16) {
190 $this->
error(
'E-AC3 parsing is incomplete and experimental in this version of getID3 ('.$this->getid3->version().
'). Notably the bitrate calculations are wrong -- value might (or not) be correct, but it is not calculated correctly. Email info@getid3.org if you know how to calculate EAC3 bitrate correctly.');
191 $info[
'audio'][
'dataformat'] =
'eac3';
194 $thisfile_ac3_raw_bsi[
'substreamid'] = $this->
readHeaderBSI(3);
197 if ($thisfile_ac3_raw_bsi[
'fscod'] == 3) {
199 $thisfile_ac3_raw_bsi[
'numblkscod'] = 3;
201 $thisfile_ac3_raw_bsi[
'numblkscod'] = $this->
readHeaderBSI(2);
203 $thisfile_ac3[
'bsi'][
'blocks_per_sync_frame'] = self::blocksPerSyncFrame($thisfile_ac3_raw_bsi[
'numblkscod']);
205 $thisfile_ac3_raw_bsi[
'flags'][
'lfeon'] = (bool) $this->
readHeaderBSI(1);
208 $thisfile_ac3_raw_bsi[
'flags'][
'compr'] = (bool) $this->
readHeaderBSI(1);
209 if ($thisfile_ac3_raw_bsi[
'flags'][
'compr']) {
212 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0) {
213 $thisfile_ac3_raw_bsi[
'dialnorm2'] = $this->
readHeaderBSI(5);
214 $thisfile_ac3_raw_bsi[
'flags'][
'compr2'] = (bool) $this->
readHeaderBSI(1);
215 if ($thisfile_ac3_raw_bsi[
'flags'][
'compr2']) {
219 if ($thisfile_ac3_raw_bsi[
'strmtyp'] == 1) {
220 $thisfile_ac3_raw_bsi[
'flags'][
'chanmap'] = (bool) $this->
readHeaderBSI(1);
221 if ($thisfile_ac3_raw_bsi[
'flags'][
'chanmap']) {
225 $thisfile_ac3_raw_bsi[
'flags'][
'mixmdat'] = (bool) $this->
readHeaderBSI(1);
226 if ($thisfile_ac3_raw_bsi[
'flags'][
'mixmdat']) {
227 if ($thisfile_ac3_raw_bsi[
'acmod'] > 2) {
230 if (($thisfile_ac3_raw_bsi[
'acmod'] & 0x01) && ($thisfile_ac3_raw_bsi[
'acmod'] > 2)) {
231 $thisfile_ac3_raw_bsi[
'ltrtcmixlev'] = $this->
readHeaderBSI(3);
232 $thisfile_ac3_raw_bsi[
'lorocmixlev'] = $this->
readHeaderBSI(3);
234 if ($thisfile_ac3_raw_bsi[
'acmod'] & 0x04) {
235 $thisfile_ac3_raw_bsi[
'ltrtsurmixlev'] = $this->
readHeaderBSI(3);
236 $thisfile_ac3_raw_bsi[
'lorosurmixlev'] = $this->
readHeaderBSI(3);
238 if ($thisfile_ac3_raw_bsi[
'flags'][
'lfeon']) {
239 $thisfile_ac3_raw_bsi[
'flags'][
'lfemixlevcod'] = (bool) $this->
readHeaderBSI(1);
240 if ($thisfile_ac3_raw_bsi[
'flags'][
'lfemixlevcod']) {
241 $thisfile_ac3_raw_bsi[
'lfemixlevcod'] = $this->
readHeaderBSI(5);
244 if ($thisfile_ac3_raw_bsi[
'strmtyp'] == 0) {
245 $thisfile_ac3_raw_bsi[
'flags'][
'pgmscl'] = (bool) $this->
readHeaderBSI(1);
246 if ($thisfile_ac3_raw_bsi[
'flags'][
'pgmscl']) {
249 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0) {
250 $thisfile_ac3_raw_bsi[
'flags'][
'pgmscl2'] = (bool) $this->
readHeaderBSI(1);
251 if ($thisfile_ac3_raw_bsi[
'flags'][
'pgmscl2']) {
255 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmscl'] = (bool) $this->
readHeaderBSI(1);
256 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmscl']) {
257 $thisfile_ac3_raw_bsi[
'extpgmscl'] = $this->
readHeaderBSI(6);
260 if ($thisfile_ac3_raw_bsi[
'mixdef'] == 1) {
261 $thisfile_ac3_raw_bsi[
'premixcmpsel'] = (bool) $this->
readHeaderBSI(1);
262 $thisfile_ac3_raw_bsi[
'drcsrc'] = (bool) $this->
readHeaderBSI(1);
263 $thisfile_ac3_raw_bsi[
'premixcmpscl'] = $this->
readHeaderBSI(3);
264 } elseif ($thisfile_ac3_raw_bsi[
'mixdef'] == 2) {
266 } elseif ($thisfile_ac3_raw_bsi[
'mixdef'] == 3) {
268 $thisfile_ac3_raw_bsi[
'mixdeflen'] = $this->
readHeaderBSI(5); $mixdefbitsread += 5;
269 $thisfile_ac3_raw_bsi[
'flags'][
'mixdata2'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
270 if ($thisfile_ac3_raw_bsi[
'flags'][
'mixdata2']) {
271 $thisfile_ac3_raw_bsi[
'premixcmpsel'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
272 $thisfile_ac3_raw_bsi[
'drcsrc'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
273 $thisfile_ac3_raw_bsi[
'premixcmpscl'] = $this->
readHeaderBSI(3); $mixdefbitsread += 3;
274 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmlscl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
275 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmlscl']) {
276 $thisfile_ac3_raw_bsi[
'extpgmlscl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
278 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmcscl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
279 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmcscl']) {
280 $thisfile_ac3_raw_bsi[
'extpgmcscl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
282 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmrscl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
283 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmrscl']) {
284 $thisfile_ac3_raw_bsi[
'extpgmrscl'] = $this->
readHeaderBSI(4);
286 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmlsscl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
287 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmlsscl']) {
288 $thisfile_ac3_raw_bsi[
'extpgmlsscl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
290 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmrsscl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
291 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmrsscl']) {
292 $thisfile_ac3_raw_bsi[
'extpgmrsscl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
294 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmlfescl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
295 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmlfescl']) {
296 $thisfile_ac3_raw_bsi[
'extpgmlfescl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
298 $thisfile_ac3_raw_bsi[
'flags'][
'dmixscl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
299 if ($thisfile_ac3_raw_bsi[
'flags'][
'dmixscl']) {
300 $thisfile_ac3_raw_bsi[
'dmixscl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
302 $thisfile_ac3_raw_bsi[
'flags'][
'addch'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
303 if ($thisfile_ac3_raw_bsi[
'flags'][
'addch']) {
304 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmaux1scl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
305 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmaux1scl']) {
306 $thisfile_ac3_raw_bsi[
'extpgmaux1scl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
308 $thisfile_ac3_raw_bsi[
'flags'][
'extpgmaux2scl'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
309 if ($thisfile_ac3_raw_bsi[
'flags'][
'extpgmaux2scl']) {
310 $thisfile_ac3_raw_bsi[
'extpgmaux2scl'] = $this->
readHeaderBSI(4); $mixdefbitsread += 4;
314 $thisfile_ac3_raw_bsi[
'flags'][
'mixdata3'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
315 if ($thisfile_ac3_raw_bsi[
'flags'][
'mixdata3']) {
316 $thisfile_ac3_raw_bsi[
'spchdat'] = $this->
readHeaderBSI(5); $mixdefbitsread += 5;
317 $thisfile_ac3_raw_bsi[
'flags'][
'addspchdat'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
318 if ($thisfile_ac3_raw_bsi[
'flags'][
'addspchdat']) {
319 $thisfile_ac3_raw_bsi[
'spchdat1'] = $this->
readHeaderBSI(5); $mixdefbitsread += 5;
320 $thisfile_ac3_raw_bsi[
'spchan1att'] = $this->
readHeaderBSI(2); $mixdefbitsread += 2;
321 $thisfile_ac3_raw_bsi[
'flags'][
'addspchdat1'] = (bool) $this->
readHeaderBSI(1); $mixdefbitsread += 1;
322 if ($thisfile_ac3_raw_bsi[
'flags'][
'addspchdat1']) {
323 $thisfile_ac3_raw_bsi[
'spchdat2'] = $this->
readHeaderBSI(5); $mixdefbitsread += 5;
324 $thisfile_ac3_raw_bsi[
'spchan2att'] = $this->
readHeaderBSI(3); $mixdefbitsread += 3;
328 $mixdata_bits = (8 * ($thisfile_ac3_raw_bsi[
'mixdeflen'] + 2)) - $mixdefbitsread;
329 $mixdata_fill = (($mixdata_bits % 8) ? 8 - ($mixdata_bits % 8) : 0);
330 $thisfile_ac3_raw_bsi[
'mixdata'] = $this->
readHeaderBSI($mixdata_bits);
331 $thisfile_ac3_raw_bsi[
'mixdatafill'] = $this->
readHeaderBSI($mixdata_fill);
332 unset($mixdefbitsread, $mixdata_bits, $mixdata_fill);
334 if ($thisfile_ac3_raw_bsi[
'acmod'] < 2) {
335 $thisfile_ac3_raw_bsi[
'flags'][
'paninfo'] = (bool) $this->
readHeaderBSI(1);
336 if ($thisfile_ac3_raw_bsi[
'flags'][
'paninfo']) {
340 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0) {
341 $thisfile_ac3_raw_bsi[
'flags'][
'paninfo2'] = (bool) $this->
readHeaderBSI(1);
342 if ($thisfile_ac3_raw_bsi[
'flags'][
'paninfo2']) {
348 $thisfile_ac3_raw_bsi[
'flags'][
'frmmixcfginfo'] = (bool) $this->
readHeaderBSI(1);
349 if ($thisfile_ac3_raw_bsi[
'flags'][
'frmmixcfginfo']) {
350 if ($thisfile_ac3_raw_bsi[
'numblkscod'] == 0) {
351 $thisfile_ac3_raw_bsi[
'blkmixcfginfo'][0] = $this->
readHeaderBSI(5);
353 for ($blk = 0; $blk < $thisfile_ac3_raw_bsi[
'numblkscod']; $blk++) {
354 $thisfile_ac3_raw_bsi[
'flags'][
'blkmixcfginfo'.$blk] = (bool) $this->
readHeaderBSI(1);
355 if ($thisfile_ac3_raw_bsi[
'flags'][
'blkmixcfginfo'.$blk]) {
356 $thisfile_ac3_raw_bsi[
'blkmixcfginfo'][$blk] = $this->
readHeaderBSI(5);
363 $thisfile_ac3_raw_bsi[
'flags'][
'infomdat'] = (bool) $this->
readHeaderBSI(1);
364 if ($thisfile_ac3_raw_bsi[
'flags'][
'infomdat']) {
366 $thisfile_ac3_raw_bsi[
'flags'][
'copyrightb'] = (bool) $this->
readHeaderBSI(1);
367 $thisfile_ac3_raw_bsi[
'flags'][
'origbs'] = (bool) $this->
readHeaderBSI(1);
368 if ($thisfile_ac3_raw_bsi[
'acmod'] == 2) {
370 $thisfile_ac3_raw_bsi[
'dheadphonmod'] = $this->
readHeaderBSI(2);
372 if ($thisfile_ac3_raw_bsi[
'acmod'] >= 6) {
373 $thisfile_ac3_raw_bsi[
'dsurexmod'] = $this->
readHeaderBSI(2);
375 $thisfile_ac3_raw_bsi[
'flags'][
'audprodi'] = (bool) $this->
readHeaderBSI(1);
376 if ($thisfile_ac3_raw_bsi[
'flags'][
'audprodi']) {
379 $thisfile_ac3_raw_bsi[
'flags'][
'adconvtyp'] = (bool) $this->
readHeaderBSI(1);
381 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0) {
382 $thisfile_ac3_raw_bsi[
'flags'][
'audprodi2'] = (bool) $this->
readHeaderBSI(1);
383 if ($thisfile_ac3_raw_bsi[
'flags'][
'audprodi2']) {
384 $thisfile_ac3_raw_bsi[
'mixlevel2'] = $this->
readHeaderBSI(5);
386 $thisfile_ac3_raw_bsi[
'flags'][
'adconvtyp2'] = (bool) $this->
readHeaderBSI(1);
389 if ($thisfile_ac3_raw_bsi[
'fscod'] < 3) {
390 $thisfile_ac3_raw_bsi[
'flags'][
'sourcefscod'] = (bool) $this->
readHeaderBSI(1);
393 if (($thisfile_ac3_raw_bsi[
'strmtyp'] == 0) && ($thisfile_ac3_raw_bsi[
'numblkscod'] != 3)) {
394 $thisfile_ac3_raw_bsi[
'flags'][
'convsync'] = (bool) $this->
readHeaderBSI(1);
396 if ($thisfile_ac3_raw_bsi[
'strmtyp'] == 2) {
397 if ($thisfile_ac3_raw_bsi[
'numblkscod'] != 3) {
398 $thisfile_ac3_raw_bsi[
'flags'][
'blkid'] = 1;
400 $thisfile_ac3_raw_bsi[
'flags'][
'blkid'] = (bool) $this->
readHeaderBSI(1);
402 if ($thisfile_ac3_raw_bsi[
'flags'][
'blkid']) {
403 $thisfile_ac3_raw_bsi[
'frmsizecod'] = $this->
readHeaderBSI(6);
406 $thisfile_ac3_raw_bsi[
'flags'][
'addbsi'] = (bool) $this->
readHeaderBSI(1);
407 if ($thisfile_ac3_raw_bsi[
'flags'][
'addbsi']) {
409 $thisfile_ac3_raw_bsi[
'addbsi'] = $this->
readHeaderBSI(($thisfile_ac3_raw_bsi[
'addbsil'] + 1) * 8);
414 $this->
error(
'Bit stream identification is version '.$thisfile_ac3_raw_bsi[
'bsid'].
', but getID3() only understands up to version 16. Please submit a support ticket with a sample file.');
420 if (isset($thisfile_ac3_raw_bsi[
'fscod2'])) {
421 $thisfile_ac3[
'sample_rate'] = self::sampleRateCodeLookup2($thisfile_ac3_raw_bsi[
'fscod2']);
423 $thisfile_ac3[
'sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw_bsi[
'fscod']);
425 if ($thisfile_ac3_raw_bsi[
'fscod'] <= 3) {
426 $info[
'audio'][
'sample_rate'] = $thisfile_ac3[
'sample_rate'];
428 $this->
warning(
'Unexpected ac3.bsi.fscod value: '.$thisfile_ac3_raw_bsi[
'fscod']);
430 if (isset($thisfile_ac3_raw_bsi[
'frmsizecod'])) {
431 $thisfile_ac3[
'frame_length'] = self::frameSizeLookup($thisfile_ac3_raw_bsi[
'frmsizecod'], $thisfile_ac3_raw_bsi[
'fscod']);
432 $thisfile_ac3[
'bitrate'] = self::bitrateLookup($thisfile_ac3_raw_bsi[
'frmsizecod']);
433 } elseif (!empty($thisfile_ac3_raw_bsi[
'frmsiz'])) {
436 $thisfile_ac3[
'bitrate'] = ($thisfile_ac3_raw_bsi[
'frmsiz'] + 1) * 16 * 30;
438 $thisfile_ac3[
'bitrate'] = round(($thisfile_ac3[
'bitrate'] * 1.05) / 16000) * 16000;
440 $info[
'audio'][
'bitrate'] = $thisfile_ac3[
'bitrate'];
442 $thisfile_ac3[
'service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi[
'bsmod'], $thisfile_ac3_raw_bsi[
'acmod']);
443 $ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi[
'acmod']);
444 foreach($ac3_coding_mode as
$key => $value) {
445 $thisfile_ac3[
$key] = $value;
447 switch ($thisfile_ac3_raw_bsi[
'acmod']) {
450 $info[
'audio'][
'channelmode'] =
'mono';
454 $info[
'audio'][
'channelmode'] =
'stereo';
457 $info[
'audio'][
'channelmode'] =
'surround';
460 $info[
'audio'][
'channels'] = $thisfile_ac3[
'num_channels'];
462 $thisfile_ac3[
'lfe_enabled'] = $thisfile_ac3_raw_bsi[
'flags'][
'lfeon'];
463 if ($thisfile_ac3_raw_bsi[
'flags'][
'lfeon']) {
464 $info[
'audio'][
'channels'] .=
'.1';
467 $thisfile_ac3[
'channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi[
'acmod'], $thisfile_ac3_raw_bsi[
'flags'][
'lfeon']);
468 $thisfile_ac3[
'dialogue_normalization'] =
'-'.$thisfile_ac3_raw_bsi[
'dialnorm'].
'dB';
474 $data = substr($this->AC3header[
'bsi'], $this->BSIoffset, $length);
475 $this->BSIoffset += $length;
477 return bindec(
$data);
481 static $sampleRateCodeLookup = array(
487 return (isset($sampleRateCodeLookup[$fscod]) ? $sampleRateCodeLookup[$fscod] :
false);
491 static $sampleRateCodeLookup2 = array(
497 return (isset($sampleRateCodeLookup2[$fscod2]) ? $sampleRateCodeLookup2[$fscod2] :
false);
501 static $serviceTypeLookup = array();
502 if (empty($serviceTypeLookup)) {
503 for (
$i = 0;
$i <= 7;
$i++) {
504 $serviceTypeLookup[0][
$i] =
'main audio service: complete main (CM)';
505 $serviceTypeLookup[1][
$i] =
'main audio service: music and effects (ME)';
506 $serviceTypeLookup[2][
$i] =
'associated service: visually impaired (VI)';
507 $serviceTypeLookup[3][
$i] =
'associated service: hearing impaired (HI)';
508 $serviceTypeLookup[4][
$i] =
'associated service: dialogue (D)';
509 $serviceTypeLookup[5][
$i] =
'associated service: commentary (C)';
510 $serviceTypeLookup[6][
$i] =
'associated service: emergency (E)';
513 $serviceTypeLookup[7][1] =
'associated service: voice over (VO)';
514 for (
$i = 2;
$i <= 7;
$i++) {
515 $serviceTypeLookup[7][
$i] =
'main audio service: karaoke';
518 return (isset($serviceTypeLookup[$bsmod][$acmod]) ? $serviceTypeLookup[$bsmod][$acmod] :
false);
523 static $audioCodingModeLookup = array (
524 0 => array(
'channel_config'=>
'1+1',
'num_channels'=>2,
'channel_order'=>
'Ch1,Ch2'),
525 1 => array(
'channel_config'=>
'1/0',
'num_channels'=>1,
'channel_order'=>
'C'),
526 2 => array(
'channel_config'=>
'2/0',
'num_channels'=>2,
'channel_order'=>
'L,R'),
527 3 => array(
'channel_config'=>
'3/0',
'num_channels'=>3,
'channel_order'=>
'L,C,R'),
528 4 => array(
'channel_config'=>
'2/1',
'num_channels'=>3,
'channel_order'=>
'L,R,S'),
529 5 => array(
'channel_config'=>
'3/1',
'num_channels'=>4,
'channel_order'=>
'L,C,R,S'),
530 6 => array(
'channel_config'=>
'2/2',
'num_channels'=>4,
'channel_order'=>
'L,R,SL,SR'),
531 7 => array(
'channel_config'=>
'3/2',
'num_channels'=>5,
'channel_order'=>
'L,C,R,SL,SR'),
533 return (isset($audioCodingModeLookup[$acmod]) ? $audioCodingModeLookup[$acmod] :
false);
537 static $centerMixLevelLookup;
538 if (empty($centerMixLevelLookup)) {
539 $centerMixLevelLookup = array(
540 0 => pow(2, -3.0 / 6),
541 1 => pow(2, -4.5 / 6),
542 2 => pow(2, -6.0 / 6),
546 return (isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] :
false);
550 static $surroundMixLevelLookup;
551 if (empty($surroundMixLevelLookup)) {
552 $surroundMixLevelLookup = array(
553 0 => pow(2, -3.0 / 6),
554 1 => pow(2, -6.0 / 6),
559 return (isset($surroundMixLevelLookup[$surmixlev]) ? $surroundMixLevelLookup[$surmixlev] :
false);
563 static $dolbySurroundModeLookup = array(
564 0 =>
'not indicated',
565 1 =>
'Not Dolby Surround encoded',
566 2 =>
'Dolby Surround encoded',
569 return (isset($dolbySurroundModeLookup[$dsurmod]) ? $dolbySurroundModeLookup[$dsurmod] :
false);
574 'ch1'=>(
bool) ($acmod == 0),
575 'ch2'=>(
bool) ($acmod == 0),
576 'left'=>(
bool) ($acmod > 1),
577 'right'=>(
bool) ($acmod > 1),
578 'center'=>(
bool) ($acmod & 0x01),
579 'surround_mono'=>
false,
580 'surround_left'=>
false,
581 'surround_right'=>
false,
586 $lookup[
'surround_mono'] =
true;
590 $lookup[
'surround_left'] =
true;
591 $lookup[
'surround_right'] =
true;
625 $fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4,
'0', STR_PAD_LEFT);
626 if ($fourbit{0} ==
'1') {
627 $log_gain = -8 + bindec(substr($fourbit, 1));
629 $log_gain = bindec(substr($fourbit, 1));
638 $lin_gain = (16 + ($compre & 0x0F)) / 32;
644 return $log_gain - $lin_gain;
648 static $roomTypeLookup = array(
649 0 =>
'not indicated',
650 1 =>
'large room, X curve monitor',
651 2 =>
'small room, flat monitor',
654 return (isset($roomTypeLookup[$roomtyp]) ? $roomTypeLookup[$roomtyp] :
false);
659 $padding = (bool) ($frmsizecod & 0x01);
660 $framesizeid = ($frmsizecod & 0x3E) >> 1;
662 static $frameSizeLookup = array();
663 if (empty($frameSizeLookup)) {
664 $frameSizeLookup = array (
665 0 => array( 128, 138, 192),
666 1 => array( 160, 174, 240),
667 2 => array( 192, 208, 288),
668 3 => array( 224, 242, 336),
669 4 => array( 256, 278, 384),
670 5 => array( 320, 348, 480),
671 6 => array( 384, 416, 576),
672 7 => array( 448, 486, 672),
673 8 => array( 512, 556, 768),
674 9 => array( 640, 696, 960),
675 10 => array( 768, 834, 1152),
676 11 => array( 896, 974, 1344),
677 12 => array(1024, 1114, 1536),
678 13 => array(1280, 1392, 1920),
679 14 => array(1536, 1670, 2304),
680 15 => array(1792, 1950, 2688),
681 16 => array(2048, 2228, 3072),
682 17 => array(2304, 2506, 3456),
683 18 => array(2560, 2786, 3840)
686 if (($fscod == 1) && $padding) {
688 $frameSizeLookup[$frmsizecod] += 2;
690 return (isset($frameSizeLookup[$framesizeid][$fscod]) ? $frameSizeLookup[$framesizeid][$fscod] :
false);
695 $padding = (bool) ($frmsizecod & 0x01);
696 $framesizeid = ($frmsizecod & 0x3E) >> 1;
698 static $bitrateLookup = array(
719 return (isset($bitrateLookup[$framesizeid]) ? $bitrateLookup[$framesizeid] :
false);
723 static $blocksPerSyncFrameLookup = array(
729 return (isset($blocksPerSyncFrameLookup[$numblkscod]) ? $blocksPerSyncFrameLookup[$numblkscod] :
false);
static sampleRateCodeLookup($fscod)
static surroundMixLevelLookup($surmixlev)
static serviceTypeLookup($bsmod, $acmod)
static centerMixLevelLookup($cmixlev)
static Bin2Dec($binstring, $signed=false)
static BigEndian2Bin($byteword)
static LittleEndian2Int($byteword, $signed=false)
static roomTypeLookup($roomtyp)
static RGADamplitude2dB($amplitude)
static audioCodingModeLookup($acmod)
static heavyCompression($compre)
static frameSizeLookup($frmsizecod, $fscod)
static blocksPerSyncFrame($numblkscod)
static sampleRateCodeLookup2($fscod2)
static bitrateLookup($frmsizecod)
static channelsEnabledLookup($acmod, $lfeon)
static dolbySurroundModeLookup($dsurmod)
fseek($bytes, $whence=SEEK_SET)
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
getID3() by James Heinrich info@getid3.org //