1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
<?php
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
// +----------------------------------------------------------------------+
// | PHP version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license, |
// | that is bundled with this package in the file license.txt and is |
// | available through the world-wide-web at the following url: |
// | http://www.gnu.org/copyleft/gpl.html |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <info�getid3*org> |
// | Allan Hansen <ah�artemis*dk> |
// +----------------------------------------------------------------------+
// | module.audio.vqf.php |
// | Module for analyzing VQF Audio files |
// | dependencies: NONE |
// +----------------------------------------------------------------------+
//
// $Id: module.audio.vqf.php,v 1.3 2006/11/16 23:16:31 ah Exp $
class getid3_vqf extends getid3_handler
{
public function Analyze() {
$getid3 = $this->getid3;
// based loosely on code from TTwinVQ by Jurgen Faul <jfaul�gmx*de>
// http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
$getid3->info['fileformat'] = 'vqf';
$getid3->info['audio']['dataformat'] = 'vqf';
$getid3->info['audio']['bitrate_mode'] = 'cbr';
$getid3->info['audio']['lossless'] = false;
// Shortcuts
$getid3->info['vqf']['raw'] = array ();
$info_vqf = &$getid3->info['vqf'];
$info_vqf_raw = &$info_vqf['raw'];
// Get header
fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
$vqf_header_data = fread($getid3->fp, 16);
$info_vqf_raw['header_tag'] = 'TWIN'; // Magic bytes
$info_vqf_raw['version'] = substr($vqf_header_data, 4, 8);
$info_vqf_raw['size'] = getid3_lib::BigEndian2Int(substr($vqf_header_data, 12, 4));
while (ftell($getid3->fp) < $getid3->info['avdataend']) {
$chunk_base_offset = ftell($getid3->fp);
$chunk_data = fread($getid3->fp, 8);
$chunk_name = substr($chunk_data, 0, 4);
if ($chunk_name == 'DATA') {
$getid3->info['avdataoffset'] = $chunk_base_offset;
break;
}
$chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4));
if ($chunk_size > ($getid3->info['avdataend'] - ftell($getid3->fp))) {
throw new getid3_exception('Invalid chunk size ('.$chunk_size.') for chunk "'.$chunk_name.'" at offset 8.');
}
if ($chunk_size > 0) {
$chunk_data .= fread($getid3->fp, $chunk_size);
}
switch ($chunk_name) {
case 'COMM':
$info_vqf['COMM'] = array ();
getid3_lib::ReadSequence('BigEndian2Int', $info_vqf['COMM'], $chunk_data, 8,
array (
'channel_mode' => 4,
'bitrate' => 4,
'sample_rate' => 4,
'security_level' => 4
)
);
$getid3->info['audio']['channels'] = $info_vqf['COMM']['channel_mode'] + 1;
$getid3->info['audio']['sample_rate'] = getid3_vqf::VQFchannelFrequencyLookup($info_vqf['COMM']['sample_rate']);
$getid3->info['audio']['bitrate'] = $info_vqf['COMM']['bitrate'] * 1000;
$getid3->info['audio']['encoder_options'] = 'CBR' . ceil($getid3->info['audio']['bitrate']/1000);
if ($getid3->info['audio']['bitrate'] == 0) {
throw new getid3_exception('Corrupt VQF file: bitrate_audio == zero');
}
break;
case 'NAME':
case 'AUTH':
case '(c) ':
case 'FILE':
case 'COMT':
case 'ALBM':
$info_vqf['comments'][getid3_vqf::VQFcommentNiceNameLookup($chunk_name)][] = trim(substr($chunk_data, 8));
break;
case 'DSIZ':
$info_vqf['DSIZ'] = getid3_lib::BigEndian2Int(substr($chunk_data, 8, 4));
break;
default:
$getid3->warning('Unhandled chunk type "'.$chunk_name.'" at offset 8');
break;
}
}
$getid3->info['playtime_seconds'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['audio']['bitrate'];
if (isset($info_vqf['DSIZ']) && (($info_vqf['DSIZ'] != ($getid3->info['avdataend'] - $getid3->info['avdataoffset'] - strlen('DATA'))))) {
switch ($info_vqf['DSIZ']) {
case 0:
case 1:
$getid3->warning('Invalid DSIZ value "'.$info_vqf['DSIZ'].'". This is known to happen with VQF files encoded by Ahead Nero, and seems to be its way of saying this is TwinVQF v'.($info_vqf['DSIZ'] + 1).'.0');
$getid3->info['audio']['encoder'] = 'Ahead Nero';
break;
default:
$getid3->warning('Probable corrupted file - should be '.$info_vqf['DSIZ'].' bytes, actually '.($getid3->info['avdataend'] - $getid3->info['avdataoffset'] - strlen('DATA')));
break;
}
}
return true;
}
public static function VQFchannelFrequencyLookup($frequencyid) {
static $lookup = array (
11 => 11025,
22 => 22050,
44 => 44100
);
return (isset($lookup[$frequencyid]) ? $lookup[$frequencyid] : $frequencyid * 1000);
}
public static function VQFcommentNiceNameLookup($shortname) {
static $lookup = array (
'NAME' => 'title',
'AUTH' => 'artist',
'(c) ' => 'copyright',
'FILE' => 'filename',
'COMT' => 'comment',
'ALBM' => 'album'
);
return (isset($lookup[$shortname]) ? $lookup[$shortname] : $shortname);
}
}
?>
|