]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/james-heinrich/getid3/getid3/module.audio.au.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / james-heinrich / getid3 / getid3 / module.audio.au.php
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 //          also https://github.com/JamesHeinrich/getID3       //
7 /////////////////////////////////////////////////////////////////
8 // See readme.txt for more details                             //
9 /////////////////////////////////////////////////////////////////
10 //                                                             //
11 // module.audio.au.php                                         //
12 // module for analyzing AU files                               //
13 // dependencies: NONE                                          //
14 //                                                            ///
15 /////////////////////////////////////////////////////////////////
16
17
18 class getid3_au extends getid3_handler
19 {
20
21         public function Analyze() {
22                 $info = &$this->getid3->info;
23
24                 $this->fseek($info['avdataoffset']);
25                 $AUheader  = $this->fread(8);
26
27                 $magic = '.snd';
28                 if (substr($AUheader, 0, 4) != $magic) {
29                         $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AUheader, 0, 4)).'"');
30                         return false;
31                 }
32
33                 // shortcut
34                 $info['au'] = array();
35                 $thisfile_au        = &$info['au'];
36
37                 $info['fileformat']            = 'au';
38                 $info['audio']['dataformat']   = 'au';
39                 $info['audio']['bitrate_mode'] = 'cbr';
40                 $thisfile_au['encoding']               = 'ISO-8859-1';
41
42                 $thisfile_au['header_length']   = getid3_lib::BigEndian2Int(substr($AUheader,  4, 4));
43                 $AUheader .= $this->fread($thisfile_au['header_length'] - 8);
44                 $info['avdataoffset'] += $thisfile_au['header_length'];
45
46                 $thisfile_au['data_size']             = getid3_lib::BigEndian2Int(substr($AUheader,  8, 4));
47                 $thisfile_au['data_format_id']        = getid3_lib::BigEndian2Int(substr($AUheader, 12, 4));
48                 $thisfile_au['sample_rate']           = getid3_lib::BigEndian2Int(substr($AUheader, 16, 4));
49                 $thisfile_au['channels']              = getid3_lib::BigEndian2Int(substr($AUheader, 20, 4));
50                 $thisfile_au['comments']['comment'][] =                      trim(substr($AUheader, 24));
51
52                 $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']);
53                 $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']);
54                 if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) {
55                         $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample'];
56                 } else {
57                         unset($thisfile_au['bits_per_sample']);
58                 }
59
60                 $info['audio']['sample_rate']  = $thisfile_au['sample_rate'];
61                 $info['audio']['channels']     = $thisfile_au['channels'];
62
63                 if (($info['avdataoffset'] + $thisfile_au['data_size']) > $info['avdataend']) {
64                         $this->warning('Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"');
65                 }
66
67                 $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8));
68                 $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds'];
69
70                 return true;
71         }
72
73         public function AUdataFormatNameLookup($id) {
74                 static $AUdataFormatNameLookup = array(
75                         0  => 'unspecified format',
76                         1  => '8-bit mu-law',
77                         2  => '8-bit linear',
78                         3  => '16-bit linear',
79                         4  => '24-bit linear',
80                         5  => '32-bit linear',
81                         6  => 'floating-point',
82                         7  => 'double-precision float',
83                         8  => 'fragmented sampled data',
84                         9  => 'SUN_FORMAT_NESTED',
85                         10 => 'DSP program',
86                         11 => '8-bit fixed-point',
87                         12 => '16-bit fixed-point',
88                         13 => '24-bit fixed-point',
89                         14 => '32-bit fixed-point',
90
91                         16 => 'non-audio display data',
92                         17 => 'SND_FORMAT_MULAW_SQUELCH',
93                         18 => '16-bit linear with emphasis',
94                         19 => '16-bit linear with compression',
95                         20 => '16-bit linear with emphasis + compression',
96                         21 => 'Music Kit DSP commands',
97                         22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES',
98                         23 => 'CCITT g.721 4-bit ADPCM',
99                         24 => 'CCITT g.722 ADPCM',
100                         25 => 'CCITT g.723 3-bit ADPCM',
101                         26 => 'CCITT g.723 5-bit ADPCM',
102                         27 => 'A-Law 8-bit'
103                 );
104                 return (isset($AUdataFormatNameLookup[$id]) ? $AUdataFormatNameLookup[$id] : false);
105         }
106
107         public function AUdataFormatBitsPerSampleLookup($id) {
108                 static $AUdataFormatBitsPerSampleLookup = array(
109                         1  => 8,
110                         2  => 8,
111                         3  => 16,
112                         4  => 24,
113                         5  => 32,
114                         6  => 32,
115                         7  => 64,
116
117                         11 => 8,
118                         12 => 16,
119                         13 => 24,
120                         14 => 32,
121
122                         18 => 16,
123                         19 => 16,
124                         20 => 16,
125
126                         23 => 16,
127
128                         25 => 16,
129                         26 => 16,
130                         27 => 8
131                 );
132                 return (isset($AUdataFormatBitsPerSampleLookup[$id]) ? $AUdataFormatBitsPerSampleLookup[$id] : false);
133         }
134
135         public function AUdataFormatUsedBitsPerSampleLookup($id) {
136                 static $AUdataFormatUsedBitsPerSampleLookup = array(
137                         1  => 8,
138                         2  => 8,
139                         3  => 16,
140                         4  => 24,
141                         5  => 32,
142                         6  => 32,
143                         7  => 64,
144
145                         11 => 8,
146                         12 => 16,
147                         13 => 24,
148                         14 => 32,
149
150                         18 => 16,
151                         19 => 16,
152                         20 => 16,
153
154                         23 => 4,
155
156                         25 => 3,
157                         26 => 5,
158                         27 => 8,
159                 );
160                 return (isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ? $AUdataFormatUsedBitsPerSampleLookup[$id] : false);
161         }
162
163 }