20 {
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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));
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 }