source: extensions/charlies_content/getid3/getid3/module.audio.tta.php

Last change on this file was 3544, checked in by vdigital, 15 years ago

Change: getid3 upgraded to -> 1.7.9

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1<?php
2/////////////////////////////////////////////////////////////////
3/// getID3() by James Heinrich <info@getid3.org>               //
4//  available at http://getid3.sourceforge.net                 //
5//            or http://www.getid3.org                         //
6/////////////////////////////////////////////////////////////////
7// See readme.txt for more details                             //
8/////////////////////////////////////////////////////////////////
9//                                                             //
10// module.audio.tta.php                                        //
11// module for analyzing TTA Audio files                        //
12// dependencies: NONE                                          //
13//                                                            ///
14/////////////////////////////////////////////////////////////////
15
16
17class getid3_tta
18{
19
20        function getid3_tta(&$fd, &$ThisFileInfo) {
21
22                $ThisFileInfo['fileformat']            = 'tta';
23                $ThisFileInfo['audio']['dataformat']   = 'tta';
24                $ThisFileInfo['audio']['lossless']     = true;
25                $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
26
27                fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
28                $ttaheader = fread($fd, 26);
29
30                $ThisFileInfo['tta']['magic'] = substr($ttaheader,  0,  3);
31                if ($ThisFileInfo['tta']['magic'] != 'TTA') {
32                        $ThisFileInfo['error'][] = 'Expecting "TTA" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['tta']['magic'].'"';
33                        unset($ThisFileInfo['fileformat']);
34                        unset($ThisFileInfo['audio']);
35                        unset($ThisFileInfo['tta']);
36                        return false;
37                }
38
39                switch ($ttaheader{3}) {
40                        case "\x01": // TTA v1.x
41                        case "\x02": // TTA v1.x
42                        case "\x03": // TTA v1.x
43                                // "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."
44                                $ThisFileInfo['tta']['major_version'] = 1;
45                                $ThisFileInfo['avdataoffset'] += 16;
46
47                                $ThisFileInfo['tta']['compression_level']   = ord($ttaheader{3});
48                                $ThisFileInfo['tta']['channels']            = getid3_lib::LittleEndian2Int(substr($ttaheader,  4,  2));
49                                $ThisFileInfo['tta']['bits_per_sample']     = getid3_lib::LittleEndian2Int(substr($ttaheader,  6,  2));
50                                $ThisFileInfo['tta']['sample_rate']         = getid3_lib::LittleEndian2Int(substr($ttaheader,  8,  4));
51                                $ThisFileInfo['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12,  4));
52
53                                $ThisFileInfo['audio']['encoder_options']   = '-e'.$ThisFileInfo['tta']['compression_level'];
54                                $ThisFileInfo['playtime_seconds']           = $ThisFileInfo['tta']['samples_per_channel'] / $ThisFileInfo['tta']['sample_rate'];
55                                break;
56
57                        case '2': // TTA v2.x
58                                // "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."
59                                $ThisFileInfo['tta']['major_version'] = 2;
60                                $ThisFileInfo['avdataoffset'] += 20;
61
62                                $ThisFileInfo['tta']['compression_level']   = getid3_lib::LittleEndian2Int(substr($ttaheader,  4,  2));
63                                $ThisFileInfo['tta']['audio_format']        = getid3_lib::LittleEndian2Int(substr($ttaheader,  6,  2));
64                                $ThisFileInfo['tta']['channels']            = getid3_lib::LittleEndian2Int(substr($ttaheader,  8,  2));
65                                $ThisFileInfo['tta']['bits_per_sample']     = getid3_lib::LittleEndian2Int(substr($ttaheader, 10,  2));
66                                $ThisFileInfo['tta']['sample_rate']         = getid3_lib::LittleEndian2Int(substr($ttaheader, 12,  4));
67                                $ThisFileInfo['tta']['data_length']         = getid3_lib::LittleEndian2Int(substr($ttaheader, 16,  4));
68
69                                $ThisFileInfo['audio']['encoder_options']   = '-e'.$ThisFileInfo['tta']['compression_level'];
70                                $ThisFileInfo['playtime_seconds']           = $ThisFileInfo['tta']['data_length'] / $ThisFileInfo['tta']['sample_rate'];
71                                break;
72
73                        case '1': // TTA v3.x
74                                // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher."
75                                $ThisFileInfo['tta']['major_version'] = 3;
76                                $ThisFileInfo['avdataoffset'] += 26;
77
78                                $ThisFileInfo['tta']['audio_format']        = getid3_lib::LittleEndian2Int(substr($ttaheader,  4,  2)); // getid3_riff::RIFFwFormatTagLookup()
79                                $ThisFileInfo['tta']['channels']            = getid3_lib::LittleEndian2Int(substr($ttaheader,  6,  2));
80                                $ThisFileInfo['tta']['bits_per_sample']     = getid3_lib::LittleEndian2Int(substr($ttaheader,  8,  2));
81                                $ThisFileInfo['tta']['sample_rate']         = getid3_lib::LittleEndian2Int(substr($ttaheader, 10,  4));
82                                $ThisFileInfo['tta']['data_length']         = getid3_lib::LittleEndian2Int(substr($ttaheader, 14,  4));
83                                $ThisFileInfo['tta']['crc32_footer']        =                              substr($ttaheader, 18,  4);
84                                $ThisFileInfo['tta']['seek_point']          = getid3_lib::LittleEndian2Int(substr($ttaheader, 22,  4));
85
86                                $ThisFileInfo['playtime_seconds']           = $ThisFileInfo['tta']['data_length'] / $ThisFileInfo['tta']['sample_rate'];
87                                break;
88
89                        default:
90                                $ThisFileInfo['error'][] = 'This version of getID3() 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};
91                                return false;
92                                break;
93                }
94
95                $ThisFileInfo['audio']['encoder']         = 'TTA v'.$ThisFileInfo['tta']['major_version'];
96                $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['tta']['bits_per_sample'];
97                $ThisFileInfo['audio']['sample_rate']     = $ThisFileInfo['tta']['sample_rate'];
98                $ThisFileInfo['audio']['channels']        = $ThisFileInfo['tta']['channels'];
99                $ThisFileInfo['audio']['bitrate']         = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
100
101                return true;
102        }
103
104}
105
106
107?>
Note: See TracBrowser for help on using the repository browser.