PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/getid3/module.audio.mpc.php

https://bitbucket.org/holyfield/getid3
PHP | 508 lines | 368 code | 86 blank | 54 comment | 44 complexity | 272b11ae583f01f852888a92e8cf3090 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. /////////////////////////////////////////////////////////////////
  7. // See readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.audio.mpc.php //
  11. // module for analyzing Musepack/MPEG+ Audio files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. class getid3_mpc extends getid3_handler
  16. {
  17. function Analyze() {
  18. $info = &$this->getid3->info;
  19. $info['mpc']['header'] = array();
  20. $thisfile_mpc_header = &$info['mpc']['header'];
  21. $info['fileformat'] = 'mpc';
  22. $info['audio']['dataformat'] = 'mpc';
  23. $info['audio']['bitrate_mode'] = 'vbr';
  24. $info['audio']['channels'] = 2; // up to SV7 the format appears to have been hardcoded for stereo only
  25. $info['audio']['lossless'] = false;
  26. fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
  27. $MPCheaderData = fread($this->getid3->fp, 4);
  28. $info['mpc']['header']['preamble'] = substr($MPCheaderData, 0, 4); // should be 'MPCK' (SV8) or 'MP+' (SV7), otherwise possible stream data (SV4-SV6)
  29. if (preg_match('#^MPCK#', $info['mpc']['header']['preamble'])) {
  30. // this is SV8
  31. return $this->ParseMPCsv8();
  32. } elseif (preg_match('#^MP\+#', $info['mpc']['header']['preamble'])) {
  33. // this is SV7
  34. return $this->ParseMPCsv7();
  35. } elseif (preg_match('/^[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0]/s', $MPCheaderData)) {
  36. // this is SV4 - SV6, handle seperately
  37. return $this->ParseMPCsv6();
  38. } else {
  39. $info['error'][] = 'Expecting "MP+" or "MPCK" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($MPCheaderData, 0, 4)).'"';
  40. unset($info['fileformat']);
  41. unset($info['mpc']);
  42. return false;
  43. }
  44. return false;
  45. }
  46. function ParseMPCsv8() {
  47. // this is SV8
  48. // http://trac.musepack.net/trac/wiki/SV8Specification
  49. $info = &$this->getid3->info;
  50. $thisfile_mpc_header = &$info['mpc']['header'];
  51. $keyNameSize = 2;
  52. $maxHandledPacketLength = 9; // specs say: "n*8; 0 < n < 10"
  53. $offset = ftell($this->getid3->fp);
  54. while ($offset < $info['avdataend']) {
  55. $thisPacket = array();
  56. $thisPacket['offset'] = $offset;
  57. $packet_offset = 0;
  58. // Size is a variable-size field, could be 1-4 bytes (possibly more?)
  59. // read enough data in and figure out the exact size later
  60. $MPCheaderData = fread($this->getid3->fp, $keyNameSize + $maxHandledPacketLength);
  61. $packet_offset += $keyNameSize;
  62. $thisPacket['key'] = substr($MPCheaderData, 0, $keyNameSize);
  63. $thisPacket['key_name'] = $this->MPCsv8PacketName($thisPacket['key']);
  64. if ($thisPacket['key'] == $thisPacket['key_name']) {
  65. $info['error'][] = 'Found unexpected key value "'.$thisPacket['key'].'" at offset '.$thisPacket['offset'];
  66. return false;
  67. }
  68. $packetLength = 0;
  69. $thisPacket['packet_size'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $keyNameSize), $packetLength); // includes keyname and packet_size field
  70. if ($thisPacket['packet_size'] === false) {
  71. $info['error'][] = 'Did not find expected packet length within '.$maxHandledPacketLength.' bytes at offset '.($thisPacket['offset'] + $keyNameSize);
  72. return false;
  73. }
  74. $packet_offset += $packetLength;
  75. $offset += $thisPacket['packet_size'];
  76. switch ($thisPacket['key']) {
  77. case 'SH': // Stream Header
  78. $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength;
  79. if ($moreBytesToRead > 0) {
  80. $MPCheaderData .= fread($this->getid3->fp, $moreBytesToRead);
  81. }
  82. $thisPacket['crc'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 4));
  83. $packet_offset += 4;
  84. $thisPacket['stream_version'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1));
  85. $packet_offset += 1;
  86. $packetLength = 0;
  87. $thisPacket['sample_count'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength);
  88. $packet_offset += $packetLength;
  89. $packetLength = 0;
  90. $thisPacket['beginning_silence'] = $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength);
  91. $packet_offset += $packetLength;
  92. $otherUsefulData = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2));
  93. $packet_offset += 2;
  94. $thisPacket['sample_frequency_raw'] = (($otherUsefulData & 0xE000) >> 13);
  95. $thisPacket['max_bands_used'] = (($otherUsefulData & 0x1F00) >> 8);
  96. $thisPacket['channels'] = (($otherUsefulData & 0x00F0) >> 4) + 1;
  97. $thisPacket['ms_used'] = (bool) (($otherUsefulData & 0x0008) >> 3);
  98. $thisPacket['audio_block_frames'] = (($otherUsefulData & 0x0007) >> 0);
  99. $thisPacket['sample_frequency'] = $this->MPCfrequencyLookup($thisPacket['sample_frequency_raw']);
  100. $thisfile_mpc_header['mid_side_stereo'] = $thisPacket['ms_used'];
  101. $thisfile_mpc_header['sample_rate'] = $thisPacket['sample_frequency'];
  102. $thisfile_mpc_header['samples'] = $thisPacket['sample_count'];
  103. $thisfile_mpc_header['stream_version_major'] = $thisPacket['stream_version'];
  104. $info['audio']['channels'] = $thisPacket['channels'];
  105. $info['audio']['sample_rate'] = $thisPacket['sample_frequency'];
  106. $info['playtime_seconds'] = $thisPacket['sample_count'] / $thisPacket['sample_frequency'];
  107. $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
  108. break;
  109. case 'RG': // Replay Gain
  110. $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength;
  111. if ($moreBytesToRead > 0) {
  112. $MPCheaderData .= fread($this->getid3->fp, $moreBytesToRead);
  113. }
  114. $thisPacket['replaygain_version'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1));
  115. $packet_offset += 1;
  116. $thisPacket['replaygain_title_gain'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2));
  117. $packet_offset += 2;
  118. $thisPacket['replaygain_title_peak'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2));
  119. $packet_offset += 2;
  120. $thisPacket['replaygain_album_gain'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2));
  121. $packet_offset += 2;
  122. $thisPacket['replaygain_album_peak'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 2));
  123. $packet_offset += 2;
  124. if ($thisPacket['replaygain_title_gain']) { $info['replay_gain']['title']['gain'] = $thisPacket['replaygain_title_gain']; }
  125. if ($thisPacket['replaygain_title_peak']) { $info['replay_gain']['title']['peak'] = $thisPacket['replaygain_title_peak']; }
  126. if ($thisPacket['replaygain_album_gain']) { $info['replay_gain']['album']['gain'] = $thisPacket['replaygain_album_gain']; }
  127. if ($thisPacket['replaygain_album_peak']) { $info['replay_gain']['album']['peak'] = $thisPacket['replaygain_album_peak']; }
  128. break;
  129. case 'EI': // Encoder Info
  130. $moreBytesToRead = $thisPacket['packet_size'] - $keyNameSize - $maxHandledPacketLength;
  131. if ($moreBytesToRead > 0) {
  132. $MPCheaderData .= fread($this->getid3->fp, $moreBytesToRead);
  133. }
  134. $profile_pns = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1));
  135. $packet_offset += 1;
  136. $quality_int = (($profile_pns & 0xF0) >> 4);
  137. $quality_dec = (($profile_pns & 0x0E) >> 3);
  138. $thisPacket['quality'] = (float) $quality_int + ($quality_dec / 8);
  139. $thisPacket['pns_tool'] = (bool) (($profile_pns & 0x01) >> 0);
  140. $thisPacket['version_major'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1));
  141. $packet_offset += 1;
  142. $thisPacket['version_minor'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1));
  143. $packet_offset += 1;
  144. $thisPacket['version_build'] = getid3_lib::BigEndian2Int(substr($MPCheaderData, $packet_offset, 1));
  145. $packet_offset += 1;
  146. $thisPacket['version'] = $thisPacket['version_major'].'.'.$thisPacket['version_minor'].'.'.$thisPacket['version_build'];
  147. $info['audio']['encoder'] = 'MPC v'.$thisPacket['version'].' ('.(($thisPacket['version_minor'] % 2) ? 'unstable' : 'stable').')';
  148. $thisfile_mpc_header['encoder_version'] = $info['audio']['encoder'];
  149. //$thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] / 1.5875); // values can range from 0.000 to 15.875, mapped to qualities of 0.0 to 10.0
  150. $thisfile_mpc_header['quality'] = (float) ($thisPacket['quality'] - 5); // values can range from 0.000 to 15.875, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0
  151. break;
  152. case 'SO': // Seek Table Offset
  153. $packetLength = 0;
  154. $thisPacket['seek_table_offset'] = $thisPacket['offset'] + $this->SV8variableLengthInteger(substr($MPCheaderData, $packet_offset, $maxHandledPacketLength), $packetLength);
  155. $packet_offset += $packetLength;
  156. break;
  157. case 'ST': // Seek Table
  158. case 'SE': // Stream End
  159. case 'AP': // Audio Data
  160. // nothing useful here, just skip this packet
  161. $thisPacket = array();
  162. break;
  163. default:
  164. $info['error'][] = 'Found unhandled key type "'.$thisPacket['key'].'" at offset '.$thisPacket['offset'];
  165. return false;
  166. break;
  167. }
  168. if (!empty($thisPacket)) {
  169. $info['mpc']['packets'][] = $thisPacket;
  170. }
  171. fseek($this->getid3->fp, $offset);
  172. }
  173. $thisfile_mpc_header['size'] = $offset;
  174. return true;
  175. }
  176. function ParseMPCsv7() {
  177. // this is SV7
  178. // http://www.uni-jena.de/~pfk/mpp/sv8/header.html
  179. $info = &$this->getid3->info;
  180. $thisfile_mpc_header = &$info['mpc']['header'];
  181. $offset = 0;
  182. $thisfile_mpc_header['size'] = 28;
  183. $MPCheaderData = $info['mpc']['header']['preamble'];
  184. $MPCheaderData .= fread($this->getid3->fp, $thisfile_mpc_header['size'] - strlen($info['mpc']['header']['preamble']));
  185. $offset = strlen('MP+');
  186. $StreamVersionByte = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 1));
  187. $offset += 1;
  188. $thisfile_mpc_header['stream_version_major'] = ($StreamVersionByte & 0x0F) >> 0;
  189. $thisfile_mpc_header['stream_version_minor'] = ($StreamVersionByte & 0xF0) >> 4; // should always be 0, subversions no longer exist in SV8
  190. $thisfile_mpc_header['frame_count'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4));
  191. $offset += 4;
  192. if ($thisfile_mpc_header['stream_version_major'] != 7) {
  193. $info['error'][] = 'Only Musepack SV7 supported (this file claims to be v'.$thisfile_mpc_header['stream_version_major'].')';
  194. return false;
  195. }
  196. $FlagsDWORD1 = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4));
  197. $offset += 4;
  198. $thisfile_mpc_header['intensity_stereo'] = (bool) (($FlagsDWORD1 & 0x80000000) >> 31);
  199. $thisfile_mpc_header['mid_side_stereo'] = (bool) (($FlagsDWORD1 & 0x40000000) >> 30);
  200. $thisfile_mpc_header['max_subband'] = ($FlagsDWORD1 & 0x3F000000) >> 24;
  201. $thisfile_mpc_header['raw']['profile'] = ($FlagsDWORD1 & 0x00F00000) >> 20;
  202. $thisfile_mpc_header['begin_loud'] = (bool) (($FlagsDWORD1 & 0x00080000) >> 19);
  203. $thisfile_mpc_header['end_loud'] = (bool) (($FlagsDWORD1 & 0x00040000) >> 18);
  204. $thisfile_mpc_header['raw']['sample_rate'] = ($FlagsDWORD1 & 0x00030000) >> 16;
  205. $thisfile_mpc_header['max_level'] = ($FlagsDWORD1 & 0x0000FFFF);
  206. $thisfile_mpc_header['raw']['title_peak'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2));
  207. $offset += 2;
  208. $thisfile_mpc_header['raw']['title_gain'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2), true);
  209. $offset += 2;
  210. $thisfile_mpc_header['raw']['album_peak'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2));
  211. $offset += 2;
  212. $thisfile_mpc_header['raw']['album_gain'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 2), true);
  213. $offset += 2;
  214. $FlagsDWORD2 = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 4));
  215. $offset += 4;
  216. $thisfile_mpc_header['true_gapless'] = (bool) (($FlagsDWORD2 & 0x80000000) >> 31);
  217. $thisfile_mpc_header['last_frame_length'] = ($FlagsDWORD2 & 0x7FF00000) >> 20;
  218. $thisfile_mpc_header['raw']['not_sure_what'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 3));
  219. $offset += 3;
  220. $thisfile_mpc_header['raw']['encoder_version'] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, $offset, 1));
  221. $offset += 1;
  222. $thisfile_mpc_header['profile'] = $this->MPCprofileNameLookup($thisfile_mpc_header['raw']['profile']);
  223. $thisfile_mpc_header['sample_rate'] = $this->MPCfrequencyLookup($thisfile_mpc_header['raw']['sample_rate']);
  224. if ($thisfile_mpc_header['sample_rate'] == 0) {
  225. $info['error'][] = 'Corrupt MPC file: frequency == zero';
  226. return false;
  227. }
  228. $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate'];
  229. $thisfile_mpc_header['samples'] = ((($thisfile_mpc_header['frame_count'] - 1) * 1152) + $thisfile_mpc_header['last_frame_length']) * $info['audio']['channels'];
  230. $info['playtime_seconds'] = ($thisfile_mpc_header['samples'] / $info['audio']['channels']) / $info['audio']['sample_rate'];
  231. if ($info['playtime_seconds'] == 0) {
  232. $info['error'][] = 'Corrupt MPC file: playtime_seconds == zero';
  233. return false;
  234. }
  235. // add size of file header to avdataoffset - calc bitrate correctly + MD5 data
  236. $info['avdataoffset'] += $thisfile_mpc_header['size'];
  237. $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
  238. $thisfile_mpc_header['title_peak'] = $thisfile_mpc_header['raw']['title_peak'];
  239. $thisfile_mpc_header['title_peak_db'] = $this->MPCpeakDBLookup($thisfile_mpc_header['title_peak']);
  240. if ($thisfile_mpc_header['raw']['title_gain'] < 0) {
  241. $thisfile_mpc_header['title_gain_db'] = (float) (32768 + $thisfile_mpc_header['raw']['title_gain']) / -100;
  242. } else {
  243. $thisfile_mpc_header['title_gain_db'] = (float) $thisfile_mpc_header['raw']['title_gain'] / 100;
  244. }
  245. $thisfile_mpc_header['album_peak'] = $thisfile_mpc_header['raw']['album_peak'];
  246. $thisfile_mpc_header['album_peak_db'] = $this->MPCpeakDBLookup($thisfile_mpc_header['album_peak']);
  247. if ($thisfile_mpc_header['raw']['album_gain'] < 0) {
  248. $thisfile_mpc_header['album_gain_db'] = (float) (32768 + $thisfile_mpc_header['raw']['album_gain']) / -100;
  249. } else {
  250. $thisfile_mpc_header['album_gain_db'] = (float) $thisfile_mpc_header['raw']['album_gain'] / 100;;
  251. }
  252. $thisfile_mpc_header['encoder_version'] = $this->MPCencoderVersionLookup($thisfile_mpc_header['raw']['encoder_version']);
  253. $info['replay_gain']['track']['adjustment'] = $thisfile_mpc_header['title_gain_db'];
  254. $info['replay_gain']['album']['adjustment'] = $thisfile_mpc_header['album_gain_db'];
  255. if ($thisfile_mpc_header['title_peak'] > 0) {
  256. $info['replay_gain']['track']['peak'] = $thisfile_mpc_header['title_peak'];
  257. } elseif (round($thisfile_mpc_header['max_level'] * 1.18) > 0) {
  258. $info['replay_gain']['track']['peak'] = getid3_lib::CastAsInt(round($thisfile_mpc_header['max_level'] * 1.18)); // why? I don't know - see mppdec.c
  259. }
  260. if ($thisfile_mpc_header['album_peak'] > 0) {
  261. $info['replay_gain']['album']['peak'] = $thisfile_mpc_header['album_peak'];
  262. }
  263. //$info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major'].'.'.$thisfile_mpc_header['stream_version_minor'].', '.$thisfile_mpc_header['encoder_version'];
  264. $info['audio']['encoder'] = $thisfile_mpc_header['encoder_version'];
  265. $info['audio']['encoder_options'] = $thisfile_mpc_header['profile'];
  266. $thisfile_mpc_header['quality'] = (float) ($thisfile_mpc_header['raw']['profile'] - 5); // values can range from 0 to 15, of which 0..4 are "reserved/experimental", and 5..15 are mapped to qualities of 0.0 to 10.0
  267. return true;
  268. }
  269. function ParseMPCsv6() {
  270. // this is SV4 - SV6
  271. $info = &$this->getid3->info;
  272. $thisfile_mpc_header = &$info['mpc']['header'];
  273. $offset = 0;
  274. $thisfile_mpc_header['size'] = 8;
  275. fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
  276. $MPCheaderData = fread($this->getid3->fp, $thisfile_mpc_header['size']);
  277. // add size of file header to avdataoffset - calc bitrate correctly + MD5 data
  278. $info['avdataoffset'] += $thisfile_mpc_header['size'];
  279. // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :)
  280. $HeaderDWORD[0] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 0, 4));
  281. $HeaderDWORD[1] = getid3_lib::LittleEndian2Int(substr($MPCheaderData, 4, 4));
  282. // DDDD DDDD CCCC CCCC BBBB BBBB AAAA AAAA
  283. // aaaa aaaa abcd dddd dddd deee eeff ffff
  284. //
  285. // a = bitrate = anything
  286. // b = IS = anything
  287. // c = MS = anything
  288. // d = streamversion = 0000000004 or 0000000005 or 0000000006
  289. // e = maxband = anything
  290. // f = blocksize = 000001 for SV5+, anything(?) for SV4
  291. $thisfile_mpc_header['target_bitrate'] = (($HeaderDWORD[0] & 0xFF800000) >> 23);
  292. $thisfile_mpc_header['intensity_stereo'] = (bool) (($HeaderDWORD[0] & 0x00400000) >> 22);
  293. $thisfile_mpc_header['mid_side_stereo'] = (bool) (($HeaderDWORD[0] & 0x00200000) >> 21);
  294. $thisfile_mpc_header['stream_version_major'] = ($HeaderDWORD[0] & 0x001FF800) >> 11;
  295. $thisfile_mpc_header['stream_version_minor'] = 0; // no sub-version numbers before SV7
  296. $thisfile_mpc_header['max_band'] = ($HeaderDWORD[0] & 0x000007C0) >> 6; // related to lowpass frequency, not sure how it translates exactly
  297. $thisfile_mpc_header['block_size'] = ($HeaderDWORD[0] & 0x0000003F);
  298. switch ($thisfile_mpc_header['stream_version_major']) {
  299. case 4:
  300. $thisfile_mpc_header['frame_count'] = ($HeaderDWORD[1] >> 16);
  301. break;
  302. case 5:
  303. case 6:
  304. $thisfile_mpc_header['frame_count'] = $HeaderDWORD[1];
  305. break;
  306. default:
  307. $info['error'] = 'Expecting 4, 5 or 6 in version field, found '.$thisfile_mpc_header['stream_version_major'].' instead';
  308. unset($info['mpc']);
  309. return false;
  310. break;
  311. }
  312. if (($thisfile_mpc_header['stream_version_major'] > 4) && ($thisfile_mpc_header['block_size'] != 1)) {
  313. $info['warning'][] = 'Block size expected to be 1, actual value found: '.$thisfile_mpc_header['block_size'];
  314. }
  315. $thisfile_mpc_header['sample_rate'] = 44100; // AB: used by all files up to SV7
  316. $info['audio']['sample_rate'] = $thisfile_mpc_header['sample_rate'];
  317. $thisfile_mpc_header['samples'] = $thisfile_mpc_header['frame_count'] * 1152 * $info['audio']['channels'];
  318. if ($thisfile_mpc_header['target_bitrate'] == 0) {
  319. $info['audio']['bitrate_mode'] = 'vbr';
  320. } else {
  321. $info['audio']['bitrate_mode'] = 'cbr';
  322. }
  323. $info['mpc']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 * 44100 / $thisfile_mpc_header['frame_count'] / 1152;
  324. $info['audio']['bitrate'] = $info['mpc']['bitrate'];
  325. $info['audio']['encoder'] = 'SV'.$thisfile_mpc_header['stream_version_major'];
  326. return true;
  327. }
  328. function MPCprofileNameLookup($profileid) {
  329. static $MPCprofileNameLookup = array(
  330. 0 => 'no profile',
  331. 1 => 'Experimental',
  332. 2 => 'unused',
  333. 3 => 'unused',
  334. 4 => 'unused',
  335. 5 => 'below Telephone (q = 0.0)',
  336. 6 => 'below Telephone (q = 1.0)',
  337. 7 => 'Telephone (q = 2.0)',
  338. 8 => 'Thumb (q = 3.0)',
  339. 9 => 'Radio (q = 4.0)',
  340. 10 => 'Standard (q = 5.0)',
  341. 11 => 'Extreme (q = 6.0)',
  342. 12 => 'Insane (q = 7.0)',
  343. 13 => 'BrainDead (q = 8.0)',
  344. 14 => 'above BrainDead (q = 9.0)',
  345. 15 => 'above BrainDead (q = 10.0)'
  346. );
  347. return (isset($MPCprofileNameLookup[$profileid]) ? $MPCprofileNameLookup[$profileid] : 'invalid');
  348. }
  349. function MPCfrequencyLookup($frequencyid) {
  350. static $MPCfrequencyLookup = array(
  351. 0 => 44100,
  352. 1 => 48000,
  353. 2 => 37800,
  354. 3 => 32000
  355. );
  356. return (isset($MPCfrequencyLookup[$frequencyid]) ? $MPCfrequencyLookup[$frequencyid] : 'invalid');
  357. }
  358. function MPCpeakDBLookup($intvalue) {
  359. if ($intvalue > 0) {
  360. return ((log10($intvalue) / log10(2)) - 15) * 6;
  361. }
  362. return false;
  363. }
  364. function MPCencoderVersionLookup($encoderversion) {
  365. //Encoder version * 100 (106 = 1.06)
  366. //EncoderVersion % 10 == 0 Release (1.0)
  367. //EncoderVersion % 2 == 0 Beta (1.06)
  368. //EncoderVersion % 2 == 1 Alpha (1.05a...z)
  369. if ($encoderversion == 0) {
  370. // very old version, not known exactly which
  371. return 'Buschmann v1.7.0-v1.7.9 or Klemm v0.90-v1.05';
  372. }
  373. if (($encoderversion % 10) == 0) {
  374. // release version
  375. return number_format($encoderversion / 100, 2);
  376. } elseif (($encoderversion % 2) == 0) {
  377. // beta version
  378. return number_format($encoderversion / 100, 2).' beta';
  379. }
  380. // alpha version
  381. return number_format($encoderversion / 100, 2).' alpha';
  382. }
  383. function SV8variableLengthInteger($data, &$packetLength, $maxHandledPacketLength=9) {
  384. $packet_size = 0;
  385. for ($packetLength = 1; $packetLength <= $maxHandledPacketLength; $packetLength++) {
  386. // variable-length size field:
  387. // bits, big-endian
  388. // 0xxx xxxx - value 0 to 2^7-1
  389. // 1xxx xxxx 0xxx xxxx - value 0 to 2^14-1
  390. // 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^21-1
  391. // 1xxx xxxx 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^28-1
  392. // ...
  393. $thisbyte = ord(substr($data, ($packetLength - 1), 1));
  394. // look through bytes until find a byte with MSB==0
  395. $packet_size = ($packet_size << 7);
  396. $packet_size = ($packet_size | ($thisbyte & 0x7F));
  397. if (($thisbyte & 0x80) === 0) {
  398. break;
  399. }
  400. if ($packetLength >= $maxHandledPacketLength) {
  401. return false;
  402. }
  403. }
  404. return $packet_size;
  405. }
  406. function MPCsv8PacketName($packetKey) {
  407. static $MPCsv8PacketName = array();
  408. if (empty($MPCsv8PacketName)) {
  409. $MPCsv8PacketName = array(
  410. 'AP' => 'Audio Packet',
  411. 'CT' => 'Chapter Tag',
  412. 'EI' => 'Encoder Info',
  413. 'RG' => 'Replay Gain',
  414. 'SE' => 'Stream End',
  415. 'SH' => 'Stream Header',
  416. 'SO' => 'Seek Table Offset',
  417. 'ST' => 'Seek Table',
  418. );
  419. }
  420. return (isset($MPCsv8PacketName[$packetKey]) ? $MPCsv8PacketName[$packetKey] : $packetKey);
  421. }
  422. }