ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Lpac.php
Go to the documentation of this file.
1 <?php
2 
3 namespace GetId3\Module\Audio;
4 
9 
12 // available at http://getid3.sourceforge.net //
13 // or http://www.getid3.org //
15 // See readme.txt for more details //
17 // //
18 // module.audio.lpac.php //
19 // module for analyzing LPAC Audio files //
20 // dependencies: module.audio-video.riff.php //
21 // ///
23 
31 class Lpac extends BaseHandler
32 {
33 
38  public function analyze()
39  {
40  $info = &$this->getid3->info;
41 
42  fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
43  $LPACheader = fread($this->getid3->fp, 14);
44  if (substr($LPACheader, 0, 4) != 'LPAC') {
45  $info['error'][] = 'Expected "LPAC" at offset '.$info['avdataoffset'].', found "'.$StreamMarker.'"';
46 
47  return false;
48  }
49  $info['avdataoffset'] += 14;
50 
51  $info['fileformat'] = 'lpac';
52  $info['audio']['dataformat'] = 'lpac';
53  $info['audio']['lossless'] = true;
54  $info['audio']['bitrate_mode'] = 'vbr';
55 
56  $info['lpac']['file_version'] = Helper::BigEndian2Int(substr($LPACheader, 4, 1));
57  $flags['audio_type'] = Helper::BigEndian2Int(substr($LPACheader, 5, 1));
58  $info['lpac']['total_samples']= Helper::BigEndian2Int(substr($LPACheader, 6, 4));
59  $flags['parameters'] = Helper::BigEndian2Int(substr($LPACheader, 10, 4));
60 
61  $info['lpac']['flags']['is_wave'] = (bool) ($flags['audio_type'] & 0x40);
62  $info['lpac']['flags']['stereo'] = (bool) ($flags['audio_type'] & 0x04);
63  $info['lpac']['flags']['24_bit'] = (bool) ($flags['audio_type'] & 0x02);
64  $info['lpac']['flags']['16_bit'] = (bool) ($flags['audio_type'] & 0x01);
65 
66  if ($info['lpac']['flags']['24_bit'] && $info['lpac']['flags']['16_bit']) {
67  $info['warning'][] = '24-bit and 16-bit flags cannot both be set';
68  }
69 
70  $info['lpac']['flags']['fast_compress'] = (bool) ($flags['parameters'] & 0x40000000);
71  $info['lpac']['flags']['random_access'] = (bool) ($flags['parameters'] & 0x08000000);
72  $info['lpac']['block_length'] = pow(2, (($flags['parameters'] & 0x07000000) >> 24)) * 256;
73  $info['lpac']['flags']['adaptive_prediction_order'] = (bool) ($flags['parameters'] & 0x00800000);
74  $info['lpac']['flags']['adaptive_quantization'] = (bool) ($flags['parameters'] & 0x00400000);
75  $info['lpac']['flags']['joint_stereo'] = (bool) ($flags['parameters'] & 0x00040000);
76  $info['lpac']['quantization'] = ($flags['parameters'] & 0x00001F00) >> 8;
77  $info['lpac']['max_prediction_order'] = ($flags['parameters'] & 0x0000003F);
78 
79  if ($info['lpac']['flags']['fast_compress'] && ($info['lpac']['max_prediction_order'] != 3)) {
80  $info['warning'][] = 'max_prediction_order expected to be "3" if fast_compress is true, actual value is "'.$info['lpac']['max_prediction_order'].'"';
81  }
82  switch ($info['lpac']['file_version']) {
83  case 6:
84  if ($info['lpac']['flags']['adaptive_quantization']) {
85  $info['warning'][] = 'adaptive_quantization expected to be false in LPAC file stucture v6, actually true';
86  }
87  if ($info['lpac']['quantization'] != 20) {
88  $info['warning'][] = 'Quantization expected to be 20 in LPAC file stucture v6, actually '.$info['lpac']['flags']['Q'];
89  }
90  break;
91 
92  default:
93  //$info['warning'][] = 'This version of GetId3Core() ['.$this->getid3->version().'] only supports LPAC file format version 6, this file is version '.$info['lpac']['file_version'].' - please report to info@getid3.org';
94  break;
95  }
96 
97  $getid3_temp = new GetId3Core();
98  $getid3_temp->openfile($this->getid3->filename);
99  $getid3_temp->info = $info;
100  $getid3_riff = new Riff($getid3_temp);
101  $getid3_riff->analyze();
102  $info['avdataoffset'] = $getid3_temp->info['avdataoffset'];
103  $info['riff'] = $getid3_temp->info['riff'];
104  $info['error'] = $getid3_temp->info['error'];
105  $info['warning'] = $getid3_temp->info['warning'];
106  $info['lpac']['comments']['comment'] = $getid3_temp->info['comments'];
107  $info['audio']['sample_rate'] = $getid3_temp->info['audio']['sample_rate'];
108  unset($getid3_temp, $getid3_riff);
109 
110  $info['audio']['channels'] = ($info['lpac']['flags']['stereo'] ? 2 : 1);
111 
112  if ($info['lpac']['flags']['24_bit']) {
113  $info['audio']['bits_per_sample'] = $info['riff']['audio'][0]['bits_per_sample'];
114  } elseif ($info['lpac']['flags']['16_bit']) {
115  $info['audio']['bits_per_sample'] = 16;
116  } else {
117  $info['audio']['bits_per_sample'] = 8;
118  }
119 
120  if ($info['lpac']['flags']['fast_compress']) {
121  // fast
122  $info['audio']['encoder_options'] = '-1';
123  } else {
124  switch ($info['lpac']['max_prediction_order']) {
125  case 20: // simple
126  $info['audio']['encoder_options'] = '-2';
127  break;
128  case 30: // medium
129  $info['audio']['encoder_options'] = '-3';
130  break;
131  case 40: // high
132  $info['audio']['encoder_options'] = '-4';
133  break;
134  case 60: // extrahigh
135  $info['audio']['encoder_options'] = '-5';
136  break;
137  }
138  }
139 
140  $info['playtime_seconds'] = $info['lpac']['total_samples'] / $info['audio']['sample_rate'];
141  $info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
142 
143  return true;
144  }
145 }
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:25
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
GetId3() by James Heinrich info@getid3.org //.
Definition: GetId3Core.php:25
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: Helper.php:374
GetId3() by James Heinrich info@getid3.org //.
Definition: Riff.php:42
GetId3() by James Heinrich info@getid3.org //.
Definition: Lpac.php:31