ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_avr Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_avr:
+ Collaboration diagram for getid3_avr:

Public Member Functions

 getid3_avr (&$fd, &$ThisFileInfo)
 
 Analyze ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 17 of file module.audio.avr.php.

Member Function Documentation

◆ Analyze()

getid3_avr::Analyze ( )

Definition at line 21 of file module.audio.avr.php.

References $info, getid3_lib\BigEndian2Int(), getid3_handler\fread(), getid3_handler\fseek(), and getid3_lib\PrintHexBytes().

21  {
22  $info = &$this->getid3->info;
23 
24  // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html
25  // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html
26  // offset type length name comments
27  // ---------------------------------------------------------------------
28  // 0 char 4 ID format ID == "2BIT"
29  // 4 char 8 name sample name (unused space filled with 0)
30  // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo
31  // With stereo, samples are alternated,
32  // the first voice is the left :
33  // (LRLRLRLRLRLRLRLRLR...)
34  // 14 short 1 resolution 8, 12 or 16 (bits)
35  // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed
36  // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on
37  // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127
38  // 0xFFFF means "no MIDI note defined"
39  // 22 byte 1 Replay speed Frequence in the Replay software
40  // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz,
41  // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz
42  // 6=43.885 Khz, 7=47.261 Khz
43  // -1 (0xFF)=no defined Frequence
44  // 23 byte 3 sample rate in Hertz
45  // 26 long 1 size in bytes (2 * bytes in stereo)
46  // 30 long 1 loop begin 0 for no loop
47  // 34 long 1 loop size equal to 'size' for no loop
48  // 38 short 2 Reserved, MIDI keyboard split */
49  // 40 short 2 Reserved, sample compression */
50  // 42 short 2 Reserved */
51  // 44 char 20; Additional filename space, used if (name[7] != 0)
52  // 64 byte 64 user data
53  // 128 bytes ? sample data (12 bits samples are coded on 16 bits:
54  // 0000 xxxx xxxx xxxx)
55  // ---------------------------------------------------------------------
56 
57  // Note that all values are in motorola (big-endian) format, and that long is
58  // assumed to be 4 bytes, and short 2 bytes.
59  // When reading the samples, you should handle both signed and unsigned data,
60  // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert
61  // 8-bit data between signed/unsigned just add 127 to the sample values.
62  // Simularly for 16-bit data you should add 32769
63 
64  $info['fileformat'] = 'avr';
65 
66  $this->fseek($info['avdataoffset']);
67  $AVRheader = $this->fread(128);
68 
69  $info['avr']['raw']['magic'] = substr($AVRheader, 0, 4);
70  $magic = '2BIT';
71  if ($info['avr']['raw']['magic'] != $magic) {
72  $info['error'][] = 'Expecting "'.getid3_lib::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes($info['avr']['raw']['magic']).'"';
73  unset($info['fileformat']);
74  unset($info['avr']);
75  return false;
76  }
77  $info['avdataoffset'] += 128;
78 
79  $info['avr']['sample_name'] = rtrim(substr($AVRheader, 4, 8));
80  $info['avr']['raw']['mono'] = getid3_lib::BigEndian2Int(substr($AVRheader, 12, 2));
81  $info['avr']['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($AVRheader, 14, 2));
82  $info['avr']['raw']['signed'] = getid3_lib::BigEndian2Int(substr($AVRheader, 16, 2));
83  $info['avr']['raw']['loop'] = getid3_lib::BigEndian2Int(substr($AVRheader, 18, 2));
84  $info['avr']['raw']['midi'] = getid3_lib::BigEndian2Int(substr($AVRheader, 20, 2));
85  $info['avr']['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($AVRheader, 22, 1));
86  $info['avr']['sample_rate'] = getid3_lib::BigEndian2Int(substr($AVRheader, 23, 3));
87  $info['avr']['sample_length'] = getid3_lib::BigEndian2Int(substr($AVRheader, 26, 4));
88  $info['avr']['loop_start'] = getid3_lib::BigEndian2Int(substr($AVRheader, 30, 4));
89  $info['avr']['loop_end'] = getid3_lib::BigEndian2Int(substr($AVRheader, 34, 4));
90  $info['avr']['midi_split'] = getid3_lib::BigEndian2Int(substr($AVRheader, 38, 2));
91  $info['avr']['sample_compression'] = getid3_lib::BigEndian2Int(substr($AVRheader, 40, 2));
92  $info['avr']['reserved'] = getid3_lib::BigEndian2Int(substr($AVRheader, 42, 2));
93  $info['avr']['sample_name_extra'] = rtrim(substr($AVRheader, 44, 20));
94  $info['avr']['comment'] = rtrim(substr($AVRheader, 64, 64));
95 
96  $info['avr']['flags']['stereo'] = (($info['avr']['raw']['mono'] == 0) ? false : true);
97  $info['avr']['flags']['signed'] = (($info['avr']['raw']['signed'] == 0) ? false : true);
98  $info['avr']['flags']['loop'] = (($info['avr']['raw']['loop'] == 0) ? false : true);
99 
100  $info['avr']['midi_notes'] = array();
101  if (($info['avr']['raw']['midi'] & 0xFF00) != 0xFF00) {
102  $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0xFF00) >> 8;
103  }
104  if (($info['avr']['raw']['midi'] & 0x00FF) != 0x00FF) {
105  $info['avr']['midi_notes'][] = ($info['avr']['raw']['midi'] & 0x00FF);
106  }
107 
108  if (($info['avdataend'] - $info['avdataoffset']) != ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2))) {
109  $info['warning'][] = 'Probable truncated file: expecting '.($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']);
110  }
111 
112  $info['audio']['dataformat'] = 'avr';
113  $info['audio']['lossless'] = true;
114  $info['audio']['bitrate_mode'] = 'cbr';
115  $info['audio']['bits_per_sample'] = $info['avr']['bits_per_sample'];
116  $info['audio']['sample_rate'] = $info['avr']['sample_rate'];
117  $info['audio']['channels'] = ($info['avr']['flags']['stereo'] ? 2 : 1);
118  $info['playtime_seconds'] = ($info['avr']['sample_length'] / $info['audio']['channels']) / $info['avr']['sample_rate'];
119  $info['audio']['bitrate'] = ($info['avr']['sample_length'] * (($info['avr']['bits_per_sample'] == 8) ? 8 : 16)) / $info['playtime_seconds'];
120 
121 
122  return true;
123  }
$info
Definition: example_052.php:80
fread($bytes)
Definition: getid3.php:1685
BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:234
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17
+ Here is the call graph for this function:

