source: extensions/charlies_content/getid3/getid3/module.audio.mpc_old.php @ 3318

Revision 3318, 5.1 KB checked in by vdigital, 10 years ago (diff)

+ Add Charlies' content to depository

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