egra: optimised SSE memfill and colorblend
[iv.d.git] / opl3test / imfplay.d
blob42c5a6925c5d4c8e6be174d67536127cf7d98918
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.
5 //
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.
10 import iv.cmdcon;
11 import iv.vfs;
13 import iv.nukedopl3;
14 import xalsa;
17 __gshared OPL3Chip opl;
18 __gshared short[4096] smpbuf;
19 __gshared uint smpbufpos;
22 void playbuf () {
23 if (smpbufpos == 0) return;
24 foreach (ref short v; smpbuf[0..smpbufpos]) {
25 int n = v*4;
26 if (n < short.min) n = short.min;
27 if (n > short.max) n = short.max;
28 v = cast(short)n;
30 alsaWriteX(smpbuf.ptr, smpbufpos/2);
31 smpbufpos = 0;
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;
39 if (flen == 0) {
40 flen = cast(uint)fl.size;
41 fl.seek(0);
43 opl.reset(48000);
44 alsaOpen(2);
45 scope(exit) alsaClose();
46 uint samplesLeft = 0;
47 mainloop: for (;;) {
48 while (samplesLeft == 0) {
49 if (flen < 4) break mainloop;
50 flen -= 4;
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; }
58 --samplesLeft;
59 opl.generateStream(smpbuf[smpbufpos..smpbufpos+2]);
60 smpbufpos += 2;
61 if (smpbufpos >= smpbuf.length) playbuf();
63 playbuf();