Mercurial > judyates
diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.monkey.php @ 3:3f6b44aa6b35 judyates
[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author | rlm |
---|---|
date | Mon, 22 Feb 2010 08:02:39 -0500 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.monkey.php Mon Feb 22 08:02:39 2010 -0500 1.3 @@ -0,0 +1,216 @@ 1.4 +<?php 1.5 +// +----------------------------------------------------------------------+ 1.6 +// | PHP version 5 | 1.7 +// +----------------------------------------------------------------------+ 1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen | 1.9 +// +----------------------------------------------------------------------+ 1.10 +// | This source file is subject to version 2 of the GPL license, | 1.11 +// | that is bundled with this package in the file license.txt and is | 1.12 +// | available through the world-wide-web at the following url: | 1.13 +// | http://www.gnu.org/copyleft/gpl.html | 1.14 +// +----------------------------------------------------------------------+ 1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org | 1.16 +// +----------------------------------------------------------------------+ 1.17 +// | Authors: James Heinrich <infoØgetid3*org> | 1.18 +// | Allan Hansen <ahØartemis*dk> | 1.19 +// +----------------------------------------------------------------------+ 1.20 +// | module.audio.monkey.php | 1.21 +// | Module for analyzing Monkey's Audio files | 1.22 +// | dependencies: NONE | 1.23 +// +----------------------------------------------------------------------+ 1.24 +// 1.25 +// $Id: module.audio.monkey.php,v 1.2 2006/11/02 10:48:01 ah Exp $ 1.26 + 1.27 + 1.28 + 1.29 +class getid3_monkey extends getid3_handler 1.30 +{ 1.31 + 1.32 + public function Analyze() { 1.33 + 1.34 + $getid3 = $this->getid3; 1.35 + 1.36 + // based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de> 1.37 + // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html 1.38 + 1.39 + $getid3->info['fileformat'] = 'mac'; 1.40 + $getid3->info['audio']['dataformat'] = 'mac'; 1.41 + $getid3->info['audio']['bitrate_mode'] = 'vbr'; 1.42 + $getid3->info['audio']['lossless'] = true; 1.43 + 1.44 + $getid3->info['monkeys_audio']['raw'] = array (); 1.45 + $info_monkeys_audio = &$getid3->info['monkeys_audio']; 1.46 + $info_monkeys_audio_raw = &$info_monkeys_audio['raw']; 1.47 + 1.48 + // Read file header 1.49 + fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); 1.50 + $mac_header_data = fread($getid3->fp, 74); 1.51 + 1.52 + $info_monkeys_audio_raw['magic'] = 'MAC '; // Magic bytes 1.53 + 1.54 + // Read MAC version 1.55 + $info_monkeys_audio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($mac_header_data, 4, 2)); // appears to be uint32 in 3.98+ 1.56 + 1.57 + // Parse MAC Header < v3980 1.58 + if ($info_monkeys_audio_raw['nVersion'] < 3980) { 1.59 + 1.60 + getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 6, 1.61 + array ( 1.62 + 'nCompressionLevel' => 2, 1.63 + 'nFormatFlags' => 2, 1.64 + 'nChannels' => 2, 1.65 + 'nSampleRate' => 4, 1.66 + 'nHeaderDataBytes' => 4, 1.67 + 'nWAVTerminatingBytes' => 4, 1.68 + 'nTotalFrames' => 4, 1.69 + 'nFinalFrameSamples' => 4, 1.70 + 'nPeakLevel' => 4, 1.71 + 'IGNORE-1' => 2, 1.72 + 'nSeekElements' => 2 1.73 + ) 1.74 + ); 1.75 + } 1.76 + 1.77 + // Parse MAC Header >= v3980 1.78 + else { 1.79 + 1.80 + getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 8, 1.81 + array ( 1.82 + // APE_DESCRIPTOR 1.83 + 'nDescriptorBytes' => 4, 1.84 + 'nHeaderBytes' => 4, 1.85 + 'nSeekTableBytes' => 4, 1.86 + 'nHeaderDataBytes' => 4, 1.87 + 'nAPEFrameDataBytes' => 4, 1.88 + 'nAPEFrameDataBytesHigh'=> 4, 1.89 + 'nTerminatingDataBytes' => 4, 1.90 + 1.91 + // MD5 - string 1.92 + 'cFileMD5' => -16, 1.93 + 1.94 + // APE_HEADER 1.95 + 'nCompressionLevel' => 2, 1.96 + 'nFormatFlags' => 2, 1.97 + 'nBlocksPerFrame' => 4, 1.98 + 'nFinalFrameBlocks' => 4, 1.99 + 'nTotalFrames' => 4, 1.100 + 'nBitsPerSample' => 2, 1.101 + 'nChannels' => 2, 1.102 + 'nSampleRate' => 4 1.103 + ) 1.104 + ); 1.105 + } 1.106 + 1.107 + // Process data 1.108 + $info_monkeys_audio['flags']['8-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0001); 1.109 + $info_monkeys_audio['flags']['crc-32'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0002); 1.110 + $info_monkeys_audio['flags']['peak_level'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0004); 1.111 + $info_monkeys_audio['flags']['24-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0008); 1.112 + $info_monkeys_audio['flags']['seek_elements'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0010); 1.113 + $info_monkeys_audio['flags']['no_wav_header'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0020); 1.114 + 1.115 + $info_monkeys_audio['version'] = $info_monkeys_audio_raw['nVersion'] / 1000; 1.116 + 1.117 + $info_monkeys_audio['compression'] = getid3_monkey::MonkeyCompressionLevelNameLookup($info_monkeys_audio_raw['nCompressionLevel']); 1.118 + 1.119 + $info_monkeys_audio['bits_per_sample'] = ($info_monkeys_audio['flags']['24-bit'] ? 24 : ($info_monkeys_audio['flags']['8-bit'] ? 8 : 16)); 1.120 + 1.121 + $info_monkeys_audio['channels'] = $info_monkeys_audio_raw['nChannels']; 1.122 + 1.123 + $getid3->info['audio']['channels'] = $info_monkeys_audio['channels']; 1.124 + 1.125 + $info_monkeys_audio['sample_rate'] = $info_monkeys_audio_raw['nSampleRate']; 1.126 + 1.127 + $getid3->info['audio']['sample_rate'] = $info_monkeys_audio['sample_rate']; 1.128 + 1.129 + if ($info_monkeys_audio['flags']['peak_level']) { 1.130 + $info_monkeys_audio['peak_level'] = $info_monkeys_audio_raw['nPeakLevel']; 1.131 + $info_monkeys_audio['peak_ratio'] = $info_monkeys_audio['peak_level'] / pow(2, $info_monkeys_audio['bits_per_sample'] - 1); 1.132 + } 1.133 + 1.134 + // MAC >= v3980 1.135 + if ($info_monkeys_audio_raw['nVersion'] >= 3980) { 1.136 + $info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio_raw['nBlocksPerFrame']) + $info_monkeys_audio_raw['nFinalFrameBlocks']; 1.137 + } 1.138 + 1.139 + // MAC < v3980 1.140 + else { 1.141 + $info_monkeys_audio['samples_per_frame'] = getid3_monkey::MonkeySamplesPerFrame($info_monkeys_audio_raw['nVersion'], $info_monkeys_audio_raw['nCompressionLevel']); 1.142 + $info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio['samples_per_frame']) + $info_monkeys_audio_raw['nFinalFrameSamples']; 1.143 + } 1.144 + 1.145 + $info_monkeys_audio['playtime'] = $info_monkeys_audio['samples'] / $info_monkeys_audio['sample_rate']; 1.146 + 1.147 + $getid3->info['playtime_seconds'] = $info_monkeys_audio['playtime']; 1.148 + 1.149 + $info_monkeys_audio['compressed_size'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset']; 1.150 + $info_monkeys_audio['uncompressed_size'] = $info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * ($info_monkeys_audio['bits_per_sample'] / 8); 1.151 + $info_monkeys_audio['compression_ratio'] = $info_monkeys_audio['compressed_size'] / ($info_monkeys_audio['uncompressed_size'] + $info_monkeys_audio_raw['nHeaderDataBytes']); 1.152 + $info_monkeys_audio['bitrate'] = (($info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * $info_monkeys_audio['bits_per_sample']) / $info_monkeys_audio['playtime']) * $info_monkeys_audio['compression_ratio']; 1.153 + 1.154 + $getid3->info['audio']['bitrate'] = $info_monkeys_audio['bitrate']; 1.155 + 1.156 + $getid3->info['audio']['bits_per_sample'] = $info_monkeys_audio['bits_per_sample']; 1.157 + $getid3->info['audio']['encoder'] = 'MAC v'.number_format($info_monkeys_audio['version'], 2); 1.158 + $getid3->info['audio']['encoder_options'] = ucfirst($info_monkeys_audio['compression']).' compression'; 1.159 + 1.160 + // MAC >= v3980 - get avdataoffsets from MAC header 1.161 + if ($info_monkeys_audio_raw['nVersion'] >= 3980) { 1.162 + $getid3->info['avdataoffset'] += $info_monkeys_audio_raw['nDescriptorBytes'] + $info_monkeys_audio_raw['nHeaderBytes'] + $info_monkeys_audio_raw['nSeekTableBytes'] + $info_monkeys_audio_raw['nHeaderDataBytes']; 1.163 + $getid3->info['avdataend'] -= $info_monkeys_audio_raw['nTerminatingDataBytes']; 1.164 + } 1.165 + 1.166 + // MAC < v3980 Add size of MAC header to avdataoffset 1.167 + else { 1.168 + $getid3->info['avdataoffset'] += 8; 1.169 + } 1.170 + 1.171 + // Convert md5sum to 32 byte string 1.172 + if (@$info_monkeys_audio_raw['cFileMD5']) { 1.173 + if ($info_monkeys_audio_raw['cFileMD5'] !== str_repeat("\x00", 16)) { 1.174 + $getid3->info['md5_data_source'] = ''; 1.175 + $md5 = $info_monkeys_audio_raw['cFileMD5']; 1.176 + for ($i = 0; $i < strlen($md5); $i++) { 1.177 + $getid3->info['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT); 1.178 + } 1.179 + if (!preg_match('/^[0-9a-f]{32}$/', $getid3->info['md5_data_source'])) { 1.180 + unset($getid3->info['md5_data_source']); 1.181 + } 1.182 + } 1.183 + } 1.184 + 1.185 + 1.186 + return true; 1.187 + } 1.188 + 1.189 + 1.190 + 1.191 + public static function MonkeyCompressionLevelNameLookup($compression_level) { 1.192 + 1.193 + static $lookup = array ( 1.194 + 0 => 'unknown', 1.195 + 1000 => 'fast', 1.196 + 2000 => 'normal', 1.197 + 3000 => 'high', 1.198 + 4000 => 'extra-high', 1.199 + 5000 => 'insane' 1.200 + ); 1.201 + return (isset($lookup[$compression_level]) ? $lookup[$compression_level] : 'invalid'); 1.202 + } 1.203 + 1.204 + 1.205 + 1.206 + public static function MonkeySamplesPerFrame($version_id, $compression_level) { 1.207 + 1.208 + if ($version_id >= 3950) { 1.209 + return 73728 * 4; 1.210 + } 1.211 + if (($version_id >= 3900) || (($version_id >= 3800) && ($compression_level == 4000))) { 1.212 + return 73728; 1.213 + } 1.214 + return 9216; 1.215 + } 1.216 + 1.217 +} 1.218 + 1.219 +?> 1.220 \ No newline at end of file