module.audio.rkau.php 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.shorten.php //
  11. // module for analyzing Shorten Audio files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. class getid3_rkau
  16. {
  17. function getid3_rkau(&$fd, &$ThisFileInfo) {
  18. fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
  19. $RKAUHeader = fread($fd, 20);
  20. if (substr($RKAUHeader, 0, 3) != 'RKA') {
  21. $ThisFileInfo['error'][] = 'Expecting "RKA" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($RKAUHeader, 0, 3).'"';
  22. return false;
  23. }
  24. $ThisFileInfo['fileformat'] = 'rkau';
  25. $ThisFileInfo['audio']['dataformat'] = 'rkau';
  26. $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
  27. $ThisFileInfo['rkau']['raw']['version'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 3, 1));
  28. $ThisFileInfo['rkau']['version'] = '1.'.str_pad($ThisFileInfo['rkau']['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT);
  29. if (($ThisFileInfo['rkau']['version'] > 1.07) || ($ThisFileInfo['rkau']['version'] < 1.06)) {
  30. $ThisFileInfo['error'][] = 'This version of getID3() can only parse RKAU files v1.06 and 1.07 (this file is v'.$ThisFileInfo['rkau']['version'].')';
  31. unset($ThisFileInfo['rkau']);
  32. return false;
  33. }
  34. $ThisFileInfo['rkau']['source_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 4, 4));
  35. $ThisFileInfo['rkau']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 8, 4));
  36. $ThisFileInfo['rkau']['channels'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 12, 1));
  37. $ThisFileInfo['rkau']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 13, 1));
  38. $ThisFileInfo['rkau']['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 14, 1));
  39. $this->RKAUqualityLookup($ThisFileInfo['rkau']);
  40. $ThisFileInfo['rkau']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 15, 1));
  41. $ThisFileInfo['rkau']['flags']['joint_stereo'] = (bool) (!($ThisFileInfo['rkau']['raw']['flags'] & 0x01));
  42. $ThisFileInfo['rkau']['flags']['streaming'] = (bool) ($ThisFileInfo['rkau']['raw']['flags'] & 0x02);
  43. $ThisFileInfo['rkau']['flags']['vrq_lossy_mode'] = (bool) ($ThisFileInfo['rkau']['raw']['flags'] & 0x04);
  44. if ($ThisFileInfo['rkau']['flags']['streaming']) {
  45. $ThisFileInfo['avdataoffset'] += 20;
  46. $ThisFileInfo['rkau']['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 16, 4));
  47. } else {
  48. $ThisFileInfo['avdataoffset'] += 16;
  49. $ThisFileInfo['rkau']['compressed_bytes'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] - 1;
  50. }
  51. // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes,
  52. // sometimes it's more, sometimes less. No idea why(?)
  53. $ThisFileInfo['audio']['lossless'] = $ThisFileInfo['rkau']['lossless'];
  54. $ThisFileInfo['audio']['channels'] = $ThisFileInfo['rkau']['channels'];
  55. $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['rkau']['bits_per_sample'];
  56. $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['rkau']['sample_rate'];
  57. $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['rkau']['source_bytes'] / ($ThisFileInfo['rkau']['sample_rate'] * $ThisFileInfo['rkau']['channels'] * ($ThisFileInfo['rkau']['bits_per_sample'] / 8));
  58. $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['rkau']['compressed_bytes'] * 8) / $ThisFileInfo['playtime_seconds'];
  59. return true;
  60. }
  61. function RKAUqualityLookup(&$RKAUdata) {
  62. $level = ($RKAUdata['raw']['quality'] & 0xF0) >> 4;
  63. $quality = $RKAUdata['raw']['quality'] & 0x0F;
  64. $RKAUdata['lossless'] = (($quality == 0) ? true : false);
  65. $RKAUdata['compression_level'] = $level + 1;
  66. if (!$RKAUdata['lossless']) {
  67. $RKAUdata['quality_setting'] = $quality;
  68. }
  69. return true;
  70. }
  71. }
  72. ?>