ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_monkey Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_monkey:
+ Collaboration diagram for getid3_monkey:

Public Member Functions

 getid3_monkey (&$fd, &$ThisFileInfo)
 
 MonkeyCompressionLevelNameLookup ($compressionlevel)
 
 MonkeySamplesPerFrame ($versionid, $compressionlevel)
 
 Analyze ()
 
 MonkeyCompressionLevelNameLookup ($compressionlevel)
 
 MonkeySamplesPerFrame ($versionid, $compressionlevel)
 
- 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)
 

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

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.audio.monkey.php.

Member Function Documentation

◆ Analyze()

getid3_monkey::Analyze ( )

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

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

21  {
22  $info = &$this->getid3->info;
23 
24  // based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de>
25  // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
26 
27  $info['fileformat'] = 'mac';
28  $info['audio']['dataformat'] = 'mac';
29  $info['audio']['bitrate_mode'] = 'vbr';
30  $info['audio']['lossless'] = true;
31 
32  $info['monkeys_audio']['raw'] = array();
33  $thisfile_monkeysaudio = &$info['monkeys_audio'];
34  $thisfile_monkeysaudio_raw = &$thisfile_monkeysaudio['raw'];
35 
36  $this->fseek($info['avdataoffset']);
37  $MACheaderData = $this->fread(74);
38 
39  $thisfile_monkeysaudio_raw['magic'] = substr($MACheaderData, 0, 4);
40  $magic = 'MAC ';
41  if ($thisfile_monkeysaudio_raw['magic'] != $magic) {
42  $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($thisfile_monkeysaudio_raw['magic']).'"';
43  unset($info['fileformat']);
44  return false;
45  }
46  $thisfile_monkeysaudio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 4, 2)); // appears to be uint32 in 3.98+
47 
48  if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) {
49  $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 6, 2));
50  $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 8, 2));
51  $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 10, 2));
52  $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 12, 4));
53  $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 16, 4));
54  $thisfile_monkeysaudio_raw['nWAVTerminatingBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 20, 4));
55  $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 24, 4));
56  $thisfile_monkeysaudio_raw['nFinalFrameSamples'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 28, 4));
57  $thisfile_monkeysaudio_raw['nPeakLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 32, 4));
58  $thisfile_monkeysaudio_raw['nSeekElements'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 38, 2));
59  $offset = 8;
60  } else {
61  $offset = 8;
62  // APE_DESCRIPTOR
63  $thisfile_monkeysaudio_raw['nDescriptorBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
64  $offset += 4;
65  $thisfile_monkeysaudio_raw['nHeaderBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
66  $offset += 4;
67  $thisfile_monkeysaudio_raw['nSeekTableBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
68  $offset += 4;
69  $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
70  $offset += 4;
71  $thisfile_monkeysaudio_raw['nAPEFrameDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
72  $offset += 4;
73  $thisfile_monkeysaudio_raw['nAPEFrameDataBytesHigh'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
74  $offset += 4;
75  $thisfile_monkeysaudio_raw['nTerminatingDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
76  $offset += 4;
77  $thisfile_monkeysaudio_raw['cFileMD5'] = substr($MACheaderData, $offset, 16);
78  $offset += 16;
79 
80  // APE_HEADER
81  $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
82  $offset += 2;
83  $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
84  $offset += 2;
85  $thisfile_monkeysaudio_raw['nBlocksPerFrame'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
86  $offset += 4;
87  $thisfile_monkeysaudio_raw['nFinalFrameBlocks'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
88  $offset += 4;
89  $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
90  $offset += 4;
91  $thisfile_monkeysaudio_raw['nBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
92  $offset += 2;
93  $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
94  $offset += 2;
95  $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
96  $offset += 4;
97  }
98 
99  $thisfile_monkeysaudio['flags']['8-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0001);
100  $thisfile_monkeysaudio['flags']['crc-32'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0002);
101  $thisfile_monkeysaudio['flags']['peak_level'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0004);
102  $thisfile_monkeysaudio['flags']['24-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0008);
103  $thisfile_monkeysaudio['flags']['seek_elements'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0010);
104  $thisfile_monkeysaudio['flags']['no_wav_header'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0020);
105  $thisfile_monkeysaudio['version'] = $thisfile_monkeysaudio_raw['nVersion'] / 1000;
106  $thisfile_monkeysaudio['compression'] = $this->MonkeyCompressionLevelNameLookup($thisfile_monkeysaudio_raw['nCompressionLevel']);
107  if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) {
108  $thisfile_monkeysaudio['samples_per_frame'] = $this->MonkeySamplesPerFrame($thisfile_monkeysaudio_raw['nVersion'], $thisfile_monkeysaudio_raw['nCompressionLevel']);
109  }
110  $thisfile_monkeysaudio['bits_per_sample'] = ($thisfile_monkeysaudio['flags']['24-bit'] ? 24 : ($thisfile_monkeysaudio['flags']['8-bit'] ? 8 : 16));
111  $thisfile_monkeysaudio['channels'] = $thisfile_monkeysaudio_raw['nChannels'];
112  $info['audio']['channels'] = $thisfile_monkeysaudio['channels'];
113  $thisfile_monkeysaudio['sample_rate'] = $thisfile_monkeysaudio_raw['nSampleRate'];
114  if ($thisfile_monkeysaudio['sample_rate'] == 0) {
115  $info['error'][] = 'Corrupt MAC file: frequency == zero';
116  return false;
117  }
118  $info['audio']['sample_rate'] = $thisfile_monkeysaudio['sample_rate'];
119  if ($thisfile_monkeysaudio['flags']['peak_level']) {
120  $thisfile_monkeysaudio['peak_level'] = $thisfile_monkeysaudio_raw['nPeakLevel'];
121  $thisfile_monkeysaudio['peak_ratio'] = $thisfile_monkeysaudio['peak_level'] / pow(2, $thisfile_monkeysaudio['bits_per_sample'] - 1);
122  }
123  if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
124  $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio_raw['nBlocksPerFrame']) + $thisfile_monkeysaudio_raw['nFinalFrameBlocks'];
125  } else {
126  $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio['samples_per_frame']) + $thisfile_monkeysaudio_raw['nFinalFrameSamples'];
127  }
128  $thisfile_monkeysaudio['playtime'] = $thisfile_monkeysaudio['samples'] / $thisfile_monkeysaudio['sample_rate'];
129  if ($thisfile_monkeysaudio['playtime'] == 0) {
130  $info['error'][] = 'Corrupt MAC file: playtime == zero';
131  return false;
132  }
133  $info['playtime_seconds'] = $thisfile_monkeysaudio['playtime'];
134  $thisfile_monkeysaudio['compressed_size'] = $info['avdataend'] - $info['avdataoffset'];
135  $thisfile_monkeysaudio['uncompressed_size'] = $thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * ($thisfile_monkeysaudio['bits_per_sample'] / 8);
136  if ($thisfile_monkeysaudio['uncompressed_size'] == 0) {
137  $info['error'][] = 'Corrupt MAC file: uncompressed_size == zero';
138  return false;
139  }
140  $thisfile_monkeysaudio['compression_ratio'] = $thisfile_monkeysaudio['compressed_size'] / ($thisfile_monkeysaudio['uncompressed_size'] + $thisfile_monkeysaudio_raw['nHeaderDataBytes']);
141  $thisfile_monkeysaudio['bitrate'] = (($thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * $thisfile_monkeysaudio['bits_per_sample']) / $thisfile_monkeysaudio['playtime']) * $thisfile_monkeysaudio['compression_ratio'];
142  $info['audio']['bitrate'] = $thisfile_monkeysaudio['bitrate'];
143 
144  // add size of MAC header to avdataoffset
145  if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
146  $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nDescriptorBytes'];
147  $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderBytes'];
148  $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nSeekTableBytes'];
149  $info['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderDataBytes'];
150 
151  $info['avdataend'] -= $thisfile_monkeysaudio_raw['nTerminatingDataBytes'];
152  } else {
153  $info['avdataoffset'] += $offset;
154  }
155 
156  if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
157  if ($thisfile_monkeysaudio_raw['cFileMD5'] === str_repeat("\x00", 16)) {
158  //$info['warning'][] = 'cFileMD5 is null';
159  } else {
160  $info['md5_data_source'] = '';
161  $md5 = $thisfile_monkeysaudio_raw['cFileMD5'];
162  for ($i = 0; $i < strlen($md5); $i++) {
163  $info['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
164  }
165  if (!preg_match('/^[0-9a-f]{32}$/', $info['md5_data_source'])) {
166  unset($info['md5_data_source']);
167  }
168  }
169  }
170 
171 
172 
173  $info['audio']['bits_per_sample'] = $thisfile_monkeysaudio['bits_per_sample'];
174  $info['audio']['encoder'] = 'MAC v'.number_format($thisfile_monkeysaudio['version'], 2);
175  $info['audio']['encoder_options'] = ucfirst($thisfile_monkeysaudio['compression']).' compression';
176 
177  return true;
178  }
MonkeyCompressionLevelNameLookup($compressionlevel)
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
$info
Definition: example_052.php:80
fread($bytes)
Definition: getid3.php:1685
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
MonkeySamplesPerFrame($versionid, $compressionlevel)
+ Here is the call graph for this function:

◆ getid3_monkey()

getid3_monkey::getid3_monkey ( $fd,
$ThisFileInfo 
)

Definition at line 20 of file module.audio.monkey.php.

References getid3_handler\fread(), getid3_handler\fseek(), getid3_lib\LittleEndian2Int(), MonkeyCompressionLevelNameLookup(), and MonkeySamplesPerFrame().

20  {
21  // based loosely on code from TMonkey by Jurgen Faul <jfaulØgmx*de>
22  // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
23 
24  $ThisFileInfo['fileformat'] = 'mac';
25  $ThisFileInfo['audio']['dataformat'] = 'mac';
26  $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
27  $ThisFileInfo['audio']['lossless'] = true;
28 
29  $ThisFileInfo['monkeys_audio']['raw'] = array();
30  $thisfile_monkeysaudio = &$ThisFileInfo['monkeys_audio'];
31  $thisfile_monkeysaudio_raw = &$thisfile_monkeysaudio['raw'];
32 
33  fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
34  $MACheaderData = fread($fd, 74);
35 
36  $thisfile_monkeysaudio_raw['magic'] = substr($MACheaderData, 0, 4);
37  if ($thisfile_monkeysaudio_raw['magic'] != 'MAC ') {
38  $ThisFileInfo['error'][] = 'Expecting "MAC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$thisfile_monkeysaudio_raw['magic'].'"';
39  unset($ThisFileInfo['fileformat']);
40  return false;
41  }
42  $thisfile_monkeysaudio_raw['nVersion'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 4, 2)); // appears to be uint32 in 3.98+
43 
44  if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) {
45  $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 6, 2));
46  $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 8, 2));
47  $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 10, 2));
48  $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 12, 4));
49  $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 16, 4));
50  $thisfile_monkeysaudio_raw['nWAVTerminatingBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 20, 4));
51  $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 24, 4));
52  $thisfile_monkeysaudio_raw['nFinalFrameSamples'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 28, 4));
53  $thisfile_monkeysaudio_raw['nPeakLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 32, 4));
54  $thisfile_monkeysaudio_raw['nSeekElements'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, 38, 2));
55  $offset = 8;
56  } else {
57  $offset = 8;
58  // APE_DESCRIPTOR
59  $thisfile_monkeysaudio_raw['nDescriptorBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
60  $offset += 4;
61  $thisfile_monkeysaudio_raw['nHeaderBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
62  $offset += 4;
63  $thisfile_monkeysaudio_raw['nSeekTableBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
64  $offset += 4;
65  $thisfile_monkeysaudio_raw['nHeaderDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
66  $offset += 4;
67  $thisfile_monkeysaudio_raw['nAPEFrameDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
68  $offset += 4;
69  $thisfile_monkeysaudio_raw['nAPEFrameDataBytesHigh'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
70  $offset += 4;
71  $thisfile_monkeysaudio_raw['nTerminatingDataBytes'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
72  $offset += 4;
73  $thisfile_monkeysaudio_raw['cFileMD5'] = substr($MACheaderData, $offset, 16);
74  $offset += 16;
75 
76  // APE_HEADER
77  $thisfile_monkeysaudio_raw['nCompressionLevel'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
78  $offset += 2;
79  $thisfile_monkeysaudio_raw['nFormatFlags'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
80  $offset += 2;
81  $thisfile_monkeysaudio_raw['nBlocksPerFrame'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
82  $offset += 4;
83  $thisfile_monkeysaudio_raw['nFinalFrameBlocks'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
84  $offset += 4;
85  $thisfile_monkeysaudio_raw['nTotalFrames'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
86  $offset += 4;
87  $thisfile_monkeysaudio_raw['nBitsPerSample'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
88  $offset += 2;
89  $thisfile_monkeysaudio_raw['nChannels'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 2));
90  $offset += 2;
91  $thisfile_monkeysaudio_raw['nSampleRate'] = getid3_lib::LittleEndian2Int(substr($MACheaderData, $offset, 4));
92  $offset += 4;
93  }
94 
95  $thisfile_monkeysaudio['flags']['8-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0001);
96  $thisfile_monkeysaudio['flags']['crc-32'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0002);
97  $thisfile_monkeysaudio['flags']['peak_level'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0004);
98  $thisfile_monkeysaudio['flags']['24-bit'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0008);
99  $thisfile_monkeysaudio['flags']['seek_elements'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0010);
100  $thisfile_monkeysaudio['flags']['no_wav_header'] = (bool) ($thisfile_monkeysaudio_raw['nFormatFlags'] & 0x0020);
101  $thisfile_monkeysaudio['version'] = $thisfile_monkeysaudio_raw['nVersion'] / 1000;
102  $thisfile_monkeysaudio['compression'] = $this->MonkeyCompressionLevelNameLookup($thisfile_monkeysaudio_raw['nCompressionLevel']);
103  if ($thisfile_monkeysaudio_raw['nVersion'] < 3980) {
104  $thisfile_monkeysaudio['samples_per_frame'] = $this->MonkeySamplesPerFrame($thisfile_monkeysaudio_raw['nVersion'], $thisfile_monkeysaudio_raw['nCompressionLevel']);
105  }
106  $thisfile_monkeysaudio['bits_per_sample'] = ($thisfile_monkeysaudio['flags']['24-bit'] ? 24 : ($thisfile_monkeysaudio['flags']['8-bit'] ? 8 : 16));
107  $thisfile_monkeysaudio['channels'] = $thisfile_monkeysaudio_raw['nChannels'];
108  $ThisFileInfo['audio']['channels'] = $thisfile_monkeysaudio['channels'];
109  $thisfile_monkeysaudio['sample_rate'] = $thisfile_monkeysaudio_raw['nSampleRate'];
110  if ($thisfile_monkeysaudio['sample_rate'] == 0) {
111  $ThisFileInfo['error'][] = 'Corrupt MAC file: frequency == zero';
112  return false;
113  }
114  $ThisFileInfo['audio']['sample_rate'] = $thisfile_monkeysaudio['sample_rate'];
115  if ($thisfile_monkeysaudio['flags']['peak_level']) {
116  $thisfile_monkeysaudio['peak_level'] = $thisfile_monkeysaudio_raw['nPeakLevel'];
117  $thisfile_monkeysaudio['peak_ratio'] = $thisfile_monkeysaudio['peak_level'] / pow(2, $thisfile_monkeysaudio['bits_per_sample'] - 1);
118  }
119  if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
120  $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio_raw['nBlocksPerFrame']) + $thisfile_monkeysaudio_raw['nFinalFrameBlocks'];
121  } else {
122  $thisfile_monkeysaudio['samples'] = (($thisfile_monkeysaudio_raw['nTotalFrames'] - 1) * $thisfile_monkeysaudio['samples_per_frame']) + $thisfile_monkeysaudio_raw['nFinalFrameSamples'];
123  }
124  $thisfile_monkeysaudio['playtime'] = $thisfile_monkeysaudio['samples'] / $thisfile_monkeysaudio['sample_rate'];
125  if ($thisfile_monkeysaudio['playtime'] == 0) {
126  $ThisFileInfo['error'][] = 'Corrupt MAC file: playtime == zero';
127  return false;
128  }
129  $ThisFileInfo['playtime_seconds'] = $thisfile_monkeysaudio['playtime'];
130  $thisfile_monkeysaudio['compressed_size'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'];
131  $thisfile_monkeysaudio['uncompressed_size'] = $thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * ($thisfile_monkeysaudio['bits_per_sample'] / 8);
132  if ($thisfile_monkeysaudio['uncompressed_size'] == 0) {
133  $ThisFileInfo['error'][] = 'Corrupt MAC file: uncompressed_size == zero';
134  return false;
135  }
136  $thisfile_monkeysaudio['compression_ratio'] = $thisfile_monkeysaudio['compressed_size'] / ($thisfile_monkeysaudio['uncompressed_size'] + $thisfile_monkeysaudio_raw['nHeaderDataBytes']);
137  $thisfile_monkeysaudio['bitrate'] = (($thisfile_monkeysaudio['samples'] * $thisfile_monkeysaudio['channels'] * $thisfile_monkeysaudio['bits_per_sample']) / $thisfile_monkeysaudio['playtime']) * $thisfile_monkeysaudio['compression_ratio'];
138  $ThisFileInfo['audio']['bitrate'] = $thisfile_monkeysaudio['bitrate'];
139 
140  // add size of MAC header to avdataoffset
141  if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
142  $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nDescriptorBytes'];
143  $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderBytes'];
144  $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nSeekTableBytes'];
145  $ThisFileInfo['avdataoffset'] += $thisfile_monkeysaudio_raw['nHeaderDataBytes'];
146 
147  $ThisFileInfo['avdataend'] -= $thisfile_monkeysaudio_raw['nTerminatingDataBytes'];
148  } else {
149  $ThisFileInfo['avdataoffset'] += $offset;
150  }
151 
152  if ($thisfile_monkeysaudio_raw['nVersion'] >= 3980) {
153  if ($thisfile_monkeysaudio_raw['cFileMD5'] === str_repeat("\x00", 16)) {
154  //$ThisFileInfo['warning'][] = 'cFileMD5 is null';
155  } else {
156  $ThisFileInfo['md5_data_source'] = '';
157  $md5 = $thisfile_monkeysaudio_raw['cFileMD5'];
158  for ($i = 0; $i < strlen($md5); $i++) {
159  $ThisFileInfo['md5_data_source'] .= str_pad(dechex(ord($md5{$i})), 2, '00', STR_PAD_LEFT);
160  }
161  if (!preg_match('/^[0-9a-f]{32}$/', $ThisFileInfo['md5_data_source'])) {
162  unset($ThisFileInfo['md5_data_source']);
163  }
164  }
165  }
166 
167 
168 
169  $ThisFileInfo['audio']['bits_per_sample'] = $thisfile_monkeysaudio['bits_per_sample'];
170  $ThisFileInfo['audio']['encoder'] = 'MAC v'.number_format($thisfile_monkeysaudio['version'], 2);
171  $ThisFileInfo['audio']['encoder_options'] = ucfirst($thisfile_monkeysaudio['compression']).' compression';
172 
173  return true;
174  }
MonkeyCompressionLevelNameLookup($compressionlevel)
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
fread($bytes)
Definition: getid3.php:1685
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
MonkeySamplesPerFrame($versionid, $compressionlevel)
+ Here is the call graph for this function:

◆ MonkeyCompressionLevelNameLookup() [1/2]

getid3_monkey::MonkeyCompressionLevelNameLookup (   $compressionlevel)

Definition at line 176 of file module.audio.monkey.php.

Referenced by Analyze(), and getid3_monkey().

176  {
177  static $MonkeyCompressionLevelNameLookup = array(
178  0 => 'unknown',
179  1000 => 'fast',
180  2000 => 'normal',
181  3000 => 'high',
182  4000 => 'extra-high',
183  5000 => 'insane'
184  );
185  return (isset($MonkeyCompressionLevelNameLookup[$compressionlevel]) ? $MonkeyCompressionLevelNameLookup[$compressionlevel] : 'invalid');
186  }
+ Here is the caller graph for this function:

◆ MonkeyCompressionLevelNameLookup() [2/2]

getid3_monkey::MonkeyCompressionLevelNameLookup (   $compressionlevel)

Definition at line 180 of file module.audio.monkey.php.

180  {
181  static $MonkeyCompressionLevelNameLookup = array(
182  0 => 'unknown',
183  1000 => 'fast',
184  2000 => 'normal',
185  3000 => 'high',
186  4000 => 'extra-high',
187  5000 => 'insane'
188  );
189  return (isset($MonkeyCompressionLevelNameLookup[$compressionlevel]) ? $MonkeyCompressionLevelNameLookup[$compressionlevel] : 'invalid');
190  }

◆ MonkeySamplesPerFrame() [1/2]

getid3_monkey::MonkeySamplesPerFrame (   $versionid,
  $compressionlevel 
)

Definition at line 188 of file module.audio.monkey.php.

Referenced by Analyze(), and getid3_monkey().

188  {
189  if ($versionid >= 3950) {
190  return 73728 * 4;
191  } elseif ($versionid >= 3900) {
192  return 73728;
193  } elseif (($versionid >= 3800) && ($compressionlevel == 4000)) {
194  return 73728;
195  } else {
196  return 9216;
197  }
198  }
+ Here is the caller graph for this function:

◆ MonkeySamplesPerFrame() [2/2]

getid3_monkey::MonkeySamplesPerFrame (   $versionid,
  $compressionlevel 
)

Definition at line 192 of file module.audio.monkey.php.

192  {
193  if ($versionid >= 3950) {
194  return 73728 * 4;
195  } elseif ($versionid >= 3900) {
196  return 73728;
197  } elseif (($versionid >= 3800) && ($compressionlevel == 4000)) {
198  return 73728;
199  } else {
200  return 9216;
201  }
202  }

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