Mercurial > judyates
view e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.la.php @ 20:1038db2374ec judyates
change address
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 08 Sep 2013 00:47:09 -0400 |
parents | 3f6b44aa6b35 |
children |
line wrap: on
line source
1 <?php2 // +----------------------------------------------------------------------+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,v 1.2 2006/11/02 10:48:01 ah Exp $26 class getid3_la extends getid3_handler27 {29 public function Analyze() {31 $getid3 = $this->getid3;33 $getid3->include_module('audio-video.riff');35 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);36 $raw_data = fread($getid3->fp, getid3::FREAD_BUFFER_SIZE);38 $getid3->info['fileformat'] = 'la';39 $getid3->info['audio']['dataformat'] = 'la';40 $getid3->info['audio']['lossless'] = true;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);46 $getid3->info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($raw_data, 4, 4));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 }53 $offset = 12;55 $getid3->info['la']['fmt_size'] = 24;56 if ($getid3->info['la']['version'] >= 0.3) {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;62 } else {64 // version 0.2 didn't support additional data blocks65 $getid3->info['la']['header_size'] = 41;66 }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;74 $fmt_size = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));75 $offset += 4;77 $getid3->info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 2));78 $offset += 2;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' => 488 )89 );90 $offset += 18;92 $getid3->info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int($raw_data{$offset++});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 }99 $getid3->info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));100 $offset += 4;102 // mikeØbevin*de103 // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16104 // in earlier versions. A seekpoint is added every blocksize * seekevery105 // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should106 // give the number of bytes used for the seekpoints. Of course, if seeking107 // is disabled, there are no seekpoints stored.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 }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']));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 }127 if ($getid3->info['la']['version'] >= 0.3) {129 // Following the main header information, the program outputs all of the130 // seekpoints. Following these is what I called the 'footer start',131 // i.e. the position immediately after the La audio data is finished.133 $getid3->info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($raw_data, $offset, 4));134 $offset += 4;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 }141 } else {143 // La v0.2 didn't have FooterStart value144 $getid3->info['la']['footerstart'] = $getid3->info['avdataend'];146 }148 if ($getid3->info['la']['footerstart'] < $getid3->info['avdataend']) {150 // Create riff header151 $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;163 // Clone getid3 - messing with offsets - better safe than sorry164 $clone = clone $getid3;166 // Analyze clone by string167 $riff = new getid3_riff($clone);168 $riff->AnalyzeString($riff_data);170 // Import from clone and destroy171 $getid3->info['riff'] = $clone->info['riff'];172 $getid3->warnings($clone->warnings());173 unset($clone);174 }176 // $getid3->info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway177 $getid3->info['avdataend'] = $getid3->info['avdataoffset'] + $getid3->info['la']['footerstart'];178 $getid3->info['avdataoffset'] = $getid3->info['avdataoffset'] + $offset;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'];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'];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'];190 return true;191 }193 }196 ?>