📄 module.audio.ac3.php
字号:
<?php//////////////////////////////////////////////////////////////////// getID3() by James Heinrich <info@getid3.org> //// available at http://getid3.sourceforge.net //// or http://www.getid3.org ///////////////////////////////////////////////////////////////////// See readme.txt for more details ///////////////////////////////////////////////////////////////////// //// module.audio.ac3.php //// module for analyzing AC-3 (aka Dolby Digital) audio files //// dependencies: NONE //// ////////////////////////////////////////////////////////////////////class getid3_ac3{ function getid3_ac3(&$fd, &$ThisFileInfo) { ///AH $ThisFileInfo['ac3']['raw']['bsi'] = array(); $thisfile_ac3 = &$ThisFileInfo['ac3']; $thisfile_ac3_raw = &$thisfile_ac3['raw']; $thisfile_ac3_raw_bsi = &$thisfile_ac3_raw['bsi']; // http://www.atsc.org/standards/a_52a.pdf $ThisFileInfo['fileformat'] = 'ac3'; $ThisFileInfo['audio']['dataformat'] = 'ac3'; $ThisFileInfo['audio']['bitrate_mode'] = 'cbr'; $ThisFileInfo['audio']['lossless'] = false; // An AC-3 serial coded audio bit stream is made up of a sequence of synchronization frames // Each synchronization frame contains 6 coded audio blocks (AB), each of which represent 256 // new audio samples per channel. A synchronization information (SI) header at the beginning // of each frame contains information needed to acquire and maintain synchronization. A // bit stream information (BSI) header follows SI, and contains parameters describing the coded // audio service. The coded audio blocks may be followed by an auxiliary data (Aux) field. At the // end of each frame is an error check field that includes a CRC word for error detection. An // additional CRC word is located in the SI header, the use of which, by a decoder, is optional. // // syncinfo() | bsi() | AB0 | AB1 | AB2 | AB3 | AB4 | AB5 | Aux | CRC fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); $AC3header['syncinfo'] = fread($fd, 5); $thisfile_ac3_raw['synchinfo']['synchword'] = substr($AC3header['syncinfo'], 0, 2); if ($thisfile_ac3_raw['synchinfo']['synchword'] != "\x0B\x77") { $ThisFileInfo['error'][] = 'Expecting "\x0B\x77" at offset '.$ThisFileInfo['avdataoffset'].', found \x'.strtoupper(dechex($AC3header['syncinfo']{0})).'\x'.strtoupper(dechex($AC3header['syncinfo']{1})).' instead'; unset($thisfile_ac3); return false; } else { // syncinfo() { // syncword 16 // crc1 16 // fscod 2 // frmsizecod 6 // } /* end of syncinfo */ $thisfile_ac3_raw['synchinfo']['crc1'] = getid3_lib::LittleEndian2Int(substr($AC3header['syncinfo'], 2, 2)); $ac3_synchinfo_fscod_frmsizecod = getid3_lib::LittleEndian2Int(substr($AC3header['syncinfo'], 4, 1)); $thisfile_ac3_raw['synchinfo']['fscod'] = ($ac3_synchinfo_fscod_frmsizecod & 0xC0) >> 6; $thisfile_ac3_raw['synchinfo']['frmsizecod'] = ($ac3_synchinfo_fscod_frmsizecod & 0x3F); $thisfile_ac3['sample_rate'] = $this->AC3sampleRateCodeLookup($thisfile_ac3_raw['synchinfo']['fscod']); if ($thisfile_ac3_raw['synchinfo']['fscod'] <= 3) { $ThisFileInfo['audio']['sample_rate'] = $thisfile_ac3['sample_rate']; } $thisfile_ac3['frame_length'] = $this->AC3frameSizeLookup($thisfile_ac3_raw['synchinfo']['frmsizecod'], $thisfile_ac3_raw['synchinfo']['fscod']); $thisfile_ac3['bitrate'] = $this->AC3bitrateLookup($thisfile_ac3_raw['synchinfo']['frmsizecod']); $ThisFileInfo['audio']['bitrate'] = $thisfile_ac3['bitrate']; $AC3header['bsi'] = getid3_lib::BigEndian2Bin(fread($fd, 15)); $ac3_bsi_offset = 0; $thisfile_ac3_raw_bsi['bsid'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 5)); $ac3_bsi_offset += 5; if ($thisfile_ac3_raw_bsi['bsid'] > 8) { // Decoders which can decode version 8 will thus be able to decode version numbers less than 8. // If this standard is extended by the addition of additional elements or features, a value of bsid greater than 8 will be used. // Decoders built to this version of the standard will not be able to decode versions with bsid greater than 8. $ThisFileInfo['error'][] = 'Bit stream identification is version '.$thisfile_ac3_raw_bsi['bsid'].', but getID3() only understands up to version 8'; unset($thisfile_ac3); return false; } $thisfile_ac3_raw_bsi['bsmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3)); $ac3_bsi_offset += 3; $thisfile_ac3_raw_bsi['acmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 3)); $ac3_bsi_offset += 3; $thisfile_ac3['service_type'] = $this->AC3serviceTypeLookup($thisfile_ac3_raw_bsi['bsmod'], $thisfile_ac3_raw_bsi['acmod']); $ac3_coding_mode = $this->AC3audioCodingModeLookup($thisfile_ac3_raw_bsi['acmod']); foreach($ac3_coding_mode as $key => $value) { $thisfile_ac3[$key] = $value; } switch ($thisfile_ac3_raw_bsi['acmod']) { case 0: case 1: $ThisFileInfo['audio']['channelmode'] = 'mono'; break; case 3: case 4: $ThisFileInfo['audio']['channelmode'] = 'stereo'; break; default: $ThisFileInfo['audio']['channelmode'] = 'surround'; break; } $ThisFileInfo['audio']['channels'] = $thisfile_ac3['num_channels']; if ($thisfile_ac3_raw_bsi['acmod'] & 0x01) { // If the lsb of acmod is a 1, center channel is in use and cmixlev follows in the bit stream. $thisfile_ac3_raw_bsi['cmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); $ac3_bsi_offset += 2; $thisfile_ac3['center_mix_level'] = $this->AC3centerMixLevelLookup($thisfile_ac3_raw_bsi['cmixlev']); } if ($thisfile_ac3_raw_bsi['acmod'] & 0x04) { // If the msb of acmod is a 1, surround channels are in use and surmixlev follows in the bit stream. $thisfile_ac3_raw_bsi['surmixlev'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); $ac3_bsi_offset += 2; $thisfile_ac3['surround_mix_level'] = $this->AC3surroundMixLevelLookup($thisfile_ac3_raw_bsi['surmixlev']); } if ($thisfile_ac3_raw_bsi['acmod'] == 0x02) { // When operating in the two channel mode, this 2-bit code indicates whether or not the program has been encoded in Dolby Surround. $thisfile_ac3_raw_bsi['dsurmod'] = bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 2)); $ac3_bsi_offset += 2; $thisfile_ac3['dolby_surround_mode'] = $this->AC3dolbySurroundModeLookup($thisfile_ac3_raw_bsi['dsurmod']); } $thisfile_ac3_raw_bsi['lfeon'] = (bool) bindec(substr($AC3header['bsi'], $ac3_bsi_offset, 1)); $ac3_bsi_offset += 1; $thisfile_ac3['lfe_enabled'] = $thisfile_ac3_raw_bsi['lfeon']; if ($thisfile_ac3_raw_bsi['lfeon']) { //$ThisFileInfo['audio']['channels']++; $ThisFileInfo['audio']['channels'] .= '.1'; } $thisfile_ac3['channels_enabled'] = $this->AC3channelsEnabledLookup($thisfile_ac3_raw_bsi['acmod'], $thisfile_ac3_raw_bsi['lfeon']); // This indicates how far the average dialogue level is below digital 100 percent. Valid values are 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -