ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Au.php
Go to the documentation of this file.
1 <?php
2 
3 namespace GetId3\Module\Audio;
4 
7 
10 // available at http://getid3.sourceforge.net //
11 // or http://www.getid3.org //
13 // See readme.txt for more details //
15 // //
16 // module.audio.au.php //
17 // module for analyzing AU files //
18 // dependencies: NONE //
19 // ///
21 
29 class Au extends BaseHandler
30 {
31 
36  public function analyze()
37  {
38  $info = &$this->getid3->info;
39 
40  fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
41  $AUheader = fread($this->getid3->fp, 8);
42 
43  $magic = '.snd';
44  if (substr($AUheader, 0, 4) != $magic) {
45  $info['error'][] = 'Expecting "'.Helper::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.Helper::PrintHexBytes(substr($AUheader, 0, 4)).'"';
46 
47  return false;
48  }
49 
50  // shortcut
51  $info['au'] = array();
52  $thisfile_au = &$info['au'];
53 
54  $info['fileformat'] = 'au';
55  $info['audio']['dataformat'] = 'au';
56  $info['audio']['bitrate_mode'] = 'cbr';
57  $thisfile_au['encoding'] = 'ISO-8859-1';
58 
59  $thisfile_au['header_length'] = Helper::BigEndian2Int(substr($AUheader, 4, 4));
60  $AUheader .= fread($this->getid3->fp, $thisfile_au['header_length'] - 8);
61  $info['avdataoffset'] += $thisfile_au['header_length'];
62 
63  $thisfile_au['data_size'] = Helper::BigEndian2Int(substr($AUheader, 8, 4));
64  $thisfile_au['data_format_id'] = Helper::BigEndian2Int(substr($AUheader, 12, 4));
65  $thisfile_au['sample_rate'] = Helper::BigEndian2Int(substr($AUheader, 16, 4));
66  $thisfile_au['channels'] = Helper::BigEndian2Int(substr($AUheader, 20, 4));
67  $thisfile_au['comments']['comment'][] = trim(substr($AUheader, 24));
68 
69  $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']);
70  $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']);
71  if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) {
72  $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample'];
73  } else {
74  unset($thisfile_au['bits_per_sample']);
75  }
76 
77  $info['audio']['sample_rate'] = $thisfile_au['sample_rate'];
78  $info['audio']['channels'] = $thisfile_au['channels'];
79 
80  if (($info['avdataoffset'] + $thisfile_au['data_size']) > $info['avdataend']) {
81  $info['warning'][] = 'Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"';
82  }
83 
84  $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8));
85  $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds'];
86 
87  return true;
88  }
89 
96  public function AUdataFormatNameLookup($id)
97  {
98  static $AUdataFormatNameLookup = array(
99  0 => 'unspecified format',
100  1 => '8-bit mu-law',
101  2 => '8-bit linear',
102  3 => '16-bit linear',
103  4 => '24-bit linear',
104  5 => '32-bit linear',
105  6 => 'floating-point',
106  7 => 'double-precision float',
107  8 => 'fragmented sampled data',
108  9 => 'SUN_FORMAT_NESTED',
109  10 => 'DSP program',
110  11 => '8-bit fixed-point',
111  12 => '16-bit fixed-point',
112  13 => '24-bit fixed-point',
113  14 => '32-bit fixed-point',
114 
115  16 => 'non-audio display data',
116  17 => 'SND_FORMAT_MULAW_SQUELCH',
117  18 => '16-bit linear with emphasis',
118  19 => '16-bit linear with compression',
119  20 => '16-bit linear with emphasis + compression',
120  21 => 'Music Kit DSP commands',
121  22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES',
122  23 => 'CCITT g.721 4-bit ADPCM',
123  24 => 'CCITT g.722 ADPCM',
124  25 => 'CCITT g.723 3-bit ADPCM',
125  26 => 'CCITT g.723 5-bit ADPCM',
126  27 => 'A-Law 8-bit'
127  );
128 
129  return (isset($AUdataFormatNameLookup[$id]) ? $AUdataFormatNameLookup[$id] : false);
130  }
131 
138  public function AUdataFormatBitsPerSampleLookup($id)
139  {
140  static $AUdataFormatBitsPerSampleLookup = array(
141  1 => 8,
142  2 => 8,
143  3 => 16,
144  4 => 24,
145  5 => 32,
146  6 => 32,
147  7 => 64,
148 
149  11 => 8,
150  12 => 16,
151  13 => 24,
152  14 => 32,
153 
154  18 => 16,
155  19 => 16,
156  20 => 16,
157 
158  23 => 16,
159 
160  25 => 16,
161  26 => 16,
162  27 => 8
163  );
164 
165  return (isset($AUdataFormatBitsPerSampleLookup[$id]) ? $AUdataFormatBitsPerSampleLookup[$id] : false);
166  }
167 
175  {
176  static $AUdataFormatUsedBitsPerSampleLookup = array(
177  1 => 8,
178  2 => 8,
179  3 => 16,
180  4 => 24,
181  5 => 32,
182  6 => 32,
183  7 => 64,
184 
185  11 => 8,
186  12 => 16,
187  13 => 24,
188  14 => 32,
189 
190  18 => 16,
191  19 => 16,
192  20 => 16,
193 
194  23 => 4,
195 
196  25 => 3,
197  26 => 5,
198  27 => 8,
199  );
200 
201  return (isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ? $AUdataFormatUsedBitsPerSampleLookup[$id] : false);
202  }
203 }
GetId3() by James Heinrich info@getid3.org //.
Definition: Au.php:29
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: Helper.php:36
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:25
AUdataFormatBitsPerSampleLookup($id)
array $AUdataFormatBitsPerSampleLookup
Definition: Au.php:138
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
Create styles array
The data for the language used.
AUdataFormatNameLookup($id)
array $AUdataFormatNameLookup
Definition: Au.php:96
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: Helper.php:374
AUdataFormatUsedBitsPerSampleLookup($id)
array $AUdataFormatUsedBitsPerSampleLookup
Definition: Au.php:174