Exemplo n.º 1
0
void _main(void)
{
  ESI argptr = top_estack;
  short a = GetIntArg (argptr);
  short b = GetIntArg (argptr);
  while (GetArgType (top_estack) != END_TAG)  // Clean up arguments
    top_estack = next_expression_index (top_estack);
  top_estack--;
  push_longint (a + b);
}
Exemplo n.º 2
0
// Implement the command interface
void ARec::ExecCommand(const string & cmdname)
{
   char buf[100];

   if (cmdname == "start")
	   StartCmd();
   else if (cmdname == "stop")
	   StopCmd();
   else if (cmdname == "setmode")
	   SetModeCmd();
   else if (cmdname == "usegrp")
	   UseGrpCmd();
   else if (cmdname == "setnbest") {
	   if(nBest==0) {
		   CreateHeap(&ansHeap,"Lattice heap",MSTAK,1,0.0,4000,4000);
		   CreateHeap(&altHeap,"Lattice heap",MSTAK,1,0.0,4000,4000);
	   }
	   int nb;
	   if (!GetIntArg(nb, 1, 100000))
		   HPostMessage(HThreadSelf(),"Setnbest, n-best num expected\n");
	   nBest=nb;
   }
   else {
	   sprintf(buf,"Unknown command %s\n", cmdname.c_str());
	   HPostMessage(HThreadSelf(),buf);
   }
}
Exemplo n.º 3
0
int GetWinspecs(int *argc, char **argv, Winspecs *winspecs)
{
	int myid;
	
	MPI_Comm_rank(MPI_COMM_WORLD, &myid);
	
	if (!myid) 
	{
		GetIntArg(argc, argv, "-height", &(winspecs->height));
		GetIntArg(argc, argv, "-width",  &(winspecs->width));
		winspecs->bw = IsArgPresent(argc, argv, "-bw");
		GetIntArg(argc, argv, "-xpos", &(winspecs->xpos));
		GetIntArg(argc, argv, "-ypos", &(winspecs->ypos));
		GetIntArg(argc, argv, "-colors", &(winspecs->numColors));
	}
	
	MPI_Bcast(winspecs, 1, winspecs_type, 0, MPI_COMM_WORLD);
	return 0;
}
Exemplo n.º 4
0
#include "LWMap.h"

#include "LGBase.h"



/* -------------------------- Trace Flags ------------------------ */



static int trace = 0;

#define T_TOP  0001              /* Top Level tracing */



/* ---------------------- Global Variables ----------------------- */



static  WordMap wmap;            /* and the word map */



/* ---------------- Configuration Parameters --------------------- */



static ConfParam *cParm[MAXGLOBS];

static int nParm = 0;            /* total num params */



/* ---------------- Process Command Line ------------------------- */



/* SetConfParms: set conf parms relevant to this tool */

void SetConfParms(void)

