diff e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.voc.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.voc.php	Mon Feb 22 08:02:39 2010 -0500
     1.3 @@ -0,0 +1,240 @@
     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.voc.php                                                 |
    1.21 +// | Module for analyzing Creative VOC Audio files.                       |
    1.22 +// | dependencies: NONE                                                   |
    1.23 +// +----------------------------------------------------------------------+
    1.24 +//
    1.25 +// $Id: module.audio.voc.php,v 1.3 2006/11/02 10:48:02 ah Exp $
    1.26 +
    1.27 +        
    1.28 +        
    1.29 +class getid3_voc extends getid3_handler
    1.30 +{
    1.31 +
    1.32 +    public function Analyze() {
    1.33 +
    1.34 +        $getid3 = $this->getid3;
    1.35 +        
    1.36 +        $original_av_data_offset = $getid3->info['avdataoffset'];
    1.37 +        
    1.38 +        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
    1.39 +        $voc_header= fread($getid3->fp, 26);
    1.40 +
    1.41 +        // Magic bytes: 'Creative Voice File'
    1.42 +
    1.43 +        $info_audio = &$getid3->info['audio'];
    1.44 +        $getid3->info['voc'] = array ();
    1.45 +        $info_voc = &$getid3->info['voc'];
    1.46 +
    1.47 +        $getid3->info['fileformat']    = 'voc';
    1.48 +        $info_audio['dataformat']      = 'voc';
    1.49 +        $info_audio['bitrate_mode']    = 'cbr';
    1.50 +        $info_audio['lossless']        = true;
    1.51 +        $info_audio['channels']        = 1;         // might be overriden below
    1.52 +        $info_audio['bits_per_sample'] = 8;         // might be overriden below
    1.53 +
    1.54 +        // byte #     Description
    1.55 +        // ------     ------------------------------------------
    1.56 +        // 00-12      'Creative Voice File'
    1.57 +        // 13         1A (eof to abort printing of file)
    1.58 +        // 14-15      Offset of first datablock in .voc file (std 1A 00 in Intel Notation)
    1.59 +        // 16-17      Version number (minor,major) (VOC-HDR puts 0A 01)
    1.60 +        // 18-19      2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
    1.61 +
    1.62 +        getid3_lib::ReadSequence('LittleEndian2Int', $info_voc['header'], $voc_header, 20,
    1.63 +            array (
    1.64 +                'datablock_offset' => 2, 
    1.65 +                'minor_version'    => 1, 
    1.66 +                'major_version'    => 1  
    1.67 +            )
    1.68 +        );
    1.69 +
    1.70 +        do {
    1.71 +            $block_offset = ftell($getid3->fp);
    1.72 +            $block_data   = fread($getid3->fp, 4);
    1.73 +            $block_type   = ord($block_data{0});
    1.74 +            $block_size   = getid3_lib::LittleEndian2Int(substr($block_data, 1, 3));
    1.75 +            $this_block   = array ();
    1.76 +
    1.77 +            @$info_voc['blocktypes'][$block_type]++;
    1.78 +            
    1.79 +            switch ($block_type) {
    1.80 +                
    1.81 +                case 0:  // Terminator
    1.82 +                    // do nothing, we'll break out of the loop down below
    1.83 +                    break;
    1.84 +
    1.85 +                case 1:  // Sound data
    1.86 +                    $block_data .= fread($getid3->fp, 2);
    1.87 +                    if ($getid3->info['avdataoffset'] <= $original_av_data_offset) {
    1.88 +                        $getid3->info['avdataoffset'] = ftell($getid3->fp);
    1.89 +                    }
    1.90 +                    fseek($getid3->fp, $block_size - 2, SEEK_CUR);
    1.91 +
    1.92 +                    getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4,
    1.93 +                        array (
    1.94 +                            'sample_rate_id'   => 1,
    1.95 +                            'compression_type' => 1
    1.96 +                        )
    1.97 +                    );
    1.98 +
    1.99 +                    $this_block['compression_name'] = getid3_voc::VOCcompressionTypeLookup($this_block['compression_type']);
   1.100 +                    if ($this_block['compression_type'] <= 3) {
   1.101 +                        $info_voc['compressed_bits_per_sample'] = (int)(str_replace('-bit', '', $this_block['compression_name']));
   1.102 +                    }
   1.103 +
   1.104 +                    // Less accurate sample_rate calculation than the Extended block (#8) data (but better than nothing if Extended Block is not available)
   1.105 +                    if (empty($info_audio['sample_rate'])) {
   1.106 +                        // SR byte = 256 - (1000000 / sample_rate)
   1.107 +                        $info_audio['sample_rate'] = (int)floor((1000000 / (256 - $this_block['sample_rate_id'])) / $info_audio['channels']);
   1.108 +                    }
   1.109 +                    break;
   1.110 +
   1.111 +                case 2:  // Sound continue
   1.112 +                case 3:  // Silence
   1.113 +                case 4:  // Marker
   1.114 +                case 6:  // Repeat
   1.115 +                case 7:  // End repeat
   1.116 +                    // nothing useful, just skip
   1.117 +                    fseek($getid3->fp, $block_size, SEEK_CUR);
   1.118 +                    break;
   1.119 +
   1.120 +                case 8:  // Extended
   1.121 +                    $block_data .= fread($getid3->fp, 4);
   1.122 +
   1.123 +                    //00-01  Time Constant:
   1.124 +                    //   Mono: 65536 - (256000000 / sample_rate)
   1.125 +                    // Stereo: 65536 - (256000000 / (sample_rate * 2))
   1.126 +                    getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4,
   1.127 +                        array (
   1.128 +                            'time_constant' => 2, 
   1.129 +                            'pack_method'   => 1, 
   1.130 +                            'stereo'        => 1        
   1.131 +                        )
   1.132 +                    );
   1.133 +                    $this_block['stereo']      = (bool)$this_block['stereo'];
   1.134 +                    
   1.135 +                    $info_audio['channels']    = ($this_block['stereo'] ? 2 : 1);
   1.136 +                    $info_audio['sample_rate'] = (int)floor((256000000 / (65536 - $this_block['time_constant'])) / $info_audio['channels']);
   1.137 +                    break;
   1.138 +
   1.139 +                case 9:  // data block that supersedes blocks 1 and 8. Used for stereo, 16 bit
   1.140 +                    $block_data .= fread($getid3->fp, 12);
   1.141 +                    if ($getid3->info['avdataoffset'] <= $original_av_data_offset) {
   1.142 +                        $getid3->info['avdataoffset'] = ftell($getid3->fp);
   1.143 +                    }
   1.144 +                    fseek($getid3->fp, $block_size - 12, SEEK_CUR);
   1.145 +
   1.146 +                    getid3_lib::ReadSequence('LittleEndian2Int', $this_block, $block_data, 4,
   1.147 +                        array (
   1.148 +                            'sample_rate'     => 4,
   1.149 +                            'bits_per_sample' => 1,
   1.150 +                            'channels'        => 1, 
   1.151 +                            'wFormat'         => 2 
   1.152 +                        )
   1.153 +                    );
   1.154 +                    
   1.155 +                    $this_block['compression_name'] = getid3_voc::VOCwFormatLookup($this_block['wFormat']);
   1.156 +                    if (getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat'])) {
   1.157 +                        $info_voc['compressed_bits_per_sample'] = getid3_voc::VOCwFormatActualBitsPerSampleLookup($this_block['wFormat']);
   1.158 +                    }
   1.159 +
   1.160 +                    $info_audio['sample_rate']     = $this_block['sample_rate'];
   1.161 +                    $info_audio['bits_per_sample'] = $this_block['bits_per_sample'];
   1.162 +                    $info_audio['channels']        = $this_block['channels'];
   1.163 +                    break;
   1.164 +
   1.165 +                default:
   1.166 +                    $getid3->warning('Unhandled block type "'.$block_type.'" at offset '.$block_offset);
   1.167 +                    fseek($getid3->fp, $block_size, SEEK_CUR);
   1.168 +                    break;
   1.169 +            }
   1.170 +
   1.171 +            if (!empty($this_block)) {
   1.172 +                $this_block['block_offset']  = $block_offset;
   1.173 +                $this_block['block_size']    = $block_size;
   1.174 +                $this_block['block_type_id'] = $block_type;
   1.175 +                $info_voc['blocks'][] = $this_block;
   1.176 +            }
   1.177 +
   1.178 +        } while (!feof($getid3->fp) && ($block_type != 0));
   1.179 +
   1.180 +        // Terminator block doesn't have size field, so seek back 3 spaces
   1.181 +        fseek($getid3->fp, -3, SEEK_CUR);
   1.182 +
   1.183 +        ksort($info_voc['blocktypes']);
   1.184 +
   1.185 +        if (!empty($info_voc['compressed_bits_per_sample'])) {
   1.186 +            $getid3->info['playtime_seconds'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / ($info_voc['compressed_bits_per_sample'] * $info_audio['channels'] * $info_audio['sample_rate']);
   1.187 +            $info_audio['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
   1.188 +        }
   1.189 +
   1.190 +        return true;
   1.191 +    }
   1.192 +
   1.193 +
   1.194 +
   1.195 +    public static function VOCcompressionTypeLookup($index) {
   1.196 +        
   1.197 +        static $lookup = array (
   1.198 +            0 => '8-bit',
   1.199 +            1 => '4-bit',
   1.200 +            2 => '2.6-bit',
   1.201 +            3 => '2-bit'
   1.202 +        );
   1.203 +        return (isset($lookup[$index]) ? $lookup[$index] : 'Multi DAC ('.($index - 3).') channels');
   1.204 +    }
   1.205 +
   1.206 +
   1.207 +
   1.208 +    public static function VOCwFormatLookup($index) {
   1.209 +        
   1.210 +        static $lookup = array (
   1.211 +            0x0000 => '8-bit unsigned PCM',
   1.212 +            0x0001 => 'Creative 8-bit to 4-bit ADPCM',
   1.213 +            0x0002 => 'Creative 8-bit to 3-bit ADPCM',
   1.214 +            0x0003 => 'Creative 8-bit to 2-bit ADPCM',
   1.215 +            0x0004 => '16-bit signed PCM',
   1.216 +            0x0006 => 'CCITT a-Law',
   1.217 +            0x0007 => 'CCITT u-Law',
   1.218 +            0x2000 => 'Creative 16-bit to 4-bit ADPCM'
   1.219 +        );
   1.220 +        return (isset($lookup[$index]) ? $lookup[$index] : false);
   1.221 +    }
   1.222 +
   1.223 +
   1.224 +
   1.225 +    public static function VOCwFormatActualBitsPerSampleLookup($index) {
   1.226 +        
   1.227 +        static $lookup = array (
   1.228 +            0x0000 => 8,
   1.229 +            0x0001 => 4,
   1.230 +            0x0002 => 3,
   1.231 +            0x0003 => 2,
   1.232 +            0x0004 => 16,
   1.233 +            0x0006 => 8,
   1.234 +            0x0007 => 8,
   1.235 +            0x2000 => 4
   1.236 +        );
   1.237 +        return (isset($lookup[$index]) ? $lookup[$index] : false);
   1.238 +    }
   1.239 +
   1.240 +}
   1.241 +
   1.242 +
   1.243 +?>
   1.244 \ No newline at end of file