ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Vqf.php
Go to the documentation of this file.
1<?php
2
3namespace GetId3\Module\Audio;
4
7
10// available at http://getid3.sourceforge.net //
11// or http://www.getid3.org //
13// See readme.txt for more details //
15// //
16// module.audio.vqf.php //
17// module for analyzing VQF audio files //
18// dependencies: NONE //
19// ///
21
29class Vqf extends BaseHandler
30{
35 public function analyze()
36 {
37 $info = &$this->getid3->info;
38
39 // based loosely on code from TTwinVQ by Jurgen Faul <jfaulØgmx*de>
40 // http://jfaul.de/atl or http://j-faul.virtualave.net/atl/atl.html
41
42 $info['fileformat'] = 'vqf';
43 $info['audio']['dataformat'] = 'vqf';
44 $info['audio']['bitrate_mode'] = 'cbr';
45 $info['audio']['lossless'] = false;
46
47 // shortcut
48 $info['vqf']['raw'] = array();
49 $thisfile_vqf = &$info['vqf'];
50 $thisfile_vqf_raw = &$thisfile_vqf['raw'];
51
52 fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
53 $VQFheaderData = fread($this->getid3->fp, 16);
54
55 $offset = 0;
56 $thisfile_vqf_raw['header_tag'] = substr($VQFheaderData, $offset, 4);
57 $magic = 'TWIN';
58 if ($thisfile_vqf_raw['header_tag'] != $magic) {
59 $info['error'][] = 'Expecting "'.Helper::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.Helper::PrintHexBytes($thisfile_vqf_raw['header_tag']).'"';
60 unset($info['vqf']);
61 unset($info['fileformat']);
62
63 return false;
64 }
65 $offset += 4;
66 $thisfile_vqf_raw['version'] = substr($VQFheaderData, $offset, 8);
67 $offset += 8;
68 $thisfile_vqf_raw['size'] = Helper::BigEndian2Int(substr($VQFheaderData, $offset, 4));
69 $offset += 4;
70
71 while (ftell($this->getid3->fp) < $info['avdataend']) {
72
73 $ChunkBaseOffset = ftell($this->getid3->fp);
74 $chunkoffset = 0;
75 $ChunkData = fread($this->getid3->fp, 8);
76 $ChunkName = substr($ChunkData, $chunkoffset, 4);
77 if ($ChunkName == 'DATA') {
78 $info['avdataoffset'] = $ChunkBaseOffset;
79 break;
80 }
81 $chunkoffset += 4;
82 $ChunkSize = Helper::BigEndian2Int(substr($ChunkData, $chunkoffset, 4));
83 $chunkoffset += 4;
84 if ($ChunkSize > ($info['avdataend'] - ftell($this->getid3->fp))) {
85 $info['error'][] = 'Invalid chunk size ('.$ChunkSize.') for chunk "'.$ChunkName.'" at offset '.$ChunkBaseOffset;
86 break;
87 }
88 if ($ChunkSize > 0) {
89 $ChunkData .= fread($this->getid3->fp, $ChunkSize);
90 }
91
92 switch ($ChunkName) {
93 case 'COMM':
94 // shortcut
95 $thisfile_vqf['COMM'] = array();
96 $thisfile_vqf_COMM = &$thisfile_vqf['COMM'];
97
98 $thisfile_vqf_COMM['channel_mode'] = Helper::BigEndian2Int(substr($ChunkData, $chunkoffset, 4));
99 $chunkoffset += 4;
100 $thisfile_vqf_COMM['bitrate'] = Helper::BigEndian2Int(substr($ChunkData, $chunkoffset, 4));
101 $chunkoffset += 4;
102 $thisfile_vqf_COMM['sample_rate'] = Helper::BigEndian2Int(substr($ChunkData, $chunkoffset, 4));
103 $chunkoffset += 4;
104 $thisfile_vqf_COMM['security_level'] = Helper::BigEndian2Int(substr($ChunkData, $chunkoffset, 4));
105 $chunkoffset += 4;
106
107 $info['audio']['channels'] = $thisfile_vqf_COMM['channel_mode'] + 1;
108 $info['audio']['sample_rate'] = $this->VQFchannelFrequencyLookup($thisfile_vqf_COMM['sample_rate']);
109 $info['audio']['bitrate'] = $thisfile_vqf_COMM['bitrate'] * 1000;
110 $info['audio']['encoder_options'] = 'CBR' . ceil($info['audio']['bitrate']/1000);
111
112 if ($info['audio']['bitrate'] == 0) {
113 $info['error'][] = 'Corrupt VQF file: bitrate_audio == zero';
114
115 return false;
116 }
117 break;
118
119 case 'NAME':
120 case 'AUTH':
121 case '(c) ':
122 case 'FILE':
123 case 'COMT':
124 case 'ALBM':
125 $thisfile_vqf['comments'][$this->VQFcommentNiceNameLookup($ChunkName)][] = trim(substr($ChunkData, 8));
126 break;
127
128 case 'DSIZ':
129 $thisfile_vqf['DSIZ'] = Helper::BigEndian2Int(substr($ChunkData, 8, 4));
130 break;
131
132 default:
133 $info['warning'][] = 'Unhandled chunk type "'.$ChunkName.'" at offset '.$ChunkBaseOffset;
134 break;
135 }
136 }
137
138 $info['playtime_seconds'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['audio']['bitrate'];
139
140 if (isset($thisfile_vqf['DSIZ']) && (($thisfile_vqf['DSIZ'] != ($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'))))) {
141 switch ($thisfile_vqf['DSIZ']) {
142 case 0:
143 case 1:
144 $info['warning'][] = 'Invalid DSIZ value "'.$thisfile_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'.($thisfile_vqf['DSIZ'] + 1).'.0';
145 $info['audio']['encoder'] = 'Ahead Nero';
146 break;
147
148 default:
149 $info['warning'][] = 'Probable corrupted file - should be '.$thisfile_vqf['DSIZ'].' bytes, actually '.($info['avdataend'] - $info['avdataoffset'] - strlen('DATA'));
150 break;
151 }
152 }
153
154 return true;
155 }
156
163 public function VQFchannelFrequencyLookup($frequencyid)
164 {
165 static $VQFchannelFrequencyLookup = array(
166 11 => 11025,
167 22 => 22050,
168 44 => 44100
169 );
170
171 return (isset($VQFchannelFrequencyLookup[$frequencyid]) ? $VQFchannelFrequencyLookup[$frequencyid] : $frequencyid * 1000);
172 }
173
180 public function VQFcommentNiceNameLookup($shortname)
181 {
182 static $VQFcommentNiceNameLookup = array(
183 'NAME' => 'title',
184 'AUTH' => 'artist',
185 '(c) ' => 'copyright',
186 'FILE' => 'filename',
187 'COMT' => 'comment',
188 'ALBM' => 'album'
189 );
190
191 return (isset($VQFcommentNiceNameLookup[$shortname]) ? $VQFcommentNiceNameLookup[$shortname] : $shortname);
192 }
193
194}
An exception for terminatinating execution or to throw for unit testing.
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:26
fseek($bytes, $whence=SEEK_SET)
GetId3() by James Heinrich info@getid3.org //.
Definition: Helper.php:27
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: Helper.php:374
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: Helper.php:36
GetId3() by James Heinrich info@getid3.org //.
Definition: Vqf.php:30
VQFchannelFrequencyLookup($frequencyid)
@staticvar array $VQFchannelFrequencyLookup
Definition: Vqf.php:163
VQFcommentNiceNameLookup($shortname)
@staticvar array $VQFcommentNiceNameLookup
Definition: Vqf.php:180
$info
Definition: example_052.php:80