annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.mpc_old.php @ 8:1b77e8657088 judyates

[svn r9] saving for transference to cd
author rlm
date Fri, 19 Mar 2010 07:17:36 -0400
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.audio.mpc_old.php |
rlm@3 18 // | Module for analyzing Musepack/MPEG+ Audio files - SV4-SV6 |
rlm@3 19 // | dependencies: NONE |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio.mpc_old.php,v 1.2 2006/11/02 10:48:01 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_mpc_old extends getid3_handler
rlm@3 27 {
rlm@3 28
rlm@3 29 public function Analyze() {
rlm@3 30
rlm@3 31 $getid3 = $this->getid3;
rlm@3 32
rlm@3 33 // http://www.uni-jena.de/~pfk/mpp/sv8/header.html
rlm@3 34
rlm@3 35 $getid3->info['mpc']['header'] = array ();
rlm@3 36 $info_mpc_header = &$getid3->info['mpc']['header'];
rlm@3 37
rlm@3 38 $getid3->info['fileformat'] = 'mpc';
rlm@3 39 $getid3->info['audio']['dataformat'] = 'mpc';
rlm@3 40 $getid3->info['audio']['bitrate_mode'] = 'vbr';
rlm@3 41 $getid3->info['audio']['channels'] = 2; // the format appears to be hardcoded for stereo only
rlm@3 42 $getid3->info['audio']['lossless'] = false;
rlm@3 43
rlm@3 44 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 45
rlm@3 46 $info_mpc_header['size'] = 8;
rlm@3 47 $getid3->info['avdataoffset'] += $info_mpc_header['size'];
rlm@3 48
rlm@3 49 $mpc_header_data = fread($getid3->fp, $info_mpc_header['size']);
rlm@3 50
rlm@3 51
rlm@3 52 // Most of this code adapted from Jurgen Faul's MPEGplus source code - thanks Jurgen! :)
rlm@3 53 $header_dword[0] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 0, 4));
rlm@3 54 $header_dword[1] = getid3_lib::LittleEndian2Int(substr($mpc_header_data, 4, 4));
rlm@3 55
rlm@3 56
rlm@3 57 // DDDD DDDD CCCC CCCC BBBB BBBB AAAA AAAA
rlm@3 58 // aaaa aaaa abcd dddd dddd deee eeff ffff
rlm@3 59 //
rlm@3 60 // a = bitrate = anything
rlm@3 61 // b = IS = anything
rlm@3 62 // c = MS = anything
rlm@3 63 // d = streamversion = 0000000004 or 0000000005 or 0000000006
rlm@3 64 // e = maxband = anything
rlm@3 65 // f = blocksize = 000001 for SV5+, anything(?) for SV4
rlm@3 66
rlm@3 67 $info_mpc_header['target_bitrate'] = (($header_dword[0] & 0xFF800000) >> 23);
rlm@3 68 $info_mpc_header['intensity_stereo'] = (bool)(($header_dword[0] & 0x00400000) >> 22);
rlm@3 69 $info_mpc_header['mid-side_stereo'] = (bool)(($header_dword[0] & 0x00200000) >> 21);
rlm@3 70 $info_mpc_header['stream_major_version'] = ($header_dword[0] & 0x001FF800) >> 11;
rlm@3 71 $info_mpc_header['stream_minor_version'] = 0;
rlm@3 72 $info_mpc_header['max_band'] = ($header_dword[0] & 0x000007C0) >> 6; // related to lowpass frequency, not sure how it translates exactly
rlm@3 73 $info_mpc_header['block_size'] = ($header_dword[0] & 0x0000003F);
rlm@3 74
rlm@3 75 switch ($info_mpc_header['stream_major_version']) {
rlm@3 76 case 4:
rlm@3 77 $info_mpc_header['frame_count'] = ($header_dword[1] >> 16);
rlm@3 78 break;
rlm@3 79 case 5:
rlm@3 80 case 6:
rlm@3 81 $info_mpc_header['frame_count'] = $header_dword[1];
rlm@3 82 break;
rlm@3 83
rlm@3 84 default:
rlm@3 85 throw new getid3_exception('Expecting 4, 5 or 6 in version field, found '.$info_mpc_header['stream_major_version'].' instead');
rlm@3 86 }
rlm@3 87
rlm@3 88 if (($info_mpc_header['stream_major_version'] > 4) && ($info_mpc_header['block_size'] != 1)) {
rlm@3 89 $getid3->warning('Block size expected to be 1, actual value found: '.$info_mpc_header['block_size']);
rlm@3 90 }
rlm@3 91
rlm@3 92 $info_mpc_header['sample_rate'] = $getid3->info['audio']['sample_rate'] = 44100; // AB: used by all files up to SV7
rlm@3 93 $info_mpc_header['samples'] = $info_mpc_header['frame_count'] * 1152 * $getid3->info['audio']['channels'];
rlm@3 94
rlm@3 95 $getid3->info['audio']['bitrate_mode'] = $info_mpc_header['target_bitrate'] == 0 ? 'vbr' : 'cbr';
rlm@3 96
rlm@3 97 $getid3->info['mpc']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 * 44100 / $info_mpc_header['frame_count'] / 1152;
rlm@3 98 $getid3->info['audio']['bitrate'] = $getid3->info['mpc']['bitrate'];
rlm@3 99 $getid3->info['audio']['encoder'] = 'SV'.$info_mpc_header['stream_major_version'];
rlm@3 100
rlm@3 101 return true;
rlm@3 102 }
rlm@3 103
rlm@3 104 }
rlm@3 105
rlm@3 106
rlm@3 107 ?>