This is sndproc1.c in view mode; [Download] [Up]
/* Copyright 1988-1992, NeXT Inc. All rights reserved. */
/* This one was made from resample.c => stereo support, no blocking.
*
* This program reads in a soundfile, applies a black box to
* the sound, and writes a new soundfile.
* Currently supports only SND_FORMAT_LINEAR_16, mono or stereo.
*
* Usage: sndproc1 <inputSoundFile> <outputSoundFile>
*
* The algorithm:
* You provide - currently just does a copy
*/
#import <stdio.h>
#import <sound/sound.h>
static void fail(char *s, char *s2)
{
printf("*** %s%s\n\n",s,s2);
exit(1); /* Exit, indicating error */
}
int processSound(int inCount, short *inPtr, short *outPtr, int nChans)
{
int i;
for (i=0; i<inCount; i++)
*outPtr++ = *inPtr++; /* copy */
return inCount;
}
void main(int argc,char **argv) {
SNDSoundStruct *sndin, *sndout;
short *inPtr, *outPtr;
FILE *outstream;
int inCount, outCount, width, nChans;
if (SNDReadSoundfile(*++argv,&sndin))
fail("could not open input file ",*argv);
else
SNDGetDataPointer(sndin, (char **)(&inPtr), &inCount, &width);
if (width != 2)
fail("Can only handle 16-bit soundfiles","");
nChans = sndin->channelCount;
inCount /= nChans; /* to get sample frames */
SNDSwapSoundToHost(inPtr, inPtr, inCount, nChans, sndin->dataFormat);
SNDAlloc(&sndout,
sndin->dataSize,
SND_FORMAT_LINEAR_16,
sndin->samplingRate,
nChans,4);
SNDGetDataPointer(sndout, (char **)(&outPtr), &outCount, &width);
outCount /= nChans; /* to get sample frames */
if (NULL == (outstream = fopen(*++argv,"w")))
fail("could not open output file ",*argv);
if (SNDWriteHeader(fileno(outstream),sndout))
fail("could not write output file ",*argv);
outCount = processSound(inCount, inPtr, outPtr, nChans);
SNDSwapHostToSound(outPtr, outPtr, outCount, nChans, sndout->dataFormat);
fwrite(outPtr,2*nChans,outCount,outstream);
SNDFree(sndin);
fclose(outstream);
SNDFree(sndout);
exit(0);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.