|
359
|
1 /*
|
|
|
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
|
|
|
3 * Copyright (C) 1999 - 2003 Simon Peter, <dn.tlp@gmx.net>, et al.
|
|
|
4 *
|
|
|
5 * This library is free software; you can redistribute it and/or
|
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
|
7 * License as published by the Free Software Foundation; either
|
|
|
8 * version 2.1 of the License, or (at your option) any later version.
|
|
|
9 *
|
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
13 * Lesser General Public License for more details.
|
|
|
14 *
|
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
|
16 * License along with this library; if not, write to the Free Software
|
|
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 *
|
|
|
19 * d00.c - D00 Player by Simon Peter <dn.tlp@gmx.net>
|
|
|
20 *
|
|
|
21 * NOTES:
|
|
|
22 * Sorry for the goto's, but the code looks so much nicer now.
|
|
|
23 * I tried it with while loops but it was just a mess. If you
|
|
|
24 * can come up with a nicer solution, just tell me.
|
|
|
25 *
|
|
|
26 * BUGS:
|
|
|
27 * Hard restart SR is sometimes wrong
|
|
|
28 */
|
|
|
29
|
|
|
30 #include <string.h>
|
|
|
31 #include <stdio.h>
|
|
|
32
|
|
|
33 #include "debug.h"
|
|
|
34 #include "d00.h"
|
|
|
35
|
|
|
36 #define HIBYTE(val) (val >> 8)
|
|
|
37 #define LOBYTE(val) (val & 0xff)
|
|
|
38
|
|
|
39 static const unsigned short notetable[12] = // D00 note table
|
|
|
40 {340,363,385,408,432,458,485,514,544,577,611,647};
|
|
|
41
|
|
|
42 /*** public methods *************************************/
|
|
|
43
|
|
|
44 CPlayer *Cd00Player::factory(Copl *newopl)
|
|
|
45 {
|
|
|
46 return new Cd00Player(newopl);
|
|
|
47 }
|
|
|
48
|
|
|
49 bool Cd00Player::load(const std::string &filename, const CFileProvider &fp)
|
|
|
50 {
|
|
|
51 binistream *f = fp.open(filename); if(!f) return false;
|
|
|
52 d00header *checkhead;
|
|
|
53 d00header1 *ch;
|
|
|
54 unsigned long filesize;
|
|
|
55 int i,ver1=0;
|
|
|
56 char *str;
|
|
|
57
|
|
|
58 // file validation section
|
|
|
59 checkhead = new d00header;
|
|
|
60 f->readString((char *)checkhead, sizeof(d00header));
|
|
|
61
|
|
|
62 // Check for version 2-4 header
|
|
|
63 if(strncmp(checkhead->id,"JCH\x26\x02\x66",6) || checkhead->type ||
|
|
|
64 !checkhead->subsongs || checkhead->soundcard) {
|
|
|
65 // Check for version 0 or 1 header (and .d00 file extension)
|
|
|
66 delete checkhead;
|
|
|
67 if(!fp.extension(filename, ".d00")) { fp.close(f); return false; }
|
|
|
68 ch = new d00header1;
|
|
|
69 f->seek(0); f->readString((char *)ch, sizeof(d00header1));
|
|
|
70 if(ch->version > 1 || !ch->subsongs)
|
|
|
71 { delete ch; fp.close(f); return false; }
|
|
|
72 delete ch;
|
|
|
73 ver1 = 1;
|
|
|
74 } else
|
|
|
75 delete checkhead;
|
|
|
76
|
|
|
77 AdPlug_LogWrite("Cd00Player::load(f,\"%s\"): %s format D00 file detected!\n",
|
|
|
78 filename.c_str(), ver1 ? "Old" : "New");
|
|
|
79
|
|
|
80 // load section
|
|
|
81 filesize = fp.filesize(f); f->seek(0);
|
|
|
82 filedata = new char [filesize + 1]; // 1 byte is needed for old-style DataInfo block
|
|
|
83 f->readString((char *)filedata, filesize);
|
|
|
84 fp.close(f);
|
|
|
85 if(!ver1) { // version 2 and above
|
|
|
86 header = (struct d00header *)filedata;
|
|
|
87 version = header->version;
|
|
|
88 datainfo = (char *)filedata + header->infoptr;
|
|
|
89 inst = (struct Sinsts *)((char *)filedata + header->instptr);
|
|
|
90 seqptr = (unsigned short *)((char *)filedata + header->seqptr);
|
|
|
91 for(i=31;i>=0;i--) // erase whitespace
|
|
|
92 if(header->songname[i] == ' ')
|
|
|
93 header->songname[i] = '\0';
|
|
|
94 else
|
|
|
95 break;
|
|
|
96 for(i=31;i>=0;i--)
|
|
|
97 if(header->author[i] == ' ')
|
|
|
98 header->author[i] = '\0';
|
|
|
99 else
|
|
|
100 break;
|
|
|
101 } else { // version 1
|
|
|
102 header1 = (struct d00header1 *)filedata;
|
|
|
103 version = header1->version;
|
|
|
104 datainfo = (char *)filedata + header1->infoptr;
|
|
|
105 inst = (struct Sinsts *)((char *)filedata + header1->instptr);
|
|
|
106 seqptr = (unsigned short *)((char *)filedata + header1->seqptr);
|
|
|
107 }
|
|
|
108 switch(version) {
|
|
|
109 case 0:
|
|
|
110 levpuls = 0;
|
|
|
111 spfx = 0;
|
|
|
112 header1->speed = 70; // v0 files default to 70Hz
|
|
|
113 break;
|
|
|
114 case 1:
|
|
|
115 levpuls = (struct Slevpuls *)((char *)filedata + header1->lpulptr);
|
|
|
116 spfx = 0;
|
|
|
117 break;
|
|
|
118 case 2:
|
|
|
119 levpuls = (struct Slevpuls *)((char *)filedata + header->spfxptr);
|
|
|
120 spfx = 0;
|
|
|
121 break;
|
|
|
122 case 3:
|
|
|
123 spfx = 0;
|
|
|
124 levpuls = 0;
|
|
|
125 break;
|
|
|
126 case 4:
|
|
|
127 spfx = (struct Sspfx *)((char *)filedata + header->spfxptr);
|
|
|
128 levpuls = 0;
|
|
|
129 break;
|
|
|
130 }
|
|
|
131 if((str = strstr(datainfo,"\xff\xff")))
|
|
|
132 while((*str == '\xff' || *str == ' ') && str >= datainfo) {
|
|
|
133 *str = '\0'; str--;
|
|
|
134 }
|
|
|
135 else // old-style block
|
|
|
136 memset((char *)filedata+filesize,0,1);
|
|
|
137
|
|
|
138 rewind(0);
|
|
|
139 return true;
|
|
|
140 }
|
|
|
141
|
|
|
142 bool Cd00Player::update()
|
|
|
143 {
|
|
|
144 unsigned char c,cnt,trackend=0,fx,note;
|
|
|
145 unsigned short ord,*patt,buf,fxop;
|
|
|
146
|
|
|
147 // effect handling (timer dependant)
|
|
|
148 for(c=0;c<9;c++) {
|
|
|
149 channel[c].slideval += channel[c].slide; setfreq(c); // sliding
|
|
|
150 vibrato(c); // vibrato
|
|
|
151
|
|
|
152 if(channel[c].spfx != 0xffff) { // SpFX
|
|
|
153 if(channel[c].fxdel)
|
|
|
154 channel[c].fxdel--;
|
|
|
155 else {
|
|
|
156 channel[c].spfx = spfx[channel[c].spfx].ptr;
|
|
|
157 channel[c].fxdel = spfx[channel[c].spfx].duration;
|
|
|
158 channel[c].inst = spfx[channel[c].spfx].instnr & 0xfff;
|
|
|
159 if(spfx[channel[c].spfx].modlev != 0xff)
|
|
|
160 channel[c].modvol = spfx[channel[c].spfx].modlev;
|
|
|
161 setinst(c);
|
|
|
162 if(spfx[channel[c].spfx].instnr & 0x8000) // locked frequency
|
|
|
163 note = spfx[channel[c].spfx].halfnote;
|
|
|
164 else // unlocked frequency
|
|
|
165 note = spfx[channel[c].spfx].halfnote + channel[c].note;
|
|
|
166 channel[c].freq = notetable[note%12] + ((note/12) << 10);
|
|
|
167 setfreq(c);
|
|
|
168 }
|
|
|
169 channel[c].modvol += spfx[channel[c].spfx].modlevadd; channel[c].modvol &= 63;
|
|
|
170 setvolume(c);
|
|
|
171 }
|
|
|
172
|
|
|
173 if(channel[c].levpuls != 0xff) // Levelpuls
|
|
|
174 if(channel[c].frameskip)
|
|
|
175 channel[c].frameskip--;
|
|
|
176 else {
|
|
|
177 channel[c].frameskip = inst[channel[c].inst].timer;
|
|
|
178 if(channel[c].fxdel)
|
|
|
179 channel[c].fxdel--;
|
|
|
180 else {
|
|
|
181 channel[c].levpuls = levpuls[channel[c].levpuls].ptr - 1;
|
|
|
182 channel[c].fxdel = levpuls[channel[c].levpuls].duration;
|
|
|
183 if(levpuls[channel[c].levpuls].level != 0xff)
|
|
|
184 channel[c].modvol = levpuls[channel[c].levpuls].level;
|
|
|
185 }
|
|
|
186 channel[c].modvol += levpuls[channel[c].levpuls].voladd; channel[c].modvol &= 63;
|
|
|
187 setvolume(c);
|
|
|
188 }
|
|
|
189 }
|
|
|
190
|
|
|
191 // song handling
|
|
|
192 for(c=0;c<9;c++)
|
|
|
193 if(version < 3 ? channel[c].del : channel[c].del <= 0x7f) {
|
|
|
194 if(version == 4) // v4: hard restart SR
|
|
|
195 if(channel[c].del == inst[channel[c].inst].timer)
|
|
|
196 if(channel[c].nextnote)
|
|
|
197 opl->write(0x83 + op_table[c], inst[channel[c].inst].sr);
|
|
|
198 if(version < 3)
|
|
|
199 channel[c].del--;
|
|
|
200 else
|
|
|
201 if(channel[c].speed)
|
|
|
202 channel[c].del += channel[c].speed;
|
|
|
203 else {
|
|
|
204 channel[c].seqend = 1;
|
|
|
205 continue;
|
|
|
206 }
|
|
|
207 } else {
|
|
|
208 if(channel[c].speed) {
|
|
|
209 if(version < 3)
|
|
|
210 channel[c].del = channel[c].speed;
|
|
|
211 else {
|
|
|
212 channel[c].del &= 0x7f;
|
|
|
213 channel[c].del += channel[c].speed;
|
|
|
214 }
|
|
|
215 } else {
|
|
|
216 channel[c].seqend = 1;
|
|
|
217 continue;
|
|
|
218 }
|
|
|
219 if(channel[c].rhcnt) { // process pending REST/HOLD events
|
|
|
220 channel[c].rhcnt--;
|
|
|
221 continue;
|
|
|
222 }
|
|
|
223 readorder: // process arrangement (orderlist)
|
|
|
224 ord = channel[c].order[channel[c].ordpos];
|
|
|
225 switch(ord) {
|
|
|
226 case 0xfffe: channel[c].seqend = 1; continue; // end of arrangement stream
|
|
|
227 case 0xffff: // jump to order
|
|
|
228 channel[c].ordpos = channel[c].order[channel[c].ordpos+1];
|
|
|
229 channel[c].seqend = 1;
|
|
|
230 goto readorder;
|
|
|
231 default:
|
|
|
232 if(ord >= 0x9000) { // set speed
|
|
|
233 channel[c].speed = ord & 0xff;
|
|
|
234 ord = channel[c].order[channel[c].ordpos - 1];
|
|
|
235 channel[c].ordpos++;
|
|
|
236 } else
|
|
|
237 if(ord >= 0x8000) { // transpose track
|
|
|
238 channel[c].transpose = ord & 0xff;
|
|
|
239 if(ord & 0x100)
|
|
|
240 channel[c].transpose = -channel[c].transpose;
|
|
|
241 ord = channel[c].order[++channel[c].ordpos];
|
|
|
242 }
|
|
|
243 patt = (unsigned short *)((char *)filedata + seqptr[ord]);
|
|
|
244 break;
|
|
|
245 }
|
|
|
246 readseq: // process sequence (pattern)
|
|
|
247 if(!version) // v0: always initialize rhcnt
|
|
|
248 channel[c].rhcnt = channel[c].irhcnt;
|
|
|
249 if(patt[channel[c].pattpos] == 0xffff) { // pattern ended?
|
|
|
250 channel[c].pattpos = 0;
|
|
|
251 channel[c].ordpos++;
|
|
|
252 goto readorder;
|
|
|
253 }
|
|
|
254 cnt = HIBYTE(patt[channel[c].pattpos]);
|
|
|
255 note = LOBYTE(patt[channel[c].pattpos]);
|
|
|
256 fx = patt[channel[c].pattpos] >> 12;
|
|
|
257 fxop = patt[channel[c].pattpos] & 0x0fff;
|
|
|
258 channel[c].pattpos++;
|
|
|
259 channel[c].nextnote = LOBYTE(patt[channel[c].pattpos]) & 0x7f;
|
|
|
260 if(version ? cnt < 0x40 : !fx) { // note event
|
|
|
261 switch(note) {
|
|
|
262 case 0: // REST event
|
|
|
263 case 0x80:
|
|
|
264 if(!note || version) {
|
|
|
265 channel[c].key = 0;
|
|
|
266 setfreq(c);
|
|
|
267 }
|
|
|
268 // fall through...
|
|
|
269 case 0x7e: // HOLD event
|
|
|
270 if(version)
|
|
|
271 channel[c].rhcnt = cnt;
|
|
|
272 channel[c].nextnote = 0;
|
|
|
273 break;
|
|
|
274 default: // play note
|
|
|
275 channel[c].slideval = 0; channel[c].slide = 0; channel[c].vibdepth = 0; // restart fx
|
|
|
276
|
|
|
277 if(version) { // note handling for v1 and above
|
|
|
278 if(note > 0x80) // locked note (no channel transpose)
|
|
|
279 note -= 0x80;
|
|
|
280 else // unlocked note
|
|
|
281 note += channel[c].transpose;
|
|
|
282 channel[c].note = note; // remember note for SpFX
|
|
|
283
|
|
|
284 if(channel[c].ispfx != 0xffff && cnt < 0x20) { // reset SpFX
|
|
|
285 channel[c].spfx = channel[c].ispfx;
|
|
|
286 if(spfx[channel[c].spfx].instnr & 0x8000) // locked frequency
|
|
|
287 note = spfx[channel[c].spfx].halfnote;
|
|
|
288 else // unlocked frequency
|
|
|
289 note += spfx[channel[c].spfx].halfnote;
|
|
|
290 channel[c].inst = spfx[channel[c].spfx].instnr & 0xfff;
|
|
|
291 channel[c].fxdel = spfx[channel[c].spfx].duration;
|
|
|
292 if(spfx[channel[c].spfx].modlev != 0xff)
|
|
|
293 channel[c].modvol = spfx[channel[c].spfx].modlev;
|
|
|
294 else
|
|
|
295 channel[c].modvol = inst[channel[c].inst].data[7] & 63;
|
|
|
296 }
|
|
|
297
|
|
|
298 if(channel[c].ilevpuls != 0xff && cnt < 0x20) { // reset LevelPuls
|
|
|
299 channel[c].levpuls = channel[c].ilevpuls;
|
|
|
300 channel[c].fxdel = levpuls[channel[c].levpuls].duration;
|
|
|
301 channel[c].frameskip = inst[channel[c].inst].timer;
|
|
|
302 if(levpuls[channel[c].levpuls].level != 0xff)
|
|
|
303 channel[c].modvol = levpuls[channel[c].levpuls].level;
|
|
|
304 else
|
|
|
305 channel[c].modvol = inst[channel[c].inst].data[7] & 63;
|
|
|
306 }
|
|
|
307
|
|
|
308 channel[c].freq = notetable[note%12] + ((note/12) << 10);
|
|
|
309 if(cnt < 0x20) // normal note
|
|
|
310 playnote(c);
|
|
|
311 else { // tienote
|
|
|
312 setfreq(c);
|
|
|
313 cnt -= 0x20; // make count proper
|
|
|
314 }
|
|
|
315 channel[c].rhcnt = cnt;
|
|
|
316 } else { // note handling for v0
|
|
|
317 if(cnt < 2) // unlocked note
|
|
|
318 note += channel[c].transpose;
|
|
|
319 channel[c].note = note;
|
|
|
320
|
|
|
321 channel[c].freq = notetable[note%12] + ((note/12) << 10);
|
|
|
322 if(cnt == 1) // tienote
|
|
|
323 setfreq(c);
|
|
|
324 else // normal note
|
|
|
325 playnote(c);
|
|
|
326 }
|
|
|
327 break;
|
|
|
328 }
|
|
|
329 continue; // event is complete
|
|
|
330 } else { // effect event
|
|
|
331 switch(fx) {
|
|
|
332 case 6: // Cut/Stop Voice
|
|
|
333 buf = channel[c].inst;
|
|
|
334 channel[c].inst = 0;
|
|
|
335 playnote(c);
|
|
|
336 channel[c].inst = buf;
|
|
|
337 channel[c].rhcnt = fxop;
|
|
|
338 continue; // no note follows this event
|
|
|
339 case 7: // Vibrato
|
|
|
340 channel[c].vibspeed = fxop & 0xff;
|
|
|
341 channel[c].vibdepth = fxop >> 8;
|
|
|
342 channel[c].trigger = fxop >> 9;
|
|
|
343 break;
|
|
|
344 case 8: // v0: Duration
|
|
|
345 if(!version)
|
|
|
346 channel[c].irhcnt = fxop;
|
|
|
347 break;
|
|
|
348 case 9: // New Level
|
|
|
349 channel[c].vol = fxop & 63;
|
|
|
350 if(channel[c].vol + channel[c].cvol < 63) // apply channel volume
|
|
|
351 channel[c].vol += channel[c].cvol;
|
|
|
352 else
|
|
|
353 channel[c].vol = 63;
|
|
|
354 setvolume(c);
|
|
|
355 break;
|
|
|
356 case 0xb: // v4: Set SpFX
|
|
|
357 if(version == 4)
|
|
|
358 channel[c].ispfx = fxop;
|
|
|
359 break;
|
|
|
360 case 0xc: // Set Instrument
|
|
|
361 channel[c].ispfx = 0xffff;
|
|
|
362 channel[c].spfx = 0xffff;
|
|
|
363 channel[c].inst = fxop;
|
|
|
364 channel[c].modvol = inst[fxop].data[7] & 63;
|
|
|
365 if(version < 3 && version && inst[fxop].tunelev) // Set LevelPuls
|
|
|
366 channel[c].ilevpuls = inst[fxop].tunelev - 1;
|
|
|
367 else {
|
|
|
368 channel[c].ilevpuls = 0xff;
|
|
|
369 channel[c].levpuls = 0xff;
|
|
|
370 }
|
|
|
371 break;
|
|
|
372 case 0xd: // Slide up
|
|
|
373 channel[c].slide = fxop;
|
|
|
374 break;
|
|
|
375 case 0xe: // Slide down
|
|
|
376 channel[c].slide = -fxop;
|
|
|
377 break;
|
|
|
378 }
|
|
|
379 goto readseq; // event is incomplete, note follows
|
|
|
380 }
|
|
|
381 }
|
|
|
382
|
|
|
383 for(c=0;c<9;c++)
|
|
|
384 if(channel[c].seqend)
|
|
|
385 trackend++;
|
|
|
386 if(trackend == 9)
|
|
|
387 songend = 1;
|
|
|
388
|
|
|
389 return !songend;
|
|
|
390 }
|
|
|
391
|
|
|
392 void Cd00Player::rewind(int subsong)
|
|
|
393 {
|
|
|
394 struct Stpoin {
|
|
|
395 unsigned short ptr[9];
|
|
|
396 unsigned char volume[9],dummy[5];
|
|
|
397 } *tpoin;
|
|
|
398 int i;
|
|
|
399
|
|
|
400 if(version > 1) { // do nothing if subsong > number of subsongs
|
|
|
401 if(subsong >= header->subsongs)
|
|
|
402 return;
|
|
|
403 } else
|
|
|
404 if(subsong >= header1->subsongs)
|
|
|
405 return;
|
|
|
406
|
|
|
407 memset(channel,0,sizeof(channel));
|
|
|
408 if(version > 1)
|
|
|
409 tpoin = (struct Stpoin *)((char *)filedata + header->tpoin);
|
|
|
410 else
|
|
|
411 tpoin = (struct Stpoin *)((char *)filedata + header1->tpoin);
|
|
|
412 for(i=0;i<9;i++) {
|
|
|
413 if(tpoin[subsong].ptr[i]) { // track enabled
|
|
|
414 channel[i].speed = *((unsigned short *)((char *)filedata + tpoin[subsong].ptr[i]));
|
|
|
415 channel[i].order = (unsigned short *)((char *)filedata + tpoin[subsong].ptr[i] + 2);
|
|
|
416 } else { // track disabled
|
|
|
417 channel[i].speed = 0;
|
|
|
418 channel[i].order = 0;
|
|
|
419 }
|
|
|
420 channel[i].ispfx = 0xffff; channel[i].spfx = 0xffff; // no SpFX
|
|
|
421 channel[i].ilevpuls = 0xff; channel[i].levpuls = 0xff; // no LevelPuls
|
|
|
422 channel[i].cvol = tpoin[subsong].volume[i] & 0x7f; // our player may savely ignore bit 7
|
|
|
423 channel[i].vol = channel[i].cvol; // initialize volume
|
|
|
424 }
|
|
|
425 songend = 0;
|
|
|
426 opl->init(); opl->write(1,32); // reset OPL chip
|
|
|
427 }
|
|
|
428
|
|
|
429 std::string Cd00Player::gettype()
|
|
|
430 {
|
|
|
431 char tmpstr[40];
|
|
|
432
|
|
|
433 sprintf(tmpstr,"EdLib packed (version %d)",version > 1 ? header->version : header1->version);
|
|
|
434 return std::string(tmpstr);
|
|
|
435 }
|
|
|
436
|
|
|
437 float Cd00Player::getrefresh()
|
|
|
438 {
|
|
|
439 if(version > 1)
|
|
|
440 return header->speed;
|
|
|
441 else
|
|
|
442 return header1->speed;
|
|
|
443 }
|
|
|
444
|
|
|
445 unsigned int Cd00Player::getsubsongs()
|
|
|
446 {
|
|
|
447 if(version <= 1) // return number of subsongs
|
|
|
448 return header1->subsongs;
|
|
|
449 else
|
|
|
450 return header->subsongs;
|
|
|
451 }
|
|
|
452
|
|
|
453 /*** private methods *************************************/
|
|
|
454
|
|
|
455 void Cd00Player::setvolume(unsigned char chan)
|
|
|
456 {
|
|
|
457 unsigned char op = op_table[chan];
|
|
|
458 unsigned short insnr = channel[chan].inst;
|
|
|
459
|
|
|
460 opl->write(0x43 + op,(int)(63-((63-(inst[insnr].data[2] & 63))/63.0)*(63-channel[chan].vol)) +
|
|
|
461 (inst[insnr].data[2] & 192));
|
|
|
462 if(inst[insnr].data[10] & 1)
|
|
|
463 opl->write(0x40 + op,(int)(63-((63-channel[chan].modvol)/63.0)*(63-channel[chan].vol)) +
|
|
|
464 (inst[insnr].data[7] & 192));
|
|
|
465 else
|
|
|
466 opl->write(0x40 + op,channel[chan].modvol + (inst[insnr].data[7] & 192));
|
|
|
467 }
|
|
|
468
|
|
|
469 void Cd00Player::setfreq(unsigned char chan)
|
|
|
470 {
|
|
|
471 unsigned short freq = channel[chan].freq;
|
|
|
472
|
|
|
473 if(version == 4) // v4: apply instrument finetune
|
|
|
474 freq += inst[channel[chan].inst].tunelev;
|
|
|
475
|
|
|
476 freq += channel[chan].slideval;
|
|
|
477 opl->write(0xa0 + chan, freq & 255);
|
|
|
478 if(channel[chan].key)
|
|
|
479 opl->write(0xb0 + chan, ((freq >> 8) & 31) | 32);
|
|
|
480 else
|
|
|
481 opl->write(0xb0 + chan, (freq >> 8) & 31);
|
|
|
482 }
|
|
|
483
|
|
|
484 void Cd00Player::setinst(unsigned char chan)
|
|
|
485 {
|
|
|
486 unsigned char op = op_table[chan];
|
|
|
487 unsigned short insnr = channel[chan].inst;
|
|
|
488
|
|
|
489 // set instrument data
|
|
|
490 opl->write(0x63 + op, inst[insnr].data[0]);
|
|
|
491 opl->write(0x83 + op, inst[insnr].data[1]);
|
|
|
492 opl->write(0x23 + op, inst[insnr].data[3]);
|
|
|
493 opl->write(0xe3 + op, inst[insnr].data[4]);
|
|
|
494 opl->write(0x60 + op, inst[insnr].data[5]);
|
|
|
495 opl->write(0x80 + op, inst[insnr].data[6]);
|
|
|
496 opl->write(0x20 + op, inst[insnr].data[8]);
|
|
|
497 opl->write(0xe0 + op, inst[insnr].data[9]);
|
|
|
498 if(version)
|
|
|
499 opl->write(0xc0 + chan, inst[insnr].data[10]);
|
|
|
500 else
|
|
|
501 opl->write(0xc0 + chan, (inst[insnr].data[10] << 1) + (inst[insnr].tunelev & 1));
|
|
|
502 }
|
|
|
503
|
|
|
504 void Cd00Player::playnote(unsigned char chan)
|
|
|
505 {
|
|
|
506 // set misc vars & play
|
|
|
507 opl->write(0xb0 + chan, 0); // stop old note
|
|
|
508 setinst(chan);
|
|
|
509 channel[chan].key = 1;
|
|
|
510 setfreq(chan);
|
|
|
511 setvolume(chan);
|
|
|
512 }
|
|
|
513
|
|
|
514 void Cd00Player::vibrato(unsigned char chan)
|
|
|
515 {
|
|
|
516 if(!channel[chan].vibdepth)
|
|
|
517 return;
|
|
|
518
|
|
|
519 if(channel[chan].trigger)
|
|
|
520 channel[chan].trigger--;
|
|
|
521 else {
|
|
|
522 channel[chan].trigger = channel[chan].vibdepth;
|
|
|
523 channel[chan].vibspeed = -channel[chan].vibspeed;
|
|
|
524 }
|
|
|
525 channel[chan].freq += channel[chan].vibspeed;
|
|
|
526 setfreq(chan);
|
|
|
527 }
|