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 /////////////////////////////////////////////////////////////////
17 if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
21 class getid3_au
extends getid3_handler
26 public function Analyze() {
27 $info = &$this->getid3
->info
;
29 $this->fseek($info['avdataoffset']);
30 $AUheader = $this->fread(8);
33 if (substr($AUheader, 0, 4) != $magic) {
34 $this->error('Expecting "'.getid3_lib
::PrintHexBytes($magic).'" (".snd") at offset '.$info['avdataoffset'].', found "'.getid3_lib
::PrintHexBytes(substr($AUheader, 0, 4)).'"');
39 $info['au'] = array();
40 $thisfile_au = &$info['au'];
42 $info['fileformat'] = 'au';
43 $info['audio']['dataformat'] = 'au';
44 $info['audio']['bitrate_mode'] = 'cbr';
45 $thisfile_au['encoding'] = 'ISO-8859-1';
47 $thisfile_au['header_length'] = getid3_lib
::BigEndian2Int(substr($AUheader, 4, 4));
48 $AUheader .= $this->fread($thisfile_au['header_length'] - 8);
49 $info['avdataoffset'] +
= $thisfile_au['header_length'];
51 $thisfile_au['data_size'] = getid3_lib
::BigEndian2Int(substr($AUheader, 8, 4));
52 $thisfile_au['data_format_id'] = getid3_lib
::BigEndian2Int(substr($AUheader, 12, 4));
53 $thisfile_au['sample_rate'] = getid3_lib
::BigEndian2Int(substr($AUheader, 16, 4));
54 $thisfile_au['channels'] = getid3_lib
::BigEndian2Int(substr($AUheader, 20, 4));
55 $thisfile_au['comments']['comment'][] = trim(substr($AUheader, 24));
57 $thisfile_au['data_format'] = $this->AUdataFormatNameLookup($thisfile_au['data_format_id']);
58 $thisfile_au['used_bits_per_sample'] = $this->AUdataFormatUsedBitsPerSampleLookup($thisfile_au['data_format_id']);
59 if ($thisfile_au['bits_per_sample'] = $this->AUdataFormatBitsPerSampleLookup($thisfile_au['data_format_id'])) {
60 $info['audio']['bits_per_sample'] = $thisfile_au['bits_per_sample'];
62 unset($thisfile_au['bits_per_sample']);
65 $info['audio']['sample_rate'] = $thisfile_au['sample_rate'];
66 $info['audio']['channels'] = $thisfile_au['channels'];
68 if (($info['avdataoffset'] +
$thisfile_au['data_size']) > $info['avdataend']) {
69 $this->warning('Possible truncated file - expecting "'.$thisfile_au['data_size'].'" bytes of audio data, only found '.($info['avdataend'] - $info['avdataoffset']).' bytes"');
72 $info['playtime_seconds'] = $thisfile_au['data_size'] / ($thisfile_au['sample_rate'] * $thisfile_au['channels'] * ($thisfile_au['used_bits_per_sample'] / 8));
73 $info['audio']['bitrate'] = ($thisfile_au['data_size'] * 8) / $info['playtime_seconds'];
81 * @return string|false
83 public function AUdataFormatNameLookup($id) {
84 static $AUdataFormatNameLookup = array(
85 0 => 'unspecified format',
91 6 => 'floating-point',
92 7 => 'double-precision float',
93 8 => 'fragmented sampled data',
94 9 => 'SUN_FORMAT_NESTED',
96 11 => '8-bit fixed-point',
97 12 => '16-bit fixed-point',
98 13 => '24-bit fixed-point',
99 14 => '32-bit fixed-point',
101 16 => 'non-audio display data',
102 17 => 'SND_FORMAT_MULAW_SQUELCH',
103 18 => '16-bit linear with emphasis',
104 19 => '16-bit linear with compression',
105 20 => '16-bit linear with emphasis + compression',
106 21 => 'Music Kit DSP commands',
107 22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES',
108 23 => 'CCITT g.721 4-bit ADPCM',
109 24 => 'CCITT g.722 ADPCM',
110 25 => 'CCITT g.723 3-bit ADPCM',
111 26 => 'CCITT g.723 5-bit ADPCM',
114 return (isset($AUdataFormatNameLookup[$id]) ?
$AUdataFormatNameLookup[$id] : false);
122 public function AUdataFormatBitsPerSampleLookup($id) {
123 static $AUdataFormatBitsPerSampleLookup = array(
147 return (isset($AUdataFormatBitsPerSampleLookup[$id]) ?
$AUdataFormatBitsPerSampleLookup[$id] : false);
155 public function AUdataFormatUsedBitsPerSampleLookup($id) {
156 static $AUdataFormatUsedBitsPerSampleLookup = array(
180 return (isset($AUdataFormatUsedBitsPerSampleLookup[$id]) ?
$AUdataFormatUsedBitsPerSampleLookup[$id] : false);