{

   int i;



   nParm = GetConfig("LGLIST", TRUE, cParm, MAXGLOBS);

   if (nParm>0){

      if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i;
Exemplo n.º 5
0
// Interface commands
void ARec::SetModeCmd()
{
   int i;

   if (GetIntArg(i,1,MAXMODEVAL)) {
      runmode = RunMode(i);
      if ((runmode&RESULT_ASAP) || (runmode&RESULT_IMMED))
         runmode = RunMode(runmode|RESULT_ATEND);
   }
   else
      HPostMessage(HThreadSelf(),"SetMode: value out of range\n");
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
	int n,a1,a2,a3,a4;

	InitThreads(sMon);
	if(InitShell(argc,argv,hthreadtest_version)<SUCCESS)
		HError(1100,"HThreadTest: InitShell failed");
	if (NumArgs() < 1) ReportUsage();
	InitMem();   InitLabel();
	InitMath();  InitSigP();
	InitWave();  InitAudio();
	InitVQ();
	if(InitParm()<SUCCESS)
		HError(3200,"HThreadTest: InitParm failed");
	InitGraf(FALSE);
   if (sMon==HT_MSGMON) HCreateMonitor(tmon4,(void *)0);
	if (NextArg() == INTARG){
		n = GetIntArg();
		switch(n){
		case 1:
			a1 = GetIntArg(); a2 = GetIntArg();
			ParallelForkAndJoin(a1,a2); break;
		case 2:
			a1 = GetIntArg(); a2 = GetIntArg();
			SimpleMutex(a1,a2); break;
		case 3:
			SimpleSignal(); break;
		case 4:
			a1 = GetIntArg(); a2 = GetIntArg();
			a3 = GetIntArg(); a4 = GetIntArg();
			BufferTest(a1,a2,a3,a4,GetStrArg()); break;
		default:
			printf("Bad test number %d\n",n); ReportUsage();
		}
	}
	if (sMon>0){
		AccessStatus();
		PrintThreadStatus("Final");
		ReleaseStatusAccess();
		if (sMon==HT_MSGMON)HJoinMonitor();
	}
}
Exemplo n.º 7
0
int GetFlags(int *argc, char **argv, Winspecs *winspecs, Flags *flags)
{
	double x, y;
	int myid, strLens[3];
	
	MPI_Comm_rank(MPI_COMM_WORLD, &myid);
	
	if (myid == 0) 
	{
		GetStringArg(argc, argv, "-l", &(flags->logfile));
		GetStringArg(argc, argv, "-i", &(flags->inf));
		/* if reading from input file, disable zooming */
		if (flags->inf) 
		{
			flags->zoom = 0;
		}
		GetStringArg(argc, argv, "-o", &(flags->outf));
		GetIntArg(argc, argv, "-breakout", &(flags->breakout));
		if (IsArgPresent(argc, argv, "-randomize")) 
		{
			flags->randomize = 0;
		}
		if (IsArgPresent(argc, argv, "+randomize")) 
		{
			flags->randomize = 1;
		}
		GetIntArg(argc, argv, "-colreduce", &(flags->colReduceFactor));
		flags->loop = IsArgPresent(argc, argv, "-loop");
		if (IsArgPresent(argc, argv, "-zoom")) 
		{
			flags->zoom = 0;
		}
		if (IsArgPresent(argc, argv, "+zoom") && !flags->inf) 
		{
			flags->zoom = 1;
		}
		flags->askNeighbor = IsArgPresent(argc, argv, "-neighbor");
		flags->sendMasterComplexity = IsArgPresent(argc, argv, "-complexity");
		flags->drawBlockRegion = IsArgPresent(argc, argv, "-delaydraw");
		
		if (IsArgPresent(argc, argv, "-mandel")) 
		{
			flags->fractal = MBROT;
		} 
		else if (IsArgPresent(argc, argv, "-julia")) 
		{
			flags->fractal = JULIA;
		} 
		else if (IsArgPresent(argc, argv, "-newton")) 
		{
			flags->fractal = NEWTON;
		}
		
		GetIntArg(argc, argv, "-maxiter", &(flags->maxiter));
		if (GetDoubleArg(argc, argv, "-boundary", &x)) 
		{
			flags->boundary_sq = x * x;
		}
		GetDoubleArg(argc, argv, "-epsilon", &(flags->epsilon));
		if (GetDoubleArg(argc, argv, "-rmin", &x)) 
		{
			NUM_ASSIGN(flags->rmin, DBL2NUM(x));
		}
		if (GetDoubleArg(argc, argv, "-rmax", &x)) 
		{
			NUM_ASSIGN(flags->rmax, DBL2NUM(x));
		}
		
		if (GetDoubleArg(argc, argv, "-imin", &x)) 
		{
			NUM_ASSIGN(flags->imin, DBL2NUM(x));
		}
		if (GetDoubleArg(argc, argv, "-imax", &x)) 
		{
			NUM_ASSIGN(flags->imax, DBL2NUM(x));
		}
		if (GetDoubleArg(argc, argv, "-radius", &x)) 
		{
			if (GetDoubleArg(argc, argv, "-rcenter", &y)) 
			{
				NUM_ASSIGN(flags->rmin, DBL2NUM(y-x));
				NUM_ASSIGN(flags->rmax, DBL2NUM(y + x));
			}
			if (GetDoubleArg(argc, argv, "-icenter", &y)) 
			{
				NUM_ASSIGN(flags->imin, DBL2NUM(y-x));
				NUM_ASSIGN(flags->imax, DBL2NUM(y + x));
			}
		}
		strLens[0] = (flags->logfile) ? strlen(flags->logfile) + 1 : 0;
		strLens[1] = (flags->inf)     ? strlen(flags->inf) + 1     : 0;
		strLens[2] = (flags->outf)    ? strlen(flags->outf) + 1    : 0;
	} /* End of myid == 0 */
	
	MPI_Bcast(flags, 1, flags_type, 0, MPI_COMM_WORLD);
	
	MPI_Bcast(strLens, 3, MPI_INT, 0, MPI_COMM_WORLD);
	
	if (myid != 0) 
	{
		flags->logfile = (strLens[0]) ?
			(char *)malloc(strLens[0] * sizeof(char)) : 0;
		flags->inf = (strLens[1]) ?
			(char *)malloc(strLens[1] * sizeof(char)) : 0;
		flags->outf = (strLens[2]) ?
			(char *)malloc(strLens[2] * sizeof(char)) : 0;
	}
	if (strLens[0]) 
		MPI_Bcast(flags->logfile, strLens[0], MPI_CHAR, 0, MPI_COMM_WORLD);
	if (strLens[1]) 
		MPI_Bcast(flags->inf,     strLens[1], MPI_CHAR, 0, MPI_COMM_WORLD);
	if (strLens[2]) 
		MPI_Bcast(flags->outf,    strLens[2], MPI_CHAR, 0, MPI_COMM_WORLD);
	
	return 0;
}
Exemplo n.º 8
0
void main(int argc, char *argv[])
{
  FILE *fwav, *ppd, *ptm;
  int byte_swap = 0;
  int headersize, sampling_rate, min_pitch, max_pitch;
  int filesize, total = 0, min_amp = 0, max_amp = 0, ten_ms;
  int min_range, max_range, verbose = 0, low_range, high_range;
  short *speech;
  int i, j;
  float mean, global_rms = 0.0, sample_interval;
  float *rho, eng;
  int x_start, num_peaks;
  short *peak_set;
  int pitch[NUM_FRAMES][MAX_CANDS], frame_ct = 0, peak_ct[NUM_FRAMES]; 
  float corr[NUM_FRAMES][MAX_CANDS];
  int start_frame, end_frame, done, counter, at, at_bad;
  short possible[GROUP_SIZE][MAX_CANDS][MAX_CANDS];
  int best_path[MAX_CANDS][GROUP_SIZE+1], cand_ct;
  float best_cost[MAX_CANDS], best_no_bad[MAX_CANDS], min, best, min_bad;
  int cur_end, at2;
  int target, index, keep_going, end_pt;
  int male;
  int num_bad, ct1, ct2, num_shared;
  float ave1, ave2;
  int targ_pitch[NUM_FRAMES], choice1[NUM_FRAMES], choice2[NUM_FRAMES];
  int ave_pit_len, ave_ct, need_fix;
  char message[100];  
  float time,start_time,out_pitch;
  int mstime;
  int length,start,last_length,last_start;
  int len_stem;
  char *stem;
  int end_of_file;
  char *ptmfn,*ppdfn;

#ifndef HTKCOMPILE 
  char *stem_ptmfn,*stem_ppdfn;
#endif

#ifdef HTKCOMPILE
  char *s;
  DataFile src;  /* src is then a DataFile type structure */
  FileFormat ff; /* ff is then a FileFormat type */
  char *wavfn;              /* Waveform input file name */
  char *tempptmfn=NULL;     /* temporary storage for command line specified ptmfn */
  char *tempppdfn=NULL;     /* temporary storage for command line specified ppdfn */
  min_pitch = DEFAULT_MIN_PITCH;
  max_pitch = DEFAULT_MAX_PITCH;
#endif

#ifndef HTKCOMPILE

  if (argc < 2) {
    ReportUsage();
    exit(1);
  }


 if (Scan_flag(argc, argv, "-o") == -1) {
   fprintf(stderr,"\n\nsrcfn.ptm  -  contains time (in seconds) against pitch (in Hz)\nsrcfn.ppd  -  contains length of voiced pitch period (in samples) against\n              start position of pitch period (in samples)\n\n");
   exit(1);
 }


  if ((fwav = Std_fopen(argv[argc - 1], "r")) == NULL) {
    fprintf(stderr,"Cannot open input file %s\n",argv[argc - 1]);
    exit(1);
  }




/* gets the stem from the input filename and creates the 
   output filenames from this, if not otherwise specified */

  len_stem = strcspn(argv[argc - 1],".");

  if ((stem = (char *)calloc((len_stem+1),sizeof(char))) == NULL) {
    fprintf(stderr,"Cannot create stem character array");
    exit(1);
  }

  *strncpy(stem,argv[argc - 1],len_stem);

  if ((stem_ptmfn = (char *)calloc((len_stem+5),sizeof(char))) == NULL) {
    fprintf(stderr,"Cannot create stem_ptmfn character array");
    exit(1);
  }

 if ((stem_ppdfn = (char *)calloc((len_stem+5),sizeof(char))) == NULL) {
    fprintf(stderr,"Cannot create stem_ppdfn character array");
    exit(1);
  }


  sprintf(stem_ptmfn,"%s.ptm",stem);
  sprintf(stem_ppdfn,"%s.ppd",stem);

  ptmfn = Scan_string(argc, argv, "-t", stem_ptmfn);
  ppdfn = Scan_string(argc, argv, "-p", stem_ppdfn);

  if ((ptm = Std_fopen(ptmfn, "w")) == NULL) {
    fprintf(stderr,"Cannot open output file %s\n",ptmfn);
    exit(1);
  }

  if ((ppd = Std_fopen(ppdfn, "w")) == NULL) {
    fprintf(stderr,"Cannot open output file %s\n",ppdfn);
    exit(1);
  }


  headersize = Scan_int(argc, argv, "-h", DEFAULT_HEADER_SIZE);
  sampling_rate= Scan_int(argc, argv, "-s", DEFAULT_SAMPLING_RATE);
  min_pitch= Scan_int(argc, argv, "-n", DEFAULT_MIN_PITCH);
  max_pitch= Scan_int(argc, argv, "-x", DEFAULT_MAX_PITCH);
  byte_swap= Scan_flag(argc, argv, "-b");


/* print out the options being used */

  fprintf(stderr,"Waveform input filename        : %s\n",argv[argc - 1]);
  fprintf(stderr,"Pitch against time output file : %s\n",ptmfn);
  fprintf(stderr,"Pitch period output file       : %s\n",ppdfn);
  fprintf(stderr,"Headersize                     : %d\n",headersize);
  fprintf(stderr,"Sampling_rate                  : %d\n",sampling_rate);
  fprintf(stderr,"Min_pitch                      : %d\n",min_pitch);
  fprintf(stderr,"Max_pitch                      : %d\n",max_pitch);
  if (byte_swap == -1)
    fprintf(stderr,"Byte swapping data\n");
  


  for (i = 0; i < NUM_FRAMES; i++)
    targ_pitch[i] = choice1[i] = choice2[i] = 0;

  /* load in the speech file */
  Panic_fseek(fwav, 0, 2);
  filesize = (ftell(fwav) - headersize) / sizeof(short);
  Panic_fseek(fwav, headersize, 0);
  speech = Panic_short_array(filesize);
  Panic_fread(speech, sizeof(*speech), filesize, fwav);
  

  /* byte swap if nesscessary */
  if (byte_swap == -1) {
    for (i = 0; i < filesize; i++) 
      Swap(&speech[i]);
  }

#endif

#ifdef HTKCOMPILE

  InitShell(argc,argv);
  InitMath(FALSE);
  if (NumArgs()==0)
    ReportUsage();
  while (NextArg() == SWITCHARG) {
    s = GetSwtArg();
    if (strlen(s)!=1)
      HError(1,"Bad switch %s; must be single letter",s);
    switch(s[0]){
    case 'o':
      fprintf(stderr,"\n\nsrcfn.ptm  -  contains time (in seconds) against pitch (in Hz)\nsrcfn.ppd  -  contains length of voiced pitch period (in samples) against\n              start position of pitch period (in samples)\n\n");
      exit(1);
      break;
    case 'n':
      min_pitch = GetIntArg();
      break;
    case 'x':
      max_pitch = GetIntArg();
      break;
    case 't':
      tempptmfn =  GetStrArg();
      break;
    case 'p':
      tempppdfn =  GetStrArg();
      break;
    case 'F':
      if (NextArg() != STRINGARG)
	HError(1,"Data File format expected");
      if((ff = Str2Format(GetStrArg())) == ALIEN)
	HError(0,"Warning ALIEN Data file format set");
      SetFormat(ff);
      break;
    default:
      HError(1,"Unknown switch %s",s);
    }
  }
  if (NextArg()!=STRINGARG)
    HError(1,"Waveform file name expected");
  wavfn = GetStrArg();


/* gets the stem from the input filename and creates the 
   output filenames from this, if not otherwise specified */

  len_stem = strcspn(wavfn,".");

  if ((stem = (char *)calloc((len_stem+1),sizeof(char))) == NULL) {
    fprintf(stderr,"Cannot create stem character array");
    exit(1);
  }

  *strncpy(stem,wavfn,len_stem);

  if (tempptmfn == NULL) {
    if ((ptmfn = (char *)calloc((len_stem+5),sizeof(char))) == NULL) {
      fprintf(stderr,"Cannot create ptmfn character array");
     exit(1);
    }
    sprintf(ptmfn,"%s.ptm",stem);
  }
  else
    ptmfn = tempptmfn;

  if (tempppdfn == NULL) {
    if ((ppdfn = (char *)calloc((len_stem+5),sizeof(char))) == NULL) {
      fprintf(stderr,"Cannot create ppdfn character array");
      exit(1);
    }
  sprintf(ppdfn,"%s.ppd",stem);
  }
  else
    ppdfn = tempppdfn;

  if ((ptm = fopen(ptmfn, "w")) == NULL) {
    fprintf(stderr,"Cannot open output file %s\n",ptmfn);
    exit(1);
  }

  if ((ppd = fopen(ppdfn, "w")) == NULL) {
    fprintf(stderr,"Cannot open output file %s\n",ppdfn);
    exit(1);
  }


/* print out the options being used */

  fprintf(stderr,"Waveform input filename        : %s\n",wavfn);
  fprintf(stderr,"Pitch against time output file : %s\n",ptmfn);
  fprintf(stderr,"Pitch period output file       : %s\n",ppdfn);
  fprintf(stderr,"Min_pitch                      : %d\n",min_pitch);
  fprintf(stderr,"Max_pitch                      : %d\n",max_pitch);
  
  SpOpen(wavfn,&src);
  if (src.sampKind != WAVEFORM)
    HError(99,"Waveform file expected");

  sampling_rate = 10000000/src.sampPeriod;
  filesize = src.nSamples;
  

  for (i = 0; i < NUM_FRAMES; i++)
    targ_pitch[i] = choice1[i] = choice2[i] = 0;

  /* load in the speech file */
  if ((speech = (short *)calloc(filesize,sizeof(short))) == NULL) {
    fprintf(stderr,"Cannot create speech array");
    exit(1);
  }
  for (i = 0; i < filesize; i++)
    GetSample(&src,i,&speech[i]);

#endif

/* The rest is independent of the HTKCOMPILE flag */

  for (i = 0; i < filesize; i++)
    total += speech[i];
  mean = (total * 1.0) / filesize;
  for (i = 0; i < filesize; i++) {
    speech[i] -= mean;
    if (speech[i] > max_amp)
      max_amp = speech[i];
    if (speech[i] < min_amp)
      min_amp = speech[i];
  }

  for (i = 0; i < filesize; i++)
    global_rms += (speech[i] * speech[i]);
  global_rms = sqrt(global_rms/(filesize * 1.0));

  sample_interval = 1.0 / (float) sampling_rate;
  ten_ms = (int) (1.0 * sampling_rate) / 100;
  min_range = (int) ((1.0/max_pitch)/sample_interval);
  max_range = (int) ((1.0/min_pitch)/sample_interval);

  if ((rho = (float *)calloc(max_range + 1,sizeof(float))) == NULL) {
    fprintf(stderr,"Cannot create rho array");
    exit(1);
  }

  if ((peak_set = (short *)calloc(MAX_CANDS,sizeof(short))) == NULL) {
    fprintf(stderr,"Cannot create peak_set array");
    exit(1);
  }

  x_start = 0;

  while (x_start + 2 * max_range < filesize) {
    for (i = 0; i <= max_range; i++)
      rho[i] = 0.0;
    eng = find_sq_eng(speech, x_start, max_range - min_range + 1);
    if (eng >= 0.05 * global_rms)  {
      for (i = min_range; i <= max_range; i++) {
        rho[i] = calculate_rho_first(speech, i, x_start, min_range);
      }
    }
    num_peaks = identify_peak_candidates(rho, min_range, 
                max_range, peak_set, x_start,
                verbose, speech, global_rms);
    if (num_peaks > MAX_CANDS) {
      sprintf(message, "MAX_CANDS not big enough for %d\n", num_peaks);
      help(message);
    }
    peak_ct[frame_ct] = num_peaks + 1;
    for (i = 0; i < num_peaks; i++) {
      pitch[frame_ct][i+1] = peak_set[i];
      corr[frame_ct][i+1] = rho[peak_set[i]]; 
    }
    frame_ct++;
    if (frame_ct >= NUM_FRAMES) {
      sprintf(message, "NUM_FRAMES not big enough for %d\n", frame_ct);
      help(message);
    }
    x_start += ten_ms;
  }


/* The stuff in finp didnt seem to be very useful - so i got rid of that output
   file - R.E.D (23:8:93) 


 fprintf(finp, "%d\n", frame_ct);
  for (i = 0; i < frame_ct; i++) {
    fprintf(finp, "%d ", peak_ct[i]);
    for (j = 1; j < peak_ct[i]; j++)
      fprintf(finp, "%d %f\n", pitch[i][j], corr[i][j]);
  }
  fclose(finp);
*/
/****
  fscanf(finp, "%d", &frame_ct);
  for (i = 0; i < frame_ct; i++) {
    fscanf(finp, "%d", peak_ct + i);
    for (j = 1; j < peak_ct[i]; j++)
      fscanf(finp, "%d %f", &(pitch[i][j]), &(corr[i][j]));
  } 
****/
  done = 0;
  counter = 0;
  while (! done) {
    /* get a group */
    while ((counter < frame_ct) && (peak_ct[counter] == 1)) counter++;
    if (counter >= frame_ct) done = 1;
    if (! done) {
      start_frame = counter;
      keep_going = 1;
      while (keep_going) {  /* hack so we don't miss singulars */
        while ((counter < frame_ct) && (peak_ct[counter] > 1)) counter++;
        if ((counter+1 < frame_ct) && (peak_ct[counter+1] > 1) &&
            (counter+2 < frame_ct) && (peak_ct[counter+2] > 1)) 
          counter = counter + 1;
        else {
          end_frame = counter-1;
          keep_going = 0;
	}
      }
      /* got a group */
      if (end_frame > start_frame) {
        make_possible(start_frame, end_frame, pitch, possible, peak_ct, corr, 
                      frame_ct);

        cand_ct = 0;
        for (j = 1; j < peak_ct[start_frame]; j++) {
        warp(start_frame, end_frame, pitch, corr, peak_ct, j, 
             possible, best_path, best_cost, &cand_ct, best_no_bad);
        }
        if (cand_ct >= MAX_CANDS) {
          sprintf(message, "cand_ct %d too big for MAX_CANDS", cand_ct);
          help(message);
        }

        /* Choosing which string to use */
        min = min_bad = VBIG;
        for (i = 0; i < cand_ct; i++) {
          if (best_cost[i] < min) {
            min = best_cost[i];
            at = i;
	  }
          if (best_no_bad[i] < min_bad) {
            min_bad = best_no_bad[i];
            at_bad = i;
	  }
	}
   
        if (at == at_bad) {
	  assign_targ(targ_pitch, start_frame, end_frame, best_path, at,
                      pitch);
	}
        else {   /* lets look at the options */
          if ((num_shared = share(at, at_bad, pitch, start_frame, 
                                  end_frame, best_path))) {
            num_bad = 0;
            for (i = start_frame; i <= end_frame; i++)
              if ((corr[i][best_path[at_bad][i-start_frame+1]] == PENALTY) &&
                  (pitch[i][best_path[at_bad][i-start_frame+1]] !=
                   pitch[i][best_path[at][i-start_frame+1]]))
                num_bad++;
            if ((end_frame-start_frame+1 == num_shared + num_bad) ||
               (num_bad > round((end_frame-start_frame+1.0-num_shared)/2.0))) {
              /* keep the original */
               assign_targ(targ_pitch, start_frame, end_frame, best_path, at,
                           pitch);
	    }
            else {  
              /* figure out which one to use by calculating average over
                 non-penalty portions */
              ave1 = ave2 = 0.0;
              ct1 = ct2 = 0;
              for (i = start_frame; i <= end_frame; i++) {
                if (corr[i][best_path[at][i-start_frame+1]] != PENALTY) {
                  ave1 += (1.0 - corr[i][best_path[at][i-start_frame+1]]);
                  ct1++;
		}
                if (corr[i][best_path[at_bad][i-start_frame+1]] != PENALTY) {
                  ave2 += (1.0 - corr[i][best_path[at_bad][i-start_frame+1]]);
                  ct2++;
		}
              }
              ave1 /= ct1;
              ave2 /= ct2;
              if (ave1 < ave2) {
                /* use at */
	        assign_targ(targ_pitch, start_frame, end_frame, best_path, at,
                            pitch);
              } 
              else {
                /* use at_bad */
	        assign_targ(targ_pitch, start_frame, end_frame, best_path, 
                            at_bad, pitch);
	      }
	    }
	  }
          else {  
            /* they dont share a common path - so lets check if one is
               much better than the other, and if not, lets delay the
               choice until we have analysed the entire sentence */
            ave1 = ave2 = 0.0;
            ct1 = ct2 = 0;
            for (i = start_frame; i <= end_frame; i++) {
              if (corr[i][best_path[at][i-start_frame+1]] != PENALTY) {
                ave1 += 1.0 - corr[i][best_path[at][i-start_frame+1]];
                ct1++;
	      }
              if (corr[i][best_path[at_bad][i-start_frame+1]] != PENALTY) {
                ave2 += 1.0 - corr[i][best_path[at_bad][i-start_frame+1]];
                ct2++;
	      }
	    }
            ave1 /= ct1;
            ave2 /= ct2;
            if (ave1 < ave2 - 0.03)  /* use at */
	      assign_targ(targ_pitch, start_frame, end_frame, best_path, 
                          at, pitch);
            else
              if (ave2 < ave1 - 0.03) /* use at_bad */
	        assign_targ(targ_pitch, start_frame, end_frame, best_path, 
                            at_bad, pitch);
              else {  /* save these 2 choices for later resolution */
	        assign_targ(choice1, start_frame, end_frame, best_path, 
                            at, pitch);
	        assign_targ(choice2, start_frame, end_frame, best_path, 
                            at_bad, pitch);
	      }
	  }
	}
      }
    }
  }

  /* now resolve any choices */
  need_fix = 0;
  ave_pit_len = ave_ct = 0;
  for (i = 0; i < frame_ct; i++) {
    if (targ_pitch[i] > 0) {
      ave_pit_len += targ_pitch[i];
      ave_ct++;
    }
    if (choice1[i] > 0)
      need_fix = 1;
  }
  if (ave_ct) 
    ave_pit_len /= ave_ct;
  else {
    if (male) ave_pit_len = 125;  /* SUSPECT HARD NUMBERING HERE **********/
    else ave_pit_len = 71;        /* But its not used i think - R.E.D */
    printf("average pitch length being set to fixed number\nwhich i think ought to be scaled by the sampling frequency - but isnt. - R.E.D");
  }
  if (need_fix) {
    done = counter = 0;
    while (! done) {
      while ((counter < frame_ct) && (choice1[counter] == 0)) counter++;
      if (counter >= frame_ct) done = 1;
      if (! done) {
        start_frame = counter;
        while ((counter < frame_ct) && (choice1[counter] > 0)) counter++;
        end_frame = counter-1;
        /* get the averages and choose the one closest to ave_pit_len */
        ave1 = ave2 = 0.0;
        ct1 = 0;
        for (i = start_frame; i <= end_frame; i++) {
          ave1 += choice1[i];
          ave2 += choice2[i];
          ct1++;
	}
        ave1 /= ct1;
        ave2 /= ct1;
        if (absof(ave1 - ave_pit_len) < absof(ave2 - ave_pit_len)) {
          for (i = start_frame; i <= end_frame; i++)
            targ_pitch[i] = choice1[i];
	}
        else {
          for (i = start_frame; i <= end_frame; i++)
            targ_pitch[i] = choice2[i];
	}
      }
    }
  }
  
  done = counter = 0;
  while (! done) {
    while ((counter < frame_ct) && (targ_pitch[counter] == 0)) counter++;
    if (counter >= frame_ct) done = 1;
    if (! done) {
      start_frame = counter;
      while ((counter < frame_ct) && (targ_pitch[counter] > 0)) counter++;
      end_frame = counter-1;
      x_start = start_frame * ten_ms;
      low_range = (int) ((1.0-MAX_SEP) * targ_pitch[start_frame]);
      if (low_range < min_range) low_range = min_range;
      high_range = (int) ((1.0+MAX_SEP) * targ_pitch[start_frame]);
      if (high_range > max_range) high_range = max_range;
      cur_end = x_start;
      end_pt = (end_frame * ten_ms) + (2 * targ_pitch[end_frame]);
      while (cur_end < end_pt) {
        for (i = 0; i <= max_range; i++)
          rho[i] = 0.0;
        best = 0.0;
        for (i = low_range; i <= high_range; i++) {
          rho[i] = calculate_rho_first(speech, i, x_start, low_range);
          if (rho[i] > best) {
            best = rho[i];
            at2 = i;
	  }
	}
        fprintf(ppd, "%d %d\n", at2, x_start);
        x_start += at2;
        index = 1 + x_start/ten_ms;
        if (index < start_frame) index = start_frame;
        if (index > end_frame) index = end_frame;
        target = targ_pitch[index];
        low_range = (int) ((1.0-MAX_SEP) * target);
        if (low_range < min_range) low_range = min_range;
        high_range = (int) ((1.0+MAX_SEP) * target);
        if (high_range > max_range) high_range = max_range;
        cur_end = x_start + at2;
      }
    }
  }
  fclose(ppd);

/* now reopen the output file written so far for reading, and from this 
   calculate a pitch file of time against pitch.  Resolution = 1 ms
   R.E.D 24:8:93 */


  if ((ppd = fopen(ppdfn, "r")) == NULL) {
    fprintf(stderr,"Cannot reopen output file %s\n",ppdfn);
    exit(1);
  }

  time = 0.0;
  mstime = 0;
  out_pitch = 0.0;
  end_of_file = 0;

  last_length = 0;
  last_start = 0;
  fscanf(ppd, "%d", &length);
  fscanf(ppd, "%d", &start);
  start_time = start*1.0/sampling_rate;


  while ( 1 == 1 ) {
    while (start_time < time) {
      
      last_length = length;
      last_start = start;

      if (fscanf(ppd, "%d", &length) == EOF) {
	end_of_file = 1;
	break;
      }
      fscanf(ppd, "%d", &start);
      
      start_time = start*1.0/sampling_rate;
    }
    
    if (end_of_file == 1)
      break;
    
    /* if voiced then interpolate for the pitch */

    if (start == last_start + last_length)
      out_pitch = ( (sampling_rate*time - last_start)/((start-last_start)*length) 
	       +(start - sampling_rate*time)/((start-last_start)*last_length))
	       *sampling_rate;
    else
      out_pitch = 0.0;

    fprintf(ptm,"%f %f\n",time,out_pitch);

    mstime++;
    time = mstime/1000.0;
  }

/* if there's an unvoiced/silent bit at the end then output zeros to the 
   output file */

  if  (filesize > (start + 3*length) ) {
    while (sampling_rate*time < filesize) {
      fprintf(ptm,"%f %f\n",time,0.0);
      mstime++;
      time = mstime/1000.0;
    }
  }

  fclose(ppd);
  fclose(ptm);




  fclose(fwav);
}
Exemplo n.º 9
0
_main() {
  SCR_RECT SCREEN = {{0, 0, LCD_WIDTH-1, LCD_HEIGHT-1}};
  SCR_RECT rect = {{0, 0, HEIGHT-1, HEIGHT-1}};

  short attr = A_XOR; // Default replace value: A_XOR

  // Parses arguments
  ESI argptr;
  InitArgPtr(argptr);
  int argtype = GetArgType(argptr);
  if (argtype == POSINT_TAG) {
    int num = GetIntArg(argptr);
    // 2. *** YOUR CODE HERE ***
  }

  // Initializes a rectangle bitmap of HEIGHT x HEIGHT
  char mask [BITMAP_SIZE];
  int i = 0;
  while (i < BITMAP_SIZE) {
    mask[i] = 0xFF; // Change this value to get different masks!
    i++;
  }
  BitmapInit(&rect, mask);

  // Puts the rectangle onto the screen
  DRAW;

  int c;
  // Main loop for getting keyboard input
  while ((c = ngetchx()) != ENTER_KEY) {
    // Erases old bitmap
    DRAW;
    switch (c) { // Moves bitmap around
    case LEFT_KEY:
      if (rect.xy.x0 - 5 >= 0) {
        rect.xy.x0 -=5;
        rect.xy.x1 -=5;
      }
      break;
    case RIGHT_KEY:
      if (rect.xy.x1 + 5 < LCD_WIDTH) {
        rect.xy.x0 +=5;
        rect.xy.x1 +=5;
      }
      break;
    case UP_KEY:
      if (rect.xy.y0 - 5 >= 0) {
        rect.xy.y0 -=5;
        rect.xy.y1 -=5;
      }
      break;
    case DOWN_KEY:
      if (rect.xy.y1 + 5 < LCD_HEIGHT) {
        rect.xy.y0 +=5;
        rect.xy.y1 +=5;
      }
      break;
    }
    // Draws new bitmap
    DRAW;
  }
}