⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 melpauto.c

📁 C50_melp.tar.gz为美军2400bps语音压缩编码算法
💻 C
字号:
/* This version for MELPAUTO is used to verify SYNTHESIS only!  */


#include <stdio.h>
#include <fcntl.h>
#include <conio.h>
#include <io.h>

#include <string.h>

#ifndef TRUE
#define TRUE    1
#define FALSE   0
#endif

#define FRAMESIZE   180
#define CHANSIZE    9
#define IO_BASE 0x340
#define RESET   0x5555
#define RUN     0x0000

#define BUFSIZE 256

#define SWAP(x) ((x >> 8) & 0xff) | ((x << 8) & 0xff00)

char filename[100];
unsigned char data[BUFSIZE];
char cmdline [512];
char *ptr;

int status;

main(int argc,char* argv[]) {

    volatile int n,i;
    int fp_si, fp_ci, fp_so;
    long frame = 0;

    char speech_in_name[20];
    char chan_in_name[20];
    char speech_out_name[20];
    char logname[20];
    volatile short data[FRAMESIZE];
    volatile short samp;
    volatile unsigned short time[3];
    volatile unsigned short mAtime = 0;
    volatile unsigned short mStime = 0;

    int errorFlag  = FALSE;

    FILE *ifp;
    FILE *fpl;
    frame = 0;
    mAtime = 0;
    mStime = 0;

    /** open input file **/
    if (argc != 2) {
      fprintf (stderr, "usage: melptst list_file\n");
      exit (1);
    }

    if (ifp = fopen (argv[1], "r"),  !ifp) {
      fprintf (stderr, "Error opening input file: %s\n", argv[1]);
      exit (1);
    }

    sprintf(logname, "%s.log", argv[1]);
    if (fpl = fopen ( logname, "w"), !fpl) {
	fprintf(stderr, "Error opening log file: %s\n", logname);
	exit(1);
    }

    while (fgets (filename, 100, ifp)) {

	if (ptr = strchr (filename,'\n'),  ptr != 0)
	  *ptr = 0; /*  Discard the return character  */

	if (strcmp(filename,"rewind") == 0){
	  rewind(ifp);
	  continue;
	}

	if (filename[0] == '#') {
	  continue;
	}

	/* Build the file names we need to run with */
	sprintf(chan_in_name, "%s.chn", filename);
	sprintf(speech_out_name, "%s.spo", filename);

	/* List file names for sanity */
	printf(" Channel file name is %s\n", chan_in_name);
	printf(" Output  file name is %s\n", speech_out_name);

	fprintf(fpl, "Running input file %s - ", chan_in_name);
	fflush (fpl);



	if( (fp_ci = open(chan_in_name, O_RDONLY | O_BINARY, 0777)) == -1) {
	    printf("Error opening file %s\n", chan_in_name);
	    exit(1);
	}

	if( (fp_so = open(speech_out_name, O_RDONLY | O_BINARY, 0777)) == -1) {
	    printf("Error opening file %s\n", speech_out_name);
	    close(fp_ci);
	    exit(1);
	}

	/* initialize variables */
	errorFlag = FALSE;
	frame = 0;
	mAtime = 0;
	mStime = 0;

	/* Initialze the TIGER5XF board */
	outpw( (IO_BASE + 0x804), 0x9000);


	/* Now read a buffer of data and send to the DSP */
	while ((n= (volatile int)read(fp_ci, data, CHANSIZE*4)) == CHANSIZE*4 ) {


	  /* Send the run command */
	  while ( ((volatile int)inpw((IO_BASE + 0x804)) & 1) == 0) {
	    kbhit();
	  }

	  /* Now send command to DSP */
	  outpw( (IO_BASE + 0x800), RUN);


	  for(i=0;i<CHANSIZE;i++) {
	    static int once = 0;
	    while ( ((volatile int)inpw((IO_BASE + 0x804)) & 1) == 0) {
	      if(once == 100) {
		printf("Waiting for DSP to read sample %d,frame=%ld\n",i,frame);
	      } else {
		kbhit();
	      }
	      once++;
	    }

	    once = 0;

	    /* Build samples from buffer */
	    samp = (short)SWAP(data[(i * 2) +1]);


	    /* Now send sample to DSP */
	    outpw( (IO_BASE + 0x800), samp);
	  }


	  if (frame != 0) {
	    /* All samples in this frame writen, now get results from DSP */
	    if ( (n=(volatile int)read(fp_so, data, FRAMESIZE*2)) != FRAMESIZE*2) {
	      printf("Error reading samples from output file\n");
	      break;
	    }
	  }

	  for(i=0;i<FRAMESIZE;i++) {

	    while ( ((volatile int)inpw( (IO_BASE + 0x804) ) & 2) == 0) {
	      kbhit();
	    }

	    samp = inpw(IO_BASE + 0x800);

	    if ( errorFlag == FALSE && frame != 0 && samp != (short)(SWAP(data[i])) ) {
	      printf("Synthesis Error - File %s, Frame %ld, sample %d, PC = %x, DSP = %x\n",
		     chan_in_name, frame, i, (short)(SWAP(data[i])), samp);

	      fprintf(fpl, "\nSynthesis Error - File %s, Frame %ld, sample %d, PC = %x, DSP = %x\n",
		     chan_in_name, frame, i, (short)(SWAP(data[i])), samp);
	      fflush(fpl);

	      /* Signal loop exit, an error has occured */
	      errorFlag = TRUE;
	    }
	  }

	  /* Now get the run times */
	  for(i=0;i<3;i++) {

	    while ( ((volatile int)inpw( (IO_BASE + 0x804) ) & 2) == 0) {
	      kbhit();
	    }

	    time[i] = (volatile unsigned)inpw(IO_BASE + 0x800);

	  }

	  if (  (time[0] + time[1]) > 225) {
	      printf("Frame = %ld, ATime = %5.1fMs, STime = %5.1fMs, Time = %5.1fMs  *** \n",
		     frame++, (float)time[0] / 10., (float)time[1] / 10.,
		    (float)time[2] / 10.);
	  }  else   {
	      printf("Frame = %ld, ATime = %5.1fMs, STime = %5.1fMs, Time = %5.1fMs\n",
		     frame++, (float)time[0] / 10., (float)time[1] / 10.,
		    (float)time[2] / 10.);
	 }

	  if ( time[0] > mAtime) mAtime = time[0];
	  if ( time[1] > mStime) mStime = time[1];

	  /* Exit this file if any error has already been detected */
	  if (errorFlag == TRUE) break;
	}

	printf("Max Anal time = %5.1fMs, Synth time = %5.1fMs\n", (float)mAtime/10., (float)mStime / 10.);
	fprintf(fpl, "Max Anal time = %5.1fMs, Synth time = %5.1fMs\n", (float)mAtime/10., (float)mStime / 10.);
	fflush(fpl);

	/* Send the run command */
	while ( ((volatile int)inpw((IO_BASE + 0x804)) & 1) == 0) {
	  kbhit();
	}

	/* Now send command to DSP */
	outpw( (IO_BASE + 0x800), RESET);

	/*  All Done! Now close all input files */
	close(fp_ci);
	close(fp_so);
    }

    fclose(ifp);
    fclose(fpl);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -