22 $ThisFileInfo[
'fileformat'] =
'ofr';
23 $ThisFileInfo[
'audio'][
'dataformat'] =
'ofr';
24 $ThisFileInfo[
'audio'][
'bitrate_mode'] =
'vbr';
25 $ThisFileInfo[
'audio'][
'lossless'] =
true;
27 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
28 $OFRheader = fread($fd, 8);
29 if (substr($OFRheader, 0, 5) ==
'*RIFF') {
33 } elseif (substr($OFRheader, 0, 3) ==
'OFR') {
39 $ThisFileInfo[
'error'][] =
'Expecting "*RIFF" or "OFR " at offset '.$ThisFileInfo[
'avdataoffset'].
', found "'.$OFRheader.
'"';
40 unset($ThisFileInfo[
'fileformat']);
48 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
49 $OptimFROGheaderData = fread($fd, 45);
50 $ThisFileInfo[
'avdataoffset'] = 45;
53 $OptimFROGencoderVersion_major = floor($OptimFROGencoderVersion_raw / 10);
54 $OptimFROGencoderVersion_minor = $OptimFROGencoderVersion_raw - ($OptimFROGencoderVersion_major * 10);
55 $RIFFdata = substr($OptimFROGheaderData, 1, 44);
59 if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
60 $ThisFileInfo[
'avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
61 fseek($fd, $ThisFileInfo[
'avdataend'], SEEK_SET);
62 $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize);
68 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
71 $ThisFileInfo[
'audio'][
'encoder'] =
'OptimFROG '.$OptimFROGencoderVersion_major.
'.'.$OptimFROGencoderVersion_minor;
72 $ThisFileInfo[
'audio'][
'channels'] = $ThisFileInfo[
'riff'][
'audio'][0][
'channels'];
73 $ThisFileInfo[
'audio'][
'sample_rate'] = $ThisFileInfo[
'riff'][
'audio'][0][
'sample_rate'];
74 $ThisFileInfo[
'audio'][
'bits_per_sample'] = $ThisFileInfo[
'riff'][
'audio'][0][
'bits_per_sample'];
75 $ThisFileInfo[
'playtime_seconds'] = $OrignalRIFFdataSize / ($ThisFileInfo[
'audio'][
'channels'] * $ThisFileInfo[
'audio'][
'sample_rate'] * ($ThisFileInfo[
'audio'][
'bits_per_sample'] / 8));
76 $ThisFileInfo[
'audio'][
'bitrate'] = (($ThisFileInfo[
'avdataend'] - $ThisFileInfo[
'avdataoffset']) * 8) / $ThisFileInfo[
'playtime_seconds'];
86 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
87 while (!feof($fd) && (ftell($fd) < $ThisFileInfo[
'avdataend'])) {
88 $BlockOffset = ftell($fd);
89 $BlockData = fread($fd, 8);
91 $BlockName = substr($BlockData, 0, 4);
94 if ($BlockName ==
'OFRX') {
97 if (!isset($ThisFileInfo[
'ofr'][$BlockName])) {
98 $ThisFileInfo[
'ofr'][$BlockName] = array();
100 $thisfile_ofr_thisblock = &$ThisFileInfo[
'ofr'][$BlockName];
102 switch ($BlockName) {
106 $thisfile_ofr_thisblock[
'offset'] = $BlockOffset;
107 $thisfile_ofr_thisblock[
'size'] = $BlockSize;
109 $ThisFileInfo[
'audio'][
'encoder'] =
'OptimFROG 4.50 alpha';
110 switch ($BlockSize) {
117 $ThisFileInfo[
'warning'][] =
'"'.$BlockName.
'" contains more data than expected (expected 12 or 15 bytes, found '.$BlockSize.
' bytes)';
120 $BlockData .= fread($fd, $BlockSize);
125 $thisfile_ofr_thisblock[
'sample_type'] = $this->
OptimFROGsampleTypeLookup($thisfile_ofr_thisblock[
'raw'][
'sample_type']);
128 $thisfile_ofr_thisblock[
'channels'] = $thisfile_ofr_thisblock[
'channel_config'];
133 if ($BlockSize > 12) {
142 $thisfile_ofr_thisblock[
'speedup'] = $this->
OptimFROGspeedupLookup($thisfile_ofr_thisblock[
'raw'][
'compression']);
145 $ThisFileInfo[
'audio'][
'encoder'] =
'OptimFROG '.$thisfile_ofr_thisblock[
'encoder'];
146 $ThisFileInfo[
'audio'][
'encoder_options'] =
'--mode '.$thisfile_ofr_thisblock[
'compression'];
148 if ((($thisfile_ofr_thisblock[
'raw'][
'encoder_id'] & 0xF0) >> 4) == 7) {
152 $ThisFileInfo[
'audio'][
'dataformat'] =
'ofs';
153 $ThisFileInfo[
'audio'][
'lossless'] =
true;
159 $ThisFileInfo[
'audio'][
'channels'] = $thisfile_ofr_thisblock[
'channels'];
160 $ThisFileInfo[
'audio'][
'sample_rate'] = $thisfile_ofr_thisblock[
'sample_rate'];
168 $COMPdata[
'offset'] = $BlockOffset;
169 $COMPdata[
'size'] = $BlockSize;
171 if ($ThisFileInfo[
'avdataoffset'] == 0) {
172 $ThisFileInfo[
'avdataoffset'] = $BlockOffset;
176 $BlockData .= fread($fd, 14);
177 fseek($fd, $BlockSize - 14, SEEK_CUR);
193 if ($ThisFileInfo[
'ofr'][
'OFR '][
'size'] > 12) {
202 if ($COMPdata[
'crc_32'] == 0x454E4F4E) {
204 $COMPdata[
'crc_32'] =
false;
207 $thisfile_ofr_thisblock[] = $COMPdata;
211 $thisfile_ofr_thisblock[
'offset'] = $BlockOffset;
212 $thisfile_ofr_thisblock[
'size'] = $BlockSize;
214 $RIFFdata .= fread($fd, $BlockSize);
218 $thisfile_ofr_thisblock[
'offset'] = $BlockOffset;
219 $thisfile_ofr_thisblock[
'size'] = $BlockSize;
221 if ($BlockSize > 0) {
222 $RIFFdata .= fread($fd, $BlockSize);
229 $thisfile_ofr_thisblock[
'offset'] = $BlockOffset;
230 $thisfile_ofr_thisblock[
'size'] = $BlockSize;
232 fseek($fd, $BlockSize, SEEK_CUR);
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()';
243 fseek($fd, $BlockSize, SEEK_CUR);
250 $thisfile_ofr_thisblock[
'offset'] = $BlockOffset;
251 $thisfile_ofr_thisblock[
'size'] = $BlockSize;
253 if ($BlockSize == 16) {
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'];
261 $ThisFileInfo[
'warning'][] =
'Expecting block size of 16 in "MD5 " chunk, found '.$BlockSize.
' instead';
262 fseek($fd, $BlockSize, SEEK_CUR);
269 $thisfile_ofr_thisblock[
'offset'] = $BlockOffset;
270 $thisfile_ofr_thisblock[
'size'] = $BlockSize;
272 $ThisFileInfo[
'warning'][] =
'Unhandled OptimFROG block type "'.$BlockName.
'" at offset '.$thisfile_ofr_thisblock[
'offset'];
273 fseek($fd, $BlockSize, SEEK_CUR);
277 if (isset($ThisFileInfo[
'ofr'][
'TAIL'][
'offset'])) {
278 $ThisFileInfo[
'avdataend'] = $ThisFileInfo[
'ofr'][
'TAIL'][
'offset'];
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'];
287 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
295 static $OptimFROGsampleTypeLookup = array(
296 0 =>
'unsigned int (8-bit)',
297 1 =>
'signed int (8-bit)',
298 2 =>
'unsigned int (16-bit)',
299 3 =>
'signed int (16-bit)',
300 4 =>
'unsigned int (24-bit)',
301 5 =>
'signed int (24-bit)',
302 6 =>
'unsigned int (32-bit)',
303 7 =>
'signed int (32-bit)',
304 8 =>
'float 0.24 (32-bit)',
305 9 =>
'float 16.8 (32-bit)',
306 10 =>
'float 24.0 (32-bit)'
308 return (isset($OptimFROGsampleTypeLookup[$SampleType]) ? $OptimFROGsampleTypeLookup[$SampleType] :
false);
312 static $OptimFROGbitsPerSampleTypeLookup = array(
325 return (isset($OptimFROGbitsPerSampleTypeLookup[$SampleType]) ? $OptimFROGbitsPerSampleTypeLookup[$SampleType] :
false);
329 static $OptimFROGchannelConfigurationLookup = array(
333 return (isset($OptimFROGchannelConfigurationLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigurationLookup[$ChannelConfiguration] :
false);
337 static $OptimFROGchannelConfigNumChannelsLookup = array(
341 return (isset($OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration] :
false);
356 $EncoderVersion = number_format(((($EncoderID & 0xF0) >> 4) + 4500) / 1000, 3);
357 $EncoderSystemID = ($EncoderID & 0x0F);
359 static $OptimFROGencoderSystemLookup = array(
360 0x00 =>
'Windows console',
361 0x01 =>
'Linux console',
364 return $EncoderVersion.
' ('.(isset($OptimFROGencoderSystemLookup[$EncoderSystemID]) ? $OptimFROGencoderSystemLookup[$EncoderSystemID] :
'undefined encoder type (0x'.dechex($EncoderSystemID).
')').
')';
371 $CompressionModeID = ($CompressionID & 0xF8) >> 3;
374 static $OptimFROGencoderModeLookup = array(
386 return (isset($OptimFROGencoderModeLookup[$CompressionModeID]) ? $OptimFROGencoderModeLookup[$CompressionModeID] :
'undefined mode (0x'.str_pad(dechex($CompressionModeID), 2,
'0', STR_PAD_LEFT).
')');
394 $CompressionSpeedupID = ($CompressionID & 0x07);
396 static $OptimFROGencoderSpeedupLookup = array(
402 return (isset($OptimFROGencoderSpeedupLookup[$CompressionSpeedupID]) ? $OptimFROGencoderSpeedupLookup[$CompressionSpeedupID] :
'undefined mode (0x'.dechex($CompressionSpeedupID));