diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.mpc.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.mpc.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,211 @@
     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.mpc.php                                                 |
    1.21 +// | Module for analyzing Musepack/MPEG+ Audio files                      |
    1.22 +// | dependencies: NONE                                                   |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.audio.mpc.php,v 1.3 2006/11/02 10:48:01 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_mpc extends getid3_handler
    1.30 +{
    1.31 +
    1.32 +    public function Analyze() {
    1.33 +
    1.34 +        $getid3 = $this->getid3;
    1.35 +        
    1.36 +        // http://www.uni-jena.de/~pfk/mpp/sv8/header.html
    1.37 +
    1.38 +        $getid3->info['fileformat']            = 'mpc';
    1.39 +        $getid3->info['audio']['dataformat']   = 'mpc';
    1.40 +        $getid3->info['audio']['bitrate_mode'] = 'vbr';
    1.41 +        $getid3->info['audio']['channels']     = 2;  // the format appears to be hardcoded for stereo only
    1.42 +        $getid3->info['audio']['lossless']     = false;
    1.43 +        
    1.44 +        $getid3->info['mpc']['header'] = array ();
    1.45 +        $info_mpc_header = &$getid3->info['mpc']['header'];
    1.46 +        $info_mpc_header['size'] = 28;
    1.47 +        $info_mpc_header['raw']['preamble'] = 'MP+';    // Magic bytes
    1.48 +        
    1.49 +        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    1.50 +        $mpc_header_data = fread($getid3->fp, 28);
    1.51 +        
    1.52 +        $stream_version_byte = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 3, 1));
    1.53 +        $info_mpc_header['stream_major_version'] = ($stream_version_byte & 0x0F);
    1.54 +        $info_mpc_header['stream_minor_version'] = ($stream_version_byte & 0xF0) >> 4;
    1.55 +        if ($info_mpc_header['stream_major_version'] != 7) {
    1.56 +            throw new getid3_exception('Only Musepack SV7 supported');
    1.57 +        }
    1.58 +            
    1.59 +        $info_mpc_header['frame_count'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4));
    1.60 +        
    1.61 +        $info_mpc_header['raw']['title_peak']      = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 12, 2));
    1.62 +        $info_mpc_header['raw']['title_gain']      = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 14, 2), true);
    1.63 +        $info_mpc_header['raw']['album_peak']      = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 16, 2));
    1.64 +        $info_mpc_header['raw']['album_gain']      = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 18, 2), true);
    1.65 +        
    1.66 +        $info_mpc_header['raw']['not_sure_what']   = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 24, 3));
    1.67 +        $info_mpc_header['raw']['encoder_version'] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 27, 1));
    1.68 +        
    1.69 +        $flags_dword1                              = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 8, 4));
    1.70 +        $flags_dword2                              = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 20, 4));
    1.71 +        
    1.72 +        $info_mpc_header['intensity_stereo']   = (bool)(($flags_dword1 & 0x80000000) >> 31);
    1.73 +        $info_mpc_header['mid_side_stereo']    = (bool)(($flags_dword1 & 0x40000000) >> 30);
    1.74 +        $info_mpc_header['max_subband']        =         ($flags_dword1 & 0x3F000000) >> 24;
    1.75 +        $info_mpc_header['raw']['profile']     =         ($flags_dword1 & 0x00F00000) >> 20;
    1.76 +        $info_mpc_header['begin_loud']         = (bool)(($flags_dword1 & 0x00080000) >> 19);
    1.77 +        $info_mpc_header['end_loud']           = (bool)(($flags_dword1 & 0x00040000) >> 18);
    1.78 +        $info_mpc_header['raw']['sample_rate'] =         ($flags_dword1 & 0x00030000) >> 16;
    1.79 +        $info_mpc_header['max_level']          =         ($flags_dword1 & 0x0000FFFF);
    1.80 +        
    1.81 +        $info_mpc_header['true_gapless']       = (bool)(($flags_dword2 & 0x80000000) >> 31);
    1.82 +        $info_mpc_header['last_frame_length']  =         ($flags_dword2 & 0x7FF00000) >> 20;
    1.83 +        
    1.84 +        $info_mpc_header['profile']            = getid3_mpc::MPCprofileNameLookup($info_mpc_header['raw']['profile']);
    1.85 +        $info_mpc_header['sample_rate']        = getid3_mpc::MPCfrequencyLookup($info_mpc_header['raw']['sample_rate']);
    1.86 +        $getid3->info['audio']['sample_rate']  = $info_mpc_header['sample_rate'];
    1.87 +        $info_mpc_header['samples']            = ((($info_mpc_header['frame_count'] - 1) * 1152) + $info_mpc_header['last_frame_length']) * $getid3->info['audio']['channels'];
    1.88 +
    1.89 +        $getid3->info['playtime_seconds'] = ($info_mpc_header['samples'] / $getid3->info['audio']['channels']) / $getid3->info['audio']['sample_rate'];
    1.90 +
    1.91 +        $getid3->info['avdataoffset'] += $info_mpc_header['size'];
    1.92 +        
    1.93 +        $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
    1.94 +
    1.95 +        $info_mpc_header['title_peak']    = $info_mpc_header['raw']['title_peak'];
    1.96 +        $info_mpc_header['title_peak_db'] = getid3_mpc::MPCpeakDBLookup($info_mpc_header['title_peak']);
    1.97 +        if ($info_mpc_header['raw']['title_gain'] < 0) {
    1.98 +            $info_mpc_header['title_gain_db'] = (float)(32768 + $info_mpc_header['raw']['title_gain']) / -100;
    1.99 +        } 
   1.100 +        else {
   1.101 +            $info_mpc_header['title_gain_db'] = (float)$info_mpc_header['raw']['title_gain'] / 100;
   1.102 +        }
   1.103 +
   1.104 +        $info_mpc_header['album_peak']    = $info_mpc_header['raw']['album_peak'];
   1.105 +        $info_mpc_header['album_peak_db'] = getid3_mpc::MPCpeakDBLookup($info_mpc_header['album_peak']);
   1.106 +        if ($info_mpc_header['raw']['album_gain'] < 0) {
   1.107 +            $info_mpc_header['album_gain_db'] = (float)(32768 + $info_mpc_header['raw']['album_gain']) / -100;
   1.108 +        } 
   1.109 +        else {
   1.110 +            $info_mpc_header['album_gain_db'] = (float)$info_mpc_header['raw']['album_gain'] / 100;;
   1.111 +        }
   1.112 +        $info_mpc_header['encoder_version'] = getid3_mpc::MPCencoderVersionLookup($info_mpc_header['raw']['encoder_version']);
   1.113 +
   1.114 +        $getid3->info['replay_gain']['track']['adjustment'] = $info_mpc_header['title_gain_db'];
   1.115 +        $getid3->info['replay_gain']['album']['adjustment'] = $info_mpc_header['album_gain_db'];
   1.116 +
   1.117 +        if ($info_mpc_header['title_peak'] > 0) {
   1.118 +            $getid3->info['replay_gain']['track']['peak'] = $info_mpc_header['title_peak'];
   1.119 +        } 
   1.120 +        elseif (round($info_mpc_header['max_level'] * 1.18) > 0) {
   1.121 +            $getid3->info['replay_gain']['track']['peak'] = (int)(round($info_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c
   1.122 +        }
   1.123 +        if ($info_mpc_header['album_peak'] > 0) {
   1.124 +            $getid3->info['replay_gain']['album']['peak'] = $info_mpc_header['album_peak'];
   1.125 +        }
   1.126 +
   1.127 +        $getid3->info['audio']['encoder']         = $info_mpc_header['encoder_version'];
   1.128 +        $getid3->info['audio']['encoder_options'] = $info_mpc_header['profile'];
   1.129 +        
   1.130 +        return true;
   1.131 +    }
   1.132 +
   1.133 +
   1.134 +
   1.135 +    public static function MPCprofileNameLookup($profileid) {
   1.136 +        
   1.137 +        static $lookup = array (
   1.138 +            0  => 'no profile',
   1.139 +            1  => 'Experimental',
   1.140 +            2  => 'unused',
   1.141 +            3  => 'unused',
   1.142 +            4  => 'unused',
   1.143 +            5  => 'below Telephone (q = 0.0)',
   1.144 +            6  => 'below Telephone (q = 1.0)',
   1.145 +            7  => 'Telephone (q = 2.0)',
   1.146 +            8  => 'Thumb (q = 3.0)',
   1.147 +            9  => 'Radio (q = 4.0)',
   1.148 +            10 => 'Standard (q = 5.0)',
   1.149 +            11 => 'Extreme (q = 6.0)',
   1.150 +            12 => 'Insane (q = 7.0)',
   1.151 +            13 => 'BrainDead (q = 8.0)',
   1.152 +            14 => 'above BrainDead (q = 9.0)',
   1.153 +            15 => 'above BrainDead (q = 10.0)'
   1.154 +        );
   1.155 +        return (isset($lookup[$profileid]) ? $lookup[$profileid] : 'invalid');
   1.156 +    }
   1.157 +
   1.158 +
   1.159 +
   1.160 +    public static function MPCfrequencyLookup($frequencyid) {
   1.161 +        
   1.162 +        static $lookup = array (
   1.163 +            0 => 44100,
   1.164 +            1 => 48000,
   1.165 +            2 => 37800,
   1.166 +            3 => 32000
   1.167 +        );
   1.168 +        return (isset($lookup[$frequencyid]) ? $lookup[$frequencyid] : 'invalid');
   1.169 +    }
   1.170 +
   1.171 +
   1.172 +
   1.173 +    public static function MPCpeakDBLookup($int_value) {
   1.174 +        
   1.175 +        if ($int_value > 0) {
   1.176 +            return ((log10($int_value) / log10(2)) - 15) * 6;
   1.177 +        }
   1.178 +        return false;
   1.179 +    }
   1.180 +
   1.181 +
   1.182 +
   1.183 +    public static function MPCencoderVersionLookup($encoder_version) {
   1.184 +    
   1.185 +        //Encoder version * 100  (106 = 1.06)
   1.186 +        //EncoderVersion % 10 == 0        Release (1.0)
   1.187 +        //EncoderVersion %  2 == 0        Beta (1.06)
   1.188 +        //EncoderVersion %  2 == 1        Alpha (1.05a...z)
   1.189 +
   1.190 +        if ($encoder_version == 0) {
   1.191 +            // very old version, not known exactly which
   1.192 +            return 'Buschmann v1.7.0-v1.7.9 or Klemm v0.90-v1.05';
   1.193 +        }
   1.194 +
   1.195 +        if (($encoder_version % 10) == 0) {
   1.196 +
   1.197 +            // release version
   1.198 +            return number_format($encoder_version / 100, 2);
   1.199 +
   1.200 +        } elseif (($encoder_version % 2) == 0) {
   1.201 +
   1.202 +            // beta version
   1.203 +            return number_format($encoder_version / 100, 2).' beta';
   1.204 +
   1.205 +        }
   1.206 +
   1.207 +        // alpha version
   1.208 +        return number_format($encoder_version / 100, 2).' alpha';
   1.209 +    }
   1.210 +
   1.211 +}
   1.212 +
   1.213 +
   1.214 +?>
   1.215 \ No newline at end of file