module.audio.au.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.au.php //
  12. // module for analyzing AU files //
  13. // dependencies: NONE //
  14. // ///
  15. /////////////////////////////////////////////////////////////////
  16. class getid3_au extends getid3_handler
  17. {
  18. public function Analyze() {
  19. $info = &$this->getid3->info;
  20. $this->fseek($info['avdataoffset']);
  21. $AUheader = $this->fread(8);
  22. $magic = '.snd';
  23. if (substr($AUheader, 0, 4) != $magic) {
  24. $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($AUheader, 0, 4)).'"';
  25. return false;
  26. }
  27. // shortcut
  28. $info['au'] = array();
  29. $thisfile_au = &$info['au'];
  30. $info['fileformat'] = 'au';
  31. $info['audio']['dataformat'] = 'au';
  32. $info['audio']['bitrate_mode'] = 'cbr';
  33. $thisfile_au['encoding'] = 'ISO-8859-1';
  34. $thisfile_au['header_length'] = getid3_lib::BigEndian2Int(substr($AUheader, 4, 4));
  35. $AUheader .= $this->fread($thisfile_au['header_length'] - 8);
  36. $info['avdataoffset'] += $thisfile_au['header_length'];
  37. $thisfile_au['data_size'] = getid3_lib::BigEndian2Int(substr($AUheader, 8, 4));
  38. $thisfile_au['data_format_id'] = getid3_lib::BigEndian2Int(substr($AUheader, 12, 4));
  39. $thisfile_au['sample_rate'] = getid3_lib::BigEndian2Int(substr($AUheader, 16, 4));
  40. $thisfile_au['channels'] = getid3_lib::BigEndian2Int(substr($AUheader, 20, 4));
  41. $thisfile_au['comments']['comment'][] = trim(substr($AUheader, 24));
  42. $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']);
  43. $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']);
  44. if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) {
  45. $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample'];
  46. } else {
  47. unset($thisfile_au['bits_per_sample']);
  48. }
  49. $info['audio']['sample_rate'] = $thisfile_au['sample_rate'];
  50. $info['audio']['channels'] = $thisfile_au['channels'];
  51. if (($info['avdataoffset'] + $thisfile_au['data_size']) > $info['avdataend']) {
  52. $info['warning'][] = 'Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"';
  53. }
  54. $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8));
  55. $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds'];
  56. return true;
  57. }
  58. public function AUdataFormatNameLookup($id) {
  59. static $AUdataFormatNameLookup = array(
  60. 0 => 'unspecified format',
  61. 1 => '8-bit mu-law',
  62. 2 => '8-bit linear',
  63. 3 => '16-bit linear',
  64. 4 => '24-bit linear',
  65. 5 => '32-bit linear',
  66. 6 => 'floating-point',
  67. 7 => 'double-precision float',
  68. 8 => 'fragmented sampled data',
  69. 9 => 'SUN_FORMAT_NESTED',
  70. 10 => 'DSP program',
  71. 11 => '8-bit fixed-point',
  72. 12 => '16-bit fixed-point',
  73. 13 => '24-bit fixed-point',
  74. 14 => '32-bit fixed-point',
  75. 16 => 'non-audio display data',
  76. 17 => 'SND_FORMAT_MULAW_SQUELCH',
  77. 18 => '16-bit linear with emphasis',
  78. 19 => '16-bit linear with compression',
  79. 20 => '16-bit linear with emphasis + compression',
  80. 21 => 'Music Kit DSP commands',
  81. 22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES',
  82. 23 => 'CCITT g.721 4-bit ADPCM',
  83. 24 => 'CCITT g.722 ADPCM',
  84. 25 => 'CCITT g.723 3-bit ADPCM',
  85. 26 => 'CCITT g.723 5-bit ADPCM',
  86. 27 => 'A-Law 8-bit'
  87. );
  88. return (isset($AUdataFormatNameLookup[$id]) ? $AUdataFormatNameLookup[$id] : false);
  89. }
  90. public function AUdataFormatBitsPerSampleLookup($id) {
  91. static $AUdataFormatBitsPerSampleLookup = array(
  92. 1 => 8,
  93. 2 => 8,
  94. 3 => 16,
  95. 4 => 24,
  96. 5 => 32,
  97. 6 => 32,
  98. 7 => 64,
  99. 11 => 8,
  100. 12 => 16,
  101. 13 => 24,
  102. 14 => 32,
  103. 18 => 16,
  104. 19 => 16,
  105. 20 => 16,
  106. 23 => 16,
  107. 25 => 16,
  108. 26 => 16,
  109. 27 => 8
  110. );
  111. return (isset($AUdataFormatBitsPerSampleLookup[$id]) ? $AUdataFormatBitsPerSampleLookup[$id] : false);
  112. }
  113. public function AUdataFormatUsedBitsPerSampleLookup($id) {
  114. static $AUdataFormatUsedBitsPerSampleLookup = array(
  115. 1 => 8,
  116. 2 => 8,
  117. 3 => 16,
  118. 4 => 24,
  119. 5 => 32,
  120. 6 => 32,
  121. 7 => 64,
  122. 11 => 8,
  123. 12 => 16,
  124. 13 => 24,
  125. 14 => 32,
  126. 18 => 16,
  127. 19 => 16,
  128. 20 => 16,
  129. 23 => 4,
  130. 25 => 3,
  131. 26 => 5,
  132. 27 => 8,
  133. );
  134. return (isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ? $AUdataFormatUsedBitsPerSampleLookup[$id] : false);
  135. }
  136. }