1 // This program is free software; you can redistribute it and/or
2 // modify it under the terms of the GNU General Public License
3 // as published by the Free Software Foundation; either version 2
4 // of the License, or (at your option) any later version.
6 // This program is distributed in the hope that it will be useful,
7 // but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // GNU General Public License for more details.
17 __gshared OPL3Chip opl
;
18 __gshared
short[4096] smpbuf
;
19 __gshared
uint smpbufpos
;
23 if (smpbufpos
== 0) return;
24 foreach (ref short v
; smpbuf
[0..smpbufpos
]) {
26 if (n
< short.min
) n
= short.min
;
27 if (n
> short.max
) n
= short.max
;
30 alsaWriteX(smpbuf
.ptr
, smpbufpos
/2);
35 void main (string
[] args
) {
36 if (args
.length
< 2) assert(0, "file?");
37 auto fl
= VFile(args
[1]);
38 uint flen
= fl
.readNum
!ushort;
40 flen
= cast(uint)fl
.size
;
45 scope(exit
) alsaClose();
48 while (samplesLeft
== 0) {
49 if (flen
< 4) break mainloop
;
51 ubyte reg
= fl
.readNum
!ubyte;
52 ubyte val
= fl
.readNum
!ubyte;
53 samplesLeft
= fl
.readNum
!ushort;
54 //conwritefln!"reg=0x%02x; val=0x%02x; delay=%s (%s)"(reg, val, samplesLeft, samplesLeft*48000/560);
55 opl
.writeReg(reg
, val
);
56 if (samplesLeft
) { samplesLeft
= samplesLeft
*48000/560; break; }
59 opl
.generateStream(smpbuf
[smpbufpos
..smpbufpos
+2]);
61 if (smpbufpos
>= smpbuf
.length
) playbuf();