[3318] | 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.la.php | |
---|
| 18 | // | Module for analyzing LA udio files | |
---|
| 19 | // | dependencies: module.audio-video.riff.php | |
---|
| 20 | // +----------------------------------------------------------------------+ |
---|
| 21 | // |
---|
| 22 | // $Id: module.audio.la.php 3318 2009-05-20 21:54:10Z vdigital $ |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | class getid3_la extends getid3_handler |
---|
| 27 | { |
---|
| 28 | |
---|
| 29 | public function Analyze() { |
---|
| 30 | |
---|
| 31 | $getid3 = $this->getid3; |
---|
| 32 | |
---|
| 33 | $getid3->include_module('audio-video.riff'); |
---|
| 34 | |
---|
| 35 | fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); |
---|
| 36 | $raw_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE); |
---|
| 37 | |
---|
| 38 | $getid3->info['fileformat'] = 'la'; |
---|
| 39 | $getid3->info['audio']['dataformat'] = 'la'; |
---|
| 40 | $getid3->info['audio']['lossless'] = true; |
---|
| 41 | |
---|
| 42 | $getid3->info['la']['version_major'] = (int)$raw_data{2}; |
---|
| 43 | $getid3->info['la']['version_minor'] = (int)$raw_data{3}; |
---|
| 44 | $getid3->info['la']['version'] = (float)$getid3->info['la']['version_major'] + ($getid3->info['la']['version_minor'] / 10); |
---|
| 45 | |
---|
| 46 | $getid3->info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, 4, 4)); |
---|
| 47 | |
---|
| 48 | $wave_chunk = substr($raw_data, 8, 4); |
---|
| 49 | if ($wave_chunk !== 'WAVE') { |
---|
| 50 | throw new getid3_exception('Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset 8, found "'.$wave_chunk.'" ('.getid3_lib::PrintHexBytes($wave_chunk).') instead.'); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | $offset = 12; |
---|
| 54 | |
---|
| 55 | $getid3->info['la']['fmt_size'] = 24; |
---|
| 56 | if ($getid3->info['la']['version'] >= 0.3) { |
---|
| 57 | |
---|
| 58 | $getid3->info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); |
---|
| 59 | $getid3->info['la']['header_size'] = 49 + $getid3->info['la']['fmt_size'] - 24; |
---|
| 60 | $offset += 4; |
---|
| 61 | |
---|
| 62 | } else { |
---|
| 63 | |
---|
| 64 | // version 0.2 didn't support additional data blocks |
---|
| 65 | $getid3->info['la']['header_size'] = 41; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | $fmt_chunk = substr($raw_data, $offset, 4); |
---|
| 69 | if ($fmt_chunk !== 'fmt ') { |
---|
| 70 | throw new getid3_exception('Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.'); |
---|
| 71 | } |
---|
| 72 | $offset += 4; |
---|
| 73 | |
---|
| 74 | $fmt_size = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); |
---|
| 75 | $offset += 4; |
---|
| 76 | |
---|
| 77 | $getid3->info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 2)); |
---|
| 78 | $offset += 2; |
---|
| 79 | |
---|
| 80 | getid3_lib::ReadSequence('LittleEndian2Int', $getid3->info['la'], $raw_data, $offset, |
---|
| 81 | array ( |
---|
| 82 | 'channels' => 2, |
---|
| 83 | 'sample_rate' => 4, |
---|
| 84 | 'bytes_per_second' => 4, |
---|
| 85 | 'bytes_per_sample' => 2, |
---|
| 86 | 'bits_per_sample' => 2, |
---|
| 87 | 'samples' => 4 |
---|
| 88 | ) |
---|
| 89 | ); |
---|
| 90 | $offset += 18; |
---|
| 91 | |
---|
| 92 | $getid3->info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int($raw_data{$offset++}); |
---|
| 93 | |
---|
| 94 | $getid3->info['la']['flags']['seekable'] = (bool)($getid3->info['la']['raw']['flags'] & 0x01); |
---|
| 95 | if ($getid3->info['la']['version'] >= 0.4) { |
---|
| 96 | $getid3->info['la']['flags']['high_compression'] = (bool)($getid3->info['la']['raw']['flags'] & 0x02); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | $getid3->info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); |
---|
| 100 | $offset += 4; |
---|
| 101 | |
---|
| 102 | // mikeØbevin*de |
---|
| 103 | // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16 |
---|
| 104 | // in earlier versions. A seekpoint is added every blocksize * seekevery |
---|
| 105 | // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should |
---|
| 106 | // give the number of bytes used for the seekpoints. Of course, if seeking |
---|
| 107 | // is disabled, there are no seekpoints stored. |
---|
| 108 | |
---|
| 109 | if ($getid3->info['la']['version'] >= 0.4) { |
---|
| 110 | $getid3->info['la']['blocksize'] = 61440; |
---|
| 111 | $getid3->info['la']['seekevery'] = 19; |
---|
| 112 | } else { |
---|
| 113 | $getid3->info['la']['blocksize'] = 73728; |
---|
| 114 | $getid3->info['la']['seekevery'] = 16; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | $getid3->info['la']['seekpoint_count'] = 0; |
---|
| 118 | if ($getid3->info['la']['flags']['seekable']) { |
---|
| 119 | $getid3->info['la']['seekpoint_count'] = floor($getid3->info['la']['samples'] / ($getid3->info['la']['blocksize'] * $getid3->info['la']['seekevery'])); |
---|
| 120 | |
---|
| 121 | for ($i = 0; $i < $getid3->info['la']['seekpoint_count']; $i++) { |
---|
| 122 | $getid3->info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); |
---|
| 123 | $offset += 4; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | if ($getid3->info['la']['version'] >= 0.3) { |
---|
| 128 | |
---|
| 129 | // Following the main header information, the program outputs all of the |
---|
| 130 | // seekpoints. Following these is what I called the 'footer start', |
---|
| 131 | // i.e. the position immediately after the La audio data is finished. |
---|
| 132 | |
---|
| 133 | $getid3->info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4)); |
---|
| 134 | $offset += 4; |
---|
| 135 | |
---|
| 136 | if ($getid3->info['la']['footerstart'] > $getid3->info['filesize']) { |
---|
| 137 | $getid3->warning('FooterStart value points to offset '.$getid3->info['la']['footerstart'].' which is beyond end-of-file ('.$getid3->info['filesize'].')'); |
---|
| 138 | $getid3->info['la']['footerstart'] = $getid3->info['filesize']; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | } else { |
---|
| 142 | |
---|
| 143 | // La v0.2 didn't have FooterStart value |
---|
| 144 | $getid3->info['la']['footerstart'] = $getid3->info['avdataend']; |
---|
| 145 | |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) { |
---|
| 149 | |
---|
| 150 | // Create riff header |
---|
| 151 | $riff_data = 'WAVE'; |
---|
| 152 | if ($getid3->info['la']['version'] == 0.2) { |
---|
| 153 | $riff_data .= substr($raw_data, 12, 24); |
---|
| 154 | } else { |
---|
| 155 | $riff_data .= substr($raw_data, 16, 24); |
---|
| 156 | } |
---|
| 157 | if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) { |
---|
| 158 | fseek($getid3->fp, $getid3->info['la']['footerstart'], SEEK_SET); |
---|
| 159 | $riff_data .= fread($getid3->fp, $getid3->info['avdataend'] - $getid3->info['la']['footerstart']); |
---|
| 160 | } |
---|
| 161 | $riff_data = 'RIFF'.getid3_lib::LittleEndian2String(strlen($riff_data), 4, false).$riff_data; |
---|
| 162 | |
---|
| 163 | // Clone getid3 - messing with offsets - better safe than sorry |
---|
| 164 | $clone = clone $getid3; |
---|
| 165 | |
---|
| 166 | // Analyze clone by string |
---|
| 167 | $riff = new getid3_riff($clone); |
---|
| 168 | $riff->AnalyzeString($riff_data); |
---|
| 169 | |
---|
| 170 | // Import from clone and destroy |
---|
| 171 | $getid3->info['riff'] = $clone->info['riff']; |
---|
| 172 | $getid3->warnings($clone->warnings()); |
---|
| 173 | unset($clone); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | // $getid3->info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway |
---|
| 177 | $getid3->info['avdataend'] = $getid3->info['avdataoffset'] + $getid3->info['la']['footerstart']; |
---|
| 178 | $getid3->info['avdataoffset'] = $getid3->info['avdataoffset'] + $offset; |
---|
| 179 | |
---|
| 180 | $getid3->info['la']['compression_ratio'] = (float)(($getid3->info['avdataend'] - $getid3->info['avdataoffset']) / $getid3->info['la']['uncompressed_size']); |
---|
| 181 | $getid3->info['playtime_seconds'] = (float)($getid3->info['la']['samples'] / $getid3->info['la']['sample_rate']) / $getid3->info['la']['channels']; |
---|
| 182 | |
---|
| 183 | $getid3->info['audio']['bitrate'] = ($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8 / $getid3->info['playtime_seconds']; |
---|
| 184 | $getid3->info['audio']['bits_per_sample'] = $getid3->info['la']['bits_per_sample']; |
---|
| 185 | |
---|
| 186 | $getid3->info['audio']['channels'] = $getid3->info['la']['channels']; |
---|
| 187 | $getid3->info['audio']['sample_rate'] = (int)$getid3->info['la']['sample_rate']; |
---|
| 188 | $getid3->info['audio']['encoder'] = 'LA v'.$getid3->info['la']['version']; |
---|
| 189 | |
---|
| 190 | return true; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | ?> |
---|