module.audio.rkau.php 4.2 KB

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