view e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.lpac.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
line wrap: on
line source
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,v 1.2 2006/11/02 10:48:01 ah Exp $
26 class getid3_lpac extends getid3_handler
27 {
29 public function Analyze() {
31 $getid3 = $this->getid3;
33 $getid3->include_module('audio-video.riff');
35 // Magic bytes - 'LPAC'
37 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
38 $lpac_header = fread($getid3->fp, 14);
40 $getid3->info['avdataoffset'] += 14;
42 $getid3->info['lpac'] = array ();
43 $info_lpac = &$getid3->info['lpac'];
45 $getid3->info['fileformat'] = 'lpac';
46 $getid3->info['audio']['dataformat'] = 'lpac';
47 $getid3->info['audio']['lossless'] = true;
48 $getid3->info['audio']['bitrate_mode'] = 'vbr';
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));
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);
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 }
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);
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 }
77 switch ($info_lpac['file_version']) {
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;
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 }
94 // Clone getid3 - messing with something - better safe than sorry
95 $clone = clone $getid3;
97 // Analyze clone by fp
98 $riff = new getid3_riff($clone);
99 $riff->Analyze();
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);
109 $getid3->info['audio']['channels'] = ($info_lpac['flags']['stereo'] ? 2 : 1);
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 }
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 }
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'];
142 return true;
143 }
145 }
148 ?>