ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_la Class Reference
+ Inheritance diagram for getid3_la:
+ Collaboration diagram for getid3_la:

Public Member Functions

 getid3_la (&$fd, &$ThisFileInfo)
 
 Analyze ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

Definition at line 18 of file module.audio.la.php.

Member Function Documentation

◆ Analyze()

getid3_la::Analyze ( )

Definition at line 22 of file module.audio.la.php.

References $info, getid3_handler\fread(), getid3_handler\fseek(), getid3_lib\LittleEndian2Int(), and getid3_lib\PrintHexBytes().

22  {
23  $info = &$this->getid3->info;
24 
25  $offset = 0;
26  $this->fseek($info['avdataoffset']);
27  $rawdata = $this->fread($this->getid3->fread_buffer_size());
28 
29  switch (substr($rawdata, $offset, 4)) {
30  case 'LA02':
31  case 'LA03':
32  case 'LA04':
33  $info['fileformat'] = 'la';
34  $info['audio']['dataformat'] = 'la';
35  $info['audio']['lossless'] = true;
36 
37  $info['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1);
38  $info['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1);
39  $info['la']['version'] = (float) $info['la']['version_major'] + ($info['la']['version_minor'] / 10);
40  $offset += 4;
41 
42  $info['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
43  $offset += 4;
44  if ($info['la']['uncompressed_size'] == 0) {
45  $info['error'][] = 'Corrupt LA file: uncompressed_size == zero';
46  return false;
47  }
48 
49  $WAVEchunk = substr($rawdata, $offset, 4);
50  if ($WAVEchunk !== 'WAVE') {
51  $info['error'][] = 'Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.';
52  return false;
53  }
54  $offset += 4;
55 
56  $info['la']['fmt_size'] = 24;
57  if ($info['la']['version'] >= 0.3) {
58 
59  $info['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
60  $info['la']['header_size'] = 49 + $info['la']['fmt_size'] - 24;
61  $offset += 4;
62 
63  } else {
64 
65  // version 0.2 didn't support additional data blocks
66  $info['la']['header_size'] = 41;
67 
68  }
69 
70  $fmt_chunk = substr($rawdata, $offset, 4);
71  if ($fmt_chunk !== 'fmt ') {
72  $info['error'][] = 'Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.';
73  return false;
74  }
75  $offset += 4;
76  $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
77  $offset += 4;
78 
79  $info['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
80  $offset += 2;
81 
82  $info['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
83  $offset += 2;
84  if ($info['la']['channels'] == 0) {
85  $info['error'][] = 'Corrupt LA file: channels == zero';
86  return false;
87  }
88 
89  $info['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
90  $offset += 4;
91  if ($info['la']['sample_rate'] == 0) {
92  $info['error'][] = 'Corrupt LA file: sample_rate == zero';
93  return false;
94  }
95 
96  $info['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
97  $offset += 4;
98  $info['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
99  $offset += 2;
100  $info['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
101  $offset += 2;
102 
103  $info['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
104  $offset += 4;
105 
106  $info['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1));
107  $offset += 1;
108  $info['la']['flags']['seekable'] = (bool) ($info['la']['raw']['flags'] & 0x01);
109  if ($info['la']['version'] >= 0.4) {
110  $info['la']['flags']['high_compression'] = (bool) ($info['la']['raw']['flags'] & 0x02);
111  }
112 
113  $info['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
114  $offset += 4;
115 
116  // mikeØbevin*de
117  // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16
118  // in earlier versions. A seekpoint is added every blocksize * seekevery
119  // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should
120  // give the number of bytes used for the seekpoints. Of course, if seeking
121  // is disabled, there are no seekpoints stored.
122  if ($info['la']['version'] >= 0.4) {
123  $info['la']['blocksize'] = 61440;
124  $info['la']['seekevery'] = 19;
125  } else {
126  $info['la']['blocksize'] = 73728;
127  $info['la']['seekevery'] = 16;
128  }
129 
130  $info['la']['seekpoint_count'] = 0;
131  if ($info['la']['flags']['seekable']) {
132  $info['la']['seekpoint_count'] = floor($info['la']['samples'] / ($info['la']['blocksize'] * $info['la']['seekevery']));
133 
134  for ($i = 0; $i < $info['la']['seekpoint_count']; $i++) {
135  $info['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
136  $offset += 4;
137  }
138  }
139 
140  if ($info['la']['version'] >= 0.3) {
141 
142  // Following the main header information, the program outputs all of the
143  // seekpoints. Following these is what I called the 'footer start',
144  // i.e. the position immediately after the La audio data is finished.
145  $info['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
146  $offset += 4;
147 
148  if ($info['la']['footerstart'] > $info['filesize']) {
149  $info['warning'][] = 'FooterStart value points to offset '.$info['la']['footerstart'].' which is beyond end-of-file ('.$info['filesize'].')';
150  $info['la']['footerstart'] = $info['filesize'];
151  }
152 
153  } else {
154 
155  // La v0.2 didn't have FooterStart value
156  $info['la']['footerstart'] = $info['avdataend'];
157 
158  }
159 
160  if ($info['la']['footerstart'] < $info['avdataend']) {
161  if ($RIFFtempfilename = tempnam(GETID3_TEMP_DIR, 'id3')) {
162  if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) {
163  $RIFFdata = 'WAVE';
164  if ($info['la']['version'] == 0.2) {
165  $RIFFdata .= substr($rawdata, 12, 24);
166  } else {
167  $RIFFdata .= substr($rawdata, 16, 24);
168  }
169  if ($info['la']['footerstart'] < $info['avdataend']) {
170  $this->fseek($info['la']['footerstart']);
171  $RIFFdata .= $this->fread($info['avdataend'] - $info['la']['footerstart']);
172  }
173  $RIFFdata = 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false).$RIFFdata;
174  fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata));
175  fclose($RIFF_fp);
176 
177  $getid3_temp = new getID3();
178  $getid3_temp->openfile($RIFFtempfilename);
179  $getid3_riff = new getid3_riff($getid3_temp);
180  $getid3_riff->Analyze();
181 
182  if (empty($getid3_temp->info['error'])) {
183  $info['riff'] = $getid3_temp->info['riff'];
184  } else {
185  $info['warning'][] = 'Error parsing RIFF portion of La file: '.implode($getid3_temp->info['error']);
186  }
187  unset($getid3_temp, $getid3_riff);
188  }
189  unlink($RIFFtempfilename);
190  }
191  }
192 
193  // $info['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway
194  $info['avdataend'] = $info['avdataoffset'] + $info['la']['footerstart'];
195  $info['avdataoffset'] = $info['avdataoffset'] + $offset;
196 
197  $info['la']['compression_ratio'] = (float) (($info['avdataend'] - $info['avdataoffset']) / $info['la']['uncompressed_size']);
198  $info['playtime_seconds'] = (float) ($info['la']['samples'] / $info['la']['sample_rate']) / $info['la']['channels'];
199  if ($info['playtime_seconds'] == 0) {
200  $info['error'][] = 'Corrupt LA file: playtime_seconds == zero';
201  return false;
202  }
203 
204  $info['audio']['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) * 8 / $info['playtime_seconds'];
205  //$info['audio']['codec'] = $info['la']['codec'];
206  $info['audio']['bits_per_sample'] = $info['la']['bits_per_sample'];
207  break;
208 
209  default:
210  if (substr($rawdata, $offset, 2) == 'LA') {
211  $info['error'][] = 'This version of getID3() ['.$this->getid3->version().'] does not support LA version '.substr($rawdata, $offset + 2, 1).'.'.substr($rawdata, $offset + 3, 1).' which this appears to be - check http://getid3.sourceforge.net for updates.';
212  } else {
213  $info['error'][] = 'Not a LA (Lossless-Audio) file';
214  }
215  return false;
216  break;
217  }
218 
219  $info['audio']['channels'] = $info['la']['channels'];
220  $info['audio']['sample_rate'] = (int) $info['la']['sample_rate'];
221  $info['audio']['encoder'] = 'LA v'.$info['la']['version'];
222 
223  return true;
224  }
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
$info
Definition: example_052.php:80
fread($bytes)
Definition: getid3.php:1685
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
+ Here is the call graph for this function:

◆ getid3_la()

getid3_la::getid3_la ( $fd,
$ThisFileInfo 
)

Definition at line 21 of file module.audio.la.php.

References getid3_handler\fread(), getid3_handler\fseek(), GETID3_FREAD_BUFFER_SIZE, getid3_lib\LittleEndian2Int(), and getid3_lib\PrintHexBytes().

21  {
22  $offset = 0;
23  fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
24  $rawdata = fread($fd, GETID3_FREAD_BUFFER_SIZE);
25 
26  switch (substr($rawdata, $offset, 4)) {
27  case 'LA02':
28  case 'LA03':
29  case 'LA04':
30  $ThisFileInfo['fileformat'] = 'la';
31  $ThisFileInfo['audio']['dataformat'] = 'la';
32  $ThisFileInfo['audio']['lossless'] = true;
33 
34  $ThisFileInfo['la']['version_major'] = (int) substr($rawdata, $offset + 2, 1);
35  $ThisFileInfo['la']['version_minor'] = (int) substr($rawdata, $offset + 3, 1);
36  $ThisFileInfo['la']['version'] = (float) $ThisFileInfo['la']['version_major'] + ($ThisFileInfo['la']['version_minor'] / 10);
37  $offset += 4;
38 
39  $ThisFileInfo['la']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
40  $offset += 4;
41  if ($ThisFileInfo['la']['uncompressed_size'] == 0) {
42  $ThisFileInfo['error'][] = 'Corrupt LA file: uncompressed_size == zero';
43  return false;
44  }
45 
46  $WAVEchunk = substr($rawdata, $offset, 4);
47  if ($WAVEchunk !== 'WAVE') {
48  $ThisFileInfo['error'][] = 'Expected "WAVE" ('.getid3_lib::PrintHexBytes('WAVE').') at offset '.$offset.', found "'.$WAVEchunk.'" ('.getid3_lib::PrintHexBytes($WAVEchunk).') instead.';
49  return false;
50  }
51  $offset += 4;
52 
53  $ThisFileInfo['la']['fmt_size'] = 24;
54  if ($ThisFileInfo['la']['version'] >= 0.3) {
55 
56  $ThisFileInfo['la']['fmt_size'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
57  $ThisFileInfo['la']['header_size'] = 49 + $ThisFileInfo['la']['fmt_size'] - 24;
58  $offset += 4;
59 
60  } else {
61 
62  // version 0.2 didn't support additional data blocks
63  $ThisFileInfo['la']['header_size'] = 41;
64 
65  }
66 
67  $fmt_chunk = substr($rawdata, $offset, 4);
68  if ($fmt_chunk !== 'fmt ') {
69  $ThisFileInfo['error'][] = 'Expected "fmt " ('.getid3_lib::PrintHexBytes('fmt ').') at offset '.$offset.', found "'.$fmt_chunk.'" ('.getid3_lib::PrintHexBytes($fmt_chunk).') instead.';
70  return false;
71  }
72  $offset += 4;
73  $fmt_size = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
74  $offset += 4;
75 
76  $ThisFileInfo['la']['raw']['format'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
77  $offset += 2;
78 
79  $ThisFileInfo['la']['channels'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
80  $offset += 2;
81  if ($ThisFileInfo['la']['channels'] == 0) {
82  $ThisFileInfo['error'][] = 'Corrupt LA file: channels == zero';
83  return false;
84  }
85 
86  $ThisFileInfo['la']['sample_rate'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
87  $offset += 4;
88  if ($ThisFileInfo['la']['sample_rate'] == 0) {
89  $ThisFileInfo['error'][] = 'Corrupt LA file: sample_rate == zero';
90  return false;
91  }
92 
93  $ThisFileInfo['la']['bytes_per_second'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
94  $offset += 4;
95  $ThisFileInfo['la']['bytes_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
96  $offset += 2;
97  $ThisFileInfo['la']['bits_per_sample'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 2));
98  $offset += 2;
99 
100  $ThisFileInfo['la']['samples'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
101  $offset += 4;
102 
103  $ThisFileInfo['la']['raw']['flags'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 1));
104  $offset += 1;
105  $ThisFileInfo['la']['flags']['seekable'] = (bool) ($ThisFileInfo['la']['raw']['flags'] & 0x01);
106  if ($ThisFileInfo['la']['version'] >= 0.4) {
107  $ThisFileInfo['la']['flags']['high_compression'] = (bool) ($ThisFileInfo['la']['raw']['flags'] & 0x02);
108  }
109 
110  $ThisFileInfo['la']['original_crc'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
111  $offset += 4;
112 
113  // mikeØbevin*de
114  // Basically, the blocksize/seekevery are 61440/19 in La0.4 and 73728/16
115  // in earlier versions. A seekpoint is added every blocksize * seekevery
116  // samples, so 4 * int(totalSamples / (blockSize * seekEvery)) should
117  // give the number of bytes used for the seekpoints. Of course, if seeking
118  // is disabled, there are no seekpoints stored.
119  if ($ThisFileInfo['la']['version'] >= 0.4) {
120  $ThisFileInfo['la']['blocksize'] = 61440;
121  $ThisFileInfo['la']['seekevery'] = 19;
122  } else {
123  $ThisFileInfo['la']['blocksize'] = 73728;
124  $ThisFileInfo['la']['seekevery'] = 16;
125  }
126 
127  $ThisFileInfo['la']['seekpoint_count'] = 0;
128  if ($ThisFileInfo['la']['flags']['seekable']) {
129  $ThisFileInfo['la']['seekpoint_count'] = floor($ThisFileInfo['la']['samples'] / ($ThisFileInfo['la']['blocksize'] * $ThisFileInfo['la']['seekevery']));
130 
131  for ($i = 0; $i < $ThisFileInfo['la']['seekpoint_count']; $i++) {
132  $ThisFileInfo['la']['seekpoints'][] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
133  $offset += 4;
134  }
135  }
136 
137  if ($ThisFileInfo['la']['version'] >= 0.3) {
138 
139  // Following the main header information, the program outputs all of the
140  // seekpoints. Following these is what I called the 'footer start',
141  // i.e. the position immediately after the La audio data is finished.
142  $ThisFileInfo['la']['footerstart'] = getid3_lib::LittleEndian2Int(substr($rawdata, $offset, 4));
143  $offset += 4;
144 
145  if ($ThisFileInfo['la']['footerstart'] > $ThisFileInfo['filesize']) {
146  $ThisFileInfo['warning'][] = 'FooterStart value points to offset '.$ThisFileInfo['la']['footerstart'].' which is beyond end-of-file ('.$ThisFileInfo['filesize'].')';
147  $ThisFileInfo['la']['footerstart'] = $ThisFileInfo['filesize'];
148  }
149 
150  } else {
151 
152  // La v0.2 didn't have FooterStart value
153  $ThisFileInfo['la']['footerstart'] = $ThisFileInfo['avdataend'];
154 
155  }
156 
157  if ($ThisFileInfo['la']['footerstart'] < $ThisFileInfo['avdataend']) {
158  if ($RIFFtempfilename = tempnam('*', 'id3')) {
159  if ($RIFF_fp = fopen($RIFFtempfilename, 'w+b')) {
160  $RIFFdata = 'WAVE';
161  if ($ThisFileInfo['la']['version'] == 0.2) {
162  $RIFFdata .= substr($rawdata, 12, 24);
163  } else {
164  $RIFFdata .= substr($rawdata, 16, 24);
165  }
166  if ($ThisFileInfo['la']['footerstart'] < $ThisFileInfo['avdataend']) {
167  fseek($fd, $ThisFileInfo['la']['footerstart'], SEEK_SET);
168  $RIFFdata .= fread($fd, $ThisFileInfo['avdataend'] - $ThisFileInfo['la']['footerstart']);
169  }
170  $RIFFdata = 'RIFF'.getid3_lib::LittleEndian2String(strlen($RIFFdata), 4, false).$RIFFdata;
171  fwrite($RIFF_fp, $RIFFdata, strlen($RIFFdata));
172  $dummy = $ThisFileInfo;
173  $dummy['filesize'] = strlen($RIFFdata);
174  $dummy['avdataoffset'] = 0;
175  $dummy['avdataend'] = $dummy['filesize'];
176 
177  $riff = new getid3_riff($RIFF_fp, $dummy);
178  if (empty($dummy['error'])) {
179  $ThisFileInfo['riff'] = $dummy['riff'];
180  } else {
181  $ThisFileInfo['warning'][] = 'Error parsing RIFF portion of La file: '.implode($dummy['error']);
182  }
183  unset($dummy);
184  fclose($RIFF_fp);
185  }
186  unlink($RIFFtempfilename);
187  }
188  }
189 
190  // $ThisFileInfo['avdataoffset'] should be zero to begin with, but just in case it's not, include the addition anyway
191  $ThisFileInfo['avdataend'] = $ThisFileInfo['avdataoffset'] + $ThisFileInfo['la']['footerstart'];
192  $ThisFileInfo['avdataoffset'] = $ThisFileInfo['avdataoffset'] + $offset;
193 
194  //$ThisFileInfo['la']['codec'] = RIFFwFormatTagLookup($ThisFileInfo['la']['raw']['format']);
195  $ThisFileInfo['la']['compression_ratio'] = (float) (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) / $ThisFileInfo['la']['uncompressed_size']);
196  $ThisFileInfo['playtime_seconds'] = (float) ($ThisFileInfo['la']['samples'] / $ThisFileInfo['la']['sample_rate']) / $ThisFileInfo['la']['channels'];
197  if ($ThisFileInfo['playtime_seconds'] == 0) {
198  $ThisFileInfo['error'][] = 'Corrupt LA file: playtime_seconds == zero';
199  return false;
200  }
201 
202  $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) * 8 / $ThisFileInfo['playtime_seconds'];
203  //$ThisFileInfo['audio']['codec'] = $ThisFileInfo['la']['codec'];
204  $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['la']['bits_per_sample'];
205  break;
206 
207  default:
208  if (substr($rawdata, $offset, 2) == 'LA') {
209  $ThisFileInfo['error'][] = 'This version of getID3() (v'.GETID3_VERSION.') doesn\'t support LA version '.substr($rawdata, $offset + 2, 1).'.'.substr($rawdata, $offset + 3, 1).' which this appears to be - check http://getid3.sourceforge.net for updates.';
210  } else {
211  $ThisFileInfo['error'][] = 'Not a LA (Lossless-Audio) file';
212  }
213  return false;
214  break;
215  }
216 
217  $ThisFileInfo['audio']['channels'] = $ThisFileInfo['la']['channels'];
218  $ThisFileInfo['audio']['sample_rate'] = (int) $ThisFileInfo['la']['sample_rate'];
219  $ThisFileInfo['audio']['encoder'] = 'LA v'.$ThisFileInfo['la']['version'];
220 
221  return true;
222  }
const GETID3_FREAD_BUFFER_SIZE
Definition: getid3.php:14
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
fread($bytes)
Definition: getid3.php:1685
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: