ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_optimfrog Class Reference
+ Inheritance diagram for getid3_optimfrog:
+ Collaboration diagram for getid3_optimfrog:

Public Member Functions

 getid3_optimfrog (&$fd, &$ThisFileInfo)
 
 ParseOptimFROGheader42 (&$fd, &$ThisFileInfo)
 
 ParseOptimFROGheader45 (&$fd, &$ThisFileInfo)
 
 OptimFROGsampleTypeLookup ($SampleType)
 
 OptimFROGbitsPerSampleTypeLookup ($SampleType)
 
 OptimFROGchannelConfigurationLookup ($ChannelConfiguration)
 
 OptimFROGchannelConfigNumChannelsLookup ($ChannelConfiguration)
 
 OptimFROGencoderNameLookup ($EncoderID)
 
 OptimFROGcompressionLookup ($CompressionID)
 
 OptimFROGspeedupLookup ($CompressionID)
 
 Analyze ()
 
 ParseOptimFROGheader42 ()
 
 ParseOptimFROGheader45 ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Static Public Member Functions

static OptimFROGsampleTypeLookup ($SampleType)
 
static OptimFROGbitsPerSampleTypeLookup ($SampleType)
 
static OptimFROGchannelConfigurationLookup ($ChannelConfiguration)
 
static OptimFROGchannelConfigNumChannelsLookup ($ChannelConfiguration)
 
static OptimFROGencoderNameLookup ($EncoderID)
 
static OptimFROGcompressionLookup ($CompressionID)
 
static OptimFROGspeedupLookup ($CompressionID)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

Definition at line 18 of file module.audio.optimfrog.php.

Member Function Documentation

◆ Analyze()

getid3_optimfrog::Analyze ( )

Reimplemented from getid3_handler.

Definition at line 22 of file module.audio.optimfrog.php.

22 {
23 $info = &$this->getid3->info;
24
25 $info['fileformat'] = 'ofr';
26 $info['audio']['dataformat'] = 'ofr';
27 $info['audio']['bitrate_mode'] = 'vbr';
28 $info['audio']['lossless'] = true;
29
30 $this->fseek($info['avdataoffset']);
31 $OFRheader = $this->fread(8);
32 if (substr($OFRheader, 0, 5) == '*RIFF') {
33
34 return $this->ParseOptimFROGheader42();
35
36 } elseif (substr($OFRheader, 0, 3) == 'OFR') {
37
38 return $this->ParseOptimFROGheader45();
39
40 }
41
42 $info['error'][] = 'Expecting "*RIFF" or "OFR " at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($OFRheader).'"';
43 unset($info['fileformat']);
44 return false;
45 }
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
fread($bytes)
Definition: getid3.php:1685
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
$info
Definition: example_052.php:80

References $info, getid3_handler\fread(), getid3_handler\fseek(), ParseOptimFROGheader42(), ParseOptimFROGheader45(), and getid3_lib\PrintHexBytes().

+ Here is the call graph for this function:

◆ getid3_optimfrog()

getid3_optimfrog::getid3_optimfrog ( $fd,
$ThisFileInfo 
)

Definition at line 21 of file module.audio.optimfrog.php.

21 {
22 $ThisFileInfo['fileformat'] = 'ofr';
23 $ThisFileInfo['audio']['dataformat'] = 'ofr';
24 $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
25 $ThisFileInfo['audio']['lossless'] = true;
26
27 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
28 $OFRheader = fread($fd, 8);
29 if (substr($OFRheader, 0, 5) == '*RIFF') {
30
31 return $this->ParseOptimFROGheader42($fd, $ThisFileInfo);
32
33 } elseif (substr($OFRheader, 0, 3) == 'OFR') {
34
35 return $this->ParseOptimFROGheader45($fd, $ThisFileInfo);
36
37 }
38
39 $ThisFileInfo['error'][] = 'Expecting "*RIFF" or "OFR " at offset '.$ThisFileInfo['avdataoffset'].', found "'.$OFRheader.'"';
40 unset($ThisFileInfo['fileformat']);
41 return false;
42 }

References getid3_handler\fread(), getid3_handler\fseek(), ParseOptimFROGheader42(), and ParseOptimFROGheader45().

+ Here is the call graph for this function:

◆ OptimFROGbitsPerSampleTypeLookup() [1/2]

getid3_optimfrog::OptimFROGbitsPerSampleTypeLookup (   $SampleType)

