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