Conditions | 23 |
Paths | > 20000 |
Total Lines | 222 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
29 | public function Analyze() { |
||
30 | |||
31 | $getid3 = $this->getid3; |
||
32 | |||
33 | // http://www.atsc.org/standards/a_52a.pdf |
||
34 | |||
35 | $getid3->info['fileformat'] = 'ac3'; |
||
36 | $getid3->info['audio']['dataformat'] = 'ac3'; |
||
37 | $getid3->info['audio']['bitrate_mode'] = 'cbr'; |
||
38 | $getid3->info['audio']['lossless'] = false; |
||
39 | |||
40 | $getid3->info['ac3']['raw']['bsi'] = array (); |
||
41 | $info_ac3 = &$getid3->info['ac3']; |
||
42 | $info_ac3_raw = &$info_ac3['raw']; |
||
43 | $info_ac3_raw_bsi = &$info_ac3_raw['bsi']; |
||
44 | |||
45 | |||
46 | // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames |
||
47 | // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256 |
||
48 | // new audio samples per channel. A synchronization information (SI) header at the beginning |
||
49 | // of each frame contains information needed to acquire and maintain synchronization. A |
||
50 | // bit stream information (BSI) header follows SI, and contains parameters describing the coded |
||
51 | // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the |
||
52 | // end of each frame is an error check field that includes a CRC word for error detection. An |
||
53 | // additional CRC word is located in the SI header, the use of which, by a decoder, is optional. |
||
54 | // |
||
55 | // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC |
||
56 | |||
57 | $this->fseek($getid3->info['avdataoffset'], SEEK_SET); |
||
58 | $ac3_header['syncinfo'] = $this->fread(5); |
||
|
|||
59 | $info_ac3_raw['synchinfo']['synchword'] = substr($ac3_header['syncinfo'], 0, 2); |
||
60 | |||
61 | if ($info_ac3_raw['synchinfo']['synchword'] != "\x0B\x77") { |
||
62 | throw new getid3_exception('Expecting "\x0B\x77" at offset '.$getid3->info['avdataoffset'].', found \x'.strtoupper(dechex($ac3_header['syncinfo']{0})).'\x'.strtoupper(dechex($ac3_header['syncinfo']{1})).' instead'); |
||
63 | } |
||
64 | |||
65 | |||
66 | // syncinfo() { |
||
67 | // syncword 16 |
||
68 | // crc1 16 |
||
69 | // fscod 2 |
||
70 | // frmsizecod 6 |
||
71 | // } /* end of syncinfo */ |
||
72 | |||
73 | $info_ac3_raw['synchinfo']['crc1'] = getid3_lib::LittleEndian2Int(substr($ac3_header['syncinfo'], 2, 2)); |
||
74 | $ac3_synchinfo_fscod_frmsizecod = getid3_lib::LittleEndian2Int(substr($ac3_header['syncinfo'], 4, 1)); |
||
75 | $info_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6; |
||
76 | $info_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F); |
||
77 | |||
78 | $info_ac3['sample_rate'] = getid3_ac3::AC3sampleRateCodeLookup($info_ac3_raw['synchinfo']['fscod']); |
||
79 | if ($info_ac3_raw['synchinfo']['fscod'] <= 3) { |
||
80 | $getid3->info['audio']['sample_rate'] = $info_ac3['sample_rate']; |
||
81 | } |
||
82 | |||
83 | $info_ac3['frame_length'] = getid3_ac3::AC3frameSizeLookup($info_ac3_raw['synchinfo']['frmsizecod'], $info_ac3_raw['synchinfo']['fscod']); |
||
84 | $info_ac3['bitrate'] = getid3_ac3::AC3bitrateLookup($info_ac3_raw['synchinfo']['frmsizecod']); |
||
85 | $getid3->info['audio']['bitrate'] = $info_ac3['bitrate']; |
||
86 | |||
87 | $ac3_header['bsi'] = getid3_lib::BigEndian2Bin($this->fread(15)); |
||
88 | |||
89 | $info_ac3_raw_bsi['bsid'] = bindec(substr($ac3_header['bsi'], 0, 5)); |
||
90 | if ($info_ac3_raw_bsi['bsid'] > 8) { |
||
91 | // Decoders which can decode version 8 will thus be able to decode version numbers less than 8. |
||
92 | // If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used. |
||
93 | // Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8. |
||
94 | throw new getid3_exception('Bit stream identification is version '.$info_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8'); |
||
95 | } |
||
96 | |||
97 | $info_ac3_raw_bsi['bsmod'] = bindec(substr($ac3_header['bsi'], 5, 3)); |
||
98 | $info_ac3_raw_bsi['acmod'] = bindec(substr($ac3_header['bsi'], 8, 3)); |
||
99 | |||
100 | $info_ac3['service_type'] = getid3_ac3::AC3serviceTypeLookup($info_ac3_raw_bsi['bsmod'], $info_ac3_raw_bsi['acmod']); |
||
101 | $ac3_coding_mode = getid3_ac3::AC3audioCodingModeLookup($info_ac3_raw_bsi['acmod']); |
||
102 | foreach($ac3_coding_mode as $key => $value) { |
||
103 | $info_ac3[$key] = $value; |
||
104 | } |
||
105 | switch ($info_ac3_raw_bsi['acmod']) { |
||
106 | case 0: |
||
107 | case 1: |
||
108 | $getid3->info['audio']['channelmode'] = 'mono'; |
||
109 | break; |
||
110 | case 3: |
||
111 | case 4: |
||
112 | $getid3->info['audio']['channelmode'] = 'stereo'; |
||
113 | break; |
||
114 | default: |
||
115 | $getid3->info['audio']['channelmode'] = 'surround'; |
||
116 | break; |
||
117 | } |
||
118 | $getid3->info['audio']['channels'] = $info_ac3['num_channels']; |
||
119 | |||
120 | $offset = 11; |
||
121 | |||
122 | if ($info_ac3_raw_bsi['acmod'] & 0x01) { |
||
123 | // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream. |
||
124 | $info_ac3_raw_bsi['cmixlev'] = bindec(substr($ac3_header['bsi'], $offset, 2)); |
||
125 | $info_ac3['center_mix_level'] = getid3_ac3::AC3centerMixLevelLookup($info_ac3_raw_bsi['cmixlev']); |
||
126 | $offset += 2; |
||
127 | } |
||
128 | |||
129 | if ($info_ac3_raw_bsi['acmod'] & 0x04) { |
||
130 | // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream. |
||
131 | $info_ac3_raw_bsi['surmixlev'] = bindec(substr($ac3_header['bsi'], $offset, 2)); |
||
132 | $info_ac3['surround_mix_level'] = getid3_ac3::AC3surroundMixLevelLookup($info_ac3_raw_bsi['surmixlev']); |
||
133 | $offset += 2; |
||
134 | } |
||
135 | |||
136 | if ($info_ac3_raw_bsi['acmod'] == 0x02) { |
||
137 | // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround. |
||
138 | $info_ac3_raw_bsi['dsurmod'] = bindec(substr($ac3_header['bsi'], $offset, 2)); |
||
139 | $info_ac3['dolby_surround_mode'] = getid3_ac3::AC3dolbySurroundModeLookup($info_ac3_raw_bsi['dsurmod']); |
||
140 | $offset += 2; |
||
141 | } |
||
142 | |||
143 | $info_ac3_raw_bsi['lfeon'] = $ac3_header['bsi']{$offset++} == '1'; |
||
144 | $info_ac3['lfe_enabled'] = $info_ac3_raw_bsi['lfeon']; |
||
145 | if ($info_ac3_raw_bsi['lfeon']) { |
||
146 | $getid3->info['audio']['channels'] .= '.1'; |
||
147 | } |
||
148 | |||
149 | $info_ac3['channels_enabled'] = getid3_ac3::AC3channelsEnabledLookup($info_ac3_raw_bsi['acmod'], $info_ac3_raw_bsi['lfeon']); |
||
150 | |||
151 | // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1�31. |
||
152 | // 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. |
||
153 | $info_ac3_raw_bsi['dialnorm'] = bindec(substr($ac3_header['bsi'], $offset, 5)); |
||
154 | $offset += 5; |
||
155 | $info_ac3['dialogue_normalization'] = '-'.$info_ac3_raw_bsi['dialnorm'].'dB'; |
||
156 | |||
157 | $info_ac3_raw_bsi['compre_flag'] = $ac3_header['bsi']{$offset++} == '1'; |
||
158 | if ($info_ac3_raw_bsi['compre_flag']) { |
||
159 | $info_ac3_raw_bsi['compr'] = bindec(substr($ac3_header['bsi'], $offset, 8)); |
||
160 | $offset += 8; |
||
161 | |||
162 | $info_ac3['heavy_compression'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr']); |
||
163 | } |
||
164 | |||
165 | $info_ac3_raw_bsi['langcode_flag'] = $ac3_header['bsi']{$offset++} == '1'; |
||
166 | if ($info_ac3_raw_bsi['langcode_flag']) { |
||
167 | $info_ac3_raw_bsi['langcod'] = bindec(substr($ac3_header['bsi'], $offset, 8)); |
||
168 | $offset += 8; |
||
169 | } |
||
170 | |||
171 | $info_ac3_raw_bsi['audprodie'] = $ac3_header['bsi']{$offset++} == '1'; |
||
172 | if ($info_ac3_raw_bsi['audprodie']) { |
||
173 | $info_ac3_raw_bsi['mixlevel'] = bindec(substr($ac3_header['bsi'], $offset, 5)); |
||
174 | $offset += 5; |
||
175 | |||
176 | $info_ac3_raw_bsi['roomtyp'] = bindec(substr($ac3_header['bsi'], $offset, 2)); |
||
177 | $offset += 2; |
||
178 | |||
179 | $info_ac3['mixing_level'] = (80 + $info_ac3_raw_bsi['mixlevel']).'dB'; |
||
180 | $info_ac3['room_type'] = getid3_ac3::AC3roomTypeLookup($info_ac3_raw_bsi['roomtyp']); |
||
181 | } |
||
182 | |||
183 | if ($info_ac3_raw_bsi['acmod'] == 0x00) { |
||
184 | // If acmod is 0, then two completely independent program channels (dual mono) |
||
185 | // are encoded into the bit stream, and are referenced as Ch1, Ch2. In this case, |
||
186 | // a number of additional items are present in BSI or audblk to fully describe Ch2. |
||
187 | |||
188 | |||
189 | // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1�31. |
||
190 | // 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. |
||
191 | $info_ac3_raw_bsi['dialnorm2'] = bindec(substr($ac3_header['bsi'], $offset, 5)); |
||
192 | $offset += 5; |
||
193 | |||
194 | $info_ac3['dialogue_normalization2'] = '-'.$info_ac3_raw_bsi['dialnorm2'].'dB'; |
||
195 | |||
196 | $info_ac3_raw_bsi['compre_flag2'] = $ac3_header['bsi']{$offset++} == '1'; |
||
197 | if ($info_ac3_raw_bsi['compre_flag2']) { |
||
198 | $info_ac3_raw_bsi['compr2'] = bindec(substr($ac3_header['bsi'], $offset, 8)); |
||
199 | $offset += 8; |
||
200 | |||
201 | $info_ac3['heavy_compression2'] = getid3_ac3::AC3heavyCompression($info_ac3_raw_bsi['compr2']); |
||
202 | } |
||
203 | |||
204 | $info_ac3_raw_bsi['langcode_flag2'] = $ac3_header['bsi']{$offset++} == '1'; |
||
205 | if ($info_ac3_raw_bsi['langcode_flag2']) { |
||
206 | $info_ac3_raw_bsi['langcod2'] = bindec(substr($ac3_header['bsi'], $offset, 8)); |
||
207 | $offset += 8; |
||
208 | } |
||
209 | |||
210 | $info_ac3_raw_bsi['audprodie2'] = $ac3_header['bsi']{$offset++} == '1'; |
||
211 | if ($info_ac3_raw_bsi['audprodie2']) { |
||
212 | $info_ac3_raw_bsi['mixlevel2'] = bindec(substr($ac3_header['bsi'], $offset, 5)); |
||
213 | $offset += 5; |
||
214 | |||
215 | $info_ac3_raw_bsi['roomtyp2'] = bindec(substr($ac3_header['bsi'], $offset, 2)); |
||
216 | $offset += 2; |
||
217 | |||
218 | $info_ac3['mixing_level2'] = (80 + $info_ac3_raw_bsi['mixlevel2']).'dB'; |
||
219 | $info_ac3['room_type2'] = getid3_ac3::AC3roomTypeLookup($info_ac3_raw_bsi['roomtyp2']); |
||
220 | } |
||
221 | |||
222 | } |
||
223 | |||
224 | $info_ac3_raw_bsi['copyright'] = $ac3_header['bsi']{$offset++} == '1'; |
||
225 | |||
226 | $info_ac3_raw_bsi['original'] = $ac3_header['bsi']{$offset++} == '1'; |
||
227 | |||
228 | $info_ac3_raw_bsi['timecode1_flag'] = $ac3_header['bsi']{$offset++} == '1'; |
||
229 | if ($info_ac3_raw_bsi['timecode1_flag']) { |
||
230 | $info_ac3_raw_bsi['timecode1'] = bindec(substr($ac3_header['bsi'], $offset, 14)); |
||
231 | $offset += 14; |
||
232 | } |
||
233 | |||
234 | $info_ac3_raw_bsi['timecode2_flag'] = $ac3_header['bsi']{$offset++} == '1'; |
||
235 | if ($info_ac3_raw_bsi['timecode2_flag']) { |
||
236 | $info_ac3_raw_bsi['timecode2'] = bindec(substr($ac3_header['bsi'], $offset, 14)); |
||
237 | $offset += 14; |
||
238 | } |
||
239 | |||
240 | $info_ac3_raw_bsi['addbsi_flag'] = $ac3_header['bsi']{$offset++} == '1'; |
||
241 | if ($info_ac3_raw_bsi['addbsi_flag']) { |
||
242 | $info_ac3_raw_bsi['addbsi_length'] = bindec(substr($ac3_header['bsi'], $offset, 6)); |
||
243 | $offset += 6; |
||
244 | |||
245 | $ac3_header['bsi'] .= getid3_lib::BigEndian2Bin($this->fread($info_ac3_raw_bsi['addbsi_length'])); |
||
246 | |||
247 | $info_ac3_raw_bsi['addbsi_data'] = substr($ac3_header['bsi'], 119, $info_ac3_raw_bsi['addbsi_length'] * 8); |
||
248 | } |
||
249 | |||
250 | return true; |
||
251 | } |
||
500 | ?> |
||