]> git.lizzy.rs Git - plan9front.git/commitdiff
games/opl3: don't buffer output and simplify (thanks umbraticus)
authorqwx <devnull@localhost>
Tue, 27 Apr 2021 07:48:14 +0000 (09:48 +0200)
committerqwx <devnull@localhost>
Tue, 27 Apr 2021 07:48:14 +0000 (09:48 +0200)
this fixes real-time applications.

-n previously specified a rate divisor rather than the rate itself,
which was used for specific applications outside of 9front.  instead,
just set the rate directly, more useful and straightforward.

sys/man/1/opl3
sys/src/games/opl3/opl3m.c

index efb16d9b057ea33dad8e3a1709f04efd40bdd8fb..0d2087399ec439455337a6e0a526c77509e535ad 100644 (file)
@@ -4,7 +4,7 @@ opl3 \- OPL3 chip emulator
 .SH SYNOPSIS
 .B opl3
 [
-.B -n
+.B -r
 .I rate
 ] [
 .I file
@@ -44,7 +44,7 @@ It is a multiple of a command period, during which the
 chip may be sampled before processing the next command.
 The period itself is the inverse of the command rate, 44100 Hz by default.
 This rate can be set using the
-.B -n
+.B -r
 parameter.
 .SH SOURCE
 .B /sys/src/games/opl3
index ef3dd66726e291702fe3cf71090e3ab051cd8ab6..3d74e9e656f02d644d41e965b6ae89824548ce0e 100644 (file)
@@ -6,29 +6,25 @@ void  opl3out(uchar *, int);
 void   opl3wr(int, int);
 void   opl3init(int);
 
-enum{
-       Rate = 44100,
-};
-
 void
 usage(void)
 {
-       fprint(2, "usage: %s [-n nsamp] [file]\n", argv0);
+       fprint(2, "usage: %s [-r rate] [file]\n", argv0);
        exits("usage");
 }
 
 void
 main(int argc, char **argv)
 {
-       int r, v, dt, nsamp, fd;
-       uchar *sb, u[5];
-       Biobuf *bi, *bo;
+       int rate, r, v, dt, fd;
+       uchar sb[65536 * 4], u[5];
+       Biobuf *bi;
 
        fd = 0;
-       nsamp = 1;
+       rate = 44100;
        ARGBEGIN{
-       case 'n':
-               nsamp = Rate / atoi(EARGF(usage()));
+       case 'r':
+               rate = atoi(EARGF(usage()));
                break;
        default:
                usage();
@@ -37,21 +33,16 @@ main(int argc, char **argv)
                if((fd = open(*argv, OREAD)) < 0)
                        sysfatal("open: %r");
        bi = Bfdopen(fd, OREAD);
-       bo = Bfdopen(1, OWRITE);
-       if(bi == nil || bo == nil)
+       if(bi == nil)
                sysfatal("Bfdopen: %r");
-       nsamp *= 4;
-       if((sb = malloc(nsamp)) == nil)
-               sysfatal("malloc: %r");
-       opl3init(Rate);
+       opl3init(rate);
        while(Bread(bi, u, sizeof u) > 0){
                r = u[1] << 8 | u[0];
                v = u[2];
-               dt = u[4] << 8 | u[3];
                opl3wr(r, v);
-               while(dt-- > 0){
-                       opl3out(sb, nsamp);
-                       Bwrite(bo, sb, nsamp);
+               if(dt = (u[4] << 8 | u[3]) * 4){        /* 16-bit stereo */
+                       opl3out(sb, dt);
+                       write(1, sb, dt);
                }
        }
 }