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