ftp.nice.ch/pub/next/unix/audio/sndutil.1.3.s.tar.gz#/sndutil-1.3/sndtools/sndtohex.c

This is sndtohex.c in view mode; [Download] [Up]

/*
 * sndtohex.c
 *	Convert a 16-bit linear soundfile to ascii integer.
 */
#import <stdio.h>
#import <sound/sound.h>
#import <architecture/byte_order.h>

void main (int argc, char *argv[])
{
    int err, i, sampleCount;
    SNDSoundStruct *s;
    FILE *fp;
    short *data;

    if (argc != 3) {
	fprintf(stderr,
		"%s - convert a 16-bit linear soundfile to ascii hexadecimal integer.\n",
		argv[0]);
	fprintf(stderr, "Usage: sndtohex soundfile ascii-file\n");
	exit(1);
    }
    err = SNDReadSoundfile(argv[1], &s);
    if (err) {
	fprintf(stderr, "Cannot read soundfile: %s\n", argv[1]);
	exit(1);
    }
    if ((fp = fopen(argv[2], "w")) == NULL) {
	fprintf(stderr, "Cannot open ascii file: %s\n", argv[2]);
	exit(1);
    }
    if (s->dataFormat != SND_FORMAT_LINEAR_16) {
	fprintf(stderr, "*** WARNING: Soundfile is not 16 bit linear\n"
		"\tNo decoding is done by this program.\n");
    }
    sampleCount = s->dataSize / sizeof(short);	/* channel independent */
    data = (short *) ((char *)s + s->dataLocation);

    for (i = 0; i < sampleCount; i++)
      fprintf(fp, "0x%04hx\n", (signed short) NXSwapBigShortToHost(data[i]));
    fclose(fp);
}



These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.