]> git.lizzy.rs Git - plan9front.git/blob - sys/src/games/opl3/opl3m.c
devcons: fix permissions for reboot and sysstat
[plan9front.git] / sys / src / games / opl3 / opl3m.c
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4
5 void    opl3out(uchar *, int);
6 void    opl3wr(int, int);
7 void    opl3init(int);
8
9 enum{
10         Rate = 44100,
11 };
12
13 void
14 usage(void)
15 {
16         fprint(2, "usage: %s [-n nsamp] [file]\n", argv0);
17         exits("usage");
18 }
19
20 void
21 main(int argc, char **argv)
22 {
23         int r, v, dt, nsamp, fd;
24         uchar *sb, u[5];
25         Biobuf *bi, *bo;
26
27         fd = 0;
28         nsamp = 1;
29         ARGBEGIN{
30         case 'n':
31                 nsamp = Rate / atoi(EARGF(usage()));
32                 break;
33         default:
34                 usage();
35         }ARGEND;
36         if(*argv != nil)
37                 if((fd = open(*argv, OREAD)) < 0)
38                         sysfatal("open: %r");
39         bi = Bfdopen(fd, OREAD);
40         bo = Bfdopen(1, OWRITE);
41         if(bi == nil || bo == nil)
42                 sysfatal("Bfdopen: %r");
43         nsamp *= 4;
44         if((sb = malloc(nsamp)) == nil)
45                 sysfatal("malloc: %r");
46         opl3init(Rate);
47         while(Bread(bi, u, sizeof u) > 0){
48                 r = u[1] << 8 | u[0];
49                 v = u[2];
50                 dt = u[4] << 8 | u[3];
51                 opl3wr(r, v);
52                 while(dt-- > 0){
53                         opl3out(sb, nsamp);
54                         Bwrite(bo, sb, nsamp);
55                 }
56         }
57 }