annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.tta.php @ 20:1038db2374ec judyates

change address
author Robert McIntyre <rlm@mit.edu>
date Sun, 08 Sep 2013 00:47:09 -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.tta.php |
rlm@3 18 // | Module for analyzing TTA Audio files |
rlm@3 19 // | dependencies: NONE |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio.tta.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_tta 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 $getid3->info['fileformat'] = 'tta';
rlm@3 34 $getid3->info['audio']['dataformat'] = 'tta';
rlm@3 35 $getid3->info['audio']['lossless'] = true;
rlm@3 36 $getid3->info['audio']['bitrate_mode'] = 'vbr';
rlm@3 37
rlm@3 38 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 39 $tta_header = fread($getid3->fp, 26);
rlm@3 40
rlm@3 41 $getid3->info['tta']['magic'] = 'TTA'; // Magic bytes
rlm@3 42
rlm@3 43 switch ($tta_header{3}) {
rlm@3 44
rlm@3 45 case "\x01": // TTA v1.x
rlm@3 46 case "\x02": // TTA v1.x
rlm@3 47 case "\x03": // TTA v1.x
rlm@3 48
rlm@3 49 // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year."
rlm@3 50 $getid3->info['tta']['major_version'] = 1;
rlm@3 51 $getid3->info['avdataoffset'] += 16;
rlm@3 52
rlm@3 53 getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
rlm@3 54 array (
rlm@3 55 'channels' => 2,
rlm@3 56 'bits_per_sample' => 2,
rlm@3 57 'sample_rate' => 4,
rlm@3 58 'samples_per_channel' => 4
rlm@3 59 )
rlm@3 60 );
rlm@3 61 $getid3->info['tta']['compression_level'] = ord($tta_header{3});
rlm@3 62
rlm@3 63 $getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level'];
rlm@3 64 $getid3->info['playtime_seconds'] = $getid3->info['tta']['samples_per_channel'] / $getid3->info['tta']['sample_rate'];
rlm@3 65 break;
rlm@3 66
rlm@3 67 case '2': // TTA v2.x
rlm@3 68 // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4."
rlm@3 69 $getid3->info['tta']['major_version'] = 2;
rlm@3 70 $getid3->info['avdataoffset'] += 20;
rlm@3 71
rlm@3 72 getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
rlm@3 73 array (
rlm@3 74 'compression_level' => 2,
rlm@3 75 'audio_format' => 2,
rlm@3 76 'channels' => 2,
rlm@3 77 'bits_per_sample' => 2,
rlm@3 78 'sample_rate' => 4,
rlm@3 79 'data_length' => 4
rlm@3 80 )
rlm@3 81 );
rlm@3 82
rlm@3 83 $getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level'];
rlm@3 84 $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate'];
rlm@3 85 break;
rlm@3 86
rlm@3 87 case '1': // TTA v3.x
rlm@3 88 // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher."
rlm@3 89 $getid3->info['tta']['major_version'] = 3;
rlm@3 90 $getid3->info['avdataoffset'] += 26;
rlm@3 91
rlm@3 92 getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
rlm@3 93 array (
rlm@3 94 'audio_format' => 2,
rlm@3 95 'channels' => 2,
rlm@3 96 'bits_per_sample'=> 2,
rlm@3 97 'sample_rate' => 4,
rlm@3 98 'data_length' => 4,
rlm@3 99 'crc32_footer' => -4, // string
rlm@3 100 'seek_point' => 4
rlm@3 101 )
rlm@3 102 );
rlm@3 103
rlm@3 104 $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate'];
rlm@3 105 break;
rlm@3 106
rlm@3 107 default:
rlm@3 108 throw new getid3_exception('This version of getID3() only knows how to handle TTA v1, v2 and v3 - it may not work correctly with this file which appears to be TTA v'.$tta_header{3});
rlm@3 109 return false;
rlm@3 110 break;
rlm@3 111 }
rlm@3 112
rlm@3 113 $getid3->info['audio']['encoder'] = 'TTA v'.$getid3->info['tta']['major_version'];
rlm@3 114 $getid3->info['audio']['bits_per_sample'] = $getid3->info['tta']['bits_per_sample'];
rlm@3 115 $getid3->info['audio']['sample_rate'] = $getid3->info['tta']['sample_rate'];
rlm@3 116 $getid3->info['audio']['channels'] = $getid3->info['tta']['channels'];
rlm@3 117 $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
rlm@3 118
rlm@3 119 return true;
rlm@3 120 }
rlm@3 121
rlm@3 122 }
rlm@3 123
rlm@3 124
rlm@3 125 ?>