82 {
83
84
85 $RIFFdata = '';
86 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
87 while (!feof($fd) && (ftell($fd) < $ThisFileInfo['avdataend'])) {
88 $BlockOffset = ftell($fd);
89 $BlockData = fread($fd, 8);
90 $offset = 8;
91 $BlockName = substr($BlockData, 0, 4);
93
94 if ($BlockName == 'OFRX') {
95 $BlockName = 'OFR ';
96 }
97 if (!isset($ThisFileInfo['ofr'][$BlockName])) {
98 $ThisFileInfo['ofr'][$BlockName] = array();
99 }
100 $thisfile_ofr_thisblock = &$ThisFileInfo['ofr'][$BlockName];
101
102 switch ($BlockName) {
103 case 'OFR ':
104
105
106 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
107 $thisfile_ofr_thisblock['size'] = $BlockSize;
108
109 $ThisFileInfo['audio']['encoder'] = 'OptimFROG 4.50 alpha';
110 switch ($BlockSize) {
111 case 12:
112 case 15:
113
114 break;
115
116 default:
117 $ThisFileInfo['warning'][] = '"'.$BlockName.'" contains more data than expected (expected 12 or 15 bytes, found '.$BlockSize.' bytes)';
118 break;
119 }
120 $BlockData .= fread($fd, $BlockSize);
121
123 $offset += 6;
125 $thisfile_ofr_thisblock[
'sample_type'] = $this->
OptimFROGsampleTypeLookup($thisfile_ofr_thisblock[
'raw'][
'sample_type']);
126 $offset += 1;
128 $thisfile_ofr_thisblock['channels'] = $thisfile_ofr_thisblock['channel_config'];
129 $offset += 1;
131 $offset += 4;
132
133 if ($BlockSize > 12) {
134
135
139 $offset += 2;
142 $thisfile_ofr_thisblock[
'speedup'] = $this->
OptimFROGspeedupLookup($thisfile_ofr_thisblock[
'raw'][
'compression']);
143 $offset += 1;
144
145 $ThisFileInfo['audio']['encoder'] = 'OptimFROG '.$thisfile_ofr_thisblock['encoder'];
146 $ThisFileInfo['audio']['encoder_options'] = '--mode '.$thisfile_ofr_thisblock['compression'];
147
148 if ((($thisfile_ofr_thisblock['raw']['encoder_id'] & 0xF0) >> 4) == 7) {
150
151
152 $ThisFileInfo['audio']['dataformat'] = 'ofs';
153 $ThisFileInfo['audio']['lossless'] = true;
154 }
155 }
156
157 }
158
159 $ThisFileInfo['audio']['channels'] = $thisfile_ofr_thisblock['channels'];
160 $ThisFileInfo['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate'];
162 break;
163
164
165 case 'COMP':
166
167
168 $COMPdata['offset'] = $BlockOffset;
169 $COMPdata['size'] = $BlockSize;
170
171 if ($ThisFileInfo['avdataoffset'] == 0) {
172 $ThisFileInfo['avdataoffset'] = $BlockOffset;
173 }
174
175
176 $BlockData .= fread($fd, 14);
177 fseek($fd, $BlockSize - 14, SEEK_CUR);
178
180 $offset += 4;
182 $offset += 4;
185 $offset += 1;
188 $offset += 1;
190
191 $offset += 2;
192
193 if ($ThisFileInfo['ofr']['OFR ']['size'] > 12) {
194
195
198 $offset += 2;
199
200 }
201
202 if ($COMPdata['crc_32'] == 0x454E4F4E) {
203
204 $COMPdata['crc_32'] = false;
205 }
206
207 $thisfile_ofr_thisblock[] = $COMPdata;
208 break;
209
210 case 'HEAD':
211 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
212 $thisfile_ofr_thisblock['size'] = $BlockSize;
213
214 $RIFFdata .= fread($fd, $BlockSize);
215 break;
216
217 case 'TAIL':
218 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
219 $thisfile_ofr_thisblock['size'] = $BlockSize;
220
221 if ($BlockSize > 0) {
222 $RIFFdata .= fread($fd, $BlockSize);
223 }
224 break;
225
226 case 'RECV':
227
228
229 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
230 $thisfile_ofr_thisblock['size'] = $BlockSize;
231
232 fseek($fd, $BlockSize, SEEK_CUR);
233 break;
234
235
236 case 'APET':
237
238
239 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
240 $thisfile_ofr_thisblock['size'] = $BlockSize;
241 $ThisFileInfo['warning'][] = 'APEtag processing inside OptimFROG not supported in this version ('.GETID3_VERSION.') of getID3()';
242
243 fseek($fd, $BlockSize, SEEK_CUR);
244 break;
245
246
247 case 'MD5 ':
248
249
250 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
251 $thisfile_ofr_thisblock['size'] = $BlockSize;
252
253 if ($BlockSize == 16) {
254
255 $thisfile_ofr_thisblock['md5_binary'] = fread($fd, $BlockSize);
256 $thisfile_ofr_thisblock[
'md5_string'] =
getid3_lib::PrintHexBytes($thisfile_ofr_thisblock[
'md5_binary'],
true,
false,
false);
257 $ThisFileInfo['md5_data_source'] = $thisfile_ofr_thisblock['md5_string'];
258
259 } else {
260
261 $ThisFileInfo['warning'][] = 'Expecting block size of 16 in "MD5 " chunk, found '.$BlockSize.' instead';
262 fseek($fd, $BlockSize, SEEK_CUR);
263
264 }
265 break;
266
267
268 default:
269 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
270 $thisfile_ofr_thisblock['size'] = $BlockSize;
271
272 $ThisFileInfo['warning'][] = 'Unhandled OptimFROG block type "'.$BlockName.'" at offset '.$thisfile_ofr_thisblock['offset'];
273 fseek($fd, $BlockSize, SEEK_CUR);
274 break;
275 }
276 }
277 if (isset($ThisFileInfo['ofr']['TAIL']['offset'])) {
278 $ThisFileInfo['avdataend'] = $ThisFileInfo['ofr']['TAIL']['offset'];
279 }
280
281 $ThisFileInfo['playtime_seconds'] = (float) $ThisFileInfo['ofr']['OFR ']['total_samples'] / ($ThisFileInfo['audio']['channels'] * $ThisFileInfo['audio']['sample_rate']);
282 $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
283
284
285
286
287 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
289
290 return true;
291 }
fileextension($filename, $numextensions=1)
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
OptimFROGcompressionLookup($CompressionID)
OptimFROGbitsPerSampleTypeLookup($SampleType)
OptimFROGsampleTypeLookup($SampleType)
OptimFROGspeedupLookup($CompressionID)
OptimFROGencoderNameLookup($EncoderID)
OptimFROGchannelConfigNumChannelsLookup($ChannelConfiguration)
OptimFROGchannelConfigurationLookup($ChannelConfiguration)