1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
<?php
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <info�getid3*org> |
// | Allan Hansen <ah�artemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.tta.php |
// | Module for analyzing TTA Audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.tta.php,v 1.2 2006/11/02 10:48:01 ah Exp $
class getid3_tta extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
$getid3->info['fileformat'] = 'tta';
$getid3->info['audio']['dataformat'] = 'tta';
$getid3->info['audio']['lossless'] = true;
$getid3->info['audio']['bitrate_mode'] = 'vbr';
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$tta_header = fread($getid3->fp, 26);
$getid3->info['tta']['magic'] = 'TTA'; // Magic bytes
switch ($tta_header{3}) {
case "\x01": // TTA v1.x
case "\x02": // TTA v1.x
case "\x03": // TTA v1.x
// "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."
$getid3->info['tta']['major_version'] = 1;
$getid3->info['avdataoffset'] += 16;
getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
array (
'channels' => 2,
'bits_per_sample' => 2,
'sample_rate' => 4,
'samples_per_channel' => 4
)
);
$getid3->info['tta']['compression_level'] = ord($tta_header{3});
$getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level'];
$getid3->info['playtime_seconds'] = $getid3->info['tta']['samples_per_channel'] / $getid3->info['tta']['sample_rate'];
break;
case '2': // TTA v2.x
// "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."
$getid3->info['tta']['major_version'] = 2;
$getid3->info['avdataoffset'] += 20;
getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
array (
'compression_level' => 2,
'audio_format' => 2,
'channels' => 2,
'bits_per_sample' => 2,
'sample_rate' => 4,
'data_length' => 4
)
);
$getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level'];
$getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate'];
break;
case '1': // TTA v3.x
// "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher."
$getid3->info['tta']['major_version'] = 3;
$getid3->info['avdataoffset'] += 26;
getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4,
array (
'audio_format' => 2,
'channels' => 2,
'bits_per_sample'=> 2,
'sample_rate' => 4,
'data_length' => 4,
'crc32_footer' => -4, // string
'seek_point' => 4
)
);
$getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate'];
break;
default:
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});
return false;
break;
}
$getid3->info['audio']['encoder'] = 'TTA v'.$getid3->info['tta']['major_version'];
$getid3->info['audio']['bits_per_sample'] = $getid3->info['tta']['bits_per_sample'];
$getid3->info['audio']['sample_rate'] = $getid3->info['tta']['sample_rate'];
$getid3->info['audio']['channels'] = $getid3->info['tta']['channels'];
$getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
return true;
}
}
?>
|