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

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

Change: getid3 upgraded to -> 1.7.9

  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1<?php
2/////////////////////////////////////////////////////////////////
3/// getID3() by James Heinrich <info@getid3.org>               //
4//  available at http://getid3.sourceforge.net                 //
5//            or http://www.getid3.org                         //
6/////////////////////////////////////////////////////////////////
7// See readme.txt for more details                             //
8/////////////////////////////////////////////////////////////////
9//                                                             //
10// module.audio.lpac.php                                       //
11// module for analyzing LPAC Audio files                       //
12// dependencies: module.audio-video.riff.php                   //
13//                                                            ///
14/////////////////////////////////////////////////////////////////
15
16getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio-video.riff.php', __FILE__, true);
17
18class getid3_lpac
19{
20
21        function getid3_lpac(&$fd, &$ThisFileInfo) {
22
23                fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
24                $LPACheader = fread($fd, 14);
25                if (substr($LPACheader, 0, 4) != 'LPAC') {
26                        $ThisFileInfo['error'][] = 'Expected "LPAC" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$StreamMarker.'"';
27                        return false;
28                }
29                $ThisFileInfo['avdataoffset'] += 14;
30
31                $ThisFileInfo['fileformat']            = 'lpac';
32                $ThisFileInfo['audio']['dataformat']   = 'lpac';
33                $ThisFileInfo['audio']['lossless']     = true;
34                $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
35
36                $ThisFileInfo['lpac']['file_version'] = getid3_lib::BigEndian2Int(substr($LPACheader,  4, 1));
37                $flags['audio_type']                  = getid3_lib::BigEndian2Int(substr($LPACheader,  5, 1));
38                $ThisFileInfo['lpac']['total_samples']= getid3_lib::BigEndian2Int(substr($LPACheader,  6, 4));
39                $flags['parameters']                  = getid3_lib::BigEndian2Int(substr($LPACheader, 10, 4));
40
41                $ThisFileInfo['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40);
42                $ThisFileInfo['lpac']['flags']['stereo']  = (bool) ($flags['audio_type'] & 0x04);
43                $ThisFileInfo['lpac']['flags']['24_bit']  = (bool) ($flags['audio_type'] & 0x02);
44                $ThisFileInfo['lpac']['flags']['16_bit']  = (bool) ($flags['audio_type'] & 0x01);
45
46                if ($ThisFileInfo['lpac']['flags']['24_bit'] && $ThisFileInfo['lpac']['flags']['16_bit']) {
47                        $ThisFileInfo['warning'][] = '24-bit and 16-bit flags cannot both be set';
48                }
49
50                $ThisFileInfo['lpac']['flags']['fast_compress']             =  (bool) ($flags['parameters'] & 0x40000000);
51                $ThisFileInfo['lpac']['flags']['random_access']             =  (bool) ($flags['parameters'] & 0x08000000);
52                $ThisFileInfo['lpac']['block_length']                       = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256;
53                $ThisFileInfo['lpac']['flags']['adaptive_prediction_order'] =  (bool) ($flags['parameters'] & 0x00800000);
54                $ThisFileInfo['lpac']['flags']['adaptive_quantization']     =  (bool) ($flags['parameters'] & 0x00400000);
55                $ThisFileInfo['lpac']['flags']['joint_stereo']              =  (bool) ($flags['parameters'] & 0x00040000);
56                $ThisFileInfo['lpac']['quantization']                       =         ($flags['parameters'] & 0x00001F00) >> 8;
57                $ThisFileInfo['lpac']['max_prediction_order']               =         ($flags['parameters'] & 0x0000003F);
58
59                if ($ThisFileInfo['lpac']['flags']['fast_compress'] && ($ThisFileInfo['lpac']['max_prediction_order'] != 3)) {
60                        $ThisFileInfo['warning'][] = 'max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$ThisFileInfo['lpac']['max_prediction_order'].'"';
61                }
62                switch ($ThisFileInfo['lpac']['file_version']) {
63                        case 6:
64                                if ($ThisFileInfo['lpac']['flags']['adaptive_quantization']) {
65                                        $ThisFileInfo['warning'][] = 'adaptive_quantization expected to be false in LPAC file stucture v6, actually true';
66                                }
67                                if ($ThisFileInfo['lpac']['quantization'] != 20) {
68                                        $ThisFileInfo['warning'][] = 'Quantization expected to be 20 in LPAC file stucture v6, actually '.$ThisFileInfo['lpac']['flags']['Q'];
69                                }
70                                break;
71
72                        default:
73                                //$ThisFileInfo['warning'][] = 'This version of getID3() only supports LPAC file format version 6, this file is version '.$ThisFileInfo['lpac']['file_version'].' - please report to info@getid3.org';
74                                break;
75                }
76
77                $dummy = $ThisFileInfo;
78                $riff = new getid3_riff($fd, $dummy);
79                unset($riff);
80                $ThisFileInfo['avdataoffset']                = $dummy['avdataoffset'];
81                $ThisFileInfo['riff']                        = $dummy['riff'];
82                $ThisFileInfo['error']                       = $dummy['error'];
83                $ThisFileInfo['warning']                     = $dummy['warning'];
84                $ThisFileInfo['lpac']['comments']['comment'] = $dummy['comments'];
85                $ThisFileInfo['audio']['sample_rate']        = $dummy['audio']['sample_rate'];
86
87                $ThisFileInfo['audio']['channels']    = ($ThisFileInfo['lpac']['flags']['stereo'] ? 2 : 1);
88
89                if ($ThisFileInfo['lpac']['flags']['24_bit']) {
90                        $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['riff']['audio'][0]['bits_per_sample'];
91                } elseif ($ThisFileInfo['lpac']['flags']['16_bit']) {
92                        $ThisFileInfo['audio']['bits_per_sample'] = 16;
93                } else {
94                        $ThisFileInfo['audio']['bits_per_sample'] = 8;
95                }
96
97                if ($ThisFileInfo['lpac']['flags']['fast_compress']) {
98                         // fast
99                        $ThisFileInfo['audio']['encoder_options'] = '-1';
100                } else {
101                        switch ($ThisFileInfo['lpac']['max_prediction_order']) {
102                                case 20: // simple
103                                        $ThisFileInfo['audio']['encoder_options'] = '-2';
104                                        break;
105                                case 30: // medium
106                                        $ThisFileInfo['audio']['encoder_options'] = '-3';
107                                        break;
108                                case 40: // high
109                                        $ThisFileInfo['audio']['encoder_options'] = '-4';
110                                        break;
111                                case 60: // extrahigh
112                                        $ThisFileInfo['audio']['encoder_options'] = '-5';
113                                        break;
114                        }
115                }
116
117                $ThisFileInfo['playtime_seconds'] = $ThisFileInfo['lpac']['total_samples'] / $ThisFileInfo['audio']['sample_rate'];
118                $ThisFileInfo['audio']['bitrate'] = (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8) / $ThisFileInfo['playtime_seconds'];
119
120                return true;
121        }
122
123}
124
125
126?>
Note: See TracBrowser for help on using the repository browser.