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

Last change on this file since 3318 was 3318, checked in by vdigital, 15 years ago

+ Add Charlies' content to depository

  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
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.lpac.php                                                |
18// | Module for analyzing LPAC Audio files                                |
19// | dependencies: module.audio-video.riff.php                            |
20// +----------------------------------------------------------------------+
21//
22// $Id: module.audio.lpac.php 3318 2009-05-20 21:54:10Z vdigital $
23
24       
25       
26class getid3_lpac extends getid3_handler
27{
28
29    public function Analyze() {
30       
31        $getid3 = $this->getid3;
32       
33        $getid3->include_module('audio-video.riff');
34       
35        // Magic bytes - 'LPAC'
36       
37        fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
38        $lpac_header = fread($getid3->fp, 14);
39       
40        $getid3->info['avdataoffset'] += 14;
41       
42        $getid3->info['lpac'] = array ();
43        $info_lpac = &$getid3->info['lpac'];
44
45        $getid3->info['fileformat']               = 'lpac';
46        $getid3->info['audio']['dataformat']      = 'lpac';
47        $getid3->info['audio']['lossless']        = true;
48        $getid3->info['audio']['bitrate_mode']    = 'vbr';
49                                                 
50        $info_lpac['file_version']     = getid3_lib::BigEndian2Int($lpac_header{4});
51        $flags['audio_type']                      = getid3_lib::BigEndian2Int($lpac_header{5});
52        $info_lpac['total_samples']    = getid3_lib::BigEndian2Int(substr($lpac_header,  6, 4));
53        $flags['parameters']                      = getid3_lib::BigEndian2Int(substr($lpac_header, 10, 4));
54
55        $info_lpac['flags']['is_wave'] = (bool)($flags['audio_type'] & 0x40);
56        $info_lpac['flags']['stereo']  = (bool)($flags['audio_type'] & 0x04);
57        $info_lpac['flags']['24_bit']  = (bool)($flags['audio_type'] & 0x02);
58        $info_lpac['flags']['16_bit']  = (bool)($flags['audio_type'] & 0x01);
59
60        if ($info_lpac['flags']['24_bit'] && $info_lpac['flags']['16_bit']) {
61            $getid3->warning('24-bit and 16-bit flags cannot both be set');
62        }
63
64        $info_lpac['flags']['fast_compress']             =   (bool)($flags['parameters'] & 0x40000000);
65        $info_lpac['flags']['random_access']             =   (bool)($flags['parameters'] & 0x08000000);
66        $info_lpac['block_length']                       = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256;
67        $info_lpac['flags']['adaptive_prediction_order'] =   (bool)($flags['parameters'] & 0x00800000);
68        $info_lpac['flags']['adaptive_quantization']     =   (bool)($flags['parameters'] & 0x00400000);
69        $info_lpac['flags']['joint_stereo']              =   (bool)($flags['parameters'] & 0x00040000);
70        $info_lpac['quantization']                       =         ($flags['parameters'] & 0x00001F00) >> 8;
71        $info_lpac['max_prediction_order']               =         ($flags['parameters'] & 0x0000003F);
72
73        if ($info_lpac['flags']['fast_compress'] && ($info_lpac['max_prediction_order'] != 3)) {
74            $getid3->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info_lpac['max_prediction_order'].'"');
75        }
76       
77        switch ($info_lpac['file_version']) {
78       
79            case 6:
80                if ($info_lpac['flags']['adaptive_quantization']) {
81                    $getid3->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true');
82                }
83                if ($info_lpac['quantization'] != 20) {
84                    $getid3->warning('Quantization expected to be 20 in LPAC file stucture v6, actually '.$info_lpac['flags']['Q']);
85                }
86                break;
87
88       
89            default:
90                //$getid3->warning('This version of getID3() only supports LPAC file format version 6, this file is version '.$info_lpac['file_version'].' - please report to info@getid3.org');
91                break;
92        }
93
94        // Clone getid3 - messing with something - better safe than sorry
95        $clone = clone $getid3;
96       
97        // Analyze clone by fp
98        $riff = new getid3_riff($clone);
99        $riff->Analyze();
100       
101        // Import from clone and destroy
102        $getid3->info['avdataoffset']                = $clone->info['avdataoffset'];
103        $getid3->info['riff']                        = $clone->info['riff'];
104        //$info_lpac['comments']['comment'] = $clone->info['comments'];
105        $getid3->info['audio']['sample_rate']        = $clone->info['audio']['sample_rate'];
106        $getid3->warnings($clone->warnings());
107        unset($clone);
108       
109        $getid3->info['audio']['channels'] = ($info_lpac['flags']['stereo'] ? 2 : 1);
110
111        if ($info_lpac['flags']['24_bit']) {
112            $getid3->info['audio']['bits_per_sample'] = $getid3->info['riff']['audio'][0]['bits_per_sample'];
113        } elseif ($info_lpac['flags']['16_bit']) {
114            $getid3->info['audio']['bits_per_sample'] = 16;
115        } else {
116            $getid3->info['audio']['bits_per_sample'] = 8;
117        }
118
119        if ($info_lpac['flags']['fast_compress']) {
120             // fast
121            $getid3->info['audio']['encoder_options'] = '-1';
122        } else {
123            switch ($info_lpac['max_prediction_order']) {
124                case 20: // simple
125                    $getid3->info['audio']['encoder_options'] = '-2';
126                    break;
127                case 30: // medium
128                    $getid3->info['audio']['encoder_options'] = '-3';
129                    break;
130                case 40: // high
131                    $getid3->info['audio']['encoder_options'] = '-4';
132                    break;
133                case 60: // extrahigh
134                    $getid3->info['audio']['encoder_options'] = '-5';
135                    break;
136            }
137        }
138
139        $getid3->info['playtime_seconds'] = $info_lpac['total_samples'] / $getid3->info['audio']['sample_rate'];
140        $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
141
142        return true;
143    }
144
145}
146
147
148?>
Note: See TracBrowser for help on using the repository browser.