Exemplo n.º 1
0
void ofApp::loadSounds() {
	sounds.clear();
	ofxXmlSettings xml;
	xml.loadFile("sounds.xml");
	int n = xml.getNumTags("sound");
	for(int i = 0; i < n; i++) {
		Pulse cur;
		xml.pushTag("sound", i);
		cur.load(xml);
		xml.popTag();
		sounds.push_back(cur);
	}
}
Exemplo n.º 2
0
bool Fluid::ApplyPulse(const Pulse& pulse, View2f* velocities) const {
  if (pulse.HasEnergy()) {
    AddForces(pulse.position, pulse.direction, pulse.sigma, pulse.amplitude, velocities);
    return true;
  }
  return false;
}
Exemplo n.º 3
0
void init(std::string const& out_file)
{
  initHist(out_file);
  
  // intime sample is [2]
  double pulseShapeTemplate[NSAMPLES+2];
  for(int i=0; i<(NSAMPLES+2); i++){
    
//     iwf/4. - (500 / 2) + 25. 
//     double x = double( IDSTART + NFREQ * (i + 3) - WFLENGTH / 2);
//     double x = double( IDSTART + NFREQ * (i + 3) - WFLENGTH / 2);
//     double x = double( IDSTART + NFREQ * (i + 3) - 500 / 2); //----> 500 ns is fixed!  
    //     x = double( IDSTART + NFREQ * i + 3*25. - 500 / 2. );  //----> 500 ns is fixed!  
    
    double x = double( IDSTART + NFREQ * (i + 3) + NFREQ - 500 / 2); //----> 500 ns is fixed!  
    
    
    pulseShapeTemplate[i] = pSh.fShape(x);
    std::cout << " >>  pulseShapeTemplate[" << i << "] " <<  pulseShapeTemplate[i] << " at x = " << x << std::endl;
    
  }
  //  for(int i=0; i<(NSAMPLES+2); i++) pulseShapeTemplate[i] /= pulseShapeTemplate[2];
  for (int i=0; i<(NSAMPLES+2); ++i) fullpulse(i+7) = pulseShapeTemplate[i];
  
  
  for (int i=0; i<NSAMPLES; ++i) {
    for (int j=0; j<NSAMPLES; ++j) {
      int vidx = std::abs(j-i);
      noisecor(i,j) = pSh.corr(vidx);
    }
  }
  
  int activeBXs[] = { -5, -4, -3, -2, -1,  0,  1,  2,  3,  4 };
  activeBX.resize(10);
  for (unsigned int ibx=0; ibx<10; ++ibx) {
    activeBX.coeffRef(ibx) = activeBXs[ibx];
  } 
  //  activeBX.resize(1);
  //  activeBX.coeffRef(0) = 0;
}
Exemplo n.º 4
0
void play(double &left, double &right) {
	if (count%(int)(SAMPLE_RATE*1.6)==0) {
		kick_freq.reset();
		env_kick.reset();
	}
	if (count%(int)(SAMPLE_RATE*6.4)==0) {
		env_bass.reset();
		bass_freq.reset();
		bass2_freq.reset();
	}
	left += kick.freq(kick_freq.val()).val() * env_kick.val() * 0.3;
	left += fil_bass.io( bass.freq(bass_freq.val()).val() + bass2.freq(bass2_freq.val()).val() ) * env_bass.val() * 0.3;

	if (count%(int)(SAMPLE_RATE*25.6)==0) {
		for (int i = 0; i < 8; i++) {
			s0_freq[i] = rand()%5000+500;
		}
	}
	if (count%(int)(SAMPLE_RATE*3.2)==0) {
		s0_fade.reset();
	}
	if (count%(int)(SAMPLE_RATE*0.1)==0) {
		if (s0_i > 7) s0_i = 0;
		s0.freq(s0_freq[s0_i++]);
		env_s0.reset();

		if (rand()%4==0) {
			env_s1.reset();
		}
	}
	left += s0.val() * env_s0.val() * s0_fade.val() * 0.1;
	left += s1.val() * env_s1.val() * 0.05;

	for (int n = 0; n < num; n++) {
		if (ars[n].done()) {
			sines[n].freq(rand()%1000+100);
			ars[n].set(0, 1, rand()%1000*0.01, 0, rand()%1000*0.01);
		}
	}
	for (int n = 0; n < num; n++) {
		left += sines[n].val() * ars[n].val() * 0.02;
	}
	right = left;
}
Exemplo n.º 5
0
double funcPulseShape( double *x, double *par )
{
  double t = x[0] - par[0];
  return par[1] + par[2] * pSh.fShape(t);
}
void runbenchmark(const vector<int>& Ls, const Pulse& tx, function<Estimator(vector<int>&,vector<int>&,vector<complex<double>>&)> estf, string name) {

  default_random_engine generator; 
      //SNRs
  double SNRdB = 10.0;
  double SNR = pow(10.0, SNRdB/10.0);
  normal_distribution<double> noise(0.0,T/Ts/SNR/2);
  uniform_int_distribution<int> unifM(1, M); //for generating M-PSK symbols
  
  vector<double> times; //array to store output
  
  for(auto L : Ls) {

    const unsigned int numpilots = L/5; //about 10% pilots 
    //symbol position setup
    vector<int> P;
    for(int i = 0; i < numpilots; i++) P.push_back(i); //pilots at the front
    vector<int> D;
    for(int i = numpilots; i < L; i++) D.push_back(i); //data at the back
    vector<complex<double>> s;
    for (int m = 1; m <= L; m++) s.push_back(polar<double>(1.0, 2 * pi * unifM(generator) / M));
    vector<complex<double>> pilots;
    for (int m = 0; m < numpilots; m++) pilots.push_back(s[m]);

    //construct the estimator we will run
    Estimator est = estf(P,D,pilots);
   
    //number of samples
    unsigned int N = (unsigned int) ceil((T*(L+40)+taumax)/Ts); //number of samples
    const complex<double> a0 = polar<double>(1,0.1*pi); //phase and amplitude
    
    //transmitted signal
    auto x = [&s,&tx,T,L] (double t) {
      int mini = max(1, (int)ceil((t - tx.tmax())/T));
      int maxi = min(L, (int)floor((t - tx.tmin())/T));
      complex<double> sum(0,0);
      for(int i = mini; i <= maxi; i++) sum += s[i-1] * tx.pulse(t - i*T);
      return sum;
    };

    //sampled received signal
    vector<complex<double>> r;
    for(int n = 1; n <= N; n++) r.push_back(a0*x(n*Ts-tau0) + complex<double>(noise(generator), noise(generator)));

    cout << "Benchmarking " << name << " L = " << L << " ... ";
    long iters = 0;
    double errmse = 0.0;
    clock_t started = clock();
    while( ((double)(clock() - started))/CLOCKS_PER_SEC < benchtime) {
      double tauhat = est.estimate(r);
      errmse += (tauhat - tau0)*(tauhat - tau0); //use tauhat otherwise it might get compiled out!
      iters++;
    }
    clock_t stopped = clock();
    double microsecs = ((double)(stopped - started))/CLOCKS_PER_SEC/iters/L*1000000;
    times.push_back(microsecs);
    cout << " requires  " << microsecs << " microseconds per symbol with average error " << (errmse/iters) << endl;
  }

  ofstream file(string("data/") + name + string("bench"));
  for(int i = 0; i < Ls.size(); i++) file << Ls[i] << "\t" << times[i] << endl;
  file.close();

}