annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.vqf.php @ 28:118cb614cf18 judyates tip

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