source: branches/MootoolsFileManager-Update/plugins/MootoolsFileManager/mootools-filemanager/Assets/Connector/Assets/getid3/module.audio.rkau.php @ 1300

Last change on this file since 1300 was 1300, checked in by gogo, 9 years ago

Update the MootoolsFileManager? to the latest cpojer with some modifications.
Add a demo for the MFM examples/mootools-file-manager.php
Change the default config for ImageManager? and ExtendedFileManager? for added security.

File size: 4.4 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.shorten.php                                    //
11// module for analyzing Shorten Audio files                    //
12// dependencies: NONE                                          //
13//                                                            ///
14/////////////////////////////////////////////////////////////////
15
16
17class getid3_rkau
18{
19
20        function getid3_rkau(&$fd, &$ThisFileInfo) {
21
22                fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
23                $RKAUHeader = fread($fd, 20);
24                if (substr($RKAUHeader, 0, 3) != 'RKA') {
25                        $ThisFileInfo['error'][] = 'Expecting "RKA" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($RKAUHeader, 0, 3).'"';
26                        return false;
27                }
28
29                $ThisFileInfo['fileformat']            = 'rkau';
30                $ThisFileInfo['audio']['dataformat']   = 'rkau';
31                $ThisFileInfo['audio']['bitrate_mode'] = 'vbr';
32
33                $ThisFileInfo['rkau']['raw']['version']   = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 3, 1));
34                $ThisFileInfo['rkau']['version']          = '1.'.str_pad($ThisFileInfo['rkau']['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT);
35                if (($ThisFileInfo['rkau']['version'] > 1.07) || ($ThisFileInfo['rkau']['version'] < 1.06)) {
36                        $ThisFileInfo['error'][] = 'This version of getID3() can only parse RKAU files v1.06 and 1.07 (this file is v'.$ThisFileInfo['rkau']['version'].')';
37                        unset($ThisFileInfo['rkau']);
38                        return false;
39                }
40
41                $ThisFileInfo['rkau']['source_bytes']     = getid3_lib::LittleEndian2Int(substr($RKAUHeader,  4, 4));
42                $ThisFileInfo['rkau']['sample_rate']      = getid3_lib::LittleEndian2Int(substr($RKAUHeader,  8, 4));
43                $ThisFileInfo['rkau']['channels']         = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 12, 1));
44                $ThisFileInfo['rkau']['bits_per_sample']  = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 13, 1));
45
46                $ThisFileInfo['rkau']['raw']['quality']   = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 14, 1));
47                $this->RKAUqualityLookup($ThisFileInfo['rkau']);
48
49                $ThisFileInfo['rkau']['raw']['flags']            = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 15, 1));
50                $ThisFileInfo['rkau']['flags']['joint_stereo']   = (bool) (!($ThisFileInfo['rkau']['raw']['flags'] & 0x01));
51                $ThisFileInfo['rkau']['flags']['streaming']      =  (bool)  ($ThisFileInfo['rkau']['raw']['flags'] & 0x02);
52                $ThisFileInfo['rkau']['flags']['vrq_lossy_mode'] =  (bool)  ($ThisFileInfo['rkau']['raw']['flags'] & 0x04);
53
54                if ($ThisFileInfo['rkau']['flags']['streaming']) {
55                        $ThisFileInfo['avdataoffset'] += 20;
56                        $ThisFileInfo['rkau']['compressed_bytes']  = getid3_lib::LittleEndian2Int(substr($RKAUHeader, 16, 4));
57                } else {
58                        $ThisFileInfo['avdataoffset'] += 16;
59                        $ThisFileInfo['rkau']['compressed_bytes'] = $ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset'] - 1;
60                }
61                // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes,
62                // sometimes it's more, sometimes less. No idea why(?)
63
64                $ThisFileInfo['audio']['lossless']        = $ThisFileInfo['rkau']['lossless'];
65                $ThisFileInfo['audio']['channels']        = $ThisFileInfo['rkau']['channels'];
66                $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['rkau']['bits_per_sample'];
67                $ThisFileInfo['audio']['sample_rate']     = $ThisFileInfo['rkau']['sample_rate'];
68
69                $ThisFileInfo['playtime_seconds']         = $ThisFileInfo['rkau']['source_bytes'] / ($ThisFileInfo['rkau']['sample_rate'] * $ThisFileInfo['rkau']['channels'] * ($ThisFileInfo['rkau']['bits_per_sample'] / 8));
70                $ThisFileInfo['audio']['bitrate']         = ($ThisFileInfo['rkau']['compressed_bytes'] * 8) / $ThisFileInfo['playtime_seconds'];
71
72                return true;
73
74        }
75
76
77        function RKAUqualityLookup(&$RKAUdata) {
78                $level   = ($RKAUdata['raw']['quality'] & 0xF0) >> 4;
79                $quality =  $RKAUdata['raw']['quality'] & 0x0F;
80
81                $RKAUdata['lossless']          = (($quality == 0) ? true : false);
82                $RKAUdata['compression_level'] = $level + 1;
83                if (!$RKAUdata['lossless']) {
84                        $RKAUdata['quality_setting'] = $quality;
85                }
86
87                return true;
88        }
89
90}
91
92?>
Note: See TracBrowser for help on using the repository browser.