123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- if (!defined('GETID3_INCLUDEPATH')) {
- exit;
- }
- getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
- class getid3_dsf extends getid3_handler
- {
-
- public function Analyze() {
- $info = &$this->getid3->info;
- $info['fileformat'] = 'dsf';
- $info['audio']['dataformat'] = 'dsf';
- $info['audio']['lossless'] = true;
- $info['audio']['bitrate_mode'] = 'cbr';
- $this->fseek($info['avdataoffset']);
- $dsfheader = $this->fread(28 + 12);
- $headeroffset = 0;
- $info['dsf']['dsd']['magic'] = substr($dsfheader, $headeroffset, 4);
- $headeroffset += 4;
- $magic = 'DSD ';
- if ($info['dsf']['dsd']['magic'] != $magic) {
- $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['dsf']['dsd']['magic']).'"');
- unset($info['fileformat']);
- unset($info['audio']);
- unset($info['dsf']);
- return false;
- }
- $info['dsf']['dsd']['dsd_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8));
- $headeroffset += 8;
- $info['dsf']['dsd']['dsf_file_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8));
- $headeroffset += 8;
- $info['dsf']['dsd']['meta_chunk_offset'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8));
- $headeroffset += 8;
- $info['dsf']['fmt']['magic'] = substr($dsfheader, $headeroffset, 4);
- $headeroffset += 4;
- $magic = 'fmt ';
- if ($info['dsf']['fmt']['magic'] != $magic) {
- $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['fmt']['magic']).'"');
- return false;
- }
- $info['dsf']['fmt']['fmt_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8));
- $headeroffset += 8;
- $dsfheader .= $this->fread($info['dsf']['fmt']['fmt_chunk_size'] - 12 + 12);
- if (strlen($dsfheader) != ($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size'] + 12)) {
- $this->error('Expecting '.($info['dsf']['dsd']['dsd_chunk_size'] + $info['dsf']['fmt']['fmt_chunk_size']).' bytes header, found '.strlen($dsfheader).' bytes');
- return false;
- }
- $info['dsf']['fmt']['format_version'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['fmt']['format_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['fmt']['channel_type_id'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['fmt']['channels'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['fmt']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['fmt']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['fmt']['sample_count'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8));
- $headeroffset += 8;
- $info['dsf']['fmt']['channel_block_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['fmt']['reserved'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 4));
- $headeroffset += 4;
- $info['dsf']['data']['magic'] = substr($dsfheader, $headeroffset, 4);
- $headeroffset += 4;
- $magic = 'data';
- if ($info['dsf']['data']['magic'] != $magic) {
- $this->error('Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$headeroffset.', found "'.getid3_lib::PrintHexBytes($info['dsf']['data']['magic']).'"');
- return false;
- }
- $info['dsf']['data']['data_chunk_size'] = getid3_lib::LittleEndian2Int(substr($dsfheader, $headeroffset, 8));
- $headeroffset += 8;
- $info['avdataoffset'] = $headeroffset;
- $info['avdataend'] = $info['avdataoffset'] + $info['dsf']['data']['data_chunk_size'];
- if ($info['dsf']['dsd']['meta_chunk_offset'] > 0) {
- $getid3_id3v2 = new getid3_id3v2($this->getid3);
- $getid3_id3v2->StartingOffset = $info['dsf']['dsd']['meta_chunk_offset'];
- $getid3_id3v2->Analyze();
- unset($getid3_id3v2);
- }
- $info['dsf']['fmt']['channel_type'] = $this->DSFchannelTypeLookup($info['dsf']['fmt']['channel_type_id']);
- $info['audio']['channelmode'] = $info['dsf']['fmt']['channel_type'];
- $info['audio']['bits_per_sample'] = $info['dsf']['fmt']['bits_per_sample'];
- $info['audio']['sample_rate'] = $info['dsf']['fmt']['sample_rate'];
- $info['audio']['channels'] = $info['dsf']['fmt']['channels'];
- $info['audio']['bitrate'] = $info['audio']['bits_per_sample'] * $info['audio']['sample_rate'] * $info['audio']['channels'];
- $info['playtime_seconds'] = ($info['dsf']['data']['data_chunk_size'] * 8) / $info['audio']['bitrate'];
- return true;
- }
-
- public static function DSFchannelTypeLookup($channel_type_id) {
- static $DSFchannelTypeLookup = array(
-
- 1 => 'mono',
- 2 => 'stereo',
- 3 => '3-channel',
- 4 => 'quad',
- 5 => '4-channel',
- 6 => '5-channel',
- 7 => '5.1',
- );
- return (isset($DSFchannelTypeLookup[$channel_type_id]) ? $DSFchannelTypeLookup[$channel_type_id] : '');
- }
- }
|