Definition at line 311 of file module.audio.optimfrog.php.

311 {
312 static $OptimFROGbitsPerSampleTypeLookup = array(
313 0 => 8,
314 1 => 8,
315 2 => 16,
316 3 => 16,
317 4 => 24,
318 5 => 24,
319 6 => 32,
320 7 => 32,
321 8 => 32,
322 9 => 32,
323 10 => 32
324 );
325 return (isset($OptimFROGbitsPerSampleTypeLookup[$SampleType]) ? $OptimFROGbitsPerSampleTypeLookup[$SampleType] : false);
326 }

Referenced by ParseOptimFROGheader45().

+ Here is the caller graph for this function:

◆ OptimFROGbitsPerSampleTypeLookup() [2/2]

static getid3_optimfrog::OptimFROGbitsPerSampleTypeLookup (   $SampleType)
static

Definition at line 334 of file module.audio.optimfrog.php.

334 {
335 static $OptimFROGbitsPerSampleTypeLookup = array(
336 0 => 8,
337 1 => 8,
338 2 => 16,
339 3 => 16,
340 4 => 24,
341 5 => 24,
342 6 => 32,
343 7 => 32,
344 8 => 32,
345 9 => 32,
346 10 => 32
347 );
348 return (isset($OptimFROGbitsPerSampleTypeLookup[$SampleType]) ? $OptimFROGbitsPerSampleTypeLookup[$SampleType] : false);
349 }

◆ OptimFROGchannelConfigNumChannelsLookup() [1/2]

getid3_optimfrog::OptimFROGchannelConfigNumChannelsLookup (   $ChannelConfiguration)

Definition at line 336 of file module.audio.optimfrog.php.

336 {
337 static $OptimFROGchannelConfigNumChannelsLookup = array(
338 0 => 1,
339 1 => 2
340 );
341 return (isset($OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration] : false);
342 }

Referenced by ParseOptimFROGheader45().

+ Here is the caller graph for this function:

◆ OptimFROGchannelConfigNumChannelsLookup() [2/2]

static getid3_optimfrog::OptimFROGchannelConfigNumChannelsLookup (   $ChannelConfiguration)
static

Definition at line 359 of file module.audio.optimfrog.php.

