ftp.nice.ch/pub/next/unix/audio/sms.N.bs.tar.gz#/sms/tools/sndReverse.c

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

/*
 *	Usage:  sndReverse <inputSoundFile> <outputSoundFile>
 */

#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;
	short *pNew = (short *) (inPtr+inCount);

    for (i=0; i<inCount; i++)
      *outPtr++ = *pNew--;
    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 */
    
    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);
    
    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.