module.audio.au.php 5.3 KB

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