--- audiofile/sfcommands/sfconvert.c.orig 2004-04-04 23:39:56.000000000 -0700 +++ audiofile/sfcommands/sfconvert.c 2004-04-05 00:00:25.000000000 -0700 @@ -66,12 +66,14 @@ AFfilehandle infile, outfile; AFfilesetup outfilesetup; - int sampleFormat, sampleWidth, channelCount; - double sampleRate; + int sampleFormat, sampleWidth, channelCount, byteOrder; + double sampleRate, outSampleRate; + int outSampleRateInt = -1; int outSampleFormat = -1, outSampleWidth = -1, - outChannelCount = -1; + outChannelCount = -1, outByteOrder = -1; double outMaxAmp = 1.0; + AFframecount totalFrames; if (argc < 3) @@ -88,7 +90,10 @@ { if (i + 1 >= argc) usageerror(); - if (!strcmp(argv[i+1], "aiff")) + + if (!strcmp(argv[i+1], "raw")) + outFileFormat = AF_FILE_RAWDATA; + else if (!strcmp(argv[i+1], "aiff")) outFileFormat = AF_FILE_AIFF; else if (!strcmp(argv[i+1], "aifc")) outFileFormat = AF_FILE_AIFFC; @@ -98,6 +103,12 @@ outFileFormat = AF_FILE_NEXTSND; else if (!strcmp(argv[i+1], "bics")) outFileFormat = AF_FILE_BICSF; + else if (!strcmp(argv[i+1], "avr")) + outFileFormat = AF_FILE_AVR; + else if (!strcmp(argv[i+1], "iff")) + outFileFormat = AF_FILE_IFF_8SVX; + else if (!strcmp(argv[i+1], "nist")) + outFileFormat = AF_FILE_NIST_SPHERE; else { fprintf(stderr, "sfconvert: Unknown format %s.\n", argv[i+1]); @@ -107,6 +118,22 @@ /* Increment for argument. */ i++; } + else if (!strcmp(argv[i], "byteorder")) + { + if (i + 1 >= argc) + usageerror(); + + if(!strcmp("big", argv[i+1])) { + outByteOrder = AF_BYTEORDER_BIGENDIAN; + } else if(!strcmp("little", argv[i+1])) { + outByteOrder = AF_BYTEORDER_LITTLEENDIAN; + } else { + usageerror(); + } + + /* Increment for argument. */ + i++; + } else if (!strcmp(argv[i], "channels")) { if (i + 1 >= argc) @@ -119,6 +146,20 @@ /* Increment for argument. */ i++; } + else if (!strcmp(argv[i], "rate")) + { + if (i + 1 >= argc) + usageerror(); + + outSampleRateInt = atoi(argv[i+1]); + if (outSampleRateInt <= 0) + usageerror(); + + outSampleRate = (double)outSampleRateInt; + + /* Increment for argument. */ + i++; + } else if (!strcmp(argv[i], "float")) { if (i + 1 >= argc) @@ -170,6 +211,7 @@ totalFrames = afGetFrameCount(infile, AF_DEFAULT_TRACK); channelCount = afGetChannels(infile, AF_DEFAULT_TRACK); sampleRate = afGetRate(infile, AF_DEFAULT_TRACK); + byteOrder = afGetByteOrder(infile, AF_DEFAULT_TRACK); afGetSampleFormat(infile, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth); /* Initialize output audio format parameters. */ @@ -184,14 +226,21 @@ outSampleWidth = sampleWidth; } + if (outByteOrder == -1) + outByteOrder = byteOrder; + if (outChannelCount == -1) outChannelCount = channelCount; + if (outSampleRateInt == -1) + outSampleRate = sampleRate; + afInitFileFormat(outfilesetup, outFileFormat); afInitSampleFormat(outfilesetup, AF_DEFAULT_TRACK, outSampleFormat, outSampleWidth); afInitChannels(outfilesetup, AF_DEFAULT_TRACK, outChannelCount); - afInitRate(outfilesetup, AF_DEFAULT_TRACK, sampleRate); + afInitRate(outfilesetup, AF_DEFAULT_TRACK, outSampleRate); + afInitByteOrder(outfilesetup, AF_DEFAULT_TRACK, outByteOrder); outfile = afOpenFile(outfilename, "w", outfilesetup); if (outfile == AF_NULL_FILEHANDLE) @@ -228,6 +277,7 @@ printf("\n"); printf("Where keywords specify format of input or output soundfile:\n"); + printf(" rate n sample rate (22050, 44100, 48000, etc.)\n"); printf(" byteorder e endian (e is big or little)\n"); printf(" channels n n-channel file (1 or 2)\n"); printf(" format f file format f (see below)\n"); @@ -239,11 +289,15 @@ printf("Currently supported formats are:\n"); printf("\n"); + printf(" raw \n"); printf(" aiff Audio Interchange File Format\n"); printf(" aifc AIFF-C File Format\n"); printf(" next NeXT/Sun Format\n"); printf(" wave MS RIFF WAVE Format\n"); printf(" bics Berkeley/IRCAM/CARL Sound File Format\n"); + printf(" avr Audio Visual Research File Format\n"); + printf(" iff Amiga IFF/8SVX Sound File Format\n"); + printf(" nist NIST SPHERE File Format\n"); printf("\n"); exit(EXIT_FAILURE);