[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / medias / lib / getid3 / module.audio.tta.php
1 <?php
2
3 /////////////////////////////////////////////////////////////////
4 /// getID3() by James Heinrich <info@getid3.org> //
5 // available at https://github.com/JamesHeinrich/getID3 //
6 // or https://www.getid3.org //
7 // or http://getid3.sourceforge.net //
8 // see readme.txt for more details //
9 /////////////////////////////////////////////////////////////////
10 // //
11 // module.audio.tta.php //
12 // module for analyzing TTA Audio files //
13 // dependencies: NONE //
14 // ///
15 /////////////////////////////////////////////////////////////////
16
17
18 class getid3_tta extends getid3_handler
19 {
20 /**
21 * @return bool
22 */
23 public function Analyze() {
24 $info = &$this->getid3->info;
25
26 $info['fileformat'] = 'tta';
27 $info['audio']['dataformat'] = 'tta';
28 $info['audio']['lossless'] = true;
29 $info['audio']['bitrate_mode'] = 'vbr';
30
31 $this->fseek($info['avdataoffset']);
32 $ttaheader = $this->fread(26);
33
34 $info['tta']['magic'] = substr($ttaheader, 0, 3);
35 $magic = 'TTA';
36 if ($info['tta']['magic'] != $magic) {
37 $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['tta']['magic']).'"');
38 unset($info['fileformat']);
39 unset($info['audio']);
40 unset($info['tta']);
41 return false;
42 }
43
44 switch ($ttaheader{3}) {
45 case "\x01": // TTA v1.x
46 case "\x02": // TTA v1.x
47 case "\x03": // TTA v1.x
48 // "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."
49 $info['tta']['major_version'] = 1;
50 $info['avdataoffset'] += 16;
51
52 $info['tta']['compression_level'] = ord($ttaheader{3});
53 $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2));
54 $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2));
55 $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 4));
56 $info['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4));
57
58 $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
59 $info['playtime_seconds'] = $info['tta']['samples_per_channel'] / $info['tta']['sample_rate'];
60 break;
61
62 case '2': // TTA v2.x
63 // "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."
64 $info['tta']['major_version'] = 2;
65 $info['avdataoffset'] += 20;
66
67 $info['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2));
68 $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2));
69 $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2));
70 $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 2));
71 $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4));
72 $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 16, 4));
73
74 $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
75 $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
76 break;
77
78 case '1': // TTA v3.x
79 // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher."
80 $info['tta']['major_version'] = 3;
81 $info['avdataoffset'] += 26;
82
83 $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); // getid3_riff::wFormatTagLookup()
84 $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2));
85 $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2));
86 $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 4));
87 $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 14, 4));
88 $info['tta']['crc32_footer'] = substr($ttaheader, 18, 4);
89 $info['tta']['seek_point'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 22, 4));
90
91 $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
92 break;
93
94 default:
95 $this->error('This version of getID3() ['.$this->getid3->version().'] only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v'.$ttaheader{3});
96 return false;
97 break;
98 }
99
100 $info['audio']['encoder'] = 'TTA v'.$info['tta']['major_version'];
101 $info['audio']['bits_per_sample'] = $info['tta']['bits_per_sample'];
102 $info['audio']['sample_rate'] = $info['tta']['sample_rate'];
103 $info['audio']['channels'] = $info['tta']['channels'];
104 $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
105
106 return true;
107 }
108
109 }