home *** CD-ROM | disk | FTP | other *** search
- /*
- convert - by Robert Hood
-
- this program converts some type of mac sound files to NeXT sound files
- Don't flame me about the code. It wasn't written to be nice to users,
- or be a piece of art.
- */
-
- #include <stdio.h>
-
- main (argc, argv)
- int argc;
- char *argv [];
- {
- FILE *input, *output;
- char filename [256], outname [256];
- int temp,last;
- char temp2;
- int fast = 0; /* 11 kHz sample rate */
- unsigned char ch;
-
- if (argc <= 1)
- {
- fprintf (stderr, "Usage: convert [-22] filename\n\n");
- exit (-1);
- }
-
- filename [0] = 0;
-
- for (temp = 1; temp < argc; ++temp)
- {
- if (strcmp ("-22", argv [temp]) == 0)
- {
- fast = 1; /* 22 kHz sample rate */
- }
- else
- {
- strcpy (filename, argv [temp]);
- }
- }
- if (filename [0] == 0)
- {
- fprintf (stderr, "You didn't specifiy a filename\n");
- exit (-1);
- }
- if ((input = fopen (filename, "rb")) == 0)
- {
- perror (filename);
- exit (-1);
- }
- strcpy (outname, filename);
- strcat (outname, ".snd");
- if ((output = fopen (outname, "wb")) == 0)
- {
- perror (outname);
- exit (-1);
- }
- temp = 0x2E736E64; /* magic */
- fwrite (&temp, 4, 1, output);
- temp = 0x0000001C; /* start of sound */
- fwrite (&temp, 4, 1, output);
- temp = 0x98 + 1; /* end of sound...doesn't seem to matter */
- fwrite (&temp, 4, 1, output);
- temp = 0x00000003; /* ?? */
- fwrite (&temp, 4, 1, output);
- temp = 0x00005622; /* sample frequency */
- fwrite (&temp, 4, 1, output);
- temp = 0x00000001; /* ?? */
- fwrite (&temp, 4, 1, output);
- temp = 0x00000000; /* space filler? */
- fwrite (&temp, 4, 1, output);
- temp = 0x00000000; /* space filler? */
- fwrite (&temp, 4, 1, output);
-
- last = 0;
- while (!feof (input))
- {
- ch = getc (input);
-
- temp = ch;
- temp = (128 - temp) * (int)64;
-
- if (!fast) /* 11 kHz is simulated by averaging the input */
- {
- last = (last + temp) / 2;
- putc ((last >> 8) & 0xFF, output);
- putc ((last) & 0xFF, output);
- last = temp;
- }
- putc ((temp >> 8) & 0xFF, output);
- putc ((temp) & 0xFF, output);
- }
- fclose (input);
- fclose (output);
- }
-
-