<Website>

getID3

PHK Home

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

Size:3572
Storage flags:strip

<?php
















class getid3_tta extends getid3_handler
{

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

$info['fileformat'] = 'tta';
$info['audio']['dataformat'] = 'tta';
$info['audio']['lossless'] = true;
$info['audio']['bitrate_mode'] = 'vbr';

$this->fseek($info['avdataoffset']);
$ttaheader $this->fread(26);

$info['tta']['magic'] = substr($ttaheader03);
$magic 'TTA';
if (
$info['tta']['magic'] != $magic) {
$info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['tta']['magic']).'"';
unset(
$info['fileformat']);
unset(
$info['audio']);
unset(
$info['tta']);
return 
false;
}

switch (
$ttaheader{3}) {
case 
"\x01"
 case 
"\x02"
 case 
"\x03"
 
 
$info['tta']['major_version'] = 1;
$info['avdataoffset'] += 16;

$info['tta']['compression_level'] = ord($ttaheader{3});
$info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader42));
$info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader62));
$info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader84));
$info['tta']['samples_per_channel'] = getid3_lib::LittleEndian2Int(substr($ttaheader124));

$info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
$info['playtime_seconds'] = $info['tta']['samples_per_channel'] / $info['tta']['sample_rate'];
break;

case 
'2'
 
 
$info['tta']['major_version'] = 2;
$info['avdataoffset'] += 20;

$info['tta']['compression_level'] = getid3_lib::LittleEndian2Int(substr($ttaheader42));
$info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader62));
$info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader82));
$info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader102));
$info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader124));
$info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader164));

$info['audio']['encoder_options'] = '-e'.$info['tta']['compression_level'];
$info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
break;

case 
'1'
 
 
$info['tta']['major_version'] = 3;
$info['avdataoffset'] += 26;

$info['tta']['audio_format'] = getid3_lib::LittleEndian2Int(substr($ttaheader42)); 
 
$info['tta']['channels'] = getid3_lib::LittleEndian2Int(substr($ttaheader62));
$info['tta']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($ttaheader82));
$info['tta']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($ttaheader104));
$info['tta']['data_length'] = getid3_lib::LittleEndian2Int(substr($ttaheader144));
$info['tta']['crc32_footer'] = substr($ttaheader184);
$info['tta']['seek_point'] = getid3_lib::LittleEndian2Int(substr($ttaheader224));

$info['playtime_seconds'] = $info['tta']['data_length'] / $info['tta']['sample_rate'];
break;

default:
$info['error'][] = 'This version of getID3() ['.$this->getid3->version().'] only knows how to handle TTA v1 and v2 - it may not work correctly with this file which appears to be TTA v'.$ttaheader{3};
return 
false;
break;
}

$info['audio']['encoder'] = 'TTA v'.$info['tta']['major_version'];
$info['audio']['bits_per_sample'] = $info['tta']['bits_per_sample'];
$info['audio']['sample_rate'] = $info['tta']['sample_rate'];
$info['audio']['channels'] = $info['tta']['channels'];
$info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];

return 
true;
}

}

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