-
Notifications
You must be signed in to change notification settings - Fork 0
/
xsfx.c
69 lines (65 loc) · 1.34 KB
/
xsfx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char **argv)
{
unsigned char buffer[8];
char *bigbuf;
FILE *fp, *in;
unsigned char path[16];
int i=0;
unsigned long l;
unsigned long off=0;
if (argc != 2)
{
printf ("Must specify input file\n");
return 1;
}
in = fopen (argv[1], "rb");
if (!in)
{
printf ("Couldn't open %s\n", argv[1]);
return 1;
}
while (!feof (in))
{
if (fread (buffer, 8, 1, in) != 1)
{
printf ("Couldn't read 8 bytes\n");
return 1;
}
if (strncmp (buffer, "RIFF", 4))
{
printf ("End of wave data. Finished.\n");
return 0;
}
l = (unsigned long) buffer[4];
l+= ((unsigned long)buffer[5])<<8;
l+= ((unsigned long)buffer[6])<<16;
l+= ((unsigned long)buffer[7])<<24;
bigbuf = malloc (l);
if (!bigbuf)
{
printf ("Out of memory\n");
return 1;
}
sprintf (path, "fx%d.wav", i);
printf ("%s : %ld bytes\n", path, l);
i++;
fp = fopen (path, "wb");
if (!fp)
{
printf ("Can't open output file %s\n", path);
return 1;
}
fread (bigbuf, l, 1, in);
fwrite (buffer, 8, 1, fp);
fwrite (bigbuf, l, 1, fp);
fclose (fp);
l+=8;
off+=(l+16)&0xfffffff0;
fread (bigbuf, 16-(l&15), 1, in);
free (bigbuf);
}
return 0;
}