◆ getid3_avr()

getid3_avr::getid3_avr ( $fd,
$ThisFileInfo 
)

Definition at line 20 of file module.audio.avr.php.

References getid3_lib\BigEndian2Int(), getid3_handler\fread(), and getid3_handler\fseek().

20  {
21 
22  // http://cui.unige.ch/OSG/info/AudioFormats/ap11.html
23  // http://www.btinternet.com/~AnthonyJ/Atari/programming/avr_format.html
24  // offset type length name comments
25  // ---------------------------------------------------------------------
26  // 0 char 4 ID format ID == "2BIT"
27  // 4 char 8 name sample name (unused space filled with 0)
28  // 12 short 1 mono/stereo 0=mono, -1 (0xFFFF)=stereo
29  // With stereo, samples are alternated,
30  // the first voice is the left :
31  // (LRLRLRLRLRLRLRLRLR...)
32  // 14 short 1 resolution 8, 12 or 16 (bits)
33  // 16 short 1 signed or not 0=unsigned, -1 (0xFFFF)=signed
34  // 18 short 1 loop or not 0=no loop, -1 (0xFFFF)=loop on
35  // 20 short 1 MIDI note 0xFFnn, where 0 <= nn <= 127
36  // 0xFFFF means "no MIDI note defined"
37  // 22 byte 1 Replay speed Frequence in the Replay software
38  // 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz,
39  // 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz
40  // 6=43.885 Khz, 7=47.261 Khz
41  // -1 (0xFF)=no defined Frequence
42  // 23 byte 3 sample rate in Hertz
43  // 26 long 1 size in bytes (2 * bytes in stereo)
44  // 30 long 1 loop begin 0 for no loop
45  // 34 long 1 loop size equal to 'size' for no loop
46  // 38 short 2 Reserved, MIDI keyboard split */
47  // 40 short 2 Reserved, sample compression */
48  // 42 short 2 Reserved */
49  // 44 char 20; Additional filename space, used if (name[7] != 0)
50  // 64 byte 64 user data
51  // 128 bytes ? sample data (12 bits samples are coded on 16 bits:
52  // 0000 xxxx xxxx xxxx)
53  // ---------------------------------------------------------------------
54 
55  // Note that all values are in motorola (big-endian) format, and that long is
56  // assumed to be 4 bytes, and short 2 bytes.
57  // When reading the samples, you should handle both signed and unsigned data,
58  // and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert
59  // 8-bit data between signed/unsigned just add 127 to the sample values.
60  // Simularly for 16-bit data you should add 32769
61 
62  $ThisFileInfo['fileformat'] = 'avr';
63 
64  fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
65  $AVRheader = fread($fd, 128);
66 
67  $ThisFileInfo['avr']['raw']['magic'] = substr($AVRheader, 0, 4);
68  if ($ThisFileInfo['avr']['raw']['magic'] != '2BIT') {
69  $ThisFileInfo['error'][] = 'Expecting "2BIT" at offset '.$ThisFileInfo['avdataoffset'].', found "'.$ThisFileInfo['avr']['raw']['magic'].'"';
70  unset($ThisFileInfo['fileformat']);
71  unset($ThisFileInfo['avr']);
72  return false;
73  }
74  $ThisFileInfo['avdataoffset'] += 128;
75 
76  $ThisFileInfo['avr']['sample_name'] = rtrim(substr($AVRheader, 4, 8));
77  $ThisFileInfo['avr']['raw']['mono'] = getid3_lib::BigEndian2Int(substr($AVRheader, 12, 2));
78  $ThisFileInfo['avr']['bits_per_sample'] = getid3_lib::BigEndian2Int(substr($AVRheader, 14, 2));
79  $ThisFileInfo['avr']['raw']['signed'] = getid3_lib::BigEndian2Int(substr($AVRheader, 16, 2));
80  $ThisFileInfo['avr']['raw']['loop'] = getid3_lib::BigEndian2Int(substr($AVRheader, 18, 2));
81  $ThisFileInfo['avr']['raw']['midi'] = getid3_lib::BigEndian2Int(substr($AVRheader, 20, 2));
82  $ThisFileInfo['avr']['raw']['replay_freq'] = getid3_lib::BigEndian2Int(substr($AVRheader, 22, 1));
83  $ThisFileInfo['avr']['sample_rate'] = getid3_lib::BigEndian2Int(substr($AVRheader, 23, 3));
84  $ThisFileInfo['avr']['sample_length'] = getid3_lib::BigEndian2Int(substr($AVRheader, 26, 4));
85  $ThisFileInfo['avr']['loop_start'] = getid3_lib::BigEndian2Int(substr($AVRheader, 30, 4));
86  $ThisFileInfo['avr']['loop_end'] = getid3_lib::BigEndian2Int(substr($AVRheader, 34, 4));
87  $ThisFileInfo['avr']['midi_split'] = getid3_lib::BigEndian2Int(substr($AVRheader, 38, 2));
88  $ThisFileInfo['avr']['sample_compression'] = getid3_lib::BigEndian2Int(substr($AVRheader, 40, 2));
89  $ThisFileInfo['avr']['reserved'] = getid3_lib::BigEndian2Int(substr($AVRheader, 42, 2));
90  $ThisFileInfo['avr']['sample_name_extra'] = rtrim(substr($AVRheader, 44, 20));
91  $ThisFileInfo['avr']['comment'] = rtrim(substr($AVRheader, 64, 64));
92 
93  $ThisFileInfo['avr']['flags']['stereo'] = (($ThisFileInfo['avr']['raw']['mono'] == 0) ? false : true);
94  $ThisFileInfo['avr']['flags']['signed'] = (($ThisFileInfo['avr']['raw']['signed'] == 0) ? false : true);
95  $ThisFileInfo['avr']['flags']['loop'] = (($ThisFileInfo['avr']['raw']['loop'] == 0) ? false : true);
96 
97  $ThisFileInfo['avr']['midi_notes'] = array();
98  if (($ThisFileInfo['avr']['raw']['midi'] & 0xFF00) != 0xFF00) {
99  $ThisFileInfo['avr']['midi_notes'][] = ($ThisFileInfo['avr']['raw']['midi'] & 0xFF00) >> 8;
100  }
101  if (($ThisFileInfo['avr']['raw']['midi'] & 0x00FF) != 0x00FF) {
102  $ThisFileInfo['avr']['midi_notes'][] = ($ThisFileInfo['avr']['raw']['midi'] & 0x00FF);
103  }
104 
105  if (($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']) != ($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 1 : 2))) {
106  $ThisFileInfo['warning'][] = 'Probable truncated file: expecting '.($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 1 : 2)).' bytes of audio data, found '.($ThisFileInfo['avdataend'] - $ThisFileInfo['avdataoffset']);
107  }
108 
109  $ThisFileInfo['audio']['dataformat'] = 'avr';
110  $ThisFileInfo['audio']['lossless'] = true;
111  $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
112  $ThisFileInfo['audio']['bits_per_sample'] = $ThisFileInfo['avr']['bits_per_sample'];
113  $ThisFileInfo['audio']['sample_rate'] = $ThisFileInfo['avr']['sample_rate'];
114  $ThisFileInfo['audio']['channels'] = ($ThisFileInfo['avr']['flags']['stereo'] ? 2 : 1);
115  $ThisFileInfo['playtime_seconds'] = ($ThisFileInfo['avr']['sample_length'] / $ThisFileInfo['audio']['channels']) / $ThisFileInfo['avr']['sample_rate'];
116  $ThisFileInfo['audio']['bitrate'] = ($ThisFileInfo['avr']['sample_length'] * (($ThisFileInfo['avr']['bits_per_sample'] == 8) ? 8 : 16)) / $ThisFileInfo['playtime_seconds'];
117 
118 
119  return true;
120  }
fread($bytes)
Definition: getid3.php:1685
BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: getid3.lib.php:234
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: