annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.mpc.php @ 18:903b91a97990 judyates

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