diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.lpac.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.lpac.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,148 @@
     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.lpac.php                                                |
    1.21 +// | Module for analyzing LPAC Audio files                                |
    1.22 +// | dependencies: module.audio-video.riff.php                            |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.audio.lpac.php,v 1.2 2006/11/02 10:48:01 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_lpac extends getid3_handler
    1.30 +{
    1.31 +
    1.32 +    public function Analyze() {
    1.33 +        
    1.34 +        $getid3 = $this->getid3;
    1.35 +        
    1.36 +        $getid3->include_module('audio-video.riff');
    1.37 +        
    1.38 +        // Magic bytes - 'LPAC'
    1.39 +        
    1.40 +        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    1.41 +        $lpac_header = fread($getid3->fp, 14);
    1.42 +        
    1.43 +        $getid3->info['avdataoffset'] += 14;
    1.44 +        
    1.45 +        $getid3->info['lpac'] = array ();
    1.46 +        $info_lpac = &$getid3->info['lpac'];
    1.47 +
    1.48 +        $getid3->info['fileformat']               = 'lpac';
    1.49 +        $getid3->info['audio']['dataformat']      = 'lpac';
    1.50 +        $getid3->info['audio']['lossless']        = true;
    1.51 +        $getid3->info['audio']['bitrate_mode']    = 'vbr';
    1.52 +                                                  
    1.53 +        $info_lpac['file_version']     = getid3_lib::BigEndian2Int($lpac_header{4});
    1.54 +        $flags['audio_type']                      = getid3_lib::BigEndian2Int($lpac_header{5});
    1.55 +        $info_lpac['total_samples']    = getid3_lib::BigEndian2Int(substr($lpac_header,  6, 4));
    1.56 +        $flags['parameters']                      = getid3_lib::BigEndian2Int(substr($lpac_header, 10, 4));
    1.57 +
    1.58 +        $info_lpac['flags']['is_wave'] = (bool)($flags['audio_type'] & 0x40);
    1.59 +        $info_lpac['flags']['stereo']  = (bool)($flags['audio_type'] & 0x04);
    1.60 +        $info_lpac['flags']['24_bit']  = (bool)($flags['audio_type'] & 0x02);
    1.61 +        $info_lpac['flags']['16_bit']  = (bool)($flags['audio_type'] & 0x01);
    1.62 +
    1.63 +        if ($info_lpac['flags']['24_bit'] && $info_lpac['flags']['16_bit']) {
    1.64 +            $getid3->warning('24-bit and 16-bit flags cannot both be set');
    1.65 +        }
    1.66 +
    1.67 +        $info_lpac['flags']['fast_compress']             =   (bool)($flags['parameters'] & 0x40000000);
    1.68 +        $info_lpac['flags']['random_access']             =   (bool)($flags['parameters'] & 0x08000000);
    1.69 +        $info_lpac['block_length']                       = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256;
    1.70 +        $info_lpac['flags']['adaptive_prediction_order'] =   (bool)($flags['parameters'] & 0x00800000);
    1.71 +        $info_lpac['flags']['adaptive_quantization']     =   (bool)($flags['parameters'] & 0x00400000);
    1.72 +        $info_lpac['flags']['joint_stereo']              =   (bool)($flags['parameters'] & 0x00040000);
    1.73 +        $info_lpac['quantization']                       =         ($flags['parameters'] & 0x00001F00) >> 8;
    1.74 +        $info_lpac['max_prediction_order']               =         ($flags['parameters'] & 0x0000003F);
    1.75 +
    1.76 +        if ($info_lpac['flags']['fast_compress'] && ($info_lpac['max_prediction_order'] != 3)) {
    1.77 +            $getid3->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info_lpac['max_prediction_order'].'"');
    1.78 +        }
    1.79 +        
    1.80 +        switch ($info_lpac['file_version']) {
    1.81 +        
    1.82 +            case 6:
    1.83 +                if ($info_lpac['flags']['adaptive_quantization']) {
    1.84 +                    $getid3->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true');
    1.85 +                }
    1.86 +                if ($info_lpac['quantization'] != 20) {
    1.87 +                    $getid3->warning('Quantization expected to be 20 in LPAC file stucture v6, actually '.$info_lpac['flags']['Q']);
    1.88 +                }
    1.89 +                break;
    1.90 +
    1.91 +        
    1.92 +            default:
    1.93 +                //$getid3->warning('This version of getID3() only supports LPAC file format version 6, this file is version '.$info_lpac['file_version'].' - please report to info@getid3.org');
    1.94 +                break;
    1.95 +        }
    1.96 +
    1.97 +        // Clone getid3 - messing with something - better safe than sorry
    1.98 +        $clone = clone $getid3;
    1.99 +        
   1.100 +        // Analyze clone by fp
   1.101 +        $riff = new getid3_riff($clone);
   1.102 +        $riff->Analyze();
   1.103 +        
   1.104 +        // Import from clone and destroy
   1.105 +        $getid3->info['avdataoffset']                = $clone->info['avdataoffset'];
   1.106 +        $getid3->info['riff']                        = $clone->info['riff'];
   1.107 +        //$info_lpac['comments']['comment'] = $clone->info['comments'];
   1.108 +        $getid3->info['audio']['sample_rate']        = $clone->info['audio']['sample_rate'];
   1.109 +        $getid3->warnings($clone->warnings());
   1.110 +        unset($clone);
   1.111 +        
   1.112 +        $getid3->info['audio']['channels'] = ($info_lpac['flags']['stereo'] ? 2 : 1);
   1.113 +
   1.114 +        if ($info_lpac['flags']['24_bit']) {
   1.115 +            $getid3->info['audio']['bits_per_sample'] = $getid3->info['riff']['audio'][0]['bits_per_sample'];
   1.116 +        } elseif ($info_lpac['flags']['16_bit']) {
   1.117 +            $getid3->info['audio']['bits_per_sample'] = 16;
   1.118 +        } else {
   1.119 +            $getid3->info['audio']['bits_per_sample'] = 8;
   1.120 +        }
   1.121 +
   1.122 +        if ($info_lpac['flags']['fast_compress']) {
   1.123 +             // fast
   1.124 +            $getid3->info['audio']['encoder_options'] = '-1';
   1.125 +        } else {
   1.126 +            switch ($info_lpac['max_prediction_order']) {
   1.127 +                case 20: // simple
   1.128 +                    $getid3->info['audio']['encoder_options'] = '-2';
   1.129 +                    break;
   1.130 +                case 30: // medium
   1.131 +                    $getid3->info['audio']['encoder_options'] = '-3';
   1.132 +                    break;
   1.133 +                case 40: // high
   1.134 +                    $getid3->info['audio']['encoder_options'] = '-4';
   1.135 +                    break;
   1.136 +                case 60: // extrahigh
   1.137 +                    $getid3->info['audio']['encoder_options'] = '-5';
   1.138 +                    break;
   1.139 +            }
   1.140 +        }
   1.141 +
   1.142 +        $getid3->info['playtime_seconds'] = $info_lpac['total_samples'] / $getid3->info['audio']['sample_rate'];
   1.143 +        $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
   1.144 +
   1.145 +        return true;
   1.146 +    }
   1.147 +
   1.148 +}
   1.149 +
   1.150 +
   1.151 +?>
   1.152 \ No newline at end of file