<Website>

getID3

PHK Home

File: /lib/module.audio.dss.php

Size:2858
Storage flags:strip

<?php
















class getid3_dss extends getid3_handler
{

public function 
Analyze() {
$info = &$this->getid3->info;

$this->fseek($info['avdataoffset']);
$DSSheader $this->fread(1540);

if (!
preg_match('#^(\x02|\x03)ds[s2]#'$DSSheader)) {
$info['error'][] = 'Expecting "[02-03] 64 73 [73|32]" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($DSSheader04)).'"';
return 
false;
}


 
$info['encoding'] = 'ISO-8859-1'
 
$info['dss'] = array();

$info['fileformat'] = 'dss';
$info['mime_type'] = 'audio/x-'.substr($DSSheader13); 
 
$info['audio']['dataformat'] = substr($DSSheader13); 
 
$info['audio']['bitrate_mode'] = 'cbr';

$info['dss']['version'] = ord(substr($DSSheader01));
$info['dss']['hardware'] = trim(substr($DSSheader1216)); 
 
$info['dss']['unknown1'] = getid3_lib::LittleEndian2Int(substr($DSSheader284));

 
$info['dss']['date_create'] = $this->DSSdateStringToUnixDate(substr($DSSheader3812));
$info['dss']['date_complete'] = $this->DSSdateStringToUnixDate(substr($DSSheader5012));
$info['dss']['playtime_sec'] = intval((substr($DSSheader622) * 3600) + (substr($DSSheader642) * 60) + substr($DSSheader662)); 
 
$info['dss']['playtime_ms'] = getid3_lib::LittleEndian2Int(substr($DSSheader5124)); 
 
$info['dss']['priority'] = ord(substr($DSSheader7931));
$info['dss']['comments'] = trim(substr($DSSheader798100));
$info['dss']['sample_rate_index'] = ord(substr($DSSheader15381)); 

$info['audio']['bits_per_sample'] = 16
 
$info['audio']['sample_rate'] = $this->DSSsampleRateLookup($info['dss']['sample_rate_index']);
$info['audio']['channels'] = 1;

$info['playtime_seconds'] = $info['dss']['playtime_ms'] / 1000;
if (
floor($info['dss']['playtime_ms'] / 1000) != $info['dss']['playtime_sec']) {

 
$info['playtime_seconds'] = $info['dss']['playtime_sec'];
$this->getid3->warning('playtime_ms ('.number_format($info['dss']['playtime_ms'] / 10003).') does not match playtime_sec ('.number_format($info['dss']['playtime_sec']).') - using playtime_sec value');
}
$info['audio']['bitrate'] = ($info['filesize'] * 8) / $info['playtime_seconds'];

return 
true;
}

public function 
DSSdateStringToUnixDate($datestring) {
$y substr($datestring02);
$m substr($datestring22);
$d substr($datestring42);
$h substr($datestring62);
$i substr($datestring82);
$s substr($datestring102);
$y += (($y 95) ? 2000 1900);
return 
mktime($h$i$s$m$d$y);
}

public function 
DSSsampleRateLookup($sample_rate_index) {
static 
$dssSampleRateLookup = array(
0x0A => 16000,
0x0C => 11025,
0x0D => 12000,
0x15 => 8000,
);
if (!
array_key_exists($sample_rate_index$dssSampleRateLookup)) {
$this->getid3->warning('unknown sample_rate_index: '.$sample_rate_index);
return 
false;
}
return 
$dssSampleRateLookup[$sample_rate_index];
}

}

For more information about the PHK package format: http://phk.tekwire.net