rlm@3: | rlm@3: // | Allan Hansen | rlm@3: // +----------------------------------------------------------------------+ rlm@3: // | module.audio.tta.php | rlm@3: // | Module for analyzing TTA Audio files | rlm@3: // | dependencies: NONE | rlm@3: // +----------------------------------------------------------------------+ rlm@3: // rlm@3: // $Id: module.audio.tta.php,v 1.2 2006/11/02 10:48:01 ah Exp $ rlm@3: rlm@3: rlm@3: rlm@3: class getid3_tta extends getid3_handler rlm@3: { rlm@3: rlm@3: public function Analyze() { rlm@3: rlm@3: $getid3 = $this->getid3; rlm@3: rlm@3: $getid3->info['fileformat'] = 'tta'; rlm@3: $getid3->info['audio']['dataformat'] = 'tta'; rlm@3: $getid3->info['audio']['lossless'] = true; rlm@3: $getid3->info['audio']['bitrate_mode'] = 'vbr'; rlm@3: rlm@3: fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); rlm@3: $tta_header = fread($getid3->fp, 26); rlm@3: rlm@3: $getid3->info['tta']['magic'] = 'TTA'; // Magic bytes rlm@3: rlm@3: switch ($tta_header{3}) { rlm@3: rlm@3: case "\x01": // TTA v1.x rlm@3: case "\x02": // TTA v1.x rlm@3: case "\x03": // TTA v1.x rlm@3: rlm@3: // "It was the demo-version of the TTA encoder. There is no released format with such header. TTA encoder v1 is not supported about a year." rlm@3: $getid3->info['tta']['major_version'] = 1; rlm@3: $getid3->info['avdataoffset'] += 16; rlm@3: rlm@3: getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, rlm@3: array ( rlm@3: 'channels' => 2, rlm@3: 'bits_per_sample' => 2, rlm@3: 'sample_rate' => 4, rlm@3: 'samples_per_channel' => 4 rlm@3: ) rlm@3: ); rlm@3: $getid3->info['tta']['compression_level'] = ord($tta_header{3}); rlm@3: rlm@3: $getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level']; rlm@3: $getid3->info['playtime_seconds'] = $getid3->info['tta']['samples_per_channel'] / $getid3->info['tta']['sample_rate']; rlm@3: break; rlm@3: rlm@3: case '2': // TTA v2.x rlm@3: // "I have hurried to release the TTA 2.0 encoder. Format documentation is removed from our site. This format still in development. Please wait the TTA2 format, encoder v4." rlm@3: $getid3->info['tta']['major_version'] = 2; rlm@3: $getid3->info['avdataoffset'] += 20; rlm@3: rlm@3: getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, rlm@3: array ( rlm@3: 'compression_level' => 2, rlm@3: 'audio_format' => 2, rlm@3: 'channels' => 2, rlm@3: 'bits_per_sample' => 2, rlm@3: 'sample_rate' => 4, rlm@3: 'data_length' => 4 rlm@3: ) rlm@3: ); rlm@3: rlm@3: $getid3->info['audio']['encoder_options'] = '-e'.$getid3->info['tta']['compression_level']; rlm@3: $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate']; rlm@3: break; rlm@3: rlm@3: case '1': // TTA v3.x rlm@3: // "This is a first stable release of the TTA format. It will be supported by the encoders v3 or higher." rlm@3: $getid3->info['tta']['major_version'] = 3; rlm@3: $getid3->info['avdataoffset'] += 26; rlm@3: rlm@3: getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['tta'], $tta_header, 4, rlm@3: array ( rlm@3: 'audio_format' => 2, rlm@3: 'channels' => 2, rlm@3: 'bits_per_sample'=> 2, rlm@3: 'sample_rate' => 4, rlm@3: 'data_length' => 4, rlm@3: 'crc32_footer' => -4, // string rlm@3: 'seek_point' => 4 rlm@3: ) rlm@3: ); rlm@3: rlm@3: $getid3->info['playtime_seconds'] = $getid3->info['tta']['data_length'] / $getid3->info['tta']['sample_rate']; rlm@3: break; rlm@3: rlm@3: default: rlm@3: throw new getid3_exception('This version of getID3() only knows how to handle TTA v1, v2 and v3 - it may not work correctly with this file which appears to be TTA v'.$tta_header{3}); rlm@3: return false; rlm@3: break; rlm@3: } rlm@3: rlm@3: $getid3->info['audio']['encoder'] = 'TTA v'.$getid3->info['tta']['major_version']; rlm@3: $getid3->info['audio']['bits_per_sample'] = $getid3->info['tta']['bits_per_sample']; rlm@3: $getid3->info['audio']['sample_rate'] = $getid3->info['tta']['sample_rate']; rlm@3: $getid3->info['audio']['channels'] = $getid3->info['tta']['channels']; rlm@3: $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds']; rlm@3: rlm@3: return true; rlm@3: } rlm@3: rlm@3: } rlm@3: rlm@3: rlm@3: ?>