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