This is smsSynth.c in view mode; [Download] [Up]
/* * * main program for smsSynth * */ #import <sound/sound.h> #include "../sms.h" #define USAGE "Usage: smsSynth [-s samplingRate] [-d] [-n] <inputSmsFile> <outputSoundFile>" void main (int argc, char *argv[]) { char *pChInputSmsFile = NULL, *pChOutputSoundFile = NULL; SMSHeader *pSmsHeader; SNDSoundStruct *pSoundHeader; char *pData; SMS_DATA smsRecord1, smsRecord2, newSmsRecord; short *pSSynthesis; long iError, iSample, i, iLastSample, iLeftRecord, iRightRecord, iOrigSizeHop; float fSamplingRate = SND_RATE_HIGH, fRecordLoc; SYNTH_PARAMS synthParams; initSms (&smsRecord1); initSms (&smsRecord2); initSms (&newSmsRecord); initSms (&synthParams.previousFrame); synthParams.iSynthesisType = 0; if (argc > 3) { for (i=1; i<argc-2; i++) if (*(argv[i]++) == '-') switch (*(argv[i]++)) { case 's': if (sscanf(argv[i],"%f",&fSamplingRate) < 1) quit("Invalid sampling rate"); break; case 'd': synthParams.iSynthesisType = 1; break; case 'n': synthParams.iSynthesisType = 2; break; default: quit(USAGE); } } else if (argc < 2) quit (USAGE); pChInputSmsFile = argv[argc-2]; pChOutputSoundFile = argv[argc-1]; if ((iError = readSmsFile (pChInputSmsFile, &pSmsHeader)) < 0) { if (iError == SMS_NOPEN) quit ("cannot open input file"); if (iError == SMS_RDERR) quit ("read error in input file"); if (iError == SMS_NSMS) quit("the input file not an SMS file"); if (iError == SMS_MALLOC) quit ("cannot allocate memory for input file"); quit ("error reading input file"); } synthParams.fOriginalSRate = pSmsHeader->fOriginalSRate; synthParams.iStochasticType = pSmsHeader->iStochasticType; if (synthParams.iStochasticType == STOC_FILTER_TYPE) quit ("Stochastic representation based on IIR filters not supported"); synthParams.sizeHop = 128; pData = (char *) pSmsHeader + pSmsHeader->iHeadBSize; if (fSamplingRate == 44100.0 && synthParams.fOriginalSRate == 44100.0) FSamplingRate = SND_RATE_HIGH; else { FSamplingRate = SND_RATE_LOW; fprintf(stderr, "Sampling Rate set to 22050 Hz\n"); } synthParams.fSamplingRate = FSamplingRate; FHalfSamplingRate = FSamplingRate / 2; iOrigSizeHop = FSamplingRate / pSmsHeader->iFrameRate; synthParams.pFStocWindow = (float *) calloc(synthParams.sizeHop * 2, sizeof(float)); Hanning (synthParams.sizeHop * 2, synthParams.pFStocWindow); synthParams.pFDetWindow = (float *) calloc(synthParams.sizeHop * 2, sizeof(float)); IFFTwindow (synthParams.sizeHop * 2, synthParams.pFDetWindow); if ((iError = SNDAlloc (&pSoundHeader, pSmsHeader->nRecords * iOrigSizeHop * sizeof(short), SND_FORMAT_LINEAR_16, FSamplingRate, 1, 0)) != SND_ERR_NONE) quit (SNDSoundError (iError)); pSSynthesis = (short *) ((char *) pSoundHeader + pSoundHeader->dataLocation); allocateSmsRecord (&synthParams.previousFrame, pSmsHeader->nTrajectories, 1 + pSmsHeader->nStochasticCoeff, 1); allocateSmsRecord (&newSmsRecord, pSmsHeader->nTrajectories, pSmsHeader->nStochasticCoeff, 0); /* prepare sinc and sine tables only the first time */ if (pFSincTab == NULL) PrepSinc (); if (pFSTab == NULL) PrepSine (2046); iSample = 0; iLastSample = pSmsHeader->nRecords * iOrigSizeHop; while (iSample < iLastSample) { fRecordLoc = (float) iSample / iOrigSizeHop; iLeftRecord = MIN (pSmsHeader->nRecords - 1, floor (fRecordLoc)); iRightRecord = (iLeftRecord < pSmsHeader->nRecords - 2) ? (1+ iLeftRecord) : iLeftRecord; setSmsRecord (pSmsHeader, pData + pSmsHeader->iRecordBSize * iLeftRecord, &smsRecord1); setSmsRecord (pSmsHeader, pData + pSmsHeader->iRecordBSize * iRightRecord, &smsRecord2); InterpolateSmsRecords (&smsRecord1, &smsRecord2, &newSmsRecord, fRecordLoc - iLeftRecord); SmsSynthesis (&newSmsRecord, pSSynthesis, &synthParams); iSample += synthParams.sizeHop; pSSynthesis += synthParams.sizeHop; if (iSample % (synthParams.sizeHop * 40) == 0) fprintf(stderr,"%.2f ", iSample / (float) FSamplingRate); } if ((iError = SNDWriteSoundfile (pChOutputSoundFile, pSoundHeader)) != SND_ERR_NONE) quit (SNDSoundError(iError)); SNDFree (pSoundHeader); free (pSmsHeader); exit (0); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.