PageRenderTime 66ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/getid3/module.audio.dss.php

https://bitbucket.org/holyfield/getid3
PHP | 74 lines | 38 code | 17 blank | 19 comment | 1 complexity | 26cc8c202dce7d794631f4fef9a87619 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.dss.php //
  11. // module for analyzing Digital Speech Standard (DSS) files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. class getid3_dss extends getid3_handler
  16. {
  17. function Analyze() {
  18. $info = &$this->getid3->info;
  19. fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
  20. $DSSheader = fread($this->getid3->fp, 1256);
  21. if (!preg_match('#^(\x02|\x03)dss#', $DSSheader)) {
  22. $info['error'][] = 'Expecting "[02-03] 64 73 73" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($DSSheader, 0, 4)).'"';
  23. return false;
  24. }
  25. // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm
  26. // shortcut
  27. $info['dss'] = array();
  28. $thisfile_dss = &$info['dss'];
  29. $info['fileformat'] = 'dss';
  30. $info['audio']['dataformat'] = 'dss';
  31. $info['audio']['bitrate_mode'] = 'cbr';
  32. //$thisfile_dss['encoding'] = 'ISO-8859-1';
  33. $thisfile_dss['version'] = ord(substr($DSSheader, 0, 1));
  34. $thisfile_dss['date_create'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12));
  35. $thisfile_dss['date_complete'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12));
  36. //$thisfile_dss['length'] = intval(substr($DSSheader, 62, 6)); // I thought time was in seconds, it's actually HHMMSS
  37. $thisfile_dss['length'] = intval((substr($DSSheader, 62, 2) * 3600) + (substr($DSSheader, 64, 2) * 60) + substr($DSSheader, 66, 2));
  38. $thisfile_dss['priority'] = ord(substr($DSSheader, 793, 1));
  39. $thisfile_dss['comments'] = trim(substr($DSSheader, 798, 100));
  40. //$info['audio']['bits_per_sample'] = ?;
  41. //$info['audio']['sample_rate'] = ?;
  42. $info['audio']['channels'] = 1;
  43. $info['playtime_seconds'] = $thisfile_dss['length'];
  44. $info['audio']['bitrate'] = ($info['filesize'] * 8) / $info['playtime_seconds'];
  45. return true;
  46. }
  47. function DSSdateStringToUnixDate($datestring) {
  48. $y = substr($datestring, 0, 2);
  49. $m = substr($datestring, 2, 2);
  50. $d = substr($datestring, 4, 2);
  51. $h = substr($datestring, 6, 2);
  52. $i = substr($datestring, 8, 2);
  53. $s = substr($datestring, 10, 2);
  54. $y += (($y < 95) ? 2000 : 1900);
  55. return mktime($h, $i, $s, $m, $d, $y);
  56. }
  57. }