<Website>

getID3

PHK Home

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

Size:6651
Storage flags:strip

<?php















getid3_lib
::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php'__FILE__true);

class 
getid3_la extends getid3_handler
{

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

$offset 0;
$this->fseek($info['avdataoffset']);
$rawdata $this->fread($this->getid3->fread_buffer_size());

switch (
substr($rawdata$offset4)) {
case 
'LA02':
case 
'LA03':
case 
'LA04':
$info['fileformat'] = 'la';
$info['audio']['dataformat'] = 'la';
$info['audio']['lossless'] = true;

$info['la']['version_major'] = (int) substr($rawdata$offset 21);
$info['la']['version_minor'] = (int) substr($rawdata$offset 31);
$info['la']['version'] = (float) $info['la']['version_major'] + ($info['la']['version_minor'] / 10);
$offset += 4;

$info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;
if (
$info['la']['uncompressed_size'] == 0) {
$info['error'][] = 'Corrupt LA file: uncompressed_size == zero';
return 
false;
}

$WAVEchunk substr($rawdata$offset4);
if (
$WAVEchunk !== 'WAVE') {
$info['error'][] = 'Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.';
return 
false;
}
$offset += 4;

$info['la']['fmt_size'] = 24;
if (
$info['la']['version'] >= 0.3) {

$info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$info['la']['header_size'] = 49 $info['la']['fmt_size'] - 24;
$offset += 4;

} else {


 
$info['la']['header_size'] = 41;

}

$fmt_chunk substr($rawdata$offset4);
if (
$fmt_chunk !== 'fmt ') {
$info['error'][] = 'Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.';
return 
false;
}
$offset += 4;
$fmt_size getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;

$info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset2));
$offset += 2;

$info['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset2));
$offset += 2;
if (
$info['la']['channels'] == 0) {
$info['error'][] = 'Corrupt LA file: channels == zero';
return 
false;
}

$info['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;
if (
$info['la']['sample_rate'] == 0) {
$info['error'][] = 'Corrupt LA file: sample_rate == zero';
return 
false;
}

$info['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;
$info['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset2));
$offset += 2;
$info['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset2));
$offset += 2;

$info['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;

$info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset1));
$offset += 1;
$info['la']['flags']['seekable'] = (bool) ($info['la']['raw']['flags'] & 0x01);
if (
$info['la']['version'] >= 0.4) {
$info['la']['flags']['high_compression'] = (bool) ($info['la']['raw']['flags'] & 0x02);
}

$info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;


 
 
 
 
 
 if (
$info['la']['version'] >= 0.4) {
$info['la']['blocksize'] = 61440;
$info['la']['seekevery'] = 19;
} else {
$info['la']['blocksize'] = 73728;
$info['la']['seekevery'] = 16;
}

$info['la']['seekpoint_count'] = 0;
if (
$info['la']['flags']['seekable']) {
$info['la']['seekpoint_count'] = floor($info['la']['samples'] / ($info['la']['blocksize'] * $info['la']['seekevery']));

for (
$i 0$i $info['la']['seekpoint_count']; $i++) {
$info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;
}
}

if (
$info['la']['version'] >= 0.3) {


 
 
 
$info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata$offset4));
$offset += 4;

if (
$info['la']['footerstart'] > $info['filesize']) {
$info['warning'][] = 'FooterStart value points to offset '.$info['la']['footerstart'].' which is beyond end-of-file ('.$info['filesize'].')';
$info['la']['footerstart'] = $info['filesize'];
}

} else {


 
$info['la']['footerstart'] = $info['avdataend'];

}

if (
$info['la']['footerstart'] < $info['avdataend']) {
if (
$RIFFtempfilename tempnam(GETID3_TEMP_DIR'id3')) {
if (
$RIFF_fp fopen($RIFFtempfilename'w+b')) {
$RIFFdata 'WAVE';
if (
$info['la']['version'] == 0.2) {
$RIFFdata .= substr($rawdata1224);
} else {
$RIFFdata .= substr($rawdata1624);
}
if (
$info['la']['footerstart'] < $info['avdataend']) {
$this->fseek($info['la']['footerstart']);
$RIFFdata .= $this->fread($info['avdataend'] - $info['la']['footerstart']);
}
$RIFFdata 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4false).$RIFFdata;
fwrite($RIFF_fp$RIFFdatastrlen($RIFFdata));
fclose($RIFF_fp);

$getid3_temp = new getID3();
$getid3_temp->openfile($RIFFtempfilename);
$getid3_riff = new getid3_riff($getid3_temp);
$getid3_riff->Analyze();

if (empty(
$getid3_temp->info['error'])) {
$info['riff'] = $getid3_temp->info['riff'];
} else {
$info['warning'][] = 'Error parsing RIFF portion of La file: '.implode($getid3_temp->info['error']);
}
unset(
$getid3_temp$getid3_riff);
}
unlink($RIFFtempfilename);
}
}


 
$info['avdataend'] = $info['avdataoffset'] + $info['la']['footerstart'];
$info['avdataoffset'] = $info['avdataoffset'] + $offset;

$info['la']['compression_ratio'] = (float) (($info['avdataend'] - $info['avdataoffset']) / $info['la']['uncompressed_size']);
$info['playtime_seconds'] = (float) ($info['la']['samples'] / $info['la']['sample_rate']) / $info['la']['channels'];
if (
$info['playtime_seconds'] == 0) {
$info['error'][] = 'Corrupt LA file: playtime_seconds == zero';
return 
false;
}

$info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * $info['playtime_seconds'];

 
$info['audio']['bits_per_sample'] = $info['la']['bits_per_sample'];
break;

default:
if (
substr($rawdata$offset2) == 'LA') {
$info['error'][] = 'This version of getID3() ['.$this->getid3->version().'] does not support LA version '.substr($rawdata$offset 21).'.'.substr($rawdata$offset 31).' which this appears to be - check http://getid3.sourceforge.net for updates.';
} else {
$info['error'][] = 'Not a LA (Lossless-Audio) file';
}
return 
false;
break;
}

$info['audio']['channels'] = $info['la']['channels'];
$info['audio']['sample_rate'] = (int) $info['la']['sample_rate'];
$info['audio']['encoder'] = 'LA v'.$info['la']['version'];

return 
true;
}

}

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