24 $ThisFileInfo[
'fileformat'] =
'mac';
25 $ThisFileInfo[
'audio'][
'dataformat'] =
'mac';
26 $ThisFileInfo[
'audio'][
'bitrate_mode'] =
'vbr';
27 $ThisFileInfo[
'audio'][
'lossless'] =
true;
29 $ThisFileInfo[
'monkeys_audio'][
'raw'] = array();
30 $thisfile_monkeysaudio = &$ThisFileInfo[
'monkeys_audio'];
31 $thisfile_monkeysaudio_raw = &$thisfile_monkeysaudio[
'raw'];
33 fseek($fd, $ThisFileInfo[
'avdataoffset'], SEEK_SET);
34 $MACheaderData = fread($fd, 74);
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']);
44 if ($thisfile_monkeysaudio_raw[
'nVersion'] < 3980) {
73 $thisfile_monkeysaudio_raw[
'cFileMD5'] = substr($MACheaderData, $offset, 16);
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;
103 if ($thisfile_monkeysaudio_raw[
'nVersion'] < 3980) {
104 $thisfile_monkeysaudio[
'samples_per_frame'] = $this->
MonkeySamplesPerFrame($thisfile_monkeysaudio_raw[
'nVersion'], $thisfile_monkeysaudio_raw[
'nCompressionLevel']);
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';
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);
119 if ($thisfile_monkeysaudio_raw[
'nVersion'] >= 3980) {
120 $thisfile_monkeysaudio[
'samples'] = (($thisfile_monkeysaudio_raw[
'nTotalFrames'] - 1) * $thisfile_monkeysaudio_raw[
'nBlocksPerFrame']) + $thisfile_monkeysaudio_raw[
'nFinalFrameBlocks'];
122 $thisfile_monkeysaudio[
'samples'] = (($thisfile_monkeysaudio_raw[
'nTotalFrames'] - 1) * $thisfile_monkeysaudio[
'samples_per_frame']) + $thisfile_monkeysaudio_raw[
'nFinalFrameSamples'];
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';
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';
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'];
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'];
147 $ThisFileInfo[
'avdataend'] -= $thisfile_monkeysaudio_raw[
'nTerminatingDataBytes'];
149 $ThisFileInfo[
'avdataoffset'] += $offset;
152 if ($thisfile_monkeysaudio_raw[
'nVersion'] >= 3980) {
153 if ($thisfile_monkeysaudio_raw[
'cFileMD5'] === str_repeat(
"\x00", 16)) {
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);
161 if (!preg_match(
'/^[0-9a-f]{32}$/', $ThisFileInfo[
'md5_data_source'])) {
162 unset($ThisFileInfo[
'md5_data_source']);
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';
177 static $MonkeyCompressionLevelNameLookup = array(
182 4000 =>
'extra-high',
185 return (isset($MonkeyCompressionLevelNameLookup[$compressionlevel]) ? $MonkeyCompressionLevelNameLookup[$compressionlevel] :
'invalid');
189 if ($versionid >= 3950) {
191 } elseif ($versionid >= 3900) {
193 } elseif (($versionid >= 3800) && ($compressionlevel == 4000)) {