PageRenderTime 414ms CodeModel.GetById 101ms app.highlight 107ms RepoModel.GetById 72ms app.codeStats 1ms

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