20 {
21
23 $ThisFileInfo['ac3']['raw']['bsi'] = array();
24 $thisfile_ac3 = &$ThisFileInfo['ac3'];
25 $thisfile_ac3_raw = &$thisfile_ac3['raw'];
26 $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi'];
27
28
29
30
31 $ThisFileInfo['fileformat'] = 'ac3';
32 $ThisFileInfo['audio']['dataformat'] = 'ac3';
33 $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
34 $ThisFileInfo['audio']['lossless'] = false;
35
36
37
38
39
40
41
42
43
44
45
46
47 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
48 $AC3header['syncinfo'] = fread($fd, 5);
49 $thisfile_ac3_raw['synchinfo']['synchword'] = substr($AC3header['syncinfo'], 0, 2);
50
51 if ($thisfile_ac3_raw['synchinfo']['synchword'] != "\x0B\x77") {
52
53 $ThisFileInfo['error'][] = 'Expecting "\x0B\x77" at offset '.$ThisFileInfo['avdataoffset'].', found \x'.strtoupper(dechex($AC3header['syncinfo']{0})).'\x'.strtoupper(dechex($AC3header['syncinfo']{1})).' instead';
54 unset($thisfile_ac3);
55 return false;
56
57 } else {
58
59
60
61
62
63
64
65
68 $thisfile_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6;
69 $thisfile_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F);
70
72 if ($thisfile_ac3_raw['synchinfo']['fscod'] <= 3) {
73 $ThisFileInfo['audio']['sample_rate'] = $thisfile_ac3['sample_rate'];
74 }
75
76 $thisfile_ac3[
'frame_length'] = $this->
AC3frameSizeLookup($thisfile_ac3_raw[
'synchinfo'][
'frmsizecod'], $thisfile_ac3_raw[
'synchinfo'][
'fscod']);
77 $thisfile_ac3[
'bitrate'] = $this->
AC3bitrateLookup($thisfile_ac3_raw[
'synchinfo'][
'frmsizecod']);
78 $ThisFileInfo['audio']['bitrate'] = $thisfile_ac3['bitrate'];
79
81 $ac3_bsi_offset = 0;
82
83 $thisfile_ac3_raw_bsi['bsid'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
84 $ac3_bsi_offset += 5;
85 if ($thisfile_ac3_raw_bsi['bsid'] > 8) {
86
87
88
89 $ThisFileInfo['error'][] = 'Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8';
90 unset($thisfile_ac3);
91 return false;
92 }
93
94 $thisfile_ac3_raw_bsi['bsmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3));
95 $ac3_bsi_offset += 3;
96 $thisfile_ac3_raw_bsi['acmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3));
97 $ac3_bsi_offset += 3;
98
99 $thisfile_ac3[
'service_type'] = $this->
AC3serviceTypeLookup($thisfile_ac3_raw_bsi[
'bsmod'], $thisfile_ac3_raw_bsi[
'acmod']);
101 foreach($ac3_coding_mode as $key => $value) {
102 $thisfile_ac3[$key] = $value;
103 }
104 switch ($thisfile_ac3_raw_bsi['acmod']) {
105 case 0:
106 case 1:
107 $ThisFileInfo['audio']['channelmode'] = 'mono';
108 break;
109 case 3:
110 case 4:
111 $ThisFileInfo['audio']['channelmode'] = 'stereo';
112 break;
113 default:
114 $ThisFileInfo['audio']['channelmode'] = 'surround';
115 break;
116 }
117 $ThisFileInfo['audio']['channels'] = $thisfile_ac3['num_channels'];
118
119 if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) {
120
121 $thisfile_ac3_raw_bsi['cmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
122 $ac3_bsi_offset += 2;
124 }
125
126 if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) {
127
128 $thisfile_ac3_raw_bsi['surmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
129 $ac3_bsi_offset += 2;
131 }
132
133 if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) {
134
135 $thisfile_ac3_raw_bsi['dsurmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
136 $ac3_bsi_offset += 2;
138 }
139
140 $thisfile_ac3_raw_bsi['lfeon'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
141 $ac3_bsi_offset += 1;
142 $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['lfeon'];
143 if ($thisfile_ac3_raw_bsi['lfeon']) {
144
145 $ThisFileInfo['audio']['channels'] .= '.1';
146 }
147
148 $thisfile_ac3[
'channels_enabled'] = $this->
AC3channelsEnabledLookup($thisfile_ac3_raw_bsi[
'acmod'], $thisfile_ac3_raw_bsi[
'lfeon']);
149
150
151
152 $thisfile_ac3_raw_bsi['dialnorm'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
153 $ac3_bsi_offset += 5;
154 $thisfile_ac3['dialogue_normalization'] = '-'.$thisfile_ac3_raw_bsi['dialnorm'].'dB';
155
156 $thisfile_ac3_raw_bsi['compre_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
157 $ac3_bsi_offset += 1;
158 if ($thisfile_ac3_raw_bsi['compre_flag']) {
159 $thisfile_ac3_raw_bsi['compr'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
160 $ac3_bsi_offset += 8;
161 $thisfile_ac3[
'heavy_compression'] = $this->
AC3heavyCompression($thisfile_ac3_raw_bsi[
'compr']);
162 }
163
164 $thisfile_ac3_raw_bsi['langcode_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
165 $ac3_bsi_offset += 1;
166 if ($thisfile_ac3_raw_bsi['langcode_flag']) {
167 $thisfile_ac3_raw_bsi['langcod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
168 $ac3_bsi_offset += 8;
169 }
170
171 $thisfile_ac3_raw_bsi['audprodie'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
172 $ac3_bsi_offset += 1;
173 if ($thisfile_ac3_raw_bsi['audprodie']) {
174 $thisfile_ac3_raw_bsi['mixlevel'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
175 $ac3_bsi_offset += 5;
176 $thisfile_ac3_raw_bsi['roomtyp'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
177 $ac3_bsi_offset += 2;
178
179 $thisfile_ac3['mixing_level'] = (80 + $thisfile_ac3_raw_bsi['mixlevel']).'dB';
180 $thisfile_ac3[
'room_type'] = $this->
AC3roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp']);
181 }
182
183 if ($thisfile_ac3_raw_bsi['acmod'] == 0x00) {
184
185
186
187
188
189
190
191 $thisfile_ac3_raw_bsi['dialnorm2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
192 $ac3_bsi_offset += 5;
193 $thisfile_ac3['dialogue_normalization2'] = '-'.$thisfile_ac3_raw_bsi['dialnorm2'].'dB';
194
195 $thisfile_ac3_raw_bsi['compre_flag2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
196 $ac3_bsi_offset += 1;
197 if ($thisfile_ac3_raw_bsi['compre_flag2']) {
198 $thisfile_ac3_raw_bsi['compr2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
199 $ac3_bsi_offset += 8;
200 $thisfile_ac3[
'heavy_compression2'] = $this->
AC3heavyCompression($thisfile_ac3_raw_bsi[
'compr2']);
201 }
202
203 $thisfile_ac3_raw_bsi['langcode_flag2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
204 $ac3_bsi_offset += 1;
205 if ($thisfile_ac3_raw_bsi['langcode_flag2']) {
206 $thisfile_ac3_raw_bsi['langcod2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 8));
207 $ac3_bsi_offset += 8;
208 }
209
210 $thisfile_ac3_raw_bsi['audprodie2'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
211 $ac3_bsi_offset += 1;
212 if ($thisfile_ac3_raw_bsi['audprodie2']) {
213 $thisfile_ac3_raw_bsi['mixlevel2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5));
214 $ac3_bsi_offset += 5;
215 $thisfile_ac3_raw_bsi['roomtyp2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2));
216 $ac3_bsi_offset += 2;
217
218 $thisfile_ac3['mixing_level2'] = (80 + $thisfile_ac3_raw_bsi['mixlevel2']).'dB';
219 $thisfile_ac3[
'room_type2'] = $this->
AC3roomTypeLookup($thisfile_ac3_raw_bsi[
'roomtyp2']);
220 }
221
222 }
223
224 $thisfile_ac3_raw_bsi['copyright'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
225 $ac3_bsi_offset += 1;
226
227 $thisfile_ac3_raw_bsi['original'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
228 $ac3_bsi_offset += 1;
229
230 $thisfile_ac3_raw_bsi['timecode1_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
231 $ac3_bsi_offset += 1;
232 if ($thisfile_ac3_raw_bsi['timecode1_flag']) {
233 $thisfile_ac3_raw_bsi['timecode1'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 14));
234 $ac3_bsi_offset += 14;
235 }
236
237 $thisfile_ac3_raw_bsi['timecode2_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
238 $ac3_bsi_offset += 1;
239 if ($thisfile_ac3_raw_bsi['timecode2_flag']) {
240 $thisfile_ac3_raw_bsi['timecode2'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 14));
241 $ac3_bsi_offset += 14;
242 }
243
244 $thisfile_ac3_raw_bsi['addbsi_flag'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1));
245 $ac3_bsi_offset += 1;
246 if ($thisfile_ac3_raw_bsi['addbsi_flag']) {
247 $thisfile_ac3_raw_bsi['addbsi_length'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 6));
248 $ac3_bsi_offset += 6;
249
251
252 $thisfile_ac3_raw_bsi['addbsi_data'] = substr($AC3header['bsi'], $ac3_bsi_offset, $thisfile_ac3_raw_bsi['addbsi_length'] * 8);
253 $ac3_bsi_offset += $thisfile_ac3_raw_bsi['addbsi_length'] * 8;
254 }
255
256 }
257
258 return true;
259 }
AC3bitrateLookup($frmsizecod)
AC3roomTypeLookup($roomtyp)
AC3centerMixLevelLookup($cmixlev)
AC3sampleRateCodeLookup($fscod)
AC3audioCodingModeLookup($acmod)
AC3serviceTypeLookup($bsmod, $acmod)
AC3channelsEnabledLookup($acmod, $lfeon)
AC3surroundMixLevelLookup($surmixlev)
AC3heavyCompression($compre)
AC3frameSizeLookup($frmsizecod, $fscod)
AC3dolbySurroundModeLookup($dsurmod)
LittleEndian2Int($byteword, $signed=false)