22 $info = &$this->getid3->info;
28 $wavpackheader = $this->
fread(32);
32 } elseif (
feof($this->getid3->fp)) {
35 isset(
$info[
'wavpack'][
'blockheader'][
'total_samples']) &&
36 isset(
$info[
'wavpack'][
'blockheader'][
'block_samples']) &&
37 (
$info[
'wavpack'][
'blockheader'][
'total_samples'] > 0) &&
38 (
$info[
'wavpack'][
'blockheader'][
'block_samples'] > 0) &&
39 (!isset(
$info[
'wavpack'][
'riff_trailer_size']) || (
$info[
'wavpack'][
'riff_trailer_size'] <= 0)) &&
40 ((isset(
$info[
'wavpack'][
'config_flags'][
'md5_checksum']) && (
$info[
'wavpack'][
'config_flags'][
'md5_checksum'] ===
false)) || !empty(
$info[
'md5_data_source']))) {
44 $blockheader_offset = $this->
ftell() - 32;
45 $blockheader_magic = substr($wavpackheader, 0, 4);
49 if ($blockheader_magic != $magic) {
51 switch (isset(
$info[
'audio'][
'dataformat']) ?
$info[
'audio'][
'dataformat'] :
'') {
56 unset($info[
'fileformat']);
57 unset($info[
'audio']);
58 unset($info[
'wavpack']);
64 if (empty(
$info[
'wavpack'][
'blockheader'][
'block_samples']) ||
65 empty(
$info[
'wavpack'][
'blockheader'][
'total_samples']) ||
66 (
$info[
'wavpack'][
'blockheader'][
'block_samples'] <= 0) ||
67 (
$info[
'wavpack'][
'blockheader'][
'total_samples'] <= 0)) {
79 $info[
'audio'][
'dataformat'] =
'wavpack';
80 $info[
'fileformat'] =
'wavpack';
81 $info[
'audio'][
'lossless'] =
true;
82 $info[
'audio'][
'bitrate_mode'] =
'vbr';
84 $info[
'wavpack'][
'blockheader'][
'offset'] = $blockheader_offset;
85 $info[
'wavpack'][
'blockheader'][
'magic'] = $blockheader_magic;
86 $info[
'wavpack'][
'blockheader'][
'size'] = $blockheader_size;
88 if (
$info[
'wavpack'][
'blockheader'][
'size'] >= 0x100000) {
89 $this->
error(
'Expecting WavPack block size less than "0x100000", found "'.
$info[
'wavpack'][
'blockheader'][
'size'].
'" at offset '.
$info[
'wavpack'][
'blockheader'][
'offset']);
90 switch (isset(
$info[
'audio'][
'dataformat']) ?
$info[
'audio'][
'dataformat'] :
'') {
95 unset($info[
'fileformat']);
96 unset($info[
'audio']);
97 unset($info[
'wavpack']);
103 $info[
'wavpack'][
'blockheader'][
'minor_version'] = ord($wavpackheader{8});
104 $info[
'wavpack'][
'blockheader'][
'major_version'] = ord($wavpackheader{9});
106 if (($info[
'wavpack'][
'blockheader'][
'major_version'] != 4) ||
107 (($info[
'wavpack'][
'blockheader'][
'minor_version'] < 4) &&
108 ($info[
'wavpack'][
'blockheader'][
'minor_version'] > 16))) {
109 $this->
error(
'Expecting WavPack version between "4.2" and "4.16", found version "'.$info[
'wavpack'][
'blockheader'][
'major_version'].
'.'.$info[
'wavpack'][
'blockheader'][
'minor_version'].
'" at offset '.$info[
'wavpack'][
'blockheader'][
'offset']);
110 switch (isset($info[
'audio'][
'dataformat']) ? $info[
'audio'][
'dataformat'] :
'') {
115 unset($info[
'fileformat']);
116 unset($info[
'audio']);
117 unset($info[
'wavpack']);
123 $info[
'wavpack'][
'blockheader'][
'track_number'] = ord($wavpackheader{10});
124 $info[
'wavpack'][
'blockheader'][
'index_number'] = ord($wavpackheader{11});
131 $info[
'wavpack'][
'blockheader'][
'flags'][
'bytes_per_sample'] = 1 + ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000003);
132 $info[
'wavpack'][
'blockheader'][
'flags'][
'mono'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000004);
133 $info[
'wavpack'][
'blockheader'][
'flags'][
'hybrid'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000008);
134 $info[
'wavpack'][
'blockheader'][
'flags'][
'joint_stereo'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000010);
135 $info[
'wavpack'][
'blockheader'][
'flags'][
'cross_decorrelation'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000020);
136 $info[
'wavpack'][
'blockheader'][
'flags'][
'hybrid_noiseshape'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000040);
137 $info[
'wavpack'][
'blockheader'][
'flags'][
'ieee_32bit_float'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000080);
138 $info[
'wavpack'][
'blockheader'][
'flags'][
'int_32bit'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000100);
139 $info[
'wavpack'][
'blockheader'][
'flags'][
'hybrid_bitrate_noise'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000200);
140 $info[
'wavpack'][
'blockheader'][
'flags'][
'hybrid_balance_noise'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000400);
141 $info[
'wavpack'][
'blockheader'][
'flags'][
'multichannel_initial'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00000800);
142 $info[
'wavpack'][
'blockheader'][
'flags'][
'multichannel_final'] = (bool) ($info[
'wavpack'][
'blockheader'][
'flags_raw'] & 0x00001000);
144 $info[
'audio'][
'lossless'] = !$info[
'wavpack'][
'blockheader'][
'flags'][
'hybrid'];
147 while (!
feof($this->getid3->fp) && ($this->
ftell() < ($blockheader_offset + $blockheader_size + 8))) {
149 $metablock = array(
'offset'=>$this->
ftell());
150 $metablockheader = $this->
fread(2);
151 if (
feof($this->getid3->fp)) {
154 $metablock[
'id'] = ord($metablockheader{0});
155 $metablock[
'function_id'] = ($metablock[
'id'] & 0x3F);
165 $metablock[
'non_decoder'] = (bool) ($metablock[
'id'] & 0x20);
167 $metablock[
'padded_data'] = (bool) ($metablock[
'id'] & 0x40);
168 $metablock[
'large_block'] = (bool) ($metablock[
'id'] & 0x80);
169 if ($metablock[
'large_block']) {
170 $metablockheader .= $this->
fread(2);
173 $metablock[
'data'] = null;
175 if ($metablock[
'size'] > 0) {
177 switch ($metablock[
'function_id']) {
184 $metablock[
'data'] = $this->
fread($metablock[
'size']);
186 if ($metablock[
'padded_data']) {
188 $metablock[
'size']--;
189 $metablock[
'data'] = substr($metablock[
'data'], 0, -1);
207 $this->
fseek($metablock[
'offset'] + ($metablock[
'large_block'] ? 4 : 2) + $metablock[
'size']);
211 $this->
warning(
'Unexpected metablock type "0x'.str_pad(dechex($metablock[
'function_id']), 2,
'0', STR_PAD_LEFT).
'" at offset '.$metablock[
'offset']);
212 $this->
fseek($metablock[
'offset'] + ($metablock[
'large_block'] ? 4 : 2) + $metablock[
'size']);
216 switch ($metablock[
'function_id']) {
221 $getid3_temp =
new getID3();
222 $getid3_temp->openfile($this->getid3->filename);
224 $getid3_riff->ParseRIFFdata($metablock[
'data']);
225 $metablock[
'riff'] = $getid3_temp->info[
'riff'];
226 $info[
'audio'][
'sample_rate'] = $getid3_temp->info[
'riff'][
'raw'][
'fmt '][
'nSamplesPerSec'];
227 unset($getid3_riff, $getid3_temp);
229 $metablock[
'riff'][
'original_filesize'] = $original_wav_filesize;
230 $info[
'wavpack'][
'riff_trailer_size'] = $original_wav_filesize - $metablock[
'riff'][
'WAVE'][
'data'][0][
'size'] - $metablock[
'riff'][
'header_size'];
231 $info[
'playtime_seconds'] = $info[
'wavpack'][
'blockheader'][
'total_samples'] / $info[
'audio'][
'sample_rate'];
234 $metablockRIFFheader = $metablock[
'data'];
239 $metablockRIFFfooter = $metablockRIFFheader.$metablock[
'data'];
242 $startoffset = $metablock[
'offset'] + ($metablock[
'large_block'] ? 4 : 2);
243 $getid3_temp =
new getID3();
244 $getid3_temp->openfile($this->getid3->filename);
245 $getid3_temp->info[
'avdataend'] = $info[
'avdataend'];
248 $metablock[
'riff'] = $getid3_riff->ParseRIFF($startoffset, $startoffset + $metablock[
'size']);
250 if (!empty($metablock[
'riff'][
'INFO'])) {
252 $info[
'tags'][
'riff'] = $metablock[
'comments'];
254 unset($getid3_temp, $getid3_riff);
259 $this->
warning(
'WavPack "Replay Gain" contents not yet handled by getID3() in metablock at offset '.$metablock[
'offset']);
264 $this->
warning(
'WavPack "Cuesheet" contents not yet handled by getID3() in metablock at offset '.$metablock[
'offset']);
271 $metablock[
'flags'][
'adobe_mode'] = (bool) ($metablock[
'flags_raw'] & 0x000001);
272 $metablock[
'flags'][
'fast_flag'] = (bool) ($metablock[
'flags_raw'] & 0x000002);
273 $metablock[
'flags'][
'very_fast_flag'] = (bool) ($metablock[
'flags_raw'] & 0x000004);
274 $metablock[
'flags'][
'high_flag'] = (bool) ($metablock[
'flags_raw'] & 0x000008);
275 $metablock[
'flags'][
'very_high_flag'] = (bool) ($metablock[
'flags_raw'] & 0x000010);
276 $metablock[
'flags'][
'bitrate_kbps'] = (bool) ($metablock[
'flags_raw'] & 0x000020);
277 $metablock[
'flags'][
'auto_shaping'] = (bool) ($metablock[
'flags_raw'] & 0x000040);
278 $metablock[
'flags'][
'shape_override'] = (bool) ($metablock[
'flags_raw'] & 0x000080);
279 $metablock[
'flags'][
'joint_override'] = (bool) ($metablock[
'flags_raw'] & 0x000100);
280 $metablock[
'flags'][
'copy_time'] = (bool) ($metablock[
'flags_raw'] & 0x000200);
281 $metablock[
'flags'][
'create_exe'] = (bool) ($metablock[
'flags_raw'] & 0x000400);
282 $metablock[
'flags'][
'create_wvc'] = (bool) ($metablock[
'flags_raw'] & 0x000800);
283 $metablock[
'flags'][
'optimize_wvc'] = (bool) ($metablock[
'flags_raw'] & 0x001000);
284 $metablock[
'flags'][
'quality_mode'] = (bool) ($metablock[
'flags_raw'] & 0x002000);
285 $metablock[
'flags'][
'raw_flag'] = (bool) ($metablock[
'flags_raw'] & 0x004000);
286 $metablock[
'flags'][
'calc_noise'] = (bool) ($metablock[
'flags_raw'] & 0x008000);
287 $metablock[
'flags'][
'lossy_mode'] = (bool) ($metablock[
'flags_raw'] & 0x010000);
288 $metablock[
'flags'][
'extra_mode'] = (bool) ($metablock[
'flags_raw'] & 0x020000);
289 $metablock[
'flags'][
'skip_wvx'] = (bool) ($metablock[
'flags_raw'] & 0x040000);
290 $metablock[
'flags'][
'md5_checksum'] = (bool) ($metablock[
'flags_raw'] & 0x080000);
291 $metablock[
'flags'][
'quiet_mode'] = (bool) ($metablock[
'flags_raw'] & 0x100000);
293 $info[
'wavpack'][
'config_flags'] = $metablock[
'flags'];
296 $info[
'audio'][
'encoder_options'] =
'';
297 if ($info[
'wavpack'][
'blockheader'][
'flags'][
'hybrid']) {
298 $info[
'audio'][
'encoder_options'] .=
' -b???';
300 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'adobe_mode'] ?
' -a' :
'');
301 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'optimize_wvc'] ?
' -cc' :
'');
302 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'create_exe'] ?
' -e' :
'');
303 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'fast_flag'] ?
' -f' :
'');
304 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'joint_override'] ?
' -j?' :
'');
305 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'high_flag'] ?
' -h' :
'');
306 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'md5_checksum'] ?
' -m' :
'');
307 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'calc_noise'] ?
' -n' :
'');
308 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'shape_override'] ?
' -s?' :
'');
309 $info[
'audio'][
'encoder_options'] .= ($metablock[
'flags'][
'extra_mode'] ?
' -x?' :
'');
310 if (!empty($info[
'audio'][
'encoder_options'])) {
311 $info[
'audio'][
'encoder_options'] = trim($info[
'audio'][
'encoder_options']);
312 } elseif (isset($info[
'audio'][
'encoder_options'])) {
313 unset($info[
'audio'][
'encoder_options']);
319 if (strlen($metablock[
'data']) == 16) {
322 $this->
warning(
'Expecting 16 bytes of WavPack "MD5 Checksum" in metablock at offset '.$metablock[
'offset'].
', but found '.strlen($metablock[
'data']).
' bytes');
346 if (!empty($metablock)) {
347 $info[
'wavpack'][
'metablocks'][] = $metablock;
354 $info[
'audio'][
'encoder'] =
'WavPack v'.$info[
'wavpack'][
'blockheader'][
'major_version'].
'.'.str_pad($info[
'wavpack'][
'blockheader'][
'minor_version'], 2,
'0', STR_PAD_LEFT);
355 $info[
'audio'][
'bits_per_sample'] = $info[
'wavpack'][
'blockheader'][
'flags'][
'bytes_per_sample'] * 8;
356 $info[
'audio'][
'channels'] = ($info[
'wavpack'][
'blockheader'][
'flags'][
'mono'] ? 1 : 2);
358 if (!empty($info[
'playtime_seconds'])) {
360 $info[
'audio'][
'bitrate'] = (($info[
'avdataend'] - $info[
'avdataoffset']) * 8) / $info[
'playtime_seconds'];
364 $info[
'audio'][
'dataformat'] =
'wvc';
static LittleEndian2Int($byteword, $signed=false)
static IncludeDependency($filename, $sourcefile, $DieOnFailure=false)
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
WavPackMetablockNameLookup(&$id)
static parseComments(&$RIFFinfoArray, &$CommentsTargetArray)
fseek($bytes, $whence=SEEK_SET)