aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-08-23 15:47:08 -0700
committerRob Landley <rob@landley.net>2018-09-15 00:07:58 -0500
commitd6c5f558eb822571472af0f2db38d6be853c06fd (patch)
tree2d412b23ec4c38003a1474e93a6759bd8a399fb6
parentd20a11f236b57fe515ce4dbb37e0300d7ba179b5 (diff)
downloadtoybox-d6c5f558eb822571472af0f2db38d6be853c06fd.tar.gz
Add .wav support to file(1).
-rw-r--r--toys/posix/file.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/toys/posix/file.c b/toys/posix/file.c
index 333869cd..552cd03f 100644
--- a/toys/posix/file.c
+++ b/toys/posix/file.c
@@ -317,6 +317,33 @@ static void do_regular_file(int fd, char *name)
if (!memcmp(s+28, "\x01vorbis", 7)) xprintf(", vorbis audio");
if (!memcmp(s+28, "YUV4MPEG", 8)) xprintf(", yuv4mpeg video");
xputc('\n');
+ } else if (len>32 && !memcmp(s, "RIF", 3) && !memcmp(s+8, "WAVEfmt ", 8)) {
+ // https://en.wikipedia.org/wiki/WAV
+ int le = (s[3] == 'F');
+ int format = le ? peek_le(s+20,2) : peek_be(s+20,2);
+ int channels = le ? peek_le(s+22,2) : peek_be(s+22,2);
+ int hz = le ? peek_le(s+24,4) : peek_be(s+24,4);
+ int bits = le ? peek_le(s+34,2) : peek_be(s+34,2);
+
+ xprintf("WAV audio, %s, ", le ? "LE" : "BE");
+ if (bits != 0) xprintf("%d-bit, ", bits);
+ if (channels==1||channels==2) xprintf("%s, ", channels==1?"mono":"stereo");
+ else xprintf("%d-channel, ", channels);
+ xprintf("%d Hz, ", hz);
+ // See https://tools.ietf.org/html/rfc2361, though there appear to be bugs
+ // in the RFC. This assumes wikipedia's example files are more correct.
+ if (format == 0x01) xprintf("PCM");
+ else if (format == 0x03) xprintf("IEEE float");
+ else if (format == 0x06) xprintf("A-law");
+ else if (format == 0x07) xprintf("ยต-law");
+ else if (format == 0x11) xprintf("ADPCM");
+ else if (format == 0x22) xprintf("Truespeech");
+ else if (format == 0x31) xprintf("GSM");
+ else if (format == 0x55) xprintf("MP3");
+ else if (format == 0x70) xprintf("CELP");
+ else if (format == 0xfffe) xprintf("extensible");
+ else xprintf("unknown format %d", format);
+ xputc('\n');
} else if (len>12 && !memcmp(s, "\x00\x01\x00\x00", 4)) {
xputs("TrueType font");
} else if (len>12 && !memcmp(s, "ttcf\x00", 5)) {