annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.lpac.php @ 25:6a3d04638a89 judyates

mailto links.
author Robert McIntyre <rlm@mit.edu>
date Sat, 19 Jul 2014 14:35:52 -0400
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.lpac.php |
rlm@3 18 // | Module for analyzing LPAC Audio files |
rlm@3 19 // | dependencies: module.audio-video.riff.php |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio.lpac.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_lpac 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 // Magic bytes - 'LPAC'
rlm@3 36
rlm@3 37 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 38 $lpac_header = fread($getid3->fp, 14);
rlm@3 39
rlm@3 40 $getid3->info['avdataoffset'] += 14;
rlm@3 41
rlm@3 42 $getid3->info['lpac'] = array ();
rlm@3 43 $info_lpac = &$getid3->info['lpac'];
rlm@3 44
rlm@3 45 $getid3->info['fileformat'] = 'lpac';
rlm@3 46 $getid3->info['audio']['dataformat'] = 'lpac';
rlm@3 47 $getid3->info['audio']['lossless'] = true;
rlm@3 48 $getid3->info['audio']['bitrate_mode'] = 'vbr';
rlm@3 49
rlm@3 50 $info_lpac['file_version'] = getid3_lib::BigEndian2Int($lpac_header{4});
rlm@3 51 $flags['audio_type'] = getid3_lib::BigEndian2Int($lpac_header{5});
rlm@3 52 $info_lpac['total_samples'] = getid3_lib::BigEndian2Int(substr($lpac_header, 6, 4));
rlm@3 53 $flags['parameters'] = getid3_lib::BigEndian2Int(substr($lpac_header, 10, 4));
rlm@3 54
rlm@3 55 $info_lpac['flags']['is_wave'] = (bool)($flags['audio_type'] & 0x40);
rlm@3 56 $info_lpac['flags']['stereo'] = (bool)($flags['audio_type'] & 0x04);
rlm@3 57 $info_lpac['flags']['24_bit'] = (bool)($flags['audio_type'] & 0x02);
rlm@3 58 $info_lpac['flags']['16_bit'] = (bool)($flags['audio_type'] & 0x01);
rlm@3 59
rlm@3 60 if ($info_lpac['flags']['24_bit'] && $info_lpac['flags']['16_bit']) {
rlm@3 61 $getid3->warning('24-bit and 16-bit flags cannot both be set');
rlm@3 62 }
rlm@3 63
rlm@3 64 $info_lpac['flags']['fast_compress'] = (bool)($flags['parameters'] & 0x40000000);
rlm@3 65 $info_lpac['flags']['random_access'] = (bool)($flags['parameters'] & 0x08000000);
rlm@3 66 $info_lpac['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256;
rlm@3 67 $info_lpac['flags']['adaptive_prediction_order'] = (bool)($flags['parameters'] & 0x00800000);
rlm@3 68 $info_lpac['flags']['adaptive_quantization'] = (bool)($flags['parameters'] & 0x00400000);
rlm@3 69 $info_lpac['flags']['joint_stereo'] = (bool)($flags['parameters'] & 0x00040000);
rlm@3 70 $info_lpac['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8;
rlm@3 71 $info_lpac['max_prediction_order'] = ($flags['parameters'] & 0x0000003F);
rlm@3 72
rlm@3 73 if ($info_lpac['flags']['fast_compress'] && ($info_lpac['max_prediction_order'] != 3)) {
rlm@3 74 $getid3->warning('max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info_lpac['max_prediction_order'].'"');
rlm@3 75 }
rlm@3 76
rlm@3 77 switch ($info_lpac['file_version']) {
rlm@3 78
rlm@3 79 case 6:
rlm@3 80 if ($info_lpac['flags']['adaptive_quantization']) {
rlm@3 81 $getid3->warning('adaptive_quantization expected to be false in LPAC file stucture v6, actually true');
rlm@3 82 }
rlm@3 83 if ($info_lpac['quantization'] != 20) {
rlm@3 84 $getid3->warning('Quantization expected to be 20 in LPAC file stucture v6, actually '.$info_lpac['flags']['Q']);
rlm@3 85 }
rlm@3 86 break;
rlm@3 87
rlm@3 88
rlm@3 89 default:
rlm@3 90 //$getid3->warning('This version of getID3() only supports LPAC file format version 6, this file is version '.$info_lpac['file_version'].' - please report to info@getid3.org');
rlm@3 91 break;
rlm@3 92 }
rlm@3 93
rlm@3 94 // Clone getid3 - messing with something - better safe than sorry
rlm@3 95 $clone = clone $getid3;
rlm@3 96
rlm@3 97 // Analyze clone by fp
rlm@3 98 $riff = new getid3_riff($clone);
rlm@3 99 $riff->Analyze();
rlm@3 100
rlm@3 101 // Import from clone and destroy
rlm@3 102 $getid3->info['avdataoffset'] = $clone->info['avdataoffset'];
rlm@3 103 $getid3->info['riff'] = $clone->info['riff'];
rlm@3 104 //$info_lpac['comments']['comment'] = $clone->info['comments'];
rlm@3 105 $getid3->info['audio']['sample_rate'] = $clone->info['audio']['sample_rate'];
rlm@3 106 $getid3->warnings($clone->warnings());
rlm@3 107 unset($clone);
rlm@3 108
rlm@3 109 $getid3->info['audio']['channels'] = ($info_lpac['flags']['stereo'] ? 2 : 1);
rlm@3 110
rlm@3 111 if ($info_lpac['flags']['24_bit']) {
rlm@3 112 $getid3->info['audio']['bits_per_sample'] = $getid3->info['riff']['audio'][0]['bits_per_sample'];
rlm@3 113 } elseif ($info_lpac['flags']['16_bit']) {
rlm@3 114 $getid3->info['audio']['bits_per_sample'] = 16;
rlm@3 115 } else {
rlm@3 116 $getid3->info['audio']['bits_per_sample'] = 8;
rlm@3 117 }
rlm@3 118
rlm@3 119 if ($info_lpac['flags']['fast_compress']) {
rlm@3 120 // fast
rlm@3 121 $getid3->info['audio']['encoder_options'] = '-1';
rlm@3 122 } else {
rlm@3 123 switch ($info_lpac['max_prediction_order']) {
rlm@3 124 case 20: // simple
rlm@3 125 $getid3->info['audio']['encoder_options'] = '-2';
rlm@3 126 break;
rlm@3 127 case 30: // medium
rlm@3 128 $getid3->info['audio']['encoder_options'] = '-3';
rlm@3 129 break;
rlm@3 130 case 40: // high
rlm@3 131 $getid3->info['audio']['encoder_options'] = '-4';
rlm@3 132 break;
rlm@3 133 case 60: // extrahigh
rlm@3 134 $getid3->info['audio']['encoder_options'] = '-5';
rlm@3 135 break;
rlm@3 136 }
rlm@3 137 }
rlm@3 138
rlm@3 139 $getid3->info['playtime_seconds'] = $info_lpac['total_samples'] / $getid3->info['audio']['sample_rate'];
rlm@3 140 $getid3->info['audio']['bitrate'] = (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) * 8) / $getid3->info['playtime_seconds'];
rlm@3 141
rlm@3 142 return true;
rlm@3 143 }
rlm@3 144
rlm@3 145 }
rlm@3 146
rlm@3 147
rlm@3 148 ?>