359 {
360 static $OptimFROGchannelConfigNumChannelsLookup = array(
361 0 => 1,
362 1 => 2
363 );
364 return (isset($OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigNumChannelsLookup[$ChannelConfiguration] : false);
365 }

◆ OptimFROGchannelConfigurationLookup() [1/2]

getid3_optimfrog::OptimFROGchannelConfigurationLookup (   $ChannelConfiguration)

Definition at line 328 of file module.audio.optimfrog.php.

328 {
329 static $OptimFROGchannelConfigurationLookup = array(
330 0 => 'mono',
331 1 => 'stereo'
332 );
333 return (isset($OptimFROGchannelConfigurationLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigurationLookup[$ChannelConfiguration] : false);
334 }

Referenced by ParseOptimFROGheader45().

+ Here is the caller graph for this function:

◆ OptimFROGchannelConfigurationLookup() [2/2]

static getid3_optimfrog::OptimFROGchannelConfigurationLookup (   $ChannelConfiguration)
static

Definition at line 351 of file module.audio.optimfrog.php.

351 {
352 static $OptimFROGchannelConfigurationLookup = array(
353 0 => 'mono',
354 1 => 'stereo'
355 );
356 return (isset($OptimFROGchannelConfigurationLookup[$ChannelConfiguration]) ? $OptimFROGchannelConfigurationLookup[$ChannelConfiguration] : false);
357 }

◆ OptimFROGcompressionLookup() [1/2]

getid3_optimfrog::OptimFROGcompressionLookup (   $CompressionID)

Definition at line 367 of file module.audio.optimfrog.php.

367 {
368 // mode = compression >> 3
369 // speedup = compression & 0x07
370
371 $CompressionModeID = ($CompressionID & 0xF8) >> 3;
372 //$CompressionSpeedupID = ($CompressionID & 0x07);
373
374 static $OptimFROGencoderModeLookup = array(
375 0x00 => 'fast',
376 0x01 => 'normal',
377 0x02 => 'high',
378 0x03 => 'extra', // extranew (some versions)
379 0x04 => 'best', // bestnew (some versions)
380 0x05 => 'ultra',
381 0x06 => 'insane',
382 0x07 => 'highnew',
383 0x08 => 'extranew',
384 0x09 => 'bestnew'
385 );
386 return (isset($OptimFROGencoderModeLookup[$CompressionModeID]) ? $OptimFROGencoderModeLookup[$CompressionModeID] : 'undefined mode (0x'.str_pad(dechex($CompressionModeID), 2, '0', STR_PAD_LEFT).')');
387 }

Referenced by ParseOptimFROGheader45().

+ Here is the caller graph for this function:

◆ OptimFROGcompressionLookup() [2/2]

static getid3_optimfrog::OptimFROGcompressionLookup (   $CompressionID)
static

Definition at line 390 of file module.audio.optimfrog.php.

390 {
391 // mode = compression >> 3
392 // speedup = compression & 0x07
393
394 $CompressionModeID = ($CompressionID & 0xF8) >> 3;
395 //$CompressionSpeedupID = ($CompressionID & 0x07);
396
397 static $OptimFROGencoderModeLookup = array(
398 0x00 => 'fast',
399 0x01 => 'normal',
400 0x02 => 'high',
401 0x03 => 'extra', // extranew (some versions)
402 0x04 => 'best', // bestnew (some versions)
403 0x05 => 'ultra',
404 0x06 => 'insane',
405 0x07 => 'highnew',
406 0x08 => 'extranew',
407 0x09 => 'bestnew'
408 );
409 return (isset($OptimFROGencoderModeLookup[$CompressionModeID]) ? $OptimFROGencoderModeLookup[$CompressionModeID] : 'undefined mode (0x'.str_pad(dechex($CompressionModeID), 2, '0', STR_PAD_LEFT).')');
410 }

◆ OptimFROGencoderNameLookup() [1/2]

getid3_optimfrog::OptimFROGencoderNameLookup (   $EncoderID)

Definition at line 352 of file module.audio.optimfrog.php.

352 {
353 // version = (encoderID >> 4) + 4500
354 // system = encoderID & 0xF
355
356 $EncoderVersion = number_format(((($EncoderID & 0xF0) >> 4) + 4500) / 1000, 3);
357 $EncoderSystemID = ($EncoderID & 0x0F);
358
359 static $OptimFROGencoderSystemLookup = array(
360 0x00 => 'Windows console',
361 0x01 => 'Linux console',
362 0x0F => 'unknown'
363 );
364 return $EncoderVersion.' ('.(isset($OptimFROGencoderSystemLookup[$EncoderSystemID]) ? $OptimFROGencoderSystemLookup[$EncoderSystemID] : 'undefined encoder type (0x'.dechex($EncoderSystemID).')').')';
365 }

Referenced by ParseOptimFROGheader45().

+ Here is the caller graph for this function:

◆ OptimFROGencoderNameLookup() [2/2]

static getid3_optimfrog::OptimFROGencoderNameLookup (   $EncoderID)
static

Definition at line 375 of file module.audio.optimfrog.php.

375 {
376 // version = (encoderID >> 4) + 4500
377 // system = encoderID & 0xF
378
379 $EncoderVersion = number_format(((($EncoderID & 0xF0) >> 4) + 4500) / 1000, 3);
380 $EncoderSystemID = ($EncoderID & 0x0F);
381
382 static $OptimFROGencoderSystemLookup = array(
383 0x00 => 'Windows console',
384 0x01 => 'Linux console',
385 0x0F => 'unknown'
386 );
387 return $EncoderVersion.' ('.(isset($OptimFROGencoderSystemLookup[$EncoderSystemID]) ? $OptimFROGencoderSystemLookup[$EncoderSystemID] : 'undefined encoder type (0x'.dechex($EncoderSystemID).')').')';
388 }

◆ OptimFROGsampleTypeLookup() [1/2]

getid3_optimfrog::OptimFROGsampleTypeLookup (   $SampleType)

Definition at line 294 of file module.audio.optimfrog.php.

294 {
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)'
307 );
308 return (isset($OptimFROGsampleTypeLookup[$SampleType]) ? $OptimFROGsampleTypeLookup[$SampleType] : false);
309 }

Referenced by ParseOptimFROGheader45().

+ Here is the caller graph for this function:

◆ OptimFROGsampleTypeLookup() [2/2]

static getid3_optimfrog::OptimFROGsampleTypeLookup (   $SampleType)
static

Definition at line 317 of file module.audio.optimfrog.php.

