PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/getid3/module.audio.tta.php

https://bitbucket.org/holyfield/getid3
PHP | 108 lines | 71 code | 21 blank | 16 comment | 3 complexity | 6fd12f73af93e5135914ae0313955dc3 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.tta.php //
  11. // module for analyzing TTA Audio files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. class getid3_tta extends getid3_handler
  16. {
  17. function Analyze() {
  18. $info = &$this->getid3->info;
  19. $info['fileformat'] = 'tta';
  20. $info['audio']['dataformat'] = 'tta';
  21. $info['audio']['lossless'] = true;
  22. $info['audio']['bitrate_mode'] = 'vbr';
  23. fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
  24. $ttaheader = fread($this->getid3->fp, 26);
  25. $info['tta']['magic'] = substr($ttaheader, 0, 3);
  26. $magic = 'TTA';
  27. if ($info['tta']['magic'] != $magic) {
  28. $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['tta']['magic']).'"';
  29. unset($info['fileformat']);
  30. unset($info['audio']);
  31. unset($info['tta']);
  32. return false;
  33. }
  34. switch ($ttaheader{3}) {
  35. case "\x01": // TTA v1.x
  36. case "\x02": // TTA v1.x
  37. case "\x03": // TTA v1.x
  38. // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year."
  39. $info['tta']['major_version'] = 1;
  40. $info['avdataoffset'] += 16;
  41. $info['tta']['compression_level'] = ord($ttaheader{3});
  42. $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2));
  43. $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2));
  44. $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 4));
  45. $info['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4));
  46. $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
  47. $info['playtime_seconds'] = $info['tta']['samples_per_channel'] / $info['tta']['sample_rate'];
  48. break;
  49. case '2': // TTA v2.x
  50. // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4."
  51. $info['tta']['major_version'] = 2;
  52. $info['avdataoffset'] += 20;
  53. $info['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2));
  54. $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2));
  55. $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2));
  56. $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 2));
  57. $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 12, 4));
  58. $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 16, 4));
  59. $info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
  60. $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
  61. break;
  62. case '1': // TTA v3.x
  63. // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher."
  64. $info['tta']['major_version'] = 3;
  65. $info['avdataoffset'] += 26;
  66. $info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 4, 2)); // getid3_riff::RIFFwFormatTagLookup()
  67. $info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 6, 2));
  68. $info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 8, 2));
  69. $info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 10, 4));
  70. $info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 14, 4));
  71. $info['tta']['crc32_footer'] = substr($ttaheader, 18, 4);
  72. $info['tta']['seek_point'] = getid3_lib::LittleEndian2Int(substr($ttaheader, 22, 4));
  73. $info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
  74. break;
  75. default:
  76. $info['error'][] = 'This version of getID3() ['.$this->getid3->version().'] only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v'.$ttaheader{3};
  77. return false;
  78. break;
  79. }
  80. $info['audio']['encoder'] = 'TTA v'.$info['tta']['major_version'];
  81. $info['audio']['bits_per_sample'] = $info['tta']['bits_per_sample'];
  82. $info['audio']['sample_rate'] = $info['tta']['sample_rate'];
  83. $info['audio']['channels'] = $info['tta']['channels'];
  84. $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
  85. return true;
  86. }
  87. }