This is asciitosnd.c in view mode; [Download] [Up]
/*
* asciitosnd.c
* Convert an ascii integer file to a 16-bit linear soundfile.
* Creates a mono file with sampling rate SND_RATE_CODEC!!!!!!!.
*/
#import <stdio.h>
#import <sound/sound.h>
#import <architecture/byte_order.h>
void main (int argc, char *argv[])
{
SNDSoundStruct s;
FILE *afp, *sfp;
short sample;
if (argc != 3) {
fprintf(stderr,
"%s - convert an ascii integer file to a 16-bit linear soundfile.\n",
argv[0]);
fprintf(stderr, "Usage: asciitosnd ascii-file soundfile\n");
exit(1);
}
if ((afp = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "Cannot open ascii file: %s\n", argv[1]);
exit(1);
}
if ((sfp = fopen(argv[2], "w+")) == NULL) {
fprintf(stderr, "Cannot open soundfile: %s\n", argv[2]);
exit(1);
}
s.magic = NXSwapHostIntToBig(SND_MAGIC);
s.dataLocation = NXSwapHostIntToBig(sizeof(SNDSoundStruct));
s.dataSize = 0;
s.dataFormat = NXSwapHostIntToBig(SND_FORMAT_LINEAR_16);
s.samplingRate = NXSwapHostIntToBig((int)SND_RATE_CODEC);
s.channelCount = NXSwapHostIntToBig(1);
*(int *)s.info = 0;
fwrite((void *)&s, sizeof(SNDSoundStruct), 1, sfp);
while (!feof(afp)) {
fscanf(afp, "%hd ", &sample);
sample = NXSwapHostShortToBig(sample);
fwrite((void *)&sample, sizeof(short), 1, sfp);
s.dataSize += sizeof(short);
}
s.dataSize = NXSwapHostIntToBig(s.dataSize);
rewind(sfp);
fwrite((void *)&s, sizeof(SNDSoundStruct), 1, sfp);
fclose(afp);
fclose(sfp);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.