annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.la.php @ 3:3f6b44aa6b35 judyates

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