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.rkau.php | |
---|
18 | // | Module for analyzing RKAU Audio files | |
---|
19 | // | dependencies: NONE | |
---|
20 | // +----------------------------------------------------------------------+ |
---|
21 | // |
---|
22 | // $Id: module.audio.rkau.php 3318 2009-05-20 21:54:10Z vdigital $ |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | class getid3_rkau extends getid3_handler |
---|
27 | { |
---|
28 | |
---|
29 | public function Analyze() { |
---|
30 | |
---|
31 | $getid3 = $this->getid3; |
---|
32 | |
---|
33 | fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); |
---|
34 | $rkau_header = fread($getid3->fp, 20); |
---|
35 | |
---|
36 | // Magic bytes 'RKA' |
---|
37 | |
---|
38 | $getid3->info['fileformat'] = 'rkau'; |
---|
39 | $getid3->info['audio']['dataformat'] = 'rkau'; |
---|
40 | $getid3->info['audio']['bitrate_mode'] = 'vbr'; |
---|
41 | |
---|
42 | // Shortcut |
---|
43 | $getid3->info['rkau'] = array (); |
---|
44 | $info_rkau = &$getid3->info['rkau']; |
---|
45 | |
---|
46 | $info_rkau['raw']['version'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 3, 1)); |
---|
47 | $info_rkau['version'] = '1.'.str_pad($info_rkau['raw']['version'] & 0x0F, 2, '0', STR_PAD_LEFT); |
---|
48 | if (($info_rkau['version'] > 1.07) || ($info_rkau['version'] < 1.06)) { |
---|
49 | throw new getid3_exception('This version of getID3() can only parse RKAU files v1.06 and 1.07 (this file is v'.$info_rkau['version'].')'); |
---|
50 | } |
---|
51 | |
---|
52 | getid3_lib::ReadSequence('LittleEndian2Int', $info_rkau, $rkau_header, 4, |
---|
53 | array ( |
---|
54 | 'source_bytes' => 4, |
---|
55 | 'sample_rate' => 4, |
---|
56 | 'channels' => 1, |
---|
57 | 'bits_per_sample' => 1 |
---|
58 | ) |
---|
59 | ); |
---|
60 | |
---|
61 | $info_rkau['raw']['quality'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 14, 1)); |
---|
62 | |
---|
63 | $quality = $info_rkau['raw']['quality'] & 0x0F; |
---|
64 | |
---|
65 | $info_rkau['lossless'] = (($quality == 0) ? true : false); |
---|
66 | $info_rkau['compression_level'] = (($info_rkau['raw']['quality'] & 0xF0) >> 4) + 1; |
---|
67 | if (!$info_rkau['lossless']) { |
---|
68 | $info_rkau['quality_setting'] = $quality; |
---|
69 | } |
---|
70 | |
---|
71 | $info_rkau['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 15, 1)); |
---|
72 | $info_rkau['flags']['joint_stereo'] = (bool)(!($info_rkau['raw']['flags'] & 0x01)); |
---|
73 | $info_rkau['flags']['streaming'] = (bool) ($info_rkau['raw']['flags'] & 0x02); |
---|
74 | $info_rkau['flags']['vrq_lossy_mode'] = (bool) ($info_rkau['raw']['flags'] & 0x04); |
---|
75 | |
---|
76 | if ($info_rkau['flags']['streaming']) { |
---|
77 | $getid3->info['avdataoffset'] += 20; |
---|
78 | $info_rkau['compressed_bytes'] = getid3_lib::LittleEndian2Int(substr($rkau_header, 16, 4)); |
---|
79 | } |
---|
80 | else { |
---|
81 | $getid3->info['avdataoffset'] += 16; |
---|
82 | $info_rkau['compressed_bytes'] = $getid3->info['avdataend'] - $getid3->info['avdataoffset'] - 1; |
---|
83 | } |
---|
84 | // Note: compressed_bytes does not always equal what appears to be the actual number of compressed bytes, |
---|
85 | // sometimes it's more, sometimes less. No idea why(?) |
---|
86 | |
---|
87 | $getid3->info['audio']['lossless'] = $info_rkau['lossless']; |
---|
88 | $getid3->info['audio']['channels'] = $info_rkau['channels']; |
---|
89 | $getid3->info['audio']['bits_per_sample'] = $info_rkau['bits_per_sample']; |
---|
90 | $getid3->info['audio']['sample_rate'] = $info_rkau['sample_rate']; |
---|
91 | |
---|
92 | $getid3->info['playtime_seconds'] = $info_rkau['source_bytes'] / ($info_rkau['sample_rate'] * $info_rkau['channels'] * ($info_rkau['bits_per_sample'] / 8)); |
---|
93 | $getid3->info['audio']['bitrate'] = ($info_rkau['compressed_bytes'] * 8) / $getid3->info['playtime_seconds']; |
---|
94 | |
---|
95 | return true; |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | ?> |
---|