annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.monkey.php @ 12:2f433df9b961 judyates

[svn r13] Modified esgallery source to enable multiple paypal buttons; got the photo gallery operational and tested.
author rlm
date Mon, 12 Apr 2010 03:24:08 -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.monkey.php |
rlm@3 18 // | Module for analyzing Monkey's Audio files |
rlm@3 19 // | dependencies: NONE |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio.monkey.php,v 1.2 2006/11/02 10:48:01 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_monkey 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 // based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de>
rlm@3 34 // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
rlm@3 35
rlm@3 36 $getid3->info['fileformat'] = 'mac';
rlm@3 37 $getid3->info['audio']['dataformat'] = 'mac';
rlm@3 38 $getid3->info['audio']['bitrate_mode'] = 'vbr';
rlm@3 39 $getid3->info['audio']['lossless'] = true;
rlm@3 40
rlm@3 41 $getid3->info['monkeys_audio']['raw'] = array ();
rlm@3 42 $info_monkeys_audio = &$getid3->info['monkeys_audio'];
rlm@3 43 $info_monkeys_audio_raw = &$info_monkeys_audio['raw'];
rlm@3 44
rlm@3 45 // Read file header
rlm@3 46 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 47 $mac_header_data = fread($getid3->fp, 74);
rlm@3 48
rlm@3 49 $info_monkeys_audio_raw['magic'] = 'MAC '; // Magic bytes
rlm@3 50
rlm@3 51 // Read MAC version
rlm@3 52 $info_monkeys_audio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($mac_header_data, 4, 2)); // appears to be uint32 in 3.98+
rlm@3 53
rlm@3 54 // Parse MAC Header < v3980
rlm@3 55 if ($info_monkeys_audio_raw['nVersion'] < 3980) {
rlm@3 56
rlm@3 57 getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 6,
rlm@3 58 array (
rlm@3 59 'nCompressionLevel' => 2,
rlm@3 60 'nFormatFlags' => 2,
rlm@3 61 'nChannels' => 2,
rlm@3 62 'nSampleRate' => 4,
rlm@3 63 'nHeaderDataBytes' => 4,
rlm@3 64 'nWAVTerminatingBytes' => 4,
rlm@3 65 'nTotalFrames' => 4,
rlm@3 66 'nFinalFrameSamples' => 4,
rlm@3 67 'nPeakLevel' => 4,
rlm@3 68 'IGNORE-1' => 2,
rlm@3 69 'nSeekElements' => 2
rlm@3 70 )
rlm@3 71 );
rlm@3 72 }
rlm@3 73
rlm@3 74 // Parse MAC Header >= v3980
rlm@3 75 else {
rlm@3 76
rlm@3 77 getid3_lib::ReadSequence("LittleEndian2Int", $info_monkeys_audio_raw, $mac_header_data, 8,
rlm@3 78 array (
rlm@3 79 // APE_DESCRIPTOR
rlm@3 80 'nDescriptorBytes' => 4,
rlm@3 81 'nHeaderBytes' => 4,
rlm@3 82 'nSeekTableBytes' => 4,
rlm@3 83 'nHeaderDataBytes' => 4,
rlm@3 84 'nAPEFrameDataBytes' => 4,
rlm@3 85 'nAPEFrameDataBytesHigh'=> 4,
rlm@3 86 'nTerminatingDataBytes' => 4,
rlm@3 87
rlm@3 88 // MD5 - string
rlm@3 89 'cFileMD5' => -16,
rlm@3 90
rlm@3 91 // APE_HEADER
rlm@3 92 'nCompressionLevel' => 2,
rlm@3 93 'nFormatFlags' => 2,
rlm@3 94 'nBlocksPerFrame' => 4,
rlm@3 95 'nFinalFrameBlocks' => 4,
rlm@3 96 'nTotalFrames' => 4,
rlm@3 97 'nBitsPerSample' => 2,
rlm@3 98 'nChannels' => 2,
rlm@3 99 'nSampleRate' => 4
rlm@3 100 )
rlm@3 101 );
rlm@3 102 }
rlm@3 103
rlm@3 104 // Process data
rlm@3 105 $info_monkeys_audio['flags']['8-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0001);
rlm@3 106 $info_monkeys_audio['flags']['crc-32'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0002);
rlm@3 107 $info_monkeys_audio['flags']['peak_level'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0004);
rlm@3 108 $info_monkeys_audio['flags']['24-bit'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0008);
rlm@3 109 $info_monkeys_audio['flags']['seek_elements'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0010);
rlm@3 110 $info_monkeys_audio['flags']['no_wav_header'] = (bool)($info_monkeys_audio_raw['nFormatFlags'] & 0x0020);
rlm@3 111
rlm@3 112 $info_monkeys_audio['version'] = $info_monkeys_audio_raw['nVersion'] / 1000;
rlm@3 113
rlm@3 114 $info_monkeys_audio['compression'] = getid3_monkey::MonkeyCompressionLevelNameLookup($info_monkeys_audio_raw['nCompressionLevel']);
rlm@3 115
rlm@3 116 $info_monkeys_audio['bits_per_sample'] = ($info_monkeys_audio['flags']['24-bit'] ? 24 : ($info_monkeys_audio['flags']['8-bit'] ? 8 : 16));
rlm@3 117
rlm@3 118 $info_monkeys_audio['channels'] = $info_monkeys_audio_raw['nChannels'];
rlm@3 119
rlm@3 120 $getid3->info['audio']['channels'] = $info_monkeys_audio['channels'];
rlm@3 121
rlm@3 122 $info_monkeys_audio['sample_rate'] = $info_monkeys_audio_raw['nSampleRate'];
rlm@3 123
rlm@3 124 $getid3->info['audio']['sample_rate'] = $info_monkeys_audio['sample_rate'];
rlm@3 125
rlm@3 126 if ($info_monkeys_audio['flags']['peak_level']) {
rlm@3 127 $info_monkeys_audio['peak_level'] = $info_monkeys_audio_raw['nPeakLevel'];
rlm@3 128 $info_monkeys_audio['peak_ratio'] = $info_monkeys_audio['peak_level'] / pow(2, $info_monkeys_audio['bits_per_sample'] - 1);
rlm@3 129 }
rlm@3 130
rlm@3 131 // MAC >= v3980
rlm@3 132 if ($info_monkeys_audio_raw['nVersion'] >= 3980) {
rlm@3 133 $info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio_raw['nBlocksPerFrame']) + $info_monkeys_audio_raw['nFinalFrameBlocks'];
rlm@3 134 }
rlm@3 135
rlm@3 136 // MAC < v3980
rlm@3 137 else {
rlm@3 138 $info_monkeys_audio['samples_per_frame'] = getid3_monkey::MonkeySamplesPerFrame($info_monkeys_audio_raw['nVersion'], $info_monkeys_audio_raw['nCompressionLevel']);
rlm@3 139 $info_monkeys_audio['samples'] = (($info_monkeys_audio_raw['nTotalFrames'] - 1) * $info_monkeys_audio['samples_per_frame']) + $info_monkeys_audio_raw['nFinalFrameSamples'];
rlm@3 140 }
rlm@3 141
rlm@3 142 $info_monkeys_audio['playtime'] = $info_monkeys_audio['samples'] / $info_monkeys_audio['sample_rate'];
rlm@3 143
rlm@3 144 $getid3->info['playtime_seconds'] = $info_monkeys_audio['playtime'];
rlm@3 145
rlm@3 146 $info_monkeys_audio['compressed_size'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'];
rlm@3 147 $info_monkeys_audio['uncompressed_size'] = $info_monkeys_audio['samples'] * $info_monkeys_audio['channels'] * ($info_monkeys_audio['bits_per_sample'] / 8);
rlm@3 148 $info_monkeys_audio['compression_ratio'] = $info_monkeys_audio['compressed_size'] / ($info_monkeys_audio['uncompressed_size'] + $info_monkeys_audio_raw['nHeaderDataBytes']);
rlm@3 149 $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'];
rlm@3 150
rlm@3 151 $getid3->info['audio']['bitrate'] = $info_monkeys_audio['bitrate'];
rlm@3 152
rlm@3 153 $getid3->info['audio']['bits_per_sample'] = $info_monkeys_audio['bits_per_sample'];
rlm@3 154 $getid3->info['audio']['encoder'] = 'MAC v'.number_format($info_monkeys_audio['version'], 2);
rlm@3 155 $getid3->info['audio']['encoder_options'] = ucfirst($info_monkeys_audio['compression']).' compression';
rlm@3 156
rlm@3 157 // MAC >= v3980 - get avdataoffsets from MAC header
rlm@3 158 if ($info_monkeys_audio_raw['nVersion'] >= 3980) {
rlm@3 159 $getid3->info['avdataoffset'] += $info_monkeys_audio_raw['nDescriptorBytes'] + $info_monkeys_audio_raw['nHeaderBytes'] + $info_monkeys_audio_raw['nSeekTableBytes'] + $info_monkeys_audio_raw['nHeaderDataBytes'];
rlm@3 160 $getid3->info['avdataend'] -= $info_monkeys_audio_raw['nTerminatingDataBytes'];
rlm@3 161 }
rlm@3 162
rlm@3 163 // MAC < v3980 Add size of MAC header to avdataoffset
rlm@3 164 else {
rlm@3 165 $getid3->info['avdataoffset'] += 8;
rlm@3 166 }
rlm@3 167
rlm@3 168 // Convert md5sum to 32 byte string
rlm@3 169 if (@$info_monkeys_audio_raw['cFileMD5']) {
rlm@3 170 if ($info_monkeys_audio_raw['cFileMD5'] !== str_repeat("\x00", 16)) {
rlm@3 171 $getid3->info['md5_data_source'] = '';
rlm@3 172 $md5 = $info_monkeys_audio_raw['cFileMD5'];
rlm@3 173 for ($i = 0; $i < strlen($md5); $i++) {
rlm@3 174 $getid3->info['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
rlm@3 175 }
rlm@3 176 if (!preg_match('/^[0-9a-f]{32}$/', $getid3->info['md5_data_source'])) {
rlm@3 177 unset($getid3->info['md5_data_source']);
rlm@3 178 }
rlm@3 179 }
rlm@3 180 }
rlm@3 181
rlm@3 182
rlm@3 183 return true;
rlm@3 184 }
rlm@3 185
rlm@3 186
rlm@3 187
rlm@3 188 public static function MonkeyCompressionLevelNameLookup($compression_level) {
rlm@3 189
rlm@3 190 static $lookup = array (
rlm@3 191 0 => 'unknown',
rlm@3 192 1000 => 'fast',
rlm@3 193 2000 => 'normal',
rlm@3 194 3000 => 'high',
rlm@3 195 4000 => 'extra-high',
rlm@3 196 5000 => 'insane'
rlm@3 197 );
rlm@3 198 return (isset($lookup[$compression_level]) ? $lookup[$compression_level] : 'invalid');
rlm@3 199 }
rlm@3 200
rlm@3 201
rlm@3 202
rlm@3 203 public static function MonkeySamplesPerFrame($version_id, $compression_level) {
rlm@3 204
rlm@3 205 if ($version_id >= 3950) {
rlm@3 206 return 73728 * 4;
rlm@3 207 }
rlm@3 208 if (($version_id >= 3900) || (($version_id >= 3800) && ($compression_level == 4000))) {
rlm@3 209 return 73728;
rlm@3 210 }
rlm@3 211 return 9216;
rlm@3 212 }
rlm@3 213
rlm@3 214 }
rlm@3 215
rlm@3 216 ?>