ref: a1a120547768ee33ddaae4ee1965dfcf85149d8a
parent: 523955c36466dac64e8ec19068333408ba4a00c7
author: qwx <[email protected]>
date: Tue Aug 8 19:45:59 EDT 2023
add games/dmx: decode doom sound effect lumps (dss*)
--- a/sys/man/1/mus
+++ b/sys/man/1/mus
@@ -1,23 +1,40 @@
.TH MUS 1
.SH NAME
-mus \- MUS to MIDI converter
+mus, dmx \- MUS to MIDI converter and DMX decoder
.SH SYNOPSIS
.B games/mus
[
.I musfile
]
+.br
+.B games/dmx
+[
+.I dmxfile
+]
.SH DESCRIPTION
The MUS format is a simplified MIDI music format used in doom
and several related games.
+DMX format is used for doom's sound effects.
.PP
.I Mus
decodes MIDI music encoded in MUS format, either from
.B musfile
or from standard input, and produces a MIDI format file on standard output.
+.PP
+.I Dmx
+similarly transcodes its input into PCM on standard output at
+.IR audio (3)'s
+default 44.1 kHz sampling rate.
.SH "SEE ALSO"
-.IR games (1)
+.IR games (1),
+.IR wadfs (4)
.SH SOURCE
.B /sys/src/games/mus.c
+.br
+.B /sys/src/games/dmx.c
.SH HISTORY
.I Mus
-first appeared in 9front (September, 2015).
+and
+.I dmx
+first appeared in 9front (respectively
+in September, 2015 and August, 2023).
--- /dev/null
+++ b/sys/src/games/dmx.c
@@ -1,0 +1,33 @@
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+
+enum{
+ Hdrsz = 2+2+4+16,
+};
+
+void
+main(int argc, char **argv)
+{
+ int n, rate, fd;
+ uchar buf[Hdrsz], *p;
+ char fmt[16], len[16];
+
+ fd = 0;
+ if(argc > 1 && (fd = open(argv[1], OREAD)) < 0)
+ sysfatal("open: %r");
+ if(read(fd, buf, sizeof buf) != sizeof buf)
+ sysfatal("short read: %r");
+ p = buf;
+ n = GBIT16(p);
+ if(n != 3) /* format number */
+ sysfatal("invalid dmx file");
+ p += 2;
+ rate = GBIT16(p); /* sample rate (usually 11025Hz) */
+ p += 2;
+ n = GBIT32(p);
+ snprint(fmt, sizeof fmt, "u8c1r%d", rate);
+ snprint(len, sizeof len, "%d", n);
+ execl("/bin/audio/pcmconv", "pcmconv", "-i", fmt, "-o", "s16c2r44100", "-l", len, nil);
+ sysfatal("execl: %r");
+}
--- a/sys/src/games/mkfile
+++ b/sys/src/games/mkfile
@@ -5,6 +5,7 @@
ana\
aout2gba\
catclock\
+ dmx\
festoon\
geigerstats\
juggle\