317 {
318 static $OptimFROGsampleTypeLookup = array(
319 0 => 'unsigned int (8-bit)',
320 1 => 'signed int (8-bit)',
321 2 => 'unsigned int (16-bit)',
322 3 => 'signed int (16-bit)',
323 4 => 'unsigned int (24-bit)',
324 5 => 'signed int (24-bit)',
325 6 => 'unsigned int (32-bit)',
326 7 => 'signed int (32-bit)',
327 8 => 'float 0.24 (32-bit)',
328 9 => 'float 16.8 (32-bit)',
329 10 => 'float 24.0 (32-bit)'
330 );
331 return (isset($OptimFROGsampleTypeLookup[$SampleType]) ? $OptimFROGsampleTypeLookup[$SampleType] : false);
332 }

◆ OptimFROGspeedupLookup() [1/2]

getid3_optimfrog::OptimFROGspeedupLookup (   $CompressionID)

Definition at line 389 of file module.audio.optimfrog.php.

389 {
390 // mode = compression >> 3
391 // speedup = compression & 0x07
392
393 //$CompressionModeID = ($CompressionID & 0xF8) >> 3;
394 $CompressionSpeedupID = ($CompressionID & 0x07);
395
396 static $OptimFROGencoderSpeedupLookup = array(
397 0x00 => '1x',
398 0x01 => '2x',
399 0x02 => '4x'
400 );
401
402 return (isset($OptimFROGencoderSpeedupLookup[$CompressionSpeedupID]) ? $OptimFROGencoderSpeedupLookup[$CompressionSpeedupID] : 'undefined mode (0x'.dechex($CompressionSpeedupID));
403 }

Referenced by ParseOptimFROGheader45().

+ Here is the caller graph for this function:

◆ OptimFROGspeedupLookup() [2/2]

static getid3_optimfrog::OptimFROGspeedupLookup (   $CompressionID)
static

Definition at line 412 of file module.audio.optimfrog.php.

412 {
413 // mode = compression >> 3
414 // speedup = compression & 0x07
415
416 //$CompressionModeID = ($CompressionID & 0xF8) >> 3;
417 $CompressionSpeedupID = ($CompressionID & 0x07);
418
419 static $OptimFROGencoderSpeedupLookup = array(
420 0x00 => '1x',
421 0x01 => '2x',
422 0x02 => '4x'
423 );
424 return (isset($OptimFROGencoderSpeedupLookup[$CompressionSpeedupID]) ? $OptimFROGencoderSpeedupLookup[$CompressionSpeedupID] : 'undefined mode (0x'.dechex($CompressionSpeedupID));
425 }

◆ ParseOptimFROGheader42() [1/2]

getid3_optimfrog::ParseOptimFROGheader42 ( $fd,
$ThisFileInfo 
)

Definition at line 45 of file module.audio.optimfrog.php.

45 {
46 // for fileformat of v4.21 and older
47
48 fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
49 $OptimFROGheaderData = fread($fd, 45);
50 $ThisFileInfo['avdataoffset'] = 45;
51
52 $OptimFROGencoderVersion_raw = getid3_lib::LittleEndian2Int(substr($OptimFROGheaderData, 0, 1));
53 $OptimFROGencoderVersion_major = floor($OptimFROGencoderVersion_raw / 10);
54 $OptimFROGencoderVersion_minor = $OptimFROGencoderVersion_raw - ($OptimFROGencoderVersion_major * 10);
55 $RIFFdata = substr($OptimFROGheaderData, 1, 44);
56 $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
57 $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
58
59 if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
60 $ThisFileInfo['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
61 fseek($fd, $ThisFileInfo['avdataend'], SEEK_SET);
62 $RIFFdata .= fread($fd, $OrignalRIFFheaderSize - $OrignalRIFFdataSize);
63 }
64
65 // move the data chunk after all other chunks (if any)
66 // so that the RIFF parser doesn't see EOF when trying
67 // to skip over the data chunk
68 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
69 getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo);
70
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'];
77
78 return true;
79 }
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
ParseRIFFdata(&$RIFFdata, &$ThisFileInfo)

References getid3_handler\fread(), getid3_handler\fseek(), getid3_lib\LittleEndian2Int(), and getid3_riff\ParseRIFFdata().

+ Here is the call graph for this function:

◆ ParseOptimFROGheader42() [2/2]

getid3_optimfrog::ParseOptimFROGheader42 ( )

Definition at line 48 of file module.audio.optimfrog.php.

