ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Tta.php
Go to the documentation of this file.
1 <?php
2 
3 namespace GetId3\Module\Audio;
4 
7 
10 // available at http://getid3.sourceforge.net //
11 // or http://www.getid3.org //
13 // See readme.txt for more details //
15 // //
16 // module.audio.tta.php //
17 // module for analyzing TTA Audio files //
18 // dependencies: NONE //
19 // ///
21 
29 class Tta extends BaseHandler
30 {
31 
36  public function analyze()
37  {
38  $info = &$this->getid3->info;
39 
40  $info['fileformat'] = 'tta';
41  $info['audio']['dataformat'] = 'tta';
42  $info['audio']['lossless'] = true;
43  $info['audio']['bitrate_mode'] = 'vbr';
44 
45  fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
46  $ttaheader = fread($this->getid3->fp, 26);
47 
48  $info['tta']['magic'] = substr($ttaheader, 0, 3);
49  $magic = 'TTA';
50  if ($info['tta']['magic'] != $magic) {
51  $info['error'][] = 'Expecting "'.Helper::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.Helper::PrintHexBytes($info['tta']['magic']).'"';
52  unset($info['fileformat']);
53  unset($info['audio']);
54  unset($info['tta']);
55 
56  return false;
57  }
58 
59  switch ($ttaheader{3}) {
60  case "\x01": // TTA v1.x
61  case "\x02": // TTA v1.x
62  case "\x03": // TTA v1.x
63  // "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."
64  $info['tta']['major_version'] = 1;
65  $info['avdataoffset'] += 16;
66 
67  $info['tta']['compression_level'] = ord($ttaheader{3});
68  $info['tta']['channels'] = Helper::LittleEndian2Int(substr($ttaheader, 4, 2));
69  $info['tta']['bits_per_sample'] = Helper::LittleEndian2Int(substr($ttaheader, 6, 2));
70  $info['tta']['sample_rate'] = Helper::LittleEndian2Int(substr($ttaheader, 8, 4));
71  $info['tta']['samples_per_channel'] = Helper::LittleEndian2Int(substr($ttaheader, 12, 4));
72 
73  $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
74  $info['playtime_seconds'] = $info['tta']['samples_per_channel'] / $info['tta']['sample_rate'];
75  break;
76 
77  case '2': // TTA v2.x
78  // "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."
79  $info['tta']['major_version'] = 2;
80  $info['avdataoffset'] += 20;
81 
82  $info['tta']['compression_level'] = Helper::LittleEndian2Int(substr($ttaheader, 4, 2));
83  $info['tta']['audio_format'] = Helper::LittleEndian2Int(substr($ttaheader, 6, 2));
84  $info['tta']['channels'] = Helper::LittleEndian2Int(substr($ttaheader, 8, 2));
85  $info['tta']['bits_per_sample'] = Helper::LittleEndian2Int(substr($ttaheader, 10, 2));
86  $info['tta']['sample_rate'] = Helper::LittleEndian2Int(substr($ttaheader, 12, 4));
87  $info['tta']['data_length'] = Helper::LittleEndian2Int(substr($ttaheader, 16, 4));
88 
89  $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
90  $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
91  break;
92 
93  case '1': // TTA v3.x
94  // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher."
95  $info['tta']['major_version'] = 3;
96  $info['avdataoffset'] += 26;
97 
98  $info['tta']['audio_format'] = Helper::LittleEndian2Int(substr($ttaheader, 4, 2)); // GetId3_riff::RIFFwFormatTagLookup()
99  $info['tta']['channels'] = Helper::LittleEndian2Int(substr($ttaheader, 6, 2));
100  $info['tta']['bits_per_sample'] = Helper::LittleEndian2Int(substr($ttaheader, 8, 2));
101  $info['tta']['sample_rate'] = Helper::LittleEndian2Int(substr($ttaheader, 10, 4));
102  $info['tta']['data_length'] = Helper::LittleEndian2Int(substr($ttaheader, 14, 4));
103  $info['tta']['crc32_footer'] = substr($ttaheader, 18, 4);
104  $info['tta']['seek_point'] = Helper::LittleEndian2Int(substr($ttaheader, 22, 4));
105 
106  $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
107  break;
108 
109  default:
110  $info['error'][] = 'This version of GetId3Core() ['.$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};
111 
112  return false;
113  break;
114  }
115 
116  $info['audio']['encoder'] = 'TTA v'.$info['tta']['major_version'];
117  $info['audio']['bits_per_sample'] = $info['tta']['bits_per_sample'];
118  $info['audio']['sample_rate'] = $info['tta']['sample_rate'];
119  $info['audio']['channels'] = $info['tta']['channels'];
120  $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
121 
122  return true;
123  }
124 
125 }
GetId3() by James Heinrich info@getid3.org //.
Definition: Tta.php:29
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: Helper.php:36
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:25
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
static LittleEndian2Int($byteword, $signed=false)
Definition: Helper.php:413