rlm@3: <?php
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | PHP version 5                                                        |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | This source file is subject to version 2 of the GPL license,         |
rlm@3: // | that is bundled with this package in the file license.txt and is     |
rlm@3: // | available through the world-wide-web at the following url:           |
rlm@3: // | http://www.gnu.org/copyleft/gpl.html                                 |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | Authors: James Heinrich <infoØgetid3*org>                            |
rlm@3: // |          Allan Hansen <ahØartemis*dk>                                |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | module.audio.au.php                                                  |
rlm@3: // | module for analyzing AU files                                        |
rlm@3: // | dependencies: NONE                                                   |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: //
rlm@3: // $Id: module.audio.au.php,v 1.2 2006/11/02 10:48:01 ah Exp $
rlm@3: 
rlm@3:         
rlm@3:         
rlm@3: class getid3_au extends getid3_handler
rlm@3: {
rlm@3: 
rlm@3:     public function Analyze() {
rlm@3: 
rlm@3:         $getid3 = $this->getid3;
rlm@3:         
rlm@3:         fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3:         $au_header  = fread($getid3->fp, 8);
rlm@3: 
rlm@3:         // Magic bytes: .snd
rlm@3: 
rlm@3:         $getid3->info['au'] = array ();
rlm@3:         $info_au = &$getid3->info['au'];
rlm@3: 
rlm@3:         $getid3->info['fileformat']            = 'au';
rlm@3:         $getid3->info['audio']['dataformat']   = 'au';
rlm@3:         $getid3->info['audio']['bitrate_mode'] = 'cbr';
rlm@3:         $info_au['encoding']                   = 'ISO-8859-1';
rlm@3: 
rlm@3:         $info_au['header_length']   = getid3_lib::BigEndian2Int(substr($au_header,  4, 4));
rlm@3:         $au_header .= fread($getid3->fp, $info_au['header_length'] - 8);
rlm@3:         $getid3->info['avdataoffset'] += $info_au['header_length'];
rlm@3: 
rlm@3:         getid3_lib::ReadSequence('BigEndian2Int', $info_au, $au_header, 8,  
rlm@3:             array (
rlm@3:                 'data_size'     => 4,
rlm@3:                 'data_format_id'=> 4,
rlm@3:                 'sample_rate'   => 4,
rlm@3:                 'channels'      => 4
rlm@3:             )
rlm@3:         );
rlm@3:         $info_au['comments']['comment'][] = trim(substr($au_header, 24));
rlm@3: 
rlm@3:         $info_au['data_format']          = getid3_au::AUdataFormatNameLookup($info_au['data_format_id']);
rlm@3:         $info_au['used_bits_per_sample'] = getid3_au::AUdataFormatUsedBitsPerSampleLookup($info_au['data_format_id']);
rlm@3:         if ($info_au['bits_per_sample']  = getid3_au::AUdataFormatBitsPerSampleLookup($info_au['data_format_id'])) {
rlm@3:             $getid3->info['audio']['bits_per_sample'] = $info_au['bits_per_sample'];
rlm@3:         } else {
rlm@3:             unset($info_au['bits_per_sample']);
rlm@3:         }
rlm@3: 
rlm@3:         $getid3->info['audio']['sample_rate'] = $info_au['sample_rate'];
rlm@3:         $getid3->info['audio']['channels']    = $info_au['channels'];
rlm@3: 
rlm@3:         if (($getid3->info['avdataoffset'] + $info_au['data_size']) > $getid3->info['avdataend']) {
rlm@3:             $getid3->warning('Possible truncated file - expecting "'.$info_au['data_size'].'" bytes of audio data, only found '.($getid3->info['avdataend'] - $getid3->info['avdataoffset']).' bytes"');
rlm@3:         }
rlm@3: 
rlm@3:         $getid3->info['playtime_seconds'] = $info_au['data_size'] / ($info_au['sample_rate'] * $info_au['channels'] * ($info_au['used_bits_per_sample'] / 8));
rlm@3:         $getid3->info['audio']['bitrate'] = ($info_au['data_size'] * 8) / $getid3->info['playtime_seconds'];
rlm@3: 
rlm@3:         return true;
rlm@3:     }
rlm@3: 
rlm@3: 
rlm@3: 
rlm@3:     public static function AUdataFormatNameLookup($id) {
rlm@3:         
rlm@3:         static $lookup = array (
rlm@3:             0  => 'unspecified format',
rlm@3:             1  => '8-bit mu-law',
rlm@3:             2  => '8-bit linear',
rlm@3:             3  => '16-bit linear',
rlm@3:             4  => '24-bit linear',
rlm@3:             5  => '32-bit linear',
rlm@3:             6  => 'floating-point',
rlm@3:             7  => 'double-precision float',
rlm@3:             8  => 'fragmented sampled data',
rlm@3:             9  => 'SUN_FORMAT_NESTED',
rlm@3:             10 => 'DSP program',
rlm@3:             11 => '8-bit fixed-point',
rlm@3:             12 => '16-bit fixed-point',
rlm@3:             13 => '24-bit fixed-point',
rlm@3:             14 => '32-bit fixed-point',
rlm@3: 
rlm@3:             16 => 'non-audio display data',
rlm@3:             17 => 'SND_FORMAT_MULAW_SQUELCH',
rlm@3:             18 => '16-bit linear with emphasis',
rlm@3:             19 => '16-bit linear with compression',
rlm@3:             20 => '16-bit linear with emphasis + compression',
rlm@3:             21 => 'Music Kit DSP commands',
rlm@3:             22 => 'SND_FORMAT_DSP_COMMANDS_SAMPLES',
rlm@3:             23 => 'CCITT g.721 4-bit ADPCM',
rlm@3:             24 => 'CCITT g.722 ADPCM',
rlm@3:             25 => 'CCITT g.723 3-bit ADPCM',
rlm@3:             26 => 'CCITT g.723 5-bit ADPCM',
rlm@3:             27 => 'A-Law 8-bit'
rlm@3:         );
rlm@3:         
rlm@3:         return (isset($lookup[$id]) ? $lookup[$id] : false);
rlm@3:     }
rlm@3: 
rlm@3: 
rlm@3: 
rlm@3:     public static function AUdataFormatBitsPerSampleLookup($id) {
rlm@3:         
rlm@3:         static $lookup = array (
rlm@3:             1  => 8,
rlm@3:             2  => 8,
rlm@3:             3  => 16,
rlm@3:             4  => 24,
rlm@3:             5  => 32,
rlm@3:             6  => 32,
rlm@3:             7  => 64,
rlm@3: 
rlm@3:             11 => 8,
rlm@3:             12 => 16,
rlm@3:             13 => 24,
rlm@3:             14 => 32,
rlm@3: 
rlm@3:             18 => 16,
rlm@3:             19 => 16,
rlm@3:             20 => 16,
rlm@3: 
rlm@3:             23 => 16,
rlm@3: 
rlm@3:             25 => 16,
rlm@3:             26 => 16,
rlm@3:             27 => 8
rlm@3:         );
rlm@3:         return (isset($lookup[$id]) ? $lookup[$id] : false);
rlm@3:     }
rlm@3: 
rlm@3: 
rlm@3: 
rlm@3:     public static function AUdataFormatUsedBitsPerSampleLookup($id) {
rlm@3:         
rlm@3:         static $lookup = array (
rlm@3:             1  => 8,
rlm@3:             2  => 8,
rlm@3:             3  => 16,
rlm@3:             4  => 24,
rlm@3:             5  => 32,
rlm@3:             6  => 32,
rlm@3:             7  => 64,
rlm@3: 
rlm@3:             11 => 8,
rlm@3:             12 => 16,
rlm@3:             13 => 24,
rlm@3:             14 => 32,
rlm@3: 
rlm@3:             18 => 16,
rlm@3:             19 => 16,
rlm@3:             20 => 16,
rlm@3: 
rlm@3:             23 => 4,
rlm@3: 
rlm@3:             25 => 3,
rlm@3:             26 => 5,
rlm@3:             27 => 8,
rlm@3:         );
rlm@3:         return (isset($lookup[$id]) ? $lookup[$id] : false);
rlm@3:     }
rlm@3: 
rlm@3: }
rlm@3: 
rlm@3: 
rlm@3: ?>