rlm@3: <?php
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | PHP version 5                                                        |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | This source file is subject to version 2 of the GPL license,         |
rlm@3: // | that is bundled with this package in the file license.txt and is     |
rlm@3: // | available through the world-wide-web at the following url:           |
rlm@3: // | http://www.gnu.org/copyleft/gpl.html                                 |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | Authors: James Heinrich <infoØgetid3*org>                            |
rlm@3: // |          Allan Hansen <ahØartemis*dk>                                |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | module.audio.mpc_old.php                                             |
rlm@3: // | Module for analyzing Musepack/MPEG+ Audio files - SV4-SV6            |
rlm@3: // | dependencies: NONE                                                   |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: //
rlm@3: // $Id: module.audio.mpc_old.php,v 1.2 2006/11/02 10:48:01 ah Exp $
rlm@3: 
rlm@3:         
rlm@3:         
rlm@3: class getid3_mpc_old extends getid3_handler
rlm@3: {
rlm@3: 
rlm@3:     public function Analyze() {
rlm@3: 
rlm@3:         $getid3 = $this->getid3;
rlm@3:         
rlm@3:         // http://www.uni-jena.de/~pfk/mpp/sv8/header.html
rlm@3:         
rlm@3:         $getid3->info['mpc']['header'] = array ();
rlm@3:         $info_mpc_header = &$getid3->info['mpc']['header'];
rlm@3: 
rlm@3:         $getid3->info['fileformat']               = 'mpc';
rlm@3:         $getid3->info['audio']['dataformat']      = 'mpc';
rlm@3:         $getid3->info['audio']['bitrate_mode']    = 'vbr';
rlm@3:         $getid3->info['audio']['channels']        = 2;  // the format appears to be hardcoded for stereo only
rlm@3:         $getid3->info['audio']['lossless']        = false;
rlm@3: 
rlm@3:         fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3: 
rlm@3:         $info_mpc_header['size'] = 8;
rlm@3:         $getid3->info['avdataoffset'] += $info_mpc_header['size'];
rlm@3:         
rlm@3:         $mpc_header_data = fread($getid3->fp, $info_mpc_header['size']);
rlm@3:             
rlm@3:         
rlm@3:         // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :)
rlm@3:         $header_dword[0] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 0, 4));
rlm@3:         $header_dword[1] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4));
rlm@3: 
rlm@3: 
rlm@3:         // DDDD DDDD  CCCC CCCC  BBBB BBBB  AAAA AAAA
rlm@3:         // aaaa aaaa  abcd dddd  dddd deee  eeff ffff
rlm@3:         //
rlm@3:         // a = bitrate       = anything
rlm@3:         // b = IS            = anything
rlm@3:         // c = MS            = anything
rlm@3:         // d = streamversion = 0000000004 or 0000000005 or 0000000006
rlm@3:         // e = maxband       = anything
rlm@3:         // f = blocksize     = 000001 for SV5+, anything(?) for SV4
rlm@3: 
rlm@3:         $info_mpc_header['target_bitrate']       =       (($header_dword[0] & 0xFF800000) >> 23);
rlm@3:         $info_mpc_header['intensity_stereo']     = (bool)(($header_dword[0] & 0x00400000) >> 22);
rlm@3:         $info_mpc_header['mid-side_stereo']      = (bool)(($header_dword[0] & 0x00200000) >> 21);
rlm@3:         $info_mpc_header['stream_major_version'] =        ($header_dword[0] & 0x001FF800) >> 11;
rlm@3:         $info_mpc_header['stream_minor_version'] = 0; 
rlm@3:         $info_mpc_header['max_band']             =        ($header_dword[0] & 0x000007C0) >>  6;  // related to lowpass frequency, not sure how it translates exactly
rlm@3:         $info_mpc_header['block_size']           =        ($header_dword[0] & 0x0000003F);
rlm@3: 
rlm@3:         switch ($info_mpc_header['stream_major_version']) {
rlm@3:             case 4:
rlm@3:                 $info_mpc_header['frame_count'] = ($header_dword[1] >> 16);
rlm@3:                 break;
rlm@3:             case 5:
rlm@3:             case 6:
rlm@3:                 $info_mpc_header['frame_count'] =  $header_dword[1];
rlm@3:                 break;
rlm@3: 
rlm@3:             default:
rlm@3:                 throw new getid3_exception('Expecting 4, 5 or 6 in version field, found '.$info_mpc_header['stream_major_version'].' instead');
rlm@3:         }
rlm@3: 
rlm@3:         if (($info_mpc_header['stream_major_version'] > 4) && ($info_mpc_header['block_size'] != 1)) {
rlm@3:             $getid3->warning('Block size expected to be 1, actual value found: '.$info_mpc_header['block_size']);
rlm@3:         }
rlm@3: 
rlm@3:         $info_mpc_header['sample_rate'] = $getid3->info['audio']['sample_rate'] = 44100; // AB: used by all files up to SV7
rlm@3:         $info_mpc_header['samples']     = $info_mpc_header['frame_count'] * 1152 * $getid3->info['audio']['channels'];
rlm@3: 
rlm@3:         $getid3->info['audio']['bitrate_mode'] = $info_mpc_header['target_bitrate'] == 0 ? 'vbr' : 'cbr';
rlm@3: 
rlm@3:         $getid3->info['mpc']['bitrate']   = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 * 44100 / $info_mpc_header['frame_count'] / 1152;
rlm@3:         $getid3->info['audio']['bitrate'] = $getid3->info['mpc']['bitrate'];
rlm@3:         $getid3->info['audio']['encoder'] = 'SV'.$info_mpc_header['stream_major_version'];
rlm@3:         
rlm@3:         return true;
rlm@3:     }
rlm@3:     
rlm@3: }
rlm@3: 
rlm@3: 
rlm@3: ?>