a99d05d7c5e188769de3df40e28a1d2906941906
3 /////////////////////////////////////////////////////////////////
4 /// getID3() by James Heinrich <info@getid3.org> //
5 // available at https://github.com/JamesHeinrich/getID3 //
6 // or https://www.getid3.org //
7 // or http://getid3.sourceforge.net //
8 // see readme.txt for more details //
9 /////////////////////////////////////////////////////////////////
11 // module.audio.au.php //
12 // module for analyzing AU files //
13 // dependencies: NONE //
15 /////////////////////////////////////////////////////////////////
18 class getid3_au
extends getid3_handler
23 public function Analyze() {
24 $info = &$this->getid3
->info
;
26 $this->fseek($info['avdataoffset']);
27 $AUheader = $this->fread(8);
30 if (substr($AUheader, 0, 4) != $magic) {
31 $this->error('Expecting "'.getid3_lib
::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.getid3_lib
::PrintHexBytes(substr($AUheader, 0, 4)).'"');
36 $info['au'] = array();
37 $thisfile_au = &$info['au'];
39 $info['fileformat'] = 'au';
40 $info['audio']['dataformat'] = 'au';
41 $info['audio']['bitrate_mode'] = 'cbr';
42 $thisfile_au['encoding'] = 'ISO-8859-1';
44 $thisfile_au['header_length'] = getid3_lib
::BigEndian2Int(substr($AUheader, 4, 4));
45 $AUheader .= $this->fread($thisfile_au['header_length'] - 8);
46 $info['avdataoffset'] +
= $thisfile_au['header_length'];
48 $thisfile_au['data_size'] = getid3_lib
::BigEndian2Int(substr($AUheader, 8, 4));
49 $thisfile_au['data_format_id'] = getid3_lib
::BigEndian2Int(substr($AUheader, 12, 4));
50 $thisfile_au['sample_rate'] = getid3_lib
::BigEndian2Int(substr($AUheader, 16, 4));
51 $thisfile_au['channels'] = getid3_lib
::BigEndian2Int(substr($AUheader, 20, 4));
52 $thisfile_au['comments']['comment'][] = trim(substr($AUheader, 24));
54 $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']);
55 $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']);
56 if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) {
57 $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample'];
59 unset($thisfile_au['bits_per_sample']);
62 $info['audio']['sample_rate'] = $thisfile_au['sample_rate'];
63 $info['audio']['channels'] = $thisfile_au['channels'];
65 if (($info['avdataoffset'] +
$thisfile_au['data_size']) > $info['avdataend']) {
66 $this->warning('Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"');
69 $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8));
70 $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds'];
78 * @return string|false
80 public function AUdataFormatNameLookup($id) {
81 static $AUdataFormatNameLookup = array(
82 0 => 'unspecified format',
88 6 => 'floating-point',
89 7 => 'double-precision float',
90 8 => 'fragmented sampled data',
91 9 => 'SUN_FORMAT_NESTED',
93 11 => '8-bit fixed-point',
94 12 => '16-bit fixed-point',
95 13 => '24-bit fixed-point',
96 14 => '32-bit fixed-point',
98 16 => 'non-audio display data',
99 17 => 'SND_FORMAT_MULAW_SQUELCH',
100 18 => '16-bit linear with emphasis',
101 19 => '16-bit linear with compression',
102 20 => '16-bit linear with emphasis + compression',
103 21 => 'Music Kit DSP commands',
104 22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES',
105 23 => 'CCITT g.721 4-bit ADPCM',
106 24 => 'CCITT g.722 ADPCM',
107 25 => 'CCITT g.723 3-bit ADPCM',
108 26 => 'CCITT g.723 5-bit ADPCM',
111 return (isset($AUdataFormatNameLookup[$id]) ?
$AUdataFormatNameLookup[$id] : false);
119 public function AUdataFormatBitsPerSampleLookup($id) {
120 static $AUdataFormatBitsPerSampleLookup = array(
144 return (isset($AUdataFormatBitsPerSampleLookup[$id]) ?
$AUdataFormatBitsPerSampleLookup[$id] : false);
152 public function AUdataFormatUsedBitsPerSampleLookup($id) {
153 static $AUdataFormatUsedBitsPerSampleLookup = array(
177 return (isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ?
$AUdataFormatUsedBitsPerSampleLookup[$id] : false);