Mercurial > judyates
view e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.mpc.php @ 28:118cb614cf18 judyates tip
judy bio.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 29 Dec 2015 16:26:18 -0800 |
parents | 3f6b44aa6b35 |
children |
line wrap: on
line source
1 <?php2 // +----------------------------------------------------------------------+3 // | PHP version 5 |4 // +----------------------------------------------------------------------+5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |6 // +----------------------------------------------------------------------+7 // | This source file is subject to version 2 of the GPL license, |8 // | that is bundled with this package in the file license.txt and is |9 // | available through the world-wide-web at the following url: |10 // | http://www.gnu.org/copyleft/gpl.html |11 // +----------------------------------------------------------------------+12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |13 // +----------------------------------------------------------------------+14 // | Authors: James Heinrich <infoØgetid3*org> |15 // | Allan Hansen <ahØartemis*dk> |16 // +----------------------------------------------------------------------+17 // | module.audio.mpc.php |18 // | Module for analyzing Musepack/MPEG+ Audio files |19 // | dependencies: NONE |20 // +----------------------------------------------------------------------+21 //22 // $Id: module.audio.mpc.php,v 1.3 2006/11/02 10:48:01 ah Exp $26 class getid3_mpc extends getid3_handler27 {29 public function Analyze() {31 $getid3 = $this->getid3;33 // http://www.uni-jena.de/~pfk/mpp/sv8/header.html35 $getid3->info['fileformat'] = 'mpc';36 $getid3->info['audio']['dataformat'] = 'mpc';37 $getid3->info['audio']['bitrate_mode'] = 'vbr';38 $getid3->info['audio']['channels'] = 2; // the format appears to be hardcoded for stereo only39 $getid3->info['audio']['lossless'] = false;41 $getid3->info['mpc']['header'] = array ();42 $info_mpc_header = &$getid3->info['mpc']['header'];43 $info_mpc_header['size'] = 28;44 $info_mpc_header['raw']['preamble'] = 'MP+'; // Magic bytes46 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);47 $mpc_header_data = fread($getid3->fp, 28);49 $stream_version_byte = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 3, 1));50 $info_mpc_header['stream_major_version'] = ($stream_version_byte & 0x0F);51 $info_mpc_header['stream_minor_version'] = ($stream_version_byte & 0xF0) >> 4;52 if ($info_mpc_header['stream_major_version'] != 7) {53 throw new getid3_exception('Only Musepack SV7 supported');54 }56 $info_mpc_header['frame_count'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4));58 $info_mpc_header['raw']['title_peak'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 12, 2));59 $info_mpc_header['raw']['title_gain'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 14, 2), true);60 $info_mpc_header['raw']['album_peak'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 16, 2));61 $info_mpc_header['raw']['album_gain'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 18, 2), true);63 $info_mpc_header['raw']['not_sure_what'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 24, 3));64 $info_mpc_header['raw']['encoder_version'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 27, 1));66 $flags_dword1 = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 8, 4));67 $flags_dword2 = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 20, 4));69 $info_mpc_header['intensity_stereo'] = (bool)(($flags_dword1 & 0x80000000) >> 31);70 $info_mpc_header['mid_side_stereo'] = (bool)(($flags_dword1 & 0x40000000) >> 30);71 $info_mpc_header['max_subband'] = ($flags_dword1 & 0x3F000000) >> 24;72 $info_mpc_header['raw']['profile'] = ($flags_dword1 & 0x00F00000) >> 20;73 $info_mpc_header['begin_loud'] = (bool)(($flags_dword1 & 0x00080000) >> 19);74 $info_mpc_header['end_loud'] = (bool)(($flags_dword1 & 0x00040000) >> 18);75 $info_mpc_header['raw']['sample_rate'] = ($flags_dword1 & 0x00030000) >> 16;76 $info_mpc_header['max_level'] = ($flags_dword1 & 0x0000FFFF);78 $info_mpc_header['true_gapless'] = (bool)(($flags_dword2 & 0x80000000) >> 31);79 $info_mpc_header['last_frame_length'] = ($flags_dword2 & 0x7FF00000) >> 20;81 $info_mpc_header['profile'] = getid3_mpc::MPCprofileNameLookup($info_mpc_header['raw']['profile']);82 $info_mpc_header['sample_rate'] = getid3_mpc::MPCfrequencyLookup($info_mpc_header['raw']['sample_rate']);83 $getid3->info['audio']['sample_rate'] = $info_mpc_header['sample_rate'];84 $info_mpc_header['samples'] = ((($info_mpc_header['frame_count'] - 1) * 1152) + $info_mpc_header['last_frame_length']) * $getid3->info['audio']['channels'];86 $getid3->info['playtime_seconds'] = ($info_mpc_header['samples'] / $getid3->info['audio']['channels']) / $getid3->info['audio']['sample_rate'];88 $getid3->info['avdataoffset'] += $info_mpc_header['size'];90 $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];92 $info_mpc_header['title_peak'] = $info_mpc_header['raw']['title_peak'];93 $info_mpc_header['title_peak_db'] = getid3_mpc::MPCpeakDBLookup($info_mpc_header['title_peak']);94 if ($info_mpc_header['raw']['title_gain'] < 0) {95 $info_mpc_header['title_gain_db'] = (float)(32768 + $info_mpc_header['raw']['title_gain']) / -100;96 }97 else {98 $info_mpc_header['title_gain_db'] = (float)$info_mpc_header['raw']['title_gain'] / 100;99 }101 $info_mpc_header['album_peak'] = $info_mpc_header['raw']['album_peak'];102 $info_mpc_header['album_peak_db'] = getid3_mpc::MPCpeakDBLookup($info_mpc_header['album_peak']);103 if ($info_mpc_header['raw']['album_gain'] < 0) {104 $info_mpc_header['album_gain_db'] = (float)(32768 + $info_mpc_header['raw']['album_gain']) / -100;105 }106 else {107 $info_mpc_header['album_gain_db'] = (float)$info_mpc_header['raw']['album_gain'] / 100;;108 }109 $info_mpc_header['encoder_version'] = getid3_mpc::MPCencoderVersionLookup($info_mpc_header['raw']['encoder_version']);111 $getid3->info['replay_gain']['track']['adjustment'] = $info_mpc_header['title_gain_db'];112 $getid3->info['replay_gain']['album']['adjustment'] = $info_mpc_header['album_gain_db'];114 if ($info_mpc_header['title_peak'] > 0) {115 $getid3->info['replay_gain']['track']['peak'] = $info_mpc_header['title_peak'];116 }117 elseif (round($info_mpc_header['max_level'] * 1.18) > 0) {118 $getid3->info['replay_gain']['track']['peak'] = (int)(round($info_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c119 }120 if ($info_mpc_header['album_peak'] > 0) {121 $getid3->info['replay_gain']['album']['peak'] = $info_mpc_header['album_peak'];122 }124 $getid3->info['audio']['encoder'] = $info_mpc_header['encoder_version'];125 $getid3->info['audio']['encoder_options'] = $info_mpc_header['profile'];127 return true;128 }132 public static function MPCprofileNameLookup($profileid) {134 static $lookup = array (135 0 => 'no profile',136 1 => 'Experimental',137 2 => 'unused',138 3 => 'unused',139 4 => 'unused',140 5 => 'below Telephone (q = 0.0)',141 6 => 'below Telephone (q = 1.0)',142 7 => 'Telephone (q = 2.0)',143 8 => 'Thumb (q = 3.0)',144 9 => 'Radio (q = 4.0)',145 10 => 'Standard (q = 5.0)',146 11 => 'Extreme (q = 6.0)',147 12 => 'Insane (q = 7.0)',148 13 => 'BrainDead (q = 8.0)',149 14 => 'above BrainDead (q = 9.0)',150 15 => 'above BrainDead (q = 10.0)'151 );152 return (isset($lookup[$profileid]) ? $lookup[$profileid] : 'invalid');153 }157 public static function MPCfrequencyLookup($frequencyid) {159 static $lookup = array (160 0 => 44100,161 1 => 48000,162 2 => 37800,163 3 => 32000164 );165 return (isset($lookup[$frequencyid]) ? $lookup[$frequencyid] : 'invalid');166 }170 public static function MPCpeakDBLookup($int_value) {172 if ($int_value > 0) {173 return ((log10($int_value) / log10(2)) - 15) * 6;174 }175 return false;176 }180 public static function MPCencoderVersionLookup($encoder_version) {182 //Encoder version * 100 (106 = 1.06)183 //EncoderVersion % 10 == 0 Release (1.0)184 //EncoderVersion % 2 == 0 Beta (1.06)185 //EncoderVersion % 2 == 1 Alpha (1.05a...z)187 if ($encoder_version == 0) {188 // very old version, not known exactly which189 return 'Buschmann v1.7.0-v1.7.9 or Klemm v0.90-v1.05';190 }192 if (($encoder_version % 10) == 0) {194 // release version195 return number_format($encoder_version / 100, 2);197 } elseif (($encoder_version % 2) == 0) {199 // beta version200 return number_format($encoder_version / 100, 2).' beta';202 }204 // alpha version205 return number_format($encoder_version / 100, 2).' alpha';206 }208 }211 ?>