48 {
49 // for fileformat of v4.21 and older
50
51 $info = &$this->getid3->info;
52 $this->fseek($info['avdataoffset']);
53 $OptimFROGheaderData = $this->fread(45);
54 $info['avdataoffset'] = 45;
55
56 $OptimFROGencoderVersion_raw = getid3_lib::LittleEndian2Int(substr($OptimFROGheaderData, 0, 1));
57 $OptimFROGencoderVersion_major = floor($OptimFROGencoderVersion_raw / 10);
58 $OptimFROGencoderVersion_minor = $OptimFROGencoderVersion_raw - ($OptimFROGencoderVersion_major * 10);
59 $RIFFdata = substr($OptimFROGheaderData, 1, 44);
60 $OrignalRIFFheaderSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 4, 4)) + 8;
61 $OrignalRIFFdataSize = getid3_lib::LittleEndian2Int(substr($RIFFdata, 40, 4)) + 44;
62
63 if ($OrignalRIFFheaderSize > $OrignalRIFFdataSize) {
64 $info['avdataend'] -= ($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
65 $this->fseek($info['avdataend']);
66 $RIFFdata .= $this->fread($OrignalRIFFheaderSize - $OrignalRIFFdataSize);
67 }
68
69 // move the data chunk after all other chunks (if any)
70 // so that the RIFF parser doesn't see EOF when trying
71 // to skip over the data chunk
72 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
73
74 $getid3_temp = new getID3();
75 $getid3_temp->openfile($this->getid3->filename);
76 $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
77 $getid3_temp->info['avdataend'] = $info['avdataend'];
78 $getid3_riff = new getid3_riff($getid3_temp);
79 $getid3_riff->ParseRIFFdata($RIFFdata);
80 $info['riff'] = $getid3_temp->info['riff'];
81
82 $info['audio']['encoder'] = 'OptimFROG '.$OptimFROGencoderVersion_major.'.'.$OptimFROGencoderVersion_minor;
83 $info['audio']['channels'] = $info['riff']['audio'][0]['channels'];
84 $info['audio']['sample_rate'] = $info['riff']['audio'][0]['sample_rate'];
85 $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample'];
86 $info['playtime_seconds'] = $OrignalRIFFdataSize / ($info['audio']['channels'] * $info['audio']['sample_rate'] * ($info['audio']['bits_per_sample'] / 8));
87 $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
88
89 unset($getid3_riff, $getid3_temp, $RIFFdata);
90
91 return true;
92 }

References $info, getid3_handler\fread(), getid3_handler\fseek(), and getid3_lib\LittleEndian2Int().

Referenced by Analyze(), and getid3_optimfrog().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseOptimFROGheader45() [1/2]

getid3_optimfrog::ParseOptimFROGheader45 ( $fd,
$ThisFileInfo 
)

Definition at line 82 of file module.audio.optimfrog.php.

