annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.audio.avr.php @ 8:1b77e8657088 judyates

[svn r9] saving for transference to cd
author rlm
date Fri, 19 Mar 2010 07:17:36 -0400
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.audio.avr.php |
rlm@3 18 // | Module for analyzing AVR audio files |
rlm@3 19 // | dependencies: NONE |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.audio.avr.php,v 1.2 2006/11/02 10:48:01 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_avr extends getid3_handler
rlm@3 27 {
rlm@3 28
rlm@3 29 public function Analyze() {
rlm@3 30
rlm@3 31 $getid3 = $this->getid3;
rlm@3 32
rlm@3 33 // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html
rlm@3 34 // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html
rlm@3 35 // offset type length name comments
rlm@3 36 // ---------------------------------------------------------------------
rlm@3 37 // 0 char 4 ID format ID == "2BIT"
rlm@3 38 // 4 char 8 name sample name (unused space filled with 0)
rlm@3 39 // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo
rlm@3 40 // With stereo, samples are alternated,
rlm@3 41 // the first voice is the left :
rlm@3 42 // (LRLRLRLRLRLRLRLRLR...)
rlm@3 43 // 14 short 1 resolution 8, 12 or 16 (bits)
rlm@3 44 // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed
rlm@3 45 // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on
rlm@3 46 // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127
rlm@3 47 // 0xFFFF means "no MIDI note defined"
rlm@3 48 // 22 byte 1 Replay speed Frequence in the Replay software
rlm@3 49 // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz,
rlm@3 50 // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz
rlm@3 51 // 6=43.885 Khz, 7=47.261 Khz
rlm@3 52 // -1 (0xFF)=no defined Frequence
rlm@3 53 // 23 byte 3 sample rate in Hertz
rlm@3 54 // 26 long 1 size in bytes (2 * bytes in stereo)
rlm@3 55 // 30 long 1 loop begin 0 for no loop
rlm@3 56 // 34 long 1 loop size equal to 'size' for no loop
rlm@3 57 // 38 short 2 Reserved, MIDI keyboard split */
rlm@3 58 // 40 short 2 Reserved, sample compression */
rlm@3 59 // 42 short 2 Reserved */
rlm@3 60 // 44 char 20; Additional filename space, used if (name[7] != 0)
rlm@3 61 // 64 byte 64 user data
rlm@3 62 // 128 bytes ? sample data (12 bits samples are coded on 16 bits:
rlm@3 63 // 0000 xxxx xxxx xxxx)
rlm@3 64 // ---------------------------------------------------------------------
rlm@3 65
rlm@3 66 // Note that all values are in motorola (big-endian) format, and that long is
rlm@3 67 // assumed to be 4 bytes, and short 2 bytes.
rlm@3 68 // When reading the samples, you should handle both signed and unsigned data,
rlm@3 69 // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert
rlm@3 70 // 8-bit data between signed/unsigned just add 127 to the sample values.
rlm@3 71 // Simularly for 16-bit data you should add 32769
rlm@3 72
rlm@3 73
rlm@3 74 // Magic bytes: '2BIT'
rlm@3 75
rlm@3 76 $getid3->info['avr'] = array ();
rlm@3 77 $info_avr = &$getid3->info['avr'];
rlm@3 78
rlm@3 79 $getid3->info['fileformat'] = 'avr';
rlm@3 80 $info_avr['raw']['magic'] = '2BIT';
rlm@3 81
rlm@3 82 fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3 83 $avr_header = fread($getid3->fp, 128);
rlm@3 84
rlm@3 85 $getid3->info['avdataoffset'] += 128;
rlm@3 86
rlm@3 87 $info_avr['sample_name'] = rtrim(substr($avr_header, 4, 8));
rlm@3 88
rlm@3 89 $info_avr['raw']['mono'] = getid3_lib::BigEndian2Int(substr($avr_header, 12, 2));
rlm@3 90 $info_avr['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($avr_header, 14, 2));
rlm@3 91 $info_avr['raw']['signed'] = getid3_lib::BigEndian2Int(substr($avr_header, 16, 2));
rlm@3 92 $info_avr['raw']['loop'] = getid3_lib::BigEndian2Int(substr($avr_header, 18, 2));
rlm@3 93 $info_avr['raw']['midi'] = getid3_lib::BigEndian2Int(substr($avr_header, 20, 2));
rlm@3 94 $info_avr['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($avr_header, 22, 1));
rlm@3 95 $info_avr['sample_rate'] = getid3_lib::BigEndian2Int(substr($avr_header, 23, 3));
rlm@3 96 $info_avr['sample_length'] = getid3_lib::BigEndian2Int(substr($avr_header, 26, 4));
rlm@3 97 $info_avr['loop_start'] = getid3_lib::BigEndian2Int(substr($avr_header, 30, 4));
rlm@3 98 $info_avr['loop_end'] = getid3_lib::BigEndian2Int(substr($avr_header, 34, 4));
rlm@3 99 $info_avr['midi_split'] = getid3_lib::BigEndian2Int(substr($avr_header, 38, 2));
rlm@3 100 $info_avr['sample_compression'] = getid3_lib::BigEndian2Int(substr($avr_header, 40, 2));
rlm@3 101 $info_avr['reserved'] = getid3_lib::BigEndian2Int(substr($avr_header, 42, 2));
rlm@3 102 $info_avr['sample_name_extra'] = rtrim(substr($avr_header, 44, 20));
rlm@3 103 $info_avr['comment'] = rtrim(substr($avr_header, 64, 64));
rlm@3 104
rlm@3 105 $info_avr['flags']['stereo'] = (($info_avr['raw']['mono'] == 0) ? false : true);
rlm@3 106 $info_avr['flags']['signed'] = (($info_avr['raw']['signed'] == 0) ? false : true);
rlm@3 107 $info_avr['flags']['loop'] = (($info_avr['raw']['loop'] == 0) ? false : true);
rlm@3 108
rlm@3 109 $info_avr['midi_notes'] = array ();
rlm@3 110 if (($info_avr['raw']['midi'] & 0xFF00) != 0xFF00) {
rlm@3 111 $info_avr['midi_notes'][] = ($info_avr['raw']['midi'] & 0xFF00) >> 8;
rlm@3 112 }
rlm@3 113 if (($info_avr['raw']['midi'] & 0x00FF) != 0x00FF) {
rlm@3 114 $info_avr['midi_notes'][] = ($info_avr['raw']['midi'] & 0x00FF);
rlm@3 115 }
rlm@3 116
rlm@3 117 if (($getid3->info['avdataend'] - $getid3->info['avdataoffset']) != ($info_avr['sample_length'] * (($info_avr['bits_per_sample'] == 8) ? 1 : 2))) {
rlm@3 118 $getid3->warning('Probable truncated file: expecting '.($info_avr['sample_length'] * (($info_avr['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($getid3->info['avdataend'] - $getid3->info['avdataoffset']));
rlm@3 119 }
rlm@3 120
rlm@3 121 $getid3->info['audio']['dataformat'] = 'avr';
rlm@3 122 $getid3->info['audio']['lossless'] = true;
rlm@3 123 $getid3->info['audio']['bitrate_mode'] = 'cbr';
rlm@3 124 $getid3->info['audio']['bits_per_sample'] = $info_avr['bits_per_sample'];
rlm@3 125 $getid3->info['audio']['sample_rate'] = $info_avr['sample_rate'];
rlm@3 126 $getid3->info['audio']['channels'] = ($info_avr['flags']['stereo'] ? 2 : 1);
rlm@3 127 $getid3->info['playtime_seconds'] = ($info_avr['sample_length'] / $getid3->info['audio']['channels']) / $info_avr['sample_rate'];
rlm@3 128 $getid3->info['audio']['bitrate'] = ($info_avr['sample_length'] * (($info_avr['bits_per_sample'] == 8) ? 8 : 16)) / $getid3->info['playtime_seconds'];
rlm@3 129
rlm@3 130 return true;
rlm@3 131 }
rlm@3 132 }
rlm@3 133
rlm@3 134
rlm@3 135 ?>