Ejemplo n.º 1
0
void GetInput(char* inputBuffer, unsigned char* inputPointer)
{
	char inputChar = NULL;
	int currentPointer = *inputPointer;
	while(true)
	{
		PrintInput(inputBuffer, currentPointer);
		inputChar = _getch();
		if(currentPointer > MAX_MSG_LENGTH)
		{
			currentPointer--;
			continue;
		}
		else if(0 < currentPointer && inputChar == 8) // backspace
		{
			inputBuffer[--currentPointer] = '\0';
		}
		else if(inputChar == '\r')
		{
			clearLine(MAX_PRINT_LINE);
			inputBuffer[currentPointer] = '\0';
			*inputPointer = currentPointer;
			break;
		}
		else 
		{
			if(currentPointer != 0 && currentPointer%MAX_LENGTH_BY_LINE == 0)
			{
				inputBuffer[currentPointer++] = '\n';
			}
			inputBuffer[currentPointer++] = inputChar;
		}
	}
}
Ejemplo n.º 2
0
void input(int argc, char*argv[]) {
    void PrintInput();
    void help();
    int i;
    //int cnt;
    //char buffer[MAX_BUFFER], *pstr;
    //MyDataF tdoub;
    if (argc < 2) {
        //fprintf(stderr, "Invalid input!\n");
        help();
        exit(-1);
    }
    for (i = 1; i < argc; i++) {
        if (strncmp(argv[i], "--niu-type=", 11) == 0) {
            niutype = atoi(argv[i] + 11);
        } else if (strncmp(argv[i], "--matlab=1", 10) == 0) {
            IsMatlabSim = 1;
        } else if (strncmp(argv[i], "--rei=", 6) == 0) {
            rei = atof(argv[i] + 6);
        } else if (strncmp(argv[i], "--niu-e=", 8) == 0) {
            mu_e = atof(argv[i] + 8);
        } else if (strncmp(argv[i], "--tm=1", 6) == 0) {
            IsTMx = 0;
            IsTEx = 1;
        } else if (strncmp(argv[i], "--maxwell-grid=", 15) == 0) {
            maxwellGridSize = atoi(argv[i] + 12);
            if (maxwellGridSize < 4)maxwellGridSize = MAXWELL_MESH_SIZE;
        } else if (strncmp(argv[i], "--fine-grid=", 12) == 0) {
            m = atoi(argv[i] + 12);
            if (m < 4)m = FINE_GRID_SIZE;
        } else if (strncmp(argv[i], "--total-time=", 13) == 0) {
            totaltime = atof(argv[i] + 13);
            if (totaltime <= 0)totaltime = TOTAL_TIME;
        } else if (strncmp(argv[i], "--is-connect=", 13) == 0) {
            isConnect = atoi(argv[i] + 13);
        } else if (strncmp(argv[i], "--with-density=", 15) == 0) {
            IfWithDensity = atoi(argv[i] + 15);
        } else if (strncmp(argv[i], "--e-max=", 8) == 0) {
            E_0 = atof(argv[i] + 8);
        }else if(strncmp(argv[i],"--waveform=",11)==0){
            srcType=atoi(argv[i]+11);
        }
#ifdef _OPENMP
        else if (strncmp(argv[i], "--thread-count=", 15) == 0) {
            thread_count = atoi(argv[i] + 15);
        }
#endif
    }
    if (niutype == 4) {
        if_erms_E_max = 1;
    }
    PrintInput();
}
Ejemplo n.º 3
0
/* ------------------------------------------------------------------ run --- */
int RVB::run()
{
	double rvbsig[2][8192];
	const int frames = framesToRun();
	const int inChans = inputChannels();

    rtgetin(in, this, frames * inChans);

	register float *outptr = &this->outbuf[0];
	/* run summed 1st and 2nd generation paths through reverberator */
 	for (int n = 0; n < frames; n++) {
		if (--_branch <= 0) {
			double p[4];
			update(p, 4);
			m_amp = p[3];
			_branch = getSkip();
		}
		if (m_amp != 0.0) {
			double rmPair[2];
			double rvbPair[2];
			rmPair[0] = in[n*inChans+2];
			rmPair[1] = in[n*inChans+3];
			doRun(rmPair, rvbPair, currentFrame() + n);
			rvbsig[0][n] = rvbPair[0] * m_amp;
			rvbsig[1][n] = rvbPair[1] * m_amp;
		}
		else
			rvbsig[0][n] = rvbsig[1][n] = 0.0;
		/* sum the input signal (which includes early response) & reverbed sigs  */
		*outptr++ = in[n*inChans] + rvbsig[0][n];
		*outptr++ = in[n*inChans+1] + rvbsig[1][n];
	}
	increment(frames);
		
	DBG(printf("FINAL MIX:\n"));
	DBG(PrintInput(&this->outbuf[0], RTBUFSAMPS));
	DBG(PrintInput(&this->outbuf[1], RTBUFSAMPS));
	
	return frames;
}
Ejemplo n.º 4
0
/* ------------------------------------------------------------------ run --- */
int RVB::run()
{
	double rvbsig[2][8192];

	// number of samples to process this time through

	const int frames = framesToRun();
    const int rsamps = frames * 2;

    rtgetin(in, this, rsamps);

	register float *outptr = &this->outbuf[0];
	/* run summed 1st and 2nd generation paths through reverberator */
 	for (int n = 0; n < frames; n++) {
		if (--_branch <= 0) {
			double p[4];
			update(p, 4);
			m_amp = p[3];
			_branch = _skip;
		}
		if (m_amp != 0.0) {
			double rmPair[2];
			double rvbPair[2];
			rmPair[0] = globalReverbInput[0][n];
			rmPair[1] = globalReverbInput[1][n];
			doRun(rmPair, rvbPair, currentFrame() + n);
			rvbsig[0][n] = rvbPair[0] * m_amp;
			rvbsig[1][n] = rvbPair[1] * m_amp;
		}
		else
			rvbsig[0][n] = rvbsig[1][n] = 0.0;
		/* sum the direct signal, early response & reverbed sigs  */
		*outptr++ = in[n*2] + globalEarlyResponse[0][n] + rvbsig[0][n];
		*outptr++ = in[n*2+1] + globalEarlyResponse[1][n] + rvbsig[1][n];
	}
	increment(frames);
	
	// Zero out global buffers for next cycle.
	for (int c = 0; c < 2; ++c) {
		memset(globalReverbInput[c], 0, sizeof(double) * RTBUFSAMPS);
		memset(globalEarlyResponse[c], 0, sizeof(double) * RTBUFSAMPS);
	}
	
	DBG(printf("FINAL MIX:\n"));
	DBG(PrintInput(&this->outbuf[i], bufsamps));
	
	return frames;
}
Ejemplo n.º 5
0
void MyApp::OnPaint3D()
{
  sInput2Update(sGetTime());
  PaintCube();
  PrintInput();

  // make XBOX controllers rumble...
  sU32 deviceType = sINPUT2_TYPE_JOYPADXBOX;
  sInt count = sInput2NumDevices(deviceType);
  
  for (sInt i=0; i<count;i++)
  {
    sInput2Device *device = sFindInput2Device(deviceType,i);
    if (device)
      device->SetMotor(device->GetAbs(sINPUT2_JOYPADXBOX_LT)*255,device->GetAbs(sINPUT2_JOYPADXBOX_RT)*255);
  }
}
Ejemplo n.º 6
0
int AUTO(AutoData *Data)
{
  struct timeval  *time0,*time1;
  integer icp[NPARX2];
  doublereal par[NPARX2], thl[NPARX];
  iap_type *iap;
  rap_type *rap;
  doublereal *thu;
  integer *iuz;
  doublereal *vuz;
  function_list list;
  
  integer i, j, k;

  // Initialize structures and constants
  gData = Data;
  
  iap = &(Data->iap);
  rap = &(Data->rap);

  Data->sp_len = Data->num_sp + (1 + floor(iap->nmx/iap->npr));
  Data->sp_inc = 5;

#ifdef USAGE
  struct rusage *init_usage,*total_usage;
  usage_start(&init_usage);
  usage_start(&total_usage);
#endif

#ifdef FLOATING_POINT_TRAP
  trapfpe();
#endif

#ifdef PTHREADS
  global_conpar_type = CONPAR_PTHREADS;
  global_setubv_type = SETUBV_PTHREADS;
  global_reduce_type = REDUCE_PTHREADS;
#endif

  fp9 = fopen("fort.9","w");
  if(fp9 == NULL) {
    fprintf(stderr,"Error:  Could not open fort.9\n");
    exit(1);
  }
  

  /* Initialization : */

  iap->mynode = mynode();
  iap->numnodes = numnodes();
  if (iap->numnodes > 1) {
    iap->parallel_flag = 1;
  } else {
    iap->parallel_flag = 0;
  }


    /* NOTE:  thu is allocated inside this function, and the
       pointer is passed back.  I know this is ugly, but
       this function does a bit of work to get thu setup correctly,
       as well as figuring out the size the array should be.
       What really should happen is to have one function which
       reads fort.2 and another fuction which initializes the array.
       That way the allocation could happen between the two calls.
    */
    init0(iap, rap, par, icp, thl, &thu, &iuz, &vuz);      

    /* Find restart label and determine type of restart point. */
    if (iap->irs > 0) {
      logical found = FALSE_;

      findlb(iap, rap, iap->irs, &(iap->nfpr), &found);
      if (! found) {
	if (iap->mynode == 0) {
	  fprintf(stderr,"\nRestart label %4ld not found\n",iap->irs);
	}
	exit(0);
      }
    }
    set_function_pointers(*iap,&list);
    init1(iap, rap, icp, par);
    chdim(iap);

    /* Create the allocations for the global structures used in 
       autlib3.c and autlib5.c.  These are purely an efficiency thing.
       The allocation and deallocation of these scratch areas takes
       up a nontrivial amount of time if done directly in the
       wrapper functions in autlib3.c*/
    allocate_global_memory(*iap);

    /* ---------------------------------------------------------- */
    /* ---------------------------------------------------------- */
    /*  One-parameter continuations */
    /* ---------------------------------------------------------- */
    /* ---------------------------------------------------------- */

#ifdef USAGE
    usage_end(init_usage,"main initialization");
#endif
    
    if (Data->print_input)
        PrintInput(Data, par, icp);
    
    // Initialize output variables
    if(list.type==AUTOAE)
        Data->u = DMATRIX(iap->nmx, iap->ndim);
    else {
        // Solution measures
        Data->usm = (doublereal ***)MALLOC((2+(int)(log2(Data->nsm)))*sizeof(doublereal **));
        Data->usm[0] = DMATRIX(iap->nmx, iap->ndim);    // MAX
        Data->usm[1] = DMATRIX(iap->nmx, iap->ndim);    // MIN
        for (i=0; i<(int)(log2(Data->nsm)); i++)
            Data->usm[2+i] = DMATRIX(iap->nmx, iap->ndim);
        
        // Jacobian of flow
        if (Data->sjac) {
            Data->c0 = DMATRIX_3D(iap->nmx, iap->ndim, iap->ndim);
            Data->c1 = DMATRIX_3D(iap->nmx, iap->ndim, iap->ndim);
        }
        
        // Jacobian of flow along cycles (temporary storage)
        if (Data->sflow) {
            Data->a1 = DMATRIX_3D(iap->ntst, iap->ndim, iap->ndim);
            Data->a2 = DMATRIX_3D(iap->ntst, iap->ndim, iap->ndim);
        }
    }
    Data->par = DMATRIX(iap->nmx, iap->nicp);
    if (iap->isp >= 1) {
        Data->ev = DCMATRIX(iap->nmx, iap->ndim);
        for (i=0; i<iap->nmx; i++) {
            for (j=0; j<iap->ndim; j++) {
                Data->ev[i][j].r = NAN; // This is a flag for bad floquet multipliers
                Data->ev[i][j].i = NAN;
            }
        }
    }
    Data->num_u = 0;

    if (Data->sp == NULL)
        Data->num_sp = 0;
    
    Data->sp = (AutoSPData *)REALLOC(Data->sp, (Data->sp_len)*sizeof(AutoSPData));

    for (i=Data->num_sp; i<Data->sp_len; i++) {
        Data->sp[i].u = NULL;
        Data->sp[i].icp = NULL;
        Data->sp[i].ups = NULL;
        Data->sp[i].udotps = NULL;
        Data->sp[i].rldot = NULL;
        Data->sp[i].a1 = NULL;
        Data->sp[i].a2 = NULL;
    }

    if(list.type==AUTOAE)
      autoae(iap, rap, par, icp, list.aelist.funi, list.aelist.stpnt, list.aelist.pvli, thl, thu, iuz, vuz);
    if(list.type==AUTOBV)
      autobv(iap, rap, par, icp, list.bvlist.funi, list.bvlist.bcni, 
	     list.bvlist.icni, list.bvlist.stpnt, list.bvlist.pvli, thl, thu, iuz, vuz);
     
    // Testing output
    if (Data->print_output)
        PrintOutput(Data);
     
#ifdef USAGE
    usage_end(total_usage,"total");

#endif
    //time_end(time0,"Total Time ",fp9);
    fprintf(fp9,"----------------------------------------------");
    fprintf(fp9,"----------------------------------------------\n");
    //time_end(time1,"",stdout);


  //}
  FREE(thu);
  FREE(iuz);
  FREE(vuz);
  fclose(fp9);

  // Clean up special solution points that were allocated and not used
  Data->sp = (AutoSPData *)REALLOC(Data->sp, (Data->num_sp)*sizeof(AutoSPData));
  assert(Data->sp);
  Data->sp_len = Data->num_sp;

  return 1;
} 
Ejemplo n.º 7
0
/* ------------------------------------------------------------------ run --- */
int MBASE::run()
{
	const int totalSamps = insamps + tapcount;
	int thisFrame = currentFrame();
	const int outChans = outputChannels();
	
	DBG1(printf("%s::run(): totalSamps = %d\n", name(), totalSamps));

	// this will return chunksamps' worth of input, even if we have
	// passed the end of the input (will produce zeros)

	getInput(thisFrame, framesToRun());

	DBG1(printf("getInput(%d, %d) called\n", thisFrame, framesToRun()));
	
	int bufsamps = getBufferSize();
	const int outputOffset = this->output_offset;
	
	// loop for required number of output samples
	const int frameCount = framesToRun();
	
	memset(this->outbuf, 0, frameCount * outChans * sizeof(BUFTYPE));
	
	int frame = 0;
	while (frame < frameCount) {
		// limit buffer size to end of current pull (chunksamps)
		if (frameCount - frame < bufsamps)
            bufsamps = max(0, frameCount - frame);

		thisFrame = currentFrame();	// store this locally for efficiency

		DBG1(printf("top of main loop: frame = %d  thisFrame = %d  bufsamps = %d\n",
                   frame, thisFrame, bufsamps));
		DBG(printf("input signal:\n"));
		DBG(PrintInput(&in[frame], bufsamps));
		
		// add signal to delay
		put_tap(thisFrame, &in[frame], bufsamps);

		// if processing input signal or flushing delay lines ... 

		if (thisFrame < totalSamps) {
			// limit buffer size of end of input data
			if (totalSamps - thisFrame < bufsamps)
				bufsamps = max(0, totalSamps - thisFrame);

			if ((tapcount = updatePosition(thisFrame)) < 0)
				RTExit(-1);

			DBG1(printf("  vector loop: bufsamps = %d\n", bufsamps));
			for (int ch = 0; ch < 2; ch++) {
				for (int path = 0; path < m_paths; path++) {
					Vector *vec = &m_vectors[ch][path];
					/* get delayed samps */
					get_tap(thisFrame, ch, path, bufsamps);
#if 0				
                    DBG(printf("signal [%d][%d] before filters:\n", ch, path));
					DBG(PrintSig(vec->Sig, bufsamps));
#endif
					/* air absorpt. filters */
         			air(vec->Sig, bufsamps, vec->Airdata);			
					/* wall absorpt. filters */
					if (path > 0)	// no filtering of direct signal
         				wall(vec->Sig, bufsamps, vec->Walldata);
					/* do binaural angle filters if necessary*/
					if (m_binaural)	{					
						fir(vec->Sig, thisFrame, g_Nterms[path], 
					    	vec->Fircoeffs, vec->Firtaps, bufsamps);
					}
                    DBG(printf("signal [%d][%d] before rvb:\n", ch, path));
                    DBG(PrintSig(vec->Sig, bufsamps));
//                    DBG(PrintSig(vec->Sig, bufsamps, SIG_THRESH));
		 		}
			}
			DBG(printf("summing vectors\n"));
			Vector *vec;
			register float *outptr = &this->outbuf[frame*outChans];
			// sum unscaled reflected paths as global input for RVB.
			for (int path = 0; path < m_paths; path++) {
				vec = &m_vectors[0][path];
				addScaleBufToOut(&outptr[2], vec->Sig, bufsamps, outChans, 1.0);
				vec = &m_vectors[1][path];
				addScaleBufToOut(&outptr[3], vec->Sig, bufsamps, outChans, 1.0);
			}
			if (!m_binaural) {
				// now do cardioid mike effect 
				// add scaled reflected paths to output as early response
				for (int path = 1; path < m_paths; path++) {
					vec = &m_vectors[0][path];
					addScaleBufToOut(&outptr[0], vec->Sig, bufsamps, outChans, vec->MikeAmp);
					vec = &m_vectors[1][path];
					addScaleBufToOut(&outptr[1], vec->Sig, bufsamps, outChans, vec->MikeAmp);
#if 0
					DBG(printf("early response L and R:\n"));
					DBG(PrintOutput(&outptr[0], bufsamps, outChans, SIG_THRESH));
					DBG(PrintOutput(&outptr[1], bufsamps, outChans, SIG_THRESH));
#endif
				}           
			}
			else {
           		// copy scaled, filtered reflected paths (reverb input) as the early reponse
				// to the output
				for (int ch = 0; ch < 2; ++ch) {
					float *dest = &outptr[ch];
					float *src = &outptr[ch+2];
					for (int n=0; n<bufsamps; ++n) {
						*dest = *src;
						dest += outChans;
						src += outChans;
					}
				}
			}
			/* add the direct signal into the output bus  */
			for (int n = 0; n < bufsamps; n++) {
				outptr[0] += m_vectors[0][0].Sig[n];
				outptr[1] += m_vectors[1][0].Sig[n];
				outptr += outChans;
			}
			DBG(printf("FINAL MIX LEFT CHAN:\n"));
			DBG(PrintOutput(&this->outbuf[frame*outChans], bufsamps, outChans));
		}		
		increment(bufsamps);
		frame += bufsamps;
		bufsamps = getBufferSize();		// update
		DBG1(printf("\tmain loop done.  thisFrame now %d\n", currentFrame()));
	}
	DBG1(printf("%s::run done\n\n", name()));
	return frame;
}
Ejemplo n.º 8
0
/* ------------------------------------------------------------------ run --- */
int BASE::run()
{
	int	i = 0;
	double roomsig[2][BUFLEN], rvbsig[2][BUFLEN];

	const int totalSamps = insamps + tapcount;

	const int frameCount = framesToRun();
	
	DBG1(printf("%s::run(): totalSamps = %d\n", name(), totalSamps));

	// this will return frameCount' worth of input, even if we have
	// passed the end of the input (will produce zeros)

	getInput(cursamp, frameCount);

	DBG1(printf("getInput(%d, %d) called\n", cursamp, frameCount));
	
	int bufsamps = getBufferSize();
	
	// loop for required number of output samples

	while (i < frameCount) {
		// limit buffer size to end of current pull (chunksamps)
		if (frameCount - i < bufsamps)
			bufsamps = max(0, frameCount - i);

		DBG1(printf("top of main loop: i = %d  cursamp = %d  bufsamps = %d\n",
				   i, cursamp, bufsamps));
		DBG(printf("input signal:\n"));
		DBG(PrintInput(&in[i], bufsamps));
		
		// add signal to delay
		put_tap(cursamp, &in[i], bufsamps);

		// if processing input signal or flushing delay lines ... 

		if (cursamp < totalSamps) {
			// limit buffer size of end of input data
			if (totalSamps - cursamp < bufsamps)
				bufsamps = max(0, totalSamps - cursamp);
			
			if ((tapcount = updatePosition(cursamp)) < 0)
				return PARAM_ERROR;

			DBG1(printf("  inner loop: bufsamps = %d\n", bufsamps));
		
			for (int ch = 0; ch < 2; ch++) {
				for (int path = 0; path < 13; path++) {
					Vector *vec = &m_vectors[ch][path];
					DBG(printf("vector[%d][%d]:\n", ch, path));
					/* get delayed samps */
					get_tap(cursamp, ch, path, bufsamps);
					DBG(PrintSig(vec->Sig, bufsamps));   
					/* air absorpt. filters */
		 				air(vec->Sig, bufsamps, vec->Airdata);			
					/* wall absorpt. filters */
					if (path > 0)	// no filtering of direct signal
		 				wall(vec->Sig, bufsamps, vec->Walldata);
					/* do binaural angle filters if necessary*/
					if (m_binaural)						
						fir(vec->Sig, cursamp, g_Nterms[path], 
							vec->Fircoeffs, vec->Firtaps, bufsamps);
		   				// sum unscaled reflected paths as input for RVB.
					// first path is set; the rest are summed
					if (path == 1)
						copyBuf(&roomsig[ch][0], vec->Sig, bufsamps);			 
					else if (path > 1)
						addBuf(&roomsig[ch][0], vec->Sig, bufsamps);			 
					/* now do cardioid mike effect if not binaural mode */
					if (!m_binaural)
						scale(vec->Sig, bufsamps, vec->MikeAmp);
					DBG(printf("after final scale before rvb:\n"));
					DBG(PrintSig(vec->Sig, bufsamps, 0.1));
		 		}
				/* scale reverb input by amp factor */
				scale(&roomsig[ch][0], bufsamps, m_rvbamp);
			}
			/* run 1st and 2nd generation paths through reverberator */
 			for (int n = 0; n < bufsamps; n++) {
				if (m_rvbamp != 0.0) {
					double rmPair[2];
					double rvbPair[2];
					rmPair[0] = roomsig[0][n];
					rmPair[1] = roomsig[1][n];
					RVB(rmPair, rvbPair, cursamp + n);
					rvbsig[0][n] = rvbPair[0];
					rvbsig[1][n] = rvbPair[1];
				}
				else
					rvbsig[0][n] = rvbsig[1][n] = 0.0;
			}
			DBG(printf("summing vectors\n"));
			if (!m_binaural) {
		   		// re-sum scaled direct and reflected paths as early response
				// first path is set; the rest are summed
				for (int path = 0; path < 13; path++) {
					if (path == 0) {
						copyBuf(&roomsig[0][0], m_vectors[0][path].Sig, bufsamps);
						copyBuf(&roomsig[1][0], m_vectors[1][path].Sig, bufsamps);
					}		   
					else {
						addBuf(&roomsig[0][0], m_vectors[0][path].Sig, bufsamps);
						addBuf(&roomsig[1][0], m_vectors[1][path].Sig, bufsamps);
					}
				}		  
			}
			DBG(printf("left signal:\n"));
			DBG(PrintSig(roomsig[0], bufsamps, 0.1));
			DBG(printf("right signal:\n"));
			DBG(PrintSig(roomsig[1], bufsamps, 0.1));
			/* sum the early response & reverbed sigs  */
			register float *outptr = &this->outbuf[i*2];
			for (int n = 0; n < bufsamps; n++) {
				*outptr++ = roomsig[0][n] + rvbsig[0][n];
				*outptr++ = roomsig[1][n] + rvbsig[1][n];
			}
			DBG(printf("FINAL MIX:\n"));
			DBG(PrintInput(&this->outbuf[i], bufsamps));
		}

		else {		 /* flushing reverb */
			// this is the current location in the main output buffer
			// to write to now
			register float *outptr = &this->outbuf[i*2];
			DBG1(printf("  flushing reverb: i = %d, bufsamps = %d\n", i, bufsamps));
			for (int n = 0; n < bufsamps; n++) {
				if (m_rvbamp > 0.0) {
					double rmPair[2];
					double rvbPair[2];
					rmPair[0] = 0.0;
					rmPair[1] = 0.0;
					RVB(rmPair, rvbPair, cursamp + n);
					*outptr++ = rvbPair[0];
					*outptr++ = rvbPair[1];
				}
				else {
					*outptr++ = 0.0;
					*outptr++ = 0.0;
				}
			}
		}
		cursamp += bufsamps;
		i += bufsamps;
		bufsamps = getBufferSize();		// update
	}
	DBG1(printf("%s::run done\n\n", name()));
	return i;
}