82 {
83 // for fileformat of v4.50a and higher
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);
92 $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 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 // shortcut
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 // good
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
122 $thisfile_ofr_thisblock['total_samples'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 6));
123 $offset += 6;
124 $thisfile_ofr_thisblock['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
125 $thisfile_ofr_thisblock['sample_type'] = $this->OptimFROGsampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']);
126 $offset += 1;
127 $thisfile_ofr_thisblock['channel_config'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
128 $thisfile_ofr_thisblock['channels'] = $thisfile_ofr_thisblock['channel_config'];
129 $offset += 1;
130 $thisfile_ofr_thisblock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
131 $offset += 4;
132
133 if ($BlockSize > 12) {
134
135 // OFR 4.504b or higher
136 $thisfile_ofr_thisblock['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($thisfile_ofr_thisblock['channel_config']);
137 $thisfile_ofr_thisblock['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
138 $thisfile_ofr_thisblock['encoder'] = $this->OptimFROGencoderNameLookup($thisfile_ofr_thisblock['raw']['encoder_id']);
139 $offset += 2;
140 $thisfile_ofr_thisblock['raw']['compression'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
141 $thisfile_ofr_thisblock['compression'] = $this->OptimFROGcompressionLookup($thisfile_ofr_thisblock['raw']['compression']);
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) { // v4.507
149 if (strtolower(getid3_lib::fileextension($ThisFileInfo['filename'])) == 'ofs') {
150 // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference
151 // between lossless and lossy other than the file extension.
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'];
161 $ThisFileInfo['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']);
162 break;
163
164
165 case 'COMP':
166 // unlike other block types, there CAN be multiple COMP blocks
167
168 $COMPdata['offset'] = $BlockOffset;
169 $COMPdata['size'] = $BlockSize;
170
171 if ($ThisFileInfo['avdataoffset'] == 0) {
172 $ThisFileInfo['avdataoffset'] = $BlockOffset;
173 }
174
175 // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data
176 $BlockData .= fread($fd, 14);
177 fseek($fd, $BlockSize - 14, SEEK_CUR);
178
179 $COMPdata['crc_32'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
180 $offset += 4;
181 $COMPdata['sample_count'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
182 $offset += 4;
183 $COMPdata['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
184 $COMPdata['sample_type'] = $this->OptimFROGsampleTypeLookup($COMPdata['raw']['sample_type']);
185 $offset += 1;
186 $COMPdata['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
187 $COMPdata['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($COMPdata['raw']['channel_configuration']);
188 $offset += 1;
189 $COMPdata['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
190 //$COMPdata['algorithm'] = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']);
191 $offset += 2;
192
193 if ($ThisFileInfo['ofr']['OFR ']['size'] > 12) {
194
195 // OFR 4.504b or higher
196 $COMPdata['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
197 $COMPdata['encoder'] = $this->OptimFROGencoderNameLookup($COMPdata['raw']['encoder_id']);
198 $offset += 2;
199
200 }
201
202 if ($COMPdata['crc_32'] == 0x454E4F4E) {
203 // ASCII value of 'NONE' - placeholder value in v4.50a
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 // block contains no useful meta data - simply note and skip
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 // APEtag v2
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 // APEtag v2
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 // move the data chunk after all other chunks (if any)
285 // so that the RIFF parser doesn't see EOF when trying
286 // to skip over the data chunk
287 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
288 getid3_riff::ParseRIFFdata($RIFFdata, $ThisFileInfo);
289
290 return true;
291 }
fileextension($filename, $numextensions=1)
Definition: getid3.lib.php:392
OptimFROGcompressionLookup($CompressionID)
OptimFROGbitsPerSampleTypeLookup($SampleType)
OptimFROGsampleTypeLookup($SampleType)
OptimFROGspeedupLookup($CompressionID)
OptimFROGencoderNameLookup($EncoderID)
OptimFROGchannelConfigNumChannelsLookup($ChannelConfiguration)
OptimFROGchannelConfigurationLookup($ChannelConfiguration)

References getid3_handler\feof(), getid3_lib\fileextension(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), OptimFROGbitsPerSampleTypeLookup(), OptimFROGchannelConfigNumChannelsLookup(), OptimFROGchannelConfigurationLookup(), OptimFROGcompressionLookup(), OptimFROGencoderNameLookup(), OptimFROGsampleTypeLookup(), OptimFROGspeedupLookup(), getid3_riff\ParseRIFFdata(), and getid3_lib\PrintHexBytes().

+ Here is the call graph for this function:

◆ ParseOptimFROGheader45() [2/2]

getid3_optimfrog::ParseOptimFROGheader45 ( )

Definition at line 95 of file module.audio.optimfrog.php.

95 {
96 // for fileformat of v4.50a and higher
97
98 $info = &$this->getid3->info;
99 $RIFFdata = '';
100 $this->fseek($info['avdataoffset']);
101 while (!feof($this->getid3->fp) && ($this->ftell() < $info['avdataend'])) {
102 $BlockOffset = $this->ftell();
103 $BlockData = $this->fread(8);
104 $offset = 8;
105 $BlockName = substr($BlockData, 0, 4);
106 $BlockSize = getid3_lib::LittleEndian2Int(substr($BlockData, 4, 4));
107
108 if ($BlockName == 'OFRX') {
109 $BlockName = 'OFR ';
110 }
111 if (!isset($info['ofr'][$BlockName])) {
112 $info['ofr'][$BlockName] = array();
113 }
114 $thisfile_ofr_thisblock = &$info['ofr'][$BlockName];
115
116 switch ($BlockName) {
117 case 'OFR ':
118
119 // shortcut
120 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
121 $thisfile_ofr_thisblock['size'] = $BlockSize;
122
123 $info['audio']['encoder'] = 'OptimFROG 4.50 alpha';
124 switch ($BlockSize) {
125 case 12:
126 case 15:
127 // good
128 break;
129
130 default:
131 $info['warning'][] = '"'.$BlockName.'" contains more data than expected (expected 12 or 15 bytes, found '.$BlockSize.' bytes)';
132 break;
133 }
134 $BlockData .= $this->fread($BlockSize);
135
136 $thisfile_ofr_thisblock['total_samples'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 6));
137 $offset += 6;
138 $thisfile_ofr_thisblock['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
139 $thisfile_ofr_thisblock['sample_type'] = $this->OptimFROGsampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']);
140 $offset += 1;
141 $thisfile_ofr_thisblock['channel_config'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
142 $thisfile_ofr_thisblock['channels'] = $thisfile_ofr_thisblock['channel_config'];
143 $offset += 1;
144 $thisfile_ofr_thisblock['sample_rate'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
145 $offset += 4;
146
147 if ($BlockSize > 12) {
148
149 // OFR 4.504b or higher
150 $thisfile_ofr_thisblock['channels'] = $this->OptimFROGchannelConfigNumChannelsLookup($thisfile_ofr_thisblock['channel_config']);
151 $thisfile_ofr_thisblock['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
152 $thisfile_ofr_thisblock['encoder'] = $this->OptimFROGencoderNameLookup($thisfile_ofr_thisblock['raw']['encoder_id']);
153 $offset += 2;
154 $thisfile_ofr_thisblock['raw']['compression'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
155 $thisfile_ofr_thisblock['compression'] = $this->OptimFROGcompressionLookup($thisfile_ofr_thisblock['raw']['compression']);
156 $thisfile_ofr_thisblock['speedup'] = $this->OptimFROGspeedupLookup($thisfile_ofr_thisblock['raw']['compression']);
157 $offset += 1;
158
159 $info['audio']['encoder'] = 'OptimFROG '.$thisfile_ofr_thisblock['encoder'];
160 $info['audio']['encoder_options'] = '--mode '.$thisfile_ofr_thisblock['compression'];
161
162 if ((($thisfile_ofr_thisblock['raw']['encoder_id'] & 0xF0) >> 4) == 7) { // v4.507
163 if (strtolower(getid3_lib::fileextension($info['filename'])) == 'ofs') {
164 // OptimFROG DualStream format is lossy, but as of v4.507 there is no way to tell the difference
165 // between lossless and lossy other than the file extension.
166 $info['audio']['dataformat'] = 'ofs';
167 $info['audio']['lossless'] = true;
168 }
169 }
170
171 }
172
173 $info['audio']['channels'] = $thisfile_ofr_thisblock['channels'];
174 $info['audio']['sample_rate'] = $thisfile_ofr_thisblock['sample_rate'];
175 $info['audio']['bits_per_sample'] = $this->OptimFROGbitsPerSampleTypeLookup($thisfile_ofr_thisblock['raw']['sample_type']);
176 break;
177
178
179 case 'COMP':
180 // unlike other block types, there CAN be multiple COMP blocks
181
182 $COMPdata['offset'] = $BlockOffset;
183 $COMPdata['size'] = $BlockSize;
184
185 if ($info['avdataoffset'] == 0) {
186 $info['avdataoffset'] = $BlockOffset;
187 }
188
189 // Only interested in first 14 bytes (only first 12 needed for v4.50 alpha), not actual audio data
190 $BlockData .= $this->fread(14);
191 $this->fseek($BlockSize - 14, SEEK_CUR);
192
193 $COMPdata['crc_32'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
194 $offset += 4;
195 $COMPdata['sample_count'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 4));
196 $offset += 4;
197 $COMPdata['raw']['sample_type'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
198 $COMPdata['sample_type'] = $this->OptimFROGsampleTypeLookup($COMPdata['raw']['sample_type']);
199 $offset += 1;
200 $COMPdata['raw']['channel_configuration'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 1));
201 $COMPdata['channel_configuration'] = $this->OptimFROGchannelConfigurationLookup($COMPdata['raw']['channel_configuration']);
202 $offset += 1;
203 $COMPdata['raw']['algorithm_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
204 //$COMPdata['algorithm'] = OptimFROGalgorithmNameLookup($COMPdata['raw']['algorithm_id']);
205 $offset += 2;
206
207 if ($info['ofr']['OFR ']['size'] > 12) {
208
209 // OFR 4.504b or higher
210 $COMPdata['raw']['encoder_id'] = getid3_lib::LittleEndian2Int(substr($BlockData, $offset, 2));
211 $COMPdata['encoder'] = $this->OptimFROGencoderNameLookup($COMPdata['raw']['encoder_id']);
212 $offset += 2;
213
214 }
215
216 if ($COMPdata['crc_32'] == 0x454E4F4E) {
217 // ASCII value of 'NONE' - placeholder value in v4.50a
218 $COMPdata['crc_32'] = false;
219 }
220
221 $thisfile_ofr_thisblock[] = $COMPdata;
222 break;
223
224 case 'HEAD':
225 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
226 $thisfile_ofr_thisblock['size'] = $BlockSize;
227
228 $RIFFdata .= $this->fread($BlockSize);
229 break;
230
231 case 'TAIL':
232 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
233 $thisfile_ofr_thisblock['size'] = $BlockSize;
234
235 if ($BlockSize > 0) {
236 $RIFFdata .= $this->fread($BlockSize);
237 }
238 break;
239
240 case 'RECV':
241 // block contains no useful meta data - simply note and skip
242
243 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
244 $thisfile_ofr_thisblock['size'] = $BlockSize;
245
246 $this->fseek($BlockSize, SEEK_CUR);
247 break;
248
249
250 case 'APET':
251 // APEtag v2
252
253 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
254 $thisfile_ofr_thisblock['size'] = $BlockSize;
255 $info['warning'][] = 'APEtag processing inside OptimFROG not supported in this version ('.$this->getid3->version().') of getID3()';
256
257 $this->fseek($BlockSize, SEEK_CUR);
258 break;
259
260
261 case 'MD5 ':
262 // APEtag v2
263
264 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
265 $thisfile_ofr_thisblock['size'] = $BlockSize;
266
267 if ($BlockSize == 16) {
268
269 $thisfile_ofr_thisblock['md5_binary'] = $this->fread($BlockSize);
270 $thisfile_ofr_thisblock['md5_string'] = getid3_lib::PrintHexBytes($thisfile_ofr_thisblock['md5_binary'], true, false, false);
271 $info['md5_data_source'] = $thisfile_ofr_thisblock['md5_string'];
272
273 } else {
274
275 $info['warning'][] = 'Expecting block size of 16 in "MD5 " chunk, found '.$BlockSize.' instead';
276 $this->fseek($BlockSize, SEEK_CUR);
277
278 }
279 break;
280
281
282 default:
283 $thisfile_ofr_thisblock['offset'] = $BlockOffset;
284 $thisfile_ofr_thisblock['size'] = $BlockSize;
285
286 $info['warning'][] = 'Unhandled OptimFROG block type "'.$BlockName.'" at offset '.$thisfile_ofr_thisblock['offset'];
287 $this->fseek($BlockSize, SEEK_CUR);
288 break;
289 }
290 }
291 if (isset($info['ofr']['TAIL']['offset'])) {
292 $info['avdataend'] = $info['ofr']['TAIL']['offset'];
293 }
294
295 $info['playtime_seconds'] = (float) $info['ofr']['OFR ']['total_samples'] / ($info['audio']['channels'] * $info['audio']['sample_rate']);
296 $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
297
298 // move the data chunk after all other chunks (if any)
299 // so that the RIFF parser doesn't see EOF when trying
300 // to skip over the data chunk
301 $RIFFdata = substr($RIFFdata, 0, 36).substr($RIFFdata, 44).substr($RIFFdata, 36, 8);
302
303 $getid3_temp = new getID3();
304 $getid3_temp->openfile($this->getid3->filename);
305 $getid3_temp->info['avdataoffset'] = $info['avdataoffset'];
306 $getid3_temp->info['avdataend'] = $info['avdataend'];
307 $getid3_riff = new getid3_riff($getid3_temp);
308 $getid3_riff->ParseRIFFdata($RIFFdata);
309 $info['riff'] = $getid3_temp->info['riff'];
310
311 unset($getid3_riff, $getid3_temp, $RIFFdata);
312
313 return true;
314 }

References $info, getid3_handler\feof(), getid3_lib\fileextension(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), OptimFROGbitsPerSampleTypeLookup(), OptimFROGchannelConfigNumChannelsLookup(), OptimFROGchannelConfigurationLookup(), OptimFROGcompressionLookup(), OptimFROGencoderNameLookup(), OptimFROGsampleTypeLookup(), OptimFROGspeedupLookup(), and getid3_lib\PrintHexBytes().

Referenced by Analyze(), and getid3_optimfrog().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: