23 $ThisFileInfo[
'ac3'][
'raw'][
'bsi'] = array();
24 $thisfile_ac3 = &$ThisFileInfo[
'ac3'];
25 $thisfile_ac3_raw = &$thisfile_ac3[
'raw'];
26 $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw[
'bsi'];
31 $ThisFileInfo[
'fileformat'] =
'ac3';
32 $ThisFileInfo[
'audio'][
'dataformat'] =
'ac3';
33 $ThisFileInfo[
'audio'][
'bitrate_mode'] =
'cbr';
34 $ThisFileInfo[
'audio'][
'lossless'] =
false;
47 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
48 $AC3header[
'syncinfo'] = fread($fd, 5);
49 $thisfile_ac3_raw[
'synchinfo'][
'synchword'] = substr($AC3header[
'syncinfo'], 0, 2);
51 if ($thisfile_ac3_raw[
'synchinfo'][
'synchword'] !=
"\x0B\x77") {
53 $ThisFileInfo[
'error'][] =
'Expecting "\x0B\x77" at offset '.$ThisFileInfo[
'avdataoffset'].
', found \x'.strtoupper(dechex($AC3header[
'syncinfo']{0})).
'\x'.strtoupper(dechex($AC3header[
'syncinfo']{1})).
' instead';
68 $thisfile_ac3_raw[
'synchinfo'][
'fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6;
69 $thisfile_ac3_raw[
'synchinfo'][
'frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F);
72 if ($thisfile_ac3_raw[
'synchinfo'][
'fscod'] <= 3) {
73 $ThisFileInfo[
'audio'][
'sample_rate'] = $thisfile_ac3[
'sample_rate'];
76 $thisfile_ac3[
'frame_length'] = $this->
AC3frameSizeLookup($thisfile_ac3_raw[
'synchinfo'][
'frmsizecod'], $thisfile_ac3_raw[
'synchinfo'][
'fscod']);
77 $thisfile_ac3[
'bitrate'] = $this->
AC3bitrateLookup($thisfile_ac3_raw[
'synchinfo'][
'frmsizecod']);
78 $ThisFileInfo[
'audio'][
'bitrate'] = $thisfile_ac3[
'bitrate'];
83 $thisfile_ac3_raw_bsi[
'bsid'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 5));
85 if ($thisfile_ac3_raw_bsi[
'bsid'] > 8) {
89 $ThisFileInfo[
'error'][] =
'Bit stream identification is version '.$thisfile_ac3_raw_bsi[
'bsid'].
', but getID3() only understands up to version 8';
94 $thisfile_ac3_raw_bsi[
'bsmod'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 3));
96 $thisfile_ac3_raw_bsi[
'acmod'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 3));
99 $thisfile_ac3[
'service_type'] = $this->
AC3serviceTypeLookup($thisfile_ac3_raw_bsi[
'bsmod'], $thisfile_ac3_raw_bsi[
'acmod']);
101 foreach($ac3_coding_mode as $key => $value) {
102 $thisfile_ac3[$key] = $value;
104 switch ($thisfile_ac3_raw_bsi[
'acmod']) {
107 $ThisFileInfo[
'audio'][
'channelmode'] =
'mono';
111 $ThisFileInfo[
'audio'][
'channelmode'] =
'stereo';
114 $ThisFileInfo[
'audio'][
'channelmode'] =
'surround';
117 $ThisFileInfo[
'audio'][
'channels'] = $thisfile_ac3[
'num_channels'];
119 if ($thisfile_ac3_raw_bsi[
'acmod'] & 0x01) {
121 $thisfile_ac3_raw_bsi[
'cmixlev'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 2));
122 $ac3_bsi_offset += 2;
126 if ($thisfile_ac3_raw_bsi[
'acmod'] & 0x04) {
128 $thisfile_ac3_raw_bsi[
'surmixlev'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 2));
129 $ac3_bsi_offset += 2;
133 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0x02) {
135 $thisfile_ac3_raw_bsi[
'dsurmod'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 2));
136 $ac3_bsi_offset += 2;
140 $thisfile_ac3_raw_bsi[
'lfeon'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
141 $ac3_bsi_offset += 1;
142 $thisfile_ac3[
'lfe_enabled'] = $thisfile_ac3_raw_bsi[
'lfeon'];
143 if ($thisfile_ac3_raw_bsi[
'lfeon']) {
145 $ThisFileInfo[
'audio'][
'channels'] .=
'.1';
148 $thisfile_ac3[
'channels_enabled'] = $this->
AC3channelsEnabledLookup($thisfile_ac3_raw_bsi[
'acmod'], $thisfile_ac3_raw_bsi[
'lfeon']);
152 $thisfile_ac3_raw_bsi[
'dialnorm'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 5));
153 $ac3_bsi_offset += 5;
154 $thisfile_ac3[
'dialogue_normalization'] =
'-'.$thisfile_ac3_raw_bsi[
'dialnorm'].
'dB';
156 $thisfile_ac3_raw_bsi[
'compre_flag'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
157 $ac3_bsi_offset += 1;
158 if ($thisfile_ac3_raw_bsi[
'compre_flag']) {
159 $thisfile_ac3_raw_bsi[
'compr'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 8));
160 $ac3_bsi_offset += 8;
161 $thisfile_ac3[
'heavy_compression'] = $this->
AC3heavyCompression($thisfile_ac3_raw_bsi[
'compr']);
164 $thisfile_ac3_raw_bsi[
'langcode_flag'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
165 $ac3_bsi_offset += 1;
166 if ($thisfile_ac3_raw_bsi[
'langcode_flag']) {
167 $thisfile_ac3_raw_bsi[
'langcod'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 8));
168 $ac3_bsi_offset += 8;
171 $thisfile_ac3_raw_bsi[
'audprodie'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
172 $ac3_bsi_offset += 1;
173 if ($thisfile_ac3_raw_bsi[
'audprodie']) {
174 $thisfile_ac3_raw_bsi[
'mixlevel'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 5));
175 $ac3_bsi_offset += 5;
176 $thisfile_ac3_raw_bsi[
'roomtyp'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 2));
177 $ac3_bsi_offset += 2;
179 $thisfile_ac3[
'mixing_level'] = (80 + $thisfile_ac3_raw_bsi[
'mixlevel']).
'dB';
180 $thisfile_ac3[
'room_type'] = $this->
AC3roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp']);
183 if ($thisfile_ac3_raw_bsi[
'acmod'] == 0x00) {
191 $thisfile_ac3_raw_bsi[
'dialnorm2'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 5));
192 $ac3_bsi_offset += 5;
193 $thisfile_ac3[
'dialogue_normalization2'] =
'-'.$thisfile_ac3_raw_bsi[
'dialnorm2'].
'dB';
195 $thisfile_ac3_raw_bsi[
'compre_flag2'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
196 $ac3_bsi_offset += 1;
197 if ($thisfile_ac3_raw_bsi[
'compre_flag2']) {
198 $thisfile_ac3_raw_bsi[
'compr2'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 8));
199 $ac3_bsi_offset += 8;
200 $thisfile_ac3[
'heavy_compression2'] = $this->
AC3heavyCompression($thisfile_ac3_raw_bsi[
'compr2']);
203 $thisfile_ac3_raw_bsi[
'langcode_flag2'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
204 $ac3_bsi_offset += 1;
205 if ($thisfile_ac3_raw_bsi[
'langcode_flag2']) {
206 $thisfile_ac3_raw_bsi[
'langcod2'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 8));
207 $ac3_bsi_offset += 8;
210 $thisfile_ac3_raw_bsi[
'audprodie2'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
211 $ac3_bsi_offset += 1;
212 if ($thisfile_ac3_raw_bsi[
'audprodie2']) {
213 $thisfile_ac3_raw_bsi[
'mixlevel2'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 5));
214 $ac3_bsi_offset += 5;
215 $thisfile_ac3_raw_bsi[
'roomtyp2'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 2));
216 $ac3_bsi_offset += 2;
218 $thisfile_ac3[
'mixing_level2'] = (80 + $thisfile_ac3_raw_bsi[
'mixlevel2']).
'dB';
219 $thisfile_ac3[
'room_type2'] = $this->
AC3roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp2']);
224 $thisfile_ac3_raw_bsi[
'copyright'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
225 $ac3_bsi_offset += 1;
227 $thisfile_ac3_raw_bsi[
'original'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
228 $ac3_bsi_offset += 1;
230 $thisfile_ac3_raw_bsi[
'timecode1_flag'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
231 $ac3_bsi_offset += 1;
232 if ($thisfile_ac3_raw_bsi[
'timecode1_flag']) {
233 $thisfile_ac3_raw_bsi[
'timecode1'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 14));
234 $ac3_bsi_offset += 14;
237 $thisfile_ac3_raw_bsi[
'timecode2_flag'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
238 $ac3_bsi_offset += 1;
239 if ($thisfile_ac3_raw_bsi[
'timecode2_flag']) {
240 $thisfile_ac3_raw_bsi[
'timecode2'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 14));
241 $ac3_bsi_offset += 14;
244 $thisfile_ac3_raw_bsi[
'addbsi_flag'] = (bool) bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 1));
245 $ac3_bsi_offset += 1;
246 if ($thisfile_ac3_raw_bsi[
'addbsi_flag']) {
247 $thisfile_ac3_raw_bsi[
'addbsi_length'] = bindec(substr($AC3header[
'bsi'], $ac3_bsi_offset, 6));
248 $ac3_bsi_offset += 6;
252 $thisfile_ac3_raw_bsi[
'addbsi_data'] = substr($AC3header[
'bsi'], $ac3_bsi_offset, $thisfile_ac3_raw_bsi[
'addbsi_length'] * 8);
253 $ac3_bsi_offset += $thisfile_ac3_raw_bsi[
'addbsi_length'] * 8;
AC3roomTypeLookup($roomtyp)
AC3centerMixLevelLookup($cmixlev)
AC3bitrateLookup($frmsizecod)
AC3sampleRateCodeLookup($fscod)
AC3serviceTypeLookup($bsmod, $acmod)
AC3frameSizeLookup($frmsizecod, $fscod)
LittleEndian2Int($byteword, $signed=false)
AC3audioCodingModeLookup($acmod)
AC3dolbySurroundModeLookup($dsurmod)
AC3channelsEnabledLookup($acmod, $lfeon)
AC3surroundMixLevelLookup($surmixlev)
AC3heavyCompression($compre)