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