wp/wp-includes/ID3/module.audio.ac3.php
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:40:08 +0200
changeset 21 48c4eec2b7e6
parent 16 a86126ab1dd4
permissions -rw-r--r--
Add CLAUDE.md documentation and sync WordPress core files - Add comprehensive CLAUDE.md documentation file with project architecture, development setup, database operations, WordPress CLI usage, file sync procedures, and Mercurial commands - Update WordPress core files from wordpress/ to wp/ directory - Sync latest WordPress admin interface, includes, and core functionality - Update plugins: portfolio plugin with latest BWS framework and fancybox integration - Maintain custom configuration and theme files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     2
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
/////////////////////////////////////////////////////////////////
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
/// getID3() by James Heinrich <info@getid3.org>               //
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     5
//  available at https://github.com/JamesHeinrich/getID3       //
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     6
//            or https://www.getid3.org                        //
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     7
//            or http://getid3.sourceforge.net                 //
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     8
//  see readme.txt for more details                            //
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/////////////////////////////////////////////////////////////////
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
//                                                             //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
// module.audio.ac3.php                                        //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
// module for analyzing AC-3 (aka Dolby Digital) audio files   //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
// dependencies: NONE                                          //
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
//                                                            ///
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
/////////////////////////////////////////////////////////////////
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    17
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    18
	exit;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    19
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
class getid3_ac3 extends getid3_handler
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
{
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    23
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    24
	 * @var array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    25
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    26
	private $AC3header = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    28
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    29
	 * @var int
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    30
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    31
	private $BSIoffset = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    33
	const syncword = 0x0B77;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    34
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    35
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    36
	 * @return bool
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    37
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	public function Analyze() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		$info = &$this->getid3->info;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		///AH
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
		$info['ac3']['raw']['bsi'] = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		$thisfile_ac3              = &$info['ac3'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		$thisfile_ac3_raw          = &$thisfile_ac3['raw'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		$thisfile_ac3_raw_bsi      = &$thisfile_ac3_raw['bsi'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		// http://www.atsc.org/standards/a_52a.pdf
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		$info['fileformat'] = 'ac3';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
		// An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		// Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		// new audio samples per channel. A synchronization information (SI) header at the beginning
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		// of each frame contains information needed to acquire and maintain synchronization. A
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		// bit stream information (BSI) header follows SI, and contains parameters describing the coded
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		// audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		// end of each frame is an error check field that includes a CRC word for error detection. An
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		// additional CRC word is located in the SI header, the use of which, by a decoder, is optional.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		// syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		// syncinfo() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		// 	 syncword    16
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		// 	 crc1        16
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		// 	 fscod        2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		// 	 frmsizecod   6
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
		// } /* end of syncinfo */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		$this->fseek($info['avdataoffset']);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    71
		$tempAC3header = $this->fread(100); // should be enough to cover all data, there are some variable-length fields...?
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    72
		$this->AC3header['syncinfo']  =     getid3_lib::BigEndian2Int(substr($tempAC3header, 0, 2));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    73
		$this->AC3header['bsi']       =     getid3_lib::BigEndian2Bin(substr($tempAC3header, 2));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    74
		$thisfile_ac3_raw_bsi['bsid'] = (getid3_lib::LittleEndian2Int(substr($tempAC3header, 5, 1)) & 0xF8) >> 3; // AC3 and E-AC3 put the "bsid" version identifier in the same place, but unfortnately the 4 bytes between the syncword and the version identifier are interpreted differently, so grab it here so the following code structure can make sense
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
		unset($tempAC3header);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
		if ($this->AC3header['syncinfo'] !== self::syncword) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			if (!$this->isDependencyFor('matroska')) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
				unset($info['fileformat'], $info['ac3']);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
				return $this->error('Expecting "'.dechex(self::syncword).'" at offset '.$info['avdataoffset'].', found "'.dechex($this->AC3header['syncinfo']).'"');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		$info['audio']['dataformat']   = 'ac3';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		$info['audio']['bitrate_mode'] = 'cbr';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
		$info['audio']['lossless']     = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    88
		if ($thisfile_ac3_raw_bsi['bsid'] <= 8) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
			$thisfile_ac3_raw_bsi['crc1']       = getid3_lib::Bin2Dec($this->readHeaderBSI(16));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
			$thisfile_ac3_raw_bsi['fscod']      =                     $this->readHeaderBSI(2);   // 5.4.1.3
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
			$thisfile_ac3_raw_bsi['frmsizecod'] =                     $this->readHeaderBSI(6);   // 5.4.1.4
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
			if ($thisfile_ac3_raw_bsi['frmsizecod'] > 37) { // binary: 100101 - see Table 5.18 Frame Size Code Table (1 word = 16 bits)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
				$this->warning('Unexpected ac3.bsi.frmsizecod value: '.$thisfile_ac3_raw_bsi['frmsizecod'].', bitrate not set correctly');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
			$thisfile_ac3_raw_bsi['bsid']  = $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
			$thisfile_ac3_raw_bsi['bsmod'] = $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
			$thisfile_ac3_raw_bsi['acmod'] = $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
			if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
				// If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
				$thisfile_ac3_raw_bsi['cmixlev'] = $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
				$thisfile_ac3['center_mix_level'] = self::centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
			if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   108
				// If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
				$thisfile_ac3_raw_bsi['surmixlev'] = $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   110
				$thisfile_ac3['surround_mix_level'] = self::surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   112
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   113
			if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   114
				// When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   115
				$thisfile_ac3_raw_bsi['dsurmod'] = $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   116
				$thisfile_ac3['dolby_surround_mode'] = self::dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   117
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   118
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   119
			$thisfile_ac3_raw_bsi['flags']['lfeon'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   120
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   121
			// This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   122
			// 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.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
			$thisfile_ac3_raw_bsi['dialnorm'] = $this->readHeaderBSI(5);                 // 5.4.2.8 dialnorm: Dialogue Normalization, 5 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   124
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   125
			$thisfile_ac3_raw_bsi['flags']['compr'] = (bool) $this->readHeaderBSI(1);       // 5.4.2.9 compre: Compression Gain Word Exists, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   126
			if ($thisfile_ac3_raw_bsi['flags']['compr']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   127
				$thisfile_ac3_raw_bsi['compr'] = $this->readHeaderBSI(8);                // 5.4.2.10 compr: Compression Gain Word, 8 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   128
				$thisfile_ac3['heavy_compression'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   129
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   130
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   131
			$thisfile_ac3_raw_bsi['flags']['langcod'] = (bool) $this->readHeaderBSI(1);     // 5.4.2.11 langcode: Language Code Exists, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   132
			if ($thisfile_ac3_raw_bsi['flags']['langcod']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   133
				$thisfile_ac3_raw_bsi['langcod'] = $this->readHeaderBSI(8);              // 5.4.2.12 langcod: Language Code, 8 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   134
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   135
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   136
			$thisfile_ac3_raw_bsi['flags']['audprodinfo'] = (bool) $this->readHeaderBSI(1);  // 5.4.2.13 audprodie: Audio Production Information Exists, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   137
			if ($thisfile_ac3_raw_bsi['flags']['audprodinfo']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
				$thisfile_ac3_raw_bsi['mixlevel'] = $this->readHeaderBSI(5);             // 5.4.2.14 mixlevel: Mixing Level, 5 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   139
				$thisfile_ac3_raw_bsi['roomtyp']  = $this->readHeaderBSI(2);             // 5.4.2.15 roomtyp: Room Type, 2 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   140
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   141
				$thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   142
				$thisfile_ac3['room_type']    = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   143
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   144
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   145
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   146
			$thisfile_ac3_raw_bsi['dialnorm2'] = $this->readHeaderBSI(5);                // 5.4.2.16 dialnorm2: Dialogue Normalization, ch2, 5 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   147
			$thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB';  // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1-31. 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.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   148
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
			$thisfile_ac3_raw_bsi['flags']['compr2'] = (bool) $this->readHeaderBSI(1);       // 5.4.2.17 compr2e: Compression Gain Word Exists, ch2, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
			if ($thisfile_ac3_raw_bsi['flags']['compr2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
				$thisfile_ac3_raw_bsi['compr2'] = $this->readHeaderBSI(8);               // 5.4.2.18 compr2: Compression Gain Word, ch2, 8 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   152
				$thisfile_ac3['heavy_compression2'] = self::heavyCompression($thisfile_ac3_raw_bsi['compr2']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   153
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   154
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   155
			$thisfile_ac3_raw_bsi['flags']['langcod2'] = (bool) $this->readHeaderBSI(1);    // 5.4.2.19 langcod2e: Language Code Exists, ch2, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   156
			if ($thisfile_ac3_raw_bsi['flags']['langcod2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   157
				$thisfile_ac3_raw_bsi['langcod2'] = $this->readHeaderBSI(8);             // 5.4.2.20 langcod2: Language Code, ch2, 8 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   158
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   159
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   160
			$thisfile_ac3_raw_bsi['flags']['audprodinfo2'] = (bool) $this->readHeaderBSI(1); // 5.4.2.21 audprodi2e: Audio Production Information Exists, ch2, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   161
			if ($thisfile_ac3_raw_bsi['flags']['audprodinfo2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
				$thisfile_ac3_raw_bsi['mixlevel2'] = $this->readHeaderBSI(5);            // 5.4.2.22 mixlevel2: Mixing Level, ch2, 5 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   163
				$thisfile_ac3_raw_bsi['roomtyp2']  = $this->readHeaderBSI(2);            // 5.4.2.23 roomtyp2: Room Type, ch2, 2 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   164
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   165
				$thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   166
				$thisfile_ac3['room_type2']    = self::roomTypeLookup($thisfile_ac3_raw_bsi['roomtyp2']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   167
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   168
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   169
			$thisfile_ac3_raw_bsi['copyright'] = (bool) $this->readHeaderBSI(1);         // 5.4.2.24 copyrightb: Copyright Bit, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   170
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
			$thisfile_ac3_raw_bsi['original']  = (bool) $this->readHeaderBSI(1);         // 5.4.2.25 origbs: Original Bit Stream, 1 Bit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   172
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   173
			$thisfile_ac3_raw_bsi['flags']['timecod1'] = $this->readHeaderBSI(2);            // 5.4.2.26 timecod1e, timcode2e: Time Code (first and second) Halves Exist, 2 Bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   174
			if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x01) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   175
				$thisfile_ac3_raw_bsi['timecod1'] = $this->readHeaderBSI(14);            // 5.4.2.27 timecod1: Time code first half, 14 bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   176
				$thisfile_ac3['timecode1'] = 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   177
				$thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x3E00) >>  9) * 3600;  // The first 5 bits of this 14-bit field represent the time in hours, with valid values of 0�23
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   178
				$thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x01F8) >>  3) *   60;  // The next 6 bits represent the time in minutes, with valid values of 0�59
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   179
				$thisfile_ac3['timecode1'] += (($thisfile_ac3_raw_bsi['timecod1'] & 0x0003) >>  0) *    8;  // The final 3 bits represents the time in 8 second increments, with valid values of 0�7 (representing 0, 8, 16, ... 56 seconds)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
			if ($thisfile_ac3_raw_bsi['flags']['timecod1'] & 0x02) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
				$thisfile_ac3_raw_bsi['timecod2'] = $this->readHeaderBSI(14);            // 5.4.2.28 timecod2: Time code second half, 14 bits
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
				$thisfile_ac3['timecode2'] = 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   184
				$thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x3800) >> 11) *   1;              // The first 3 bits of this 14-bit field represent the time in seconds, with valid values from 0�7 (representing 0-7 seconds)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   185
				$thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x07C0) >>  6) *  (1 / 30);        // The next 5 bits represents the time in frames, with valid values from 0�29 (one frame = 1/30th of a second)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   186
				$thisfile_ac3['timecode2'] += (($thisfile_ac3_raw_bsi['timecod2'] & 0x003F) >>  0) * ((1 / 30) / 60);  // The final 6 bits represents fractions of 1/64 of a frame, with valid values from 0�63
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   187
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   188
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   189
			$thisfile_ac3_raw_bsi['flags']['addbsi'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   190
			if ($thisfile_ac3_raw_bsi['flags']['addbsi']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
				$thisfile_ac3_raw_bsi['addbsi_length'] = $this->readHeaderBSI(6) + 1; // This 6-bit code, which exists only if addbside is a 1, indicates the length in bytes of additional bit stream information. The valid range of addbsil is 0�63, indicating 1�64 additional bytes, respectively.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   193
				$this->AC3header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($thisfile_ac3_raw_bsi['addbsi_length']));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   194
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
				$thisfile_ac3_raw_bsi['addbsi_data'] = substr($this->AC3header['bsi'], $this->BSIoffset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   196
				$this->BSIoffset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   197
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   198
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   199
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
		} elseif ($thisfile_ac3_raw_bsi['bsid'] <= 16) { // E-AC3
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   201
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   202
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   203
			$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.');
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   204
			$info['audio']['dataformat'] = 'eac3';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
			$thisfile_ac3_raw_bsi['strmtyp']          =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   207
			$thisfile_ac3_raw_bsi['substreamid']      =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   208
			$thisfile_ac3_raw_bsi['frmsiz']           =        $this->readHeaderBSI(11);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   209
			$thisfile_ac3_raw_bsi['fscod']            =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   210
			if ($thisfile_ac3_raw_bsi['fscod'] == 3) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
				$thisfile_ac3_raw_bsi['fscod2']       =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   212
				$thisfile_ac3_raw_bsi['numblkscod'] = 3; // six blocks per syncframe
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   213
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
				$thisfile_ac3_raw_bsi['numblkscod']   =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   216
			$thisfile_ac3['bsi']['blocks_per_sync_frame'] = self::blocksPerSyncFrame($thisfile_ac3_raw_bsi['numblkscod']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
			$thisfile_ac3_raw_bsi['acmod']            =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
			$thisfile_ac3_raw_bsi['flags']['lfeon']   = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   219
			$thisfile_ac3_raw_bsi['bsid']             =        $this->readHeaderBSI(5); // we already know this from pre-parsing the version identifier, but re-read it to let the bitstream flow as intended
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   220
			$thisfile_ac3_raw_bsi['dialnorm']         =        $this->readHeaderBSI(5);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   221
			$thisfile_ac3_raw_bsi['flags']['compr']       = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   222
			if ($thisfile_ac3_raw_bsi['flags']['compr']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   223
				$thisfile_ac3_raw_bsi['compr']        =        $this->readHeaderBSI(8);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   224
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
			if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   226
				$thisfile_ac3_raw_bsi['dialnorm2']    =        $this->readHeaderBSI(5);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   227
				$thisfile_ac3_raw_bsi['flags']['compr2']  = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
				if ($thisfile_ac3_raw_bsi['flags']['compr2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
					$thisfile_ac3_raw_bsi['compr2']   =        $this->readHeaderBSI(8);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   230
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   231
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   232
			if ($thisfile_ac3_raw_bsi['strmtyp'] == 1) { // if dependent stream
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   233
				$thisfile_ac3_raw_bsi['flags']['chanmap'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   234
				if ($thisfile_ac3_raw_bsi['flags']['chanmap']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   235
					$thisfile_ac3_raw_bsi['chanmap']  =        $this->readHeaderBSI(8);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   236
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   237
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   238
			$thisfile_ac3_raw_bsi['flags']['mixmdat']     = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   239
			if ($thisfile_ac3_raw_bsi['flags']['mixmdat']) { // Mixing metadata
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   240
				if ($thisfile_ac3_raw_bsi['acmod'] > 2) { // if more than 2 channels
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   241
					$thisfile_ac3_raw_bsi['dmixmod']  =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   242
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   243
				if (($thisfile_ac3_raw_bsi['acmod'] & 0x01) && ($thisfile_ac3_raw_bsi['acmod'] > 2)) { // if three front channels exist
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   244
					$thisfile_ac3_raw_bsi['ltrtcmixlev'] =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   245
					$thisfile_ac3_raw_bsi['lorocmixlev'] =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   246
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   247
				if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { // if a surround channel exists
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   248
					$thisfile_ac3_raw_bsi['ltrtsurmixlev'] =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   249
					$thisfile_ac3_raw_bsi['lorosurmixlev'] =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   250
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   251
				if ($thisfile_ac3_raw_bsi['flags']['lfeon']) { // if the LFE channel exists
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   252
					$thisfile_ac3_raw_bsi['flags']['lfemixlevcod'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   253
					if ($thisfile_ac3_raw_bsi['flags']['lfemixlevcod']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   254
						$thisfile_ac3_raw_bsi['lfemixlevcod']  =        $this->readHeaderBSI(5);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   255
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   256
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   257
				if ($thisfile_ac3_raw_bsi['strmtyp'] == 0) { // if independent stream
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   258
					$thisfile_ac3_raw_bsi['flags']['pgmscl'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   259
					if ($thisfile_ac3_raw_bsi['flags']['pgmscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   260
						$thisfile_ac3_raw_bsi['pgmscl']  =        $this->readHeaderBSI(6);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   261
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   262
					if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   263
						$thisfile_ac3_raw_bsi['flags']['pgmscl2'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   264
						if ($thisfile_ac3_raw_bsi['flags']['pgmscl2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   265
							$thisfile_ac3_raw_bsi['pgmscl2']  =        $this->readHeaderBSI(6);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   266
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   267
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   268
					$thisfile_ac3_raw_bsi['flags']['extpgmscl'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   269
					if ($thisfile_ac3_raw_bsi['flags']['extpgmscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   270
						$thisfile_ac3_raw_bsi['extpgmscl']  =        $this->readHeaderBSI(6);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   272
					$thisfile_ac3_raw_bsi['mixdef']  =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   273
					if ($thisfile_ac3_raw_bsi['mixdef'] == 1) { // mixing option 2
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   274
						$thisfile_ac3_raw_bsi['premixcmpsel']  = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   275
						$thisfile_ac3_raw_bsi['drcsrc']        = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   276
						$thisfile_ac3_raw_bsi['premixcmpscl']  =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   277
					} elseif ($thisfile_ac3_raw_bsi['mixdef'] == 2) { // mixing option 3
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   278
						$thisfile_ac3_raw_bsi['mixdata']       =        $this->readHeaderBSI(12);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   279
					} elseif ($thisfile_ac3_raw_bsi['mixdef'] == 3) { // mixing option 4
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   280
						$mixdefbitsread = 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   281
						$thisfile_ac3_raw_bsi['mixdeflen']     =        $this->readHeaderBSI(5); $mixdefbitsread += 5;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   282
						$thisfile_ac3_raw_bsi['flags']['mixdata2'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   283
						if ($thisfile_ac3_raw_bsi['flags']['mixdata2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   284
							$thisfile_ac3_raw_bsi['premixcmpsel']  = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   285
							$thisfile_ac3_raw_bsi['drcsrc']        = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   286
							$thisfile_ac3_raw_bsi['premixcmpscl']  =        $this->readHeaderBSI(3); $mixdefbitsread += 3;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   287
							$thisfile_ac3_raw_bsi['flags']['extpgmlscl']   = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   288
							if ($thisfile_ac3_raw_bsi['flags']['extpgmlscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   289
								$thisfile_ac3_raw_bsi['extpgmlscl']    =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   290
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   291
							$thisfile_ac3_raw_bsi['flags']['extpgmcscl']   = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   292
							if ($thisfile_ac3_raw_bsi['flags']['extpgmcscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   293
								$thisfile_ac3_raw_bsi['extpgmcscl']    =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   294
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   295
							$thisfile_ac3_raw_bsi['flags']['extpgmrscl']   = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   296
							if ($thisfile_ac3_raw_bsi['flags']['extpgmrscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   297
								$thisfile_ac3_raw_bsi['extpgmrscl']    =        $this->readHeaderBSI(4);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   298
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   299
							$thisfile_ac3_raw_bsi['flags']['extpgmlsscl']  = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   300
							if ($thisfile_ac3_raw_bsi['flags']['extpgmlsscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   301
								$thisfile_ac3_raw_bsi['extpgmlsscl']   =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   302
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   303
							$thisfile_ac3_raw_bsi['flags']['extpgmrsscl']  = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
							if ($thisfile_ac3_raw_bsi['flags']['extpgmrsscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   305
								$thisfile_ac3_raw_bsi['extpgmrsscl']   =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   306
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   307
							$thisfile_ac3_raw_bsi['flags']['extpgmlfescl'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   308
							if ($thisfile_ac3_raw_bsi['flags']['extpgmlfescl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   309
								$thisfile_ac3_raw_bsi['extpgmlfescl']  =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   310
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   311
							$thisfile_ac3_raw_bsi['flags']['dmixscl']      = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   312
							if ($thisfile_ac3_raw_bsi['flags']['dmixscl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   313
								$thisfile_ac3_raw_bsi['dmixscl']       =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   314
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
							$thisfile_ac3_raw_bsi['flags']['addch']        = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   316
							if ($thisfile_ac3_raw_bsi['flags']['addch']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   317
								$thisfile_ac3_raw_bsi['flags']['extpgmaux1scl']   = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   318
								if ($thisfile_ac3_raw_bsi['flags']['extpgmaux1scl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   319
									$thisfile_ac3_raw_bsi['extpgmaux1scl']    =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   320
								}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   321
								$thisfile_ac3_raw_bsi['flags']['extpgmaux2scl']   = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   322
								if ($thisfile_ac3_raw_bsi['flags']['extpgmaux2scl']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   323
									$thisfile_ac3_raw_bsi['extpgmaux2scl']    =        $this->readHeaderBSI(4); $mixdefbitsread += 4;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   324
								}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   325
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   327
						$thisfile_ac3_raw_bsi['flags']['mixdata3'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
						if ($thisfile_ac3_raw_bsi['flags']['mixdata3']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
							$thisfile_ac3_raw_bsi['spchdat']   =        $this->readHeaderBSI(5); $mixdefbitsread += 5;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   330
							$thisfile_ac3_raw_bsi['flags']['addspchdat'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   331
							if ($thisfile_ac3_raw_bsi['flags']['addspchdat']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   332
								$thisfile_ac3_raw_bsi['spchdat1']   =         $this->readHeaderBSI(5); $mixdefbitsread += 5;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   333
								$thisfile_ac3_raw_bsi['spchan1att'] =         $this->readHeaderBSI(2); $mixdefbitsread += 2;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   334
								$thisfile_ac3_raw_bsi['flags']['addspchdat1'] = (bool) $this->readHeaderBSI(1); $mixdefbitsread += 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   335
								if ($thisfile_ac3_raw_bsi['flags']['addspchdat1']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   336
									$thisfile_ac3_raw_bsi['spchdat2']   =         $this->readHeaderBSI(5); $mixdefbitsread += 5;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
									$thisfile_ac3_raw_bsi['spchan2att'] =         $this->readHeaderBSI(3); $mixdefbitsread += 3;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   338
								}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   339
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   340
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
						$mixdata_bits = (8 * ($thisfile_ac3_raw_bsi['mixdeflen'] + 2)) - $mixdefbitsread;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
						$mixdata_fill = (($mixdata_bits % 8) ? 8 - ($mixdata_bits % 8) : 0);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
						$thisfile_ac3_raw_bsi['mixdata']     =        $this->readHeaderBSI($mixdata_bits);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
						$thisfile_ac3_raw_bsi['mixdatafill'] =        $this->readHeaderBSI($mixdata_fill);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
						unset($mixdefbitsread, $mixdata_bits, $mixdata_fill);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
					if ($thisfile_ac3_raw_bsi['acmod'] < 2) { // if mono or dual mono source
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   348
						$thisfile_ac3_raw_bsi['flags']['paninfo'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   349
						if ($thisfile_ac3_raw_bsi['flags']['paninfo']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   350
							$thisfile_ac3_raw_bsi['panmean']   =        $this->readHeaderBSI(8);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   351
							$thisfile_ac3_raw_bsi['paninfo']   =        $this->readHeaderBSI(6);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   352
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   353
						if ($thisfile_ac3_raw_bsi['acmod'] == 0) { // if 1+1 mode (dual mono, so some items need a second value)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
							$thisfile_ac3_raw_bsi['flags']['paninfo2'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   355
							if ($thisfile_ac3_raw_bsi['flags']['paninfo2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   356
								$thisfile_ac3_raw_bsi['panmean2']   =        $this->readHeaderBSI(8);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   357
								$thisfile_ac3_raw_bsi['paninfo2']   =        $this->readHeaderBSI(6);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   360
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   361
					$thisfile_ac3_raw_bsi['flags']['frmmixcfginfo'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   362
					if ($thisfile_ac3_raw_bsi['flags']['frmmixcfginfo']) { // mixing configuration information
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   363
						if ($thisfile_ac3_raw_bsi['numblkscod'] == 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
							$thisfile_ac3_raw_bsi['blkmixcfginfo'][0]  =        $this->readHeaderBSI(5);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   365
						} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
							for ($blk = 0; $blk < $thisfile_ac3_raw_bsi['numblkscod']; $blk++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   367
								$thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   368
								if ($thisfile_ac3_raw_bsi['flags']['blkmixcfginfo'.$blk]) { // mixing configuration information
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   369
									$thisfile_ac3_raw_bsi['blkmixcfginfo'][$blk]  =        $this->readHeaderBSI(5);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   370
								}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   371
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   372
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   373
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   374
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   375
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   376
			$thisfile_ac3_raw_bsi['flags']['infomdat']          = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   377
			if ($thisfile_ac3_raw_bsi['flags']['infomdat']) { // Informational metadata
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   378
				$thisfile_ac3_raw_bsi['bsmod']                  =        $this->readHeaderBSI(3);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   379
				$thisfile_ac3_raw_bsi['flags']['copyrightb']    = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   380
				$thisfile_ac3_raw_bsi['flags']['origbs']        = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   381
				if ($thisfile_ac3_raw_bsi['acmod'] == 2) { //  if in 2/0 mode
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   382
					$thisfile_ac3_raw_bsi['dsurmod']            =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   383
					$thisfile_ac3_raw_bsi['dheadphonmod']       =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   384
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   385
				if ($thisfile_ac3_raw_bsi['acmod'] >= 6) { //  if both surround channels exist
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   386
					$thisfile_ac3_raw_bsi['dsurexmod']          =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   387
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   388
				$thisfile_ac3_raw_bsi['flags']['audprodi']      = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   389
				if ($thisfile_ac3_raw_bsi['flags']['audprodi']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
					$thisfile_ac3_raw_bsi['mixlevel']           =        $this->readHeaderBSI(5);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   391
					$thisfile_ac3_raw_bsi['roomtyp']            =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   392
					$thisfile_ac3_raw_bsi['flags']['adconvtyp'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   393
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   394
				if ($thisfile_ac3_raw_bsi['acmod'] == 0) { //  if 1+1 mode (dual mono, so some items need a second value)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   395
					$thisfile_ac3_raw_bsi['flags']['audprodi2']      = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   396
					if ($thisfile_ac3_raw_bsi['flags']['audprodi2']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   397
						$thisfile_ac3_raw_bsi['mixlevel2']           =        $this->readHeaderBSI(5);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   398
						$thisfile_ac3_raw_bsi['roomtyp2']            =        $this->readHeaderBSI(2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
						$thisfile_ac3_raw_bsi['flags']['adconvtyp2'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   400
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   401
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
				if ($thisfile_ac3_raw_bsi['fscod'] < 3) { // if not half sample rate
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
					$thisfile_ac3_raw_bsi['flags']['sourcefscod'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
			if (($thisfile_ac3_raw_bsi['strmtyp'] == 0) && ($thisfile_ac3_raw_bsi['numblkscod'] != 3)) { //  if both surround channels exist
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
				$thisfile_ac3_raw_bsi['flags']['convsync'] = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   408
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   409
			if ($thisfile_ac3_raw_bsi['strmtyp'] == 2) { //  if bit stream converted from AC-3
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
				if ($thisfile_ac3_raw_bsi['numblkscod'] != 3) { // 6 blocks per syncframe
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   411
					$thisfile_ac3_raw_bsi['flags']['blkid']  = 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   412
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   413
					$thisfile_ac3_raw_bsi['flags']['blkid']  = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   414
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   415
				if ($thisfile_ac3_raw_bsi['flags']['blkid']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   416
					$thisfile_ac3_raw_bsi['frmsizecod']  =        $this->readHeaderBSI(6);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   417
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   418
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   419
			$thisfile_ac3_raw_bsi['flags']['addbsi']  = (bool) $this->readHeaderBSI(1);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   420
			if ($thisfile_ac3_raw_bsi['flags']['addbsi']) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   421
				$thisfile_ac3_raw_bsi['addbsil']  =        $this->readHeaderBSI(6);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   422
				$thisfile_ac3_raw_bsi['addbsi']   =        $this->readHeaderBSI(($thisfile_ac3_raw_bsi['addbsil'] + 1) * 8);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   423
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   424
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   425
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   426
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   427
			$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.');
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   428
			unset($info['ac3']);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   429
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   430
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   433
		if (isset($thisfile_ac3_raw_bsi['fscod2'])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   434
			$thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup2($thisfile_ac3_raw_bsi['fscod2']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   435
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   436
			$thisfile_ac3['sample_rate'] = self::sampleRateCodeLookup($thisfile_ac3_raw_bsi['fscod']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   437
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   438
		if ($thisfile_ac3_raw_bsi['fscod'] <= 3) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   439
			$info['audio']['sample_rate'] = $thisfile_ac3['sample_rate'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   440
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   441
			$this->warning('Unexpected ac3.bsi.fscod value: '.$thisfile_ac3_raw_bsi['fscod']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   442
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   443
		if (isset($thisfile_ac3_raw_bsi['frmsizecod'])) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   444
			$thisfile_ac3['frame_length'] = self::frameSizeLookup($thisfile_ac3_raw_bsi['frmsizecod'], $thisfile_ac3_raw_bsi['fscod']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   445
			$thisfile_ac3['bitrate']      = self::bitrateLookup($thisfile_ac3_raw_bsi['frmsizecod']);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   446
		} elseif (!empty($thisfile_ac3_raw_bsi['frmsiz'])) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   447
			// this isn't right, but it's (usually) close, roughly 5% less than it should be.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   448
			// but WHERE is the actual bitrate value stored in EAC3?? email info@getid3.org if you know!
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   449
			$thisfile_ac3['bitrate']      = ($thisfile_ac3_raw_bsi['frmsiz'] + 1) * 16 * 30; // The frmsiz field shall contain a value one less than the overall size of the coded syncframe in 16-bit words. That is, this field may assume a value ranging from 0 to 2047, and these values correspond to syncframe sizes ranging from 1 to 2048.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   450
			// kludge-fix to make it approximately the expected value, still not "right":
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   451
			$thisfile_ac3['bitrate'] = round(($thisfile_ac3['bitrate'] * 1.05) / 16000) * 16000;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   452
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
		$info['audio']['bitrate'] = $thisfile_ac3['bitrate'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   455
		if (isset($thisfile_ac3_raw_bsi['bsmod']) && isset($thisfile_ac3_raw_bsi['acmod'])) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   456
			$thisfile_ac3['service_type'] = self::serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   457
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
		$ac3_coding_mode = self::audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		foreach($ac3_coding_mode as $key => $value) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			$thisfile_ac3[$key] = $value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		switch ($thisfile_ac3_raw_bsi['acmod']) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			case 0:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
			case 1:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
				$info['audio']['channelmode'] = 'mono';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
			case 3:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
			case 4:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
				$info['audio']['channelmode'] = 'stereo';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
			default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
				$info['audio']['channelmode'] = 'surround';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
		$info['audio']['channels'] = $thisfile_ac3['num_channels'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   477
		$thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['flags']['lfeon'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   478
		if ($thisfile_ac3_raw_bsi['flags']['lfeon']) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
			$info['audio']['channels'] .= '.1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   482
		$thisfile_ac3['channels_enabled'] = self::channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['flags']['lfeon']);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		$thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   488
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   489
	 * @param int $length
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   490
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   491
	 * @return int
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   492
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
	private function readHeaderBSI($length) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
		$data = substr($this->AC3header['bsi'], $this->BSIoffset, $length);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
		$this->BSIoffset += $length;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		return bindec($data);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   500
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   501
	 * @param int $fscod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   502
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   503
	 * @return int|string|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   504
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
	public static function sampleRateCodeLookup($fscod) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
		static $sampleRateCodeLookup = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
			0 => 48000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			1 => 44100,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
			2 => 32000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
			3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		return (isset($sampleRateCodeLookup[$fscod]) ? $sampleRateCodeLookup[$fscod] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   515
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   516
	 * @param int $fscod2
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   517
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   518
	 * @return int|string|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   519
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   520
	public static function sampleRateCodeLookup2($fscod2) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   521
		static $sampleRateCodeLookup2 = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   522
			0 => 24000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   523
			1 => 22050,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   524
			2 => 16000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   525
			3 => 'reserved' // If the reserved code is indicated, the decoder should not attempt to decode audio and should mute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   526
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   527
		return (isset($sampleRateCodeLookup2[$fscod2]) ? $sampleRateCodeLookup2[$fscod2] : false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   528
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   529
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   530
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   531
	 * @param int $bsmod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   532
	 * @param int $acmod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   533
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   534
	 * @return string|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   535
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	public static function serviceTypeLookup($bsmod, $acmod) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
		static $serviceTypeLookup = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		if (empty($serviceTypeLookup)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
			for ($i = 0; $i <= 7; $i++) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
				$serviceTypeLookup[0][$i] = 'main audio service: complete main (CM)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
				$serviceTypeLookup[1][$i] = 'main audio service: music and effects (ME)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
				$serviceTypeLookup[2][$i] = 'associated service: visually impaired (VI)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
				$serviceTypeLookup[3][$i] = 'associated service: hearing impaired (HI)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
				$serviceTypeLookup[4][$i] = 'associated service: dialogue (D)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
				$serviceTypeLookup[5][$i] = 'associated service: commentary (C)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
				$serviceTypeLookup[6][$i] = 'associated service: emergency (E)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
			$serviceTypeLookup[7][1]      = 'associated service: voice over (VO)';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
			for ($i = 2; $i <= 7; $i++) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
				$serviceTypeLookup[7][$i] = 'main audio service: karaoke';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
		return (isset($serviceTypeLookup[$bsmod][$acmod]) ? $serviceTypeLookup[$bsmod][$acmod] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   557
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   558
	 * @param int $acmod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   559
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   560
	 * @return array|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   561
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	public static function audioCodingModeLookup($acmod) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
		// array(channel configuration, # channels (not incl LFE), channel order)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
		static $audioCodingModeLookup = array (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
			0 => array('channel_config'=>'1+1', 'num_channels'=>2, 'channel_order'=>'Ch1,Ch2'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
			1 => array('channel_config'=>'1/0', 'num_channels'=>1, 'channel_order'=>'C'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
			2 => array('channel_config'=>'2/0', 'num_channels'=>2, 'channel_order'=>'L,R'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
			3 => array('channel_config'=>'3/0', 'num_channels'=>3, 'channel_order'=>'L,C,R'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
			4 => array('channel_config'=>'2/1', 'num_channels'=>3, 'channel_order'=>'L,R,S'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
			5 => array('channel_config'=>'3/1', 'num_channels'=>4, 'channel_order'=>'L,C,R,S'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
			6 => array('channel_config'=>'2/2', 'num_channels'=>4, 'channel_order'=>'L,R,SL,SR'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
			7 => array('channel_config'=>'3/2', 'num_channels'=>5, 'channel_order'=>'L,C,R,SL,SR'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
		return (isset($audioCodingModeLookup[$acmod]) ? $audioCodingModeLookup[$acmod] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   577
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   578
	 * @param int $cmixlev
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   579
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   580
	 * @return int|float|string|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   581
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	public static function centerMixLevelLookup($cmixlev) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		static $centerMixLevelLookup;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
		if (empty($centerMixLevelLookup)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
			$centerMixLevelLookup = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
				0 => pow(2, -3.0 / 6), // 0.707 (-3.0 dB)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
				1 => pow(2, -4.5 / 6), // 0.595 (-4.5 dB)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
				2 => pow(2, -6.0 / 6), // 0.500 (-6.0 dB)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
				3 => 'reserved'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
		return (isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   595
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   596
	 * @param int $surmixlev
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   597
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   598
	 * @return int|float|string|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   599
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	public static function surroundMixLevelLookup($surmixlev) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		static $surroundMixLevelLookup;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
		if (empty($surroundMixLevelLookup)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
			$surroundMixLevelLookup = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
				0 => pow(2, -3.0 / 6),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
				1 => pow(2, -6.0 / 6),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
				2 => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
				3 => 'reserved'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
		return (isset($surroundMixLevelLookup[$surmixlev]) ? $surroundMixLevelLookup[$surmixlev] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   613
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   614
	 * @param int $dsurmod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   615
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   616
	 * @return string|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   617
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	public static function dolbySurroundModeLookup($dsurmod) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
		static $dolbySurroundModeLookup = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
			0 => 'not indicated',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
			1 => 'Not Dolby Surround encoded',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
			2 => 'Dolby Surround encoded',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
			3 => 'reserved'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
		return (isset($dolbySurroundModeLookup[$dsurmod]) ? $dolbySurroundModeLookup[$dsurmod] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   628
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   629
	 * @param int  $acmod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   630
	 * @param bool $lfeon
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   631
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   632
	 * @return array
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   633
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
	public static function channelsEnabledLookup($acmod, $lfeon) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
		$lookup = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   636
			'ch1'=>($acmod == 0),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   637
			'ch2'=>($acmod == 0),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   638
			'left'=>($acmod > 1),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   639
			'right'=>($acmod > 1),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
			'center'=>(bool) ($acmod & 0x01),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
			'surround_mono'=>false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
			'surround_left'=>false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
			'surround_right'=>false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
			'lfe'=>$lfeon);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
		switch ($acmod) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
			case 4:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
			case 5:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
				$lookup['surround_mono']  = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
			case 6:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
			case 7:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
				$lookup['surround_left']  = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
				$lookup['surround_right'] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
		return $lookup;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   659
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   660
	 * @param int $compre
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   661
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   662
	 * @return float|int
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   663
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	public static function heavyCompression($compre) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
		// The first four bits indicate gain changes in 6.02dB increments which can be
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
		// implemented with an arithmetic shift operation. The following four bits
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
		// indicate linear gain changes, and require a 5-bit multiply.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		// We will represent the two 4-bit fields of compr as follows:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		//   X0 X1 X2 X3 . Y4 Y5 Y6 Y7
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		// The meaning of the X values is most simply described by considering X to represent a 4-bit
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
		// signed integer with values from -8 to +7. The gain indicated by X is then (X + 1) * 6.02 dB. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		// following table shows this in detail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
		// Meaning of 4 msb of compr
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
		//  7    +48.16 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		//  6    +42.14 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
		//  5    +36.12 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
		//  4    +30.10 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
		//  3    +24.08 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
		//  2    +18.06 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
		//  1    +12.04 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
		//  0     +6.02 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
		// -1         0 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		// -2     -6.02 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
		// -3    -12.04 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		// -4    -18.06 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		// -5    -24.08 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		// -6    -30.10 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		// -7    -36.12 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
		// -8    -42.14 dB
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
		$fourbit = str_pad(decbin(($compre & 0xF0) >> 4), 4, '0', STR_PAD_LEFT);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   693
		if ($fourbit[0] == '1') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
			$log_gain = -8 + bindec(substr($fourbit, 1));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
			$log_gain = bindec(substr($fourbit, 1));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		$log_gain = ($log_gain + 1) * getid3_lib::RGADamplitude2dB(2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
		// The value of Y is a linear representation of a gain change of up to -6 dB. Y is considered to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
		// be an unsigned fractional integer, with a leading value of 1, or: 0.1 Y4 Y5 Y6 Y7 (base 2). Y can
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
		// represent values between 0.111112 (or 31/32) and 0.100002 (or 1/2). Thus, Y can represent gain
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
		// changes from -0.28 dB to -6.02 dB.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
		$lin_gain = (16 + ($compre & 0x0F)) / 32;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
		// The combination of X and Y values allows compr to indicate gain changes from
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
		//  48.16 - 0.28 = +47.89 dB, to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		// -42.14 - 6.02 = -48.16 dB.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		return $log_gain - $lin_gain;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   714
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   715
	 * @param int $roomtyp
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   716
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   717
	 * @return string|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   718
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	public static function roomTypeLookup($roomtyp) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
		static $roomTypeLookup = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
			0 => 'not indicated',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
			1 => 'large room, X curve monitor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
			2 => 'small room, flat monitor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
			3 => 'reserved'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
		return (isset($roomTypeLookup[$roomtyp]) ? $roomTypeLookup[$roomtyp] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   729
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   730
	 * @param int $frmsizecod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   731
	 * @param int $fscod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   732
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   733
	 * @return int|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   734
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
	public static function frameSizeLookup($frmsizecod, $fscod) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   736
		// LSB is whether padding is used or not
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   737
		$padding     = (bool) ($frmsizecod & 0x01);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   738
		$framesizeid =        ($frmsizecod & 0x3E) >> 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		static $frameSizeLookup = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
		if (empty($frameSizeLookup)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
			$frameSizeLookup = array (
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   743
				0  => array( 128,  138,  192),  //  32 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   744
				1  => array( 160,  174,  240),  //  40 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   745
				2  => array( 192,  208,  288),  //  48 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   746
				3  => array( 224,  242,  336),  //  56 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   747
				4  => array( 256,  278,  384),  //  64 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   748
				5  => array( 320,  348,  480),  //  80 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   749
				6  => array( 384,  416,  576),  //  96 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   750
				7  => array( 448,  486,  672),  // 112 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   751
				8  => array( 512,  556,  768),  // 128 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   752
				9  => array( 640,  696,  960),  // 160 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   753
				10 => array( 768,  834, 1152),  // 192 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   754
				11 => array( 896,  974, 1344),  // 224 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   755
				12 => array(1024, 1114, 1536),  // 256 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   756
				13 => array(1280, 1392, 1920),  // 320 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   757
				14 => array(1536, 1670, 2304),  // 384 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   758
				15 => array(1792, 1950, 2688),  // 448 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   759
				16 => array(2048, 2228, 3072),  // 512 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   760
				17 => array(2304, 2506, 3456),  // 576 kbps
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   761
				18 => array(2560, 2786, 3840)   // 640 kbps
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   764
		$paddingBytes = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
		if (($fscod == 1) && $padding) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
			// frame lengths are padded by 1 word (16 bits) at 44100
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   767
			// (fscode==1) means 44100Hz (see sampleRateCodeLookup)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   768
			$paddingBytes = 2;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   770
		return (isset($frameSizeLookup[$framesizeid][$fscod]) ? $frameSizeLookup[$framesizeid][$fscod] + $paddingBytes : false);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   773
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   774
	 * @param int $frmsizecod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   775
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   776
	 * @return int|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   777
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	public static function bitrateLookup($frmsizecod) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   779
		// LSB is whether padding is used or not
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   780
		$padding     = (bool) ($frmsizecod & 0x01);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   781
		$framesizeid =        ($frmsizecod & 0x3E) >> 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
		static $bitrateLookup = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   784
			 0 =>  32000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   785
			 1 =>  40000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   786
			 2 =>  48000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
			 3 =>  56000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   788
			 4 =>  64000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   789
			 5 =>  80000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   790
			 6 =>  96000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
			 7 => 112000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   792
			 8 => 128000,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   793
			 9 => 160000,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
			10 => 192000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
			11 => 224000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
			12 => 256000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
			13 => 320000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
			14 => 384000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
			15 => 448000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
			16 => 512000,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
			17 => 576000,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   802
			18 => 640000,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
		return (isset($bitrateLookup[$framesizeid]) ? $bitrateLookup[$framesizeid] : false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   807
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   808
	 * @param int $numblkscod
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   809
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   810
	 * @return int|false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   811
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   812
	public static function blocksPerSyncFrame($numblkscod) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   813
		static $blocksPerSyncFrameLookup = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   814
			0 => 1,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   815
			1 => 2,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   816
			2 => 3,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   817
			3 => 6,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   818
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   819
		return (isset($blocksPerSyncFrameLookup[$numblkscod]) ? $blocksPerSyncFrameLookup[$numblkscod] : false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   820
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   822
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   823
}