读书人

将算法主程序main修改后使它作为一个

发布时间: 2012-04-06 12:22:24 作者: rapoo

将算法主程序main修改后,使它作为一个函数能被其它函数调用,该怎么修改呢?

int main( int argc, char * argv[] )
{
p563Results_struct tResults = {-1};

INT32i;
short int * speech_samples; /* Array of speech samples */
INT32 file_length; /* Number of samples in speech file */
INT32 num_read;/* number of elements read from file */

char* PassThroughParameters= "";
char pSpeechFilename[100];
char *pResultFileName="stdout";


FILE *speech_file;

bool RefFileSet=FALSE;
bool PassTitlesSet = FALSE;


int PartitionNumber;
FLOAT PredictedMos;


/* Open speech file and results file */

/*_controlfp(_EM_INEXACT|_EM_DENORMAL|_EM_UNDERFLOW,_MCW_EM); inexact denormal underflow */
if (argc < 2){
usagepseam();
exit(-1);
}

strcpy(pSpeechFilename,argv[1]);
RefFileSet=TRUE;

for (i=2; i<argc; i++)
{
if (!strcmp(argv[i], "-out"))
{
i++;
if (i<argc) pResultFileName = argv[i];
}
else
{
if (!RefFileSet) { strcpy(pSpeechFilename,argv[i]); RefFileSet=TRUE;}
else if (!PassTitlesSet) { PassThroughParameters = argv[i]; PassTitlesSet = TRUE;}
}
}

/* open speech file */
if((speech_file = fopen(pSpeechFilename, "rb")) == NULL )
{
printf( "Cannot open file %s\n", pSpeechFilename ) ;
exit (-1) ;
}

/* Read speech samples from file */
fseek(speech_file, 0 , SEEK_END) ;
file_length = (ftell(speech_file))/(sizeof(short int)) ;
fseek(speech_file, 0 , SEEK_SET) ;

speech_samples = (short int *)calloc(file_length, sizeof(short int)) ;
num_read = fread(speech_samples, sizeof(short int), file_length, speech_file);

if(num_read != file_length)
{
printf( "Unable to read all the data from file\n" );
exit(-1);
}

/*************************
* PROCESS MODEL *
*************************/

module1(speech_samples, file_length, &tResults);

module2(speech_samples, file_length, &tResults);

module3(speech_samples, file_length, &tResults);

PostProcessMovs( &PartitionNumber, &PredictedMos, &tResults);

PrintResults(pSpeechFilename,&tResults,pResultFileName,PassThroughParameters);

/* Clean up*/
fclose(speech_file) ;
free(speech_samples);

return(0);
}

我只知道要修改main的名字,还有形参,不知道该怎么改,谢谢大家

[解决办法]
这个问题啊

读书人网 >C++

热点推荐