This is smsSynthDet.c in view mode; [Download] [Up]
/*
*
* main program for smsSynthDet
*
*/
#import <sound/sound.h>
#include "../sms.h"
#define USAGE "Usage: smsSynthDet [-s samplingRate] <inputSmsFile> <outputSoundFile>"
void main (int argc, char *argv[])
{
char *pChInputSmsFile = NULL, *pChOutputSoundFile = NULL;
SMSHeader *pSmsHeader;
SNDSoundStruct *pSoundHeader;
char *pData;
SMS_DATA smsData;
short *pSSynthesis;
int iError, sizeHop, iRecord, i;
float fSamplingRate = SND_RATE_HIGH;
SYNTH_PARAMS synthParams;
float *pFBuffer;
initSms (&smsData);
initSms (&synthParams.previousFrame);
synthParams.iSynthesisType = 1;
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;
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;
sizeHop = FSamplingRate / pSmsHeader->iFrameRate;
pFBuffer = (float *) calloc(sizeHop, sizeof(float));
/* prepare sine table only the first time */
if (pFSTab == NULL)
PrepSine (4096);
if ((iError = SNDAlloc (&pSoundHeader,
pSmsHeader->nRecords * sizeHop * 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);
/* use first record as memory */
setSmsRecord (pSmsHeader, pData, &smsData);
copySmsRecord (&synthParams.previousFrame, &smsData);
pData += pSmsHeader->iRecordBSize;
for (iRecord = 1; iRecord < pSmsHeader->nRecords; iRecord++)
{
setSmsRecord (pSmsHeader, pData, &smsData);
memset ((char *)pFBuffer, 0, sizeof(float) * sizeHop);
FrameSineSynth (&smsData, pFBuffer, sizeHop,
&(synthParams.previousFrame));
/* de-emphasize the sound */
for(i = 0; i < sizeHop; i++)
pSSynthesis[i] = (short) DeEmphasis(pFBuffer[i]);
pData += pSmsHeader->iRecordBSize;
pSSynthesis += sizeHop;
if (iRecord % 10 == 0)
fprintf(stderr,"%.2f ", iRecord / (float) pSmsHeader->iFrameRate);
}
if ((iError = SNDWriteSoundfile (pChOutputSoundFile, pSoundHeader)) !=
SND_ERR_NONE)
quit (SNDSoundError(iError));
ClearSine ();
SNDFree (pSoundHeader);
free (pSmsHeader);
free (pFBuffer);
exit (0);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.