Move generic usernames to sysconf
[aNetHack.git] / sys / amiga / cvtsnd.c
blob2e16b764525357cfa07f6660032a408f013b22b7
1 /* NetHack 3.6 cvtsnd.c $NHDT-Date: 1432512794 2015/05/25 00:13:14 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
2 /* Copyright (c) 1995, Andrew Church, Olney, Maryland */
3 /* NetHack may be freely redistributed. See license for details. */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
9 typedef struct {
10 short namelen;
11 char name[62];
12 char misc[64]; /* rest of MacBinary header */
13 long FORM;
14 long flen;
15 long AIFF;
16 long SSND;
17 long sndlen;
18 } AIFF;
20 typedef struct {
21 char FORM[4];
22 long flen;
23 char _8SVX[4];
24 char VHDR[4];
25 long vhlen;
26 long oneshot, repeat;
27 long samples; /* 'samplesPerHiCycle' in the docs - usually 32, so
28 * we'll use that */
29 short freq;
30 char octaves, compress;
31 long volume;
32 char NAME[4];
33 long nlen; /* should be 64; see name[] comment */
34 char name[64]; /* for simplicity, i.e. just fwrite() entiree header */
35 char BODY[4];
36 long blen;
37 } IFF;
39 main(int ac, char **av)
41 FILE *in, *out;
42 AIFF aiff;
43 IFF iff;
44 static char buf[16384];
45 long n, len;
47 if (ac != 3) {
48 fprintf(stderr, "Usage: %s input-file output-file\n", av[0]);
49 exit(20);
51 if (!(in = fopen(av[1], "r"))) {
52 fprintf(stderr, "Can't open input file\n");
53 exit(20);
55 if (!(out = fopen(av[2], "w"))) {
56 fprintf(stderr, "Can't open output file\n");
57 exit(20);
60 fread(&aiff, sizeof(aiff), 1, in);
61 memcpy(iff.FORM, "FORM", 4);
62 iff.flen = sizeof(iff) + aiff.sndlen - 8;
63 memcpy(iff._8SVX, "8SVX", 4);
64 memcpy(iff.VHDR, "VHDR", 4);
65 iff.vhlen = 20;
66 iff.oneshot = aiff.sndlen;
67 iff.repeat = 0;
68 iff.samples = 32;
69 iff.freq = 22000;
70 iff.octaves = 1;
71 iff.compress = 0;
72 iff.volume = 0x10000;
73 memcpy(iff.NAME, "NAME", 4);
74 iff.nlen = 64;
75 strncpy(iff.name, aiff.name, 62);
76 iff.name[aiff.namelen] = 0;
77 memcpy(iff.BODY, "BODY", 4);
78 iff.blen = aiff.sndlen;
79 fwrite(&iff, sizeof(iff), 1, out);
80 len = aiff.sndlen;
81 do {
82 if (len >= sizeof(buf))
83 n = fread(buf, 1, sizeof(buf), in);
84 else
85 n = fread(buf, 1, len, in);
86 if (n) {
87 fwrite(buf, 1, n, out);
88 len -= n;
90 } while (len && n);
92 if (len)
93 fprintf(stderr, "Warning: %ld bytes of sample missing\n", len);
94 fclose(in);
95 fclose(out);
96 exit(0);