Example #1
0
int main() 
{

  double theta = 0.3*PI, phi = 1.2*PI, nofbin = 256, offset = 0.;
  double L = 50, d = 5;

  double *cA = (double*)malloc(nofbin*sizeof(double));
  double *cB = (double*)malloc(nofbin*sizeof(double));
  double *cC = (double*)malloc(nofbin*sizeof(double));
  double *cD = (double*)malloc(nofbin*sizeof(double));
  double *cE = (double*)malloc(nofbin*sizeof(double));
  
  FILE* file = fopen("20mod.txt","w+");
  for(int i=0; i<nofbin; i++){
    *(cA+i) = sawtooth(PI*L/d*tan(theta)*cos(i*2*PI/nofbin-phi)+offset*PI,PI);
    *(cB+i) = sawtooth(PI*L/d*tan(theta)*cos(i*2*PI/nofbin-phi)+(offset+1)*PI,PI);
    *(cC+i) = sawtooth(PI*L/d*tan(theta)*cos(i*2*PI/nofbin-phi)+(offset+2)*PI,PI);
    *(cD+i) = sawtooth(PI*L/d*tan(theta)*cos(i*2*PI/nofbin-phi)+(offset+3)*PI,PI);
    *(cE+i) = sawtooth(PI*L/d*tan(theta)*cos(i*2*PI/nofbin-phi)+(offset+4)*PI,PI);

    fprintf(file,"%f %f %f %f %f\n",*(cA+i),*(cB+i),*(cC+i),*(cD+i),*(cE+i));
  }
  fclose(file);

  system("./20mod.py");

  return 0;
}
Example #2
0
File: song.c Project: fvdsn/tuned
fun_t *cool_sound(fun_t *freq, fun_t *envelope, int pos, float vol){
	fun_t *freq8 = mult(freq,c(8)); //original cool noise freq is 55
	fun_t *freq54 = mult(freq,c(0.545454));
	fun_t *f = add(mult(sine(freq8,0,0.2),add(sawtooth(freq,add(c(4.0),sawtooth(c(1),c(1),0,2.0)),0,0.5),c(0.5))),
			square(freq54,add(sine(c(0.5),0,0.3),c(0.4)),0,0.2));
	f = mult(envelope,f);
	f = fdelay(c(pos),f);
	f =   mult(c(vol),f);
	return f;
}
Example #3
0
static int
process (jack_nframes_t  nframes,
         void           *arg)
{
  state *data = arg;

  jack_sample_t *sine_buffer     = jack_port_get_buffer (data->sine_port,     nframes);
  jack_sample_t *square_buffer   = jack_port_get_buffer (data->square_port,   nframes);
  jack_sample_t *triangle_buffer = jack_port_get_buffer (data->triangle_port, nframes);
  jack_sample_t *sawtooth_buffer = jack_port_get_buffer (data->sawtooth_port, nframes);

  double period = data->sample_rate / data->frequency;

  int i;

  for (i = 0; i < nframes; i++)
  {
    double current_position = (data->current_block * nframes + i) / period;

    sine_buffer[i]     = sine     (current_position);
    square_buffer[i]   = square   (current_position);
    triangle_buffer[i] = triangle (current_position);
    sawtooth_buffer[i] = sawtooth (current_position);
  }

  data->current_block++;

  return 0;
}
Example #4
0
void Generator::process()
{
    ISignalChain* chain = signalChain();
    float dt = chain->timeStep();
    float f = m_pInputFreq->value();
    float dPhase = f * dt;

    float out = 0.0;
    switch (m_waveform) {
    case 0:
        out = sin(m_phase * 2 * M_PI);
        break;
    case 1:
        out = m_bandlimit ? blep_sawtooth(m_phase, dPhase) : sawtooth(m_phase);
        break;
    case 2:
        out = m_bandlimit ? blep_square(m_phase, dPhase) : square(m_phase);
        break;
    case 3:
        out = m_bandlimit ? bpl_triangle(m_phase, dPhase) : triangle(m_phase);
        break;
    default:
        break;
    }

    m_phase = fmod(m_phase + dPhase, 1.0);

    m_pOutput->setValue(out);
}
Example #5
0
ControlWidget::ControlWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ControlWidget)
{
    ui->setupUi(this);
    connect(ui->pushButton_add, SIGNAL(clicked()), this, SLOT(addSineWave()));
    connect(ui->pushButton_clear, SIGNAL(clicked()), this, SIGNAL(signalClear()));
    connect(ui->pushButton_step, SIGNAL(clicked()), this, SIGNAL(signalStep()));
    connect(ui->pushButton_control, SIGNAL(clicked()), this, SLOT(pauseResume()));
    connect(ui->pushButton_squareWave, SIGNAL(clicked()), this, SLOT(square()));
    connect(ui->pushButton_sawtooth, SIGNAL(clicked()), this, SLOT(sawtooth()));
}
Example #6
0
/**
 * @brief Set up the initial guess and sawtooth boundary
 * @param cart_comm the cartesian communicator for the processes
 * @param rank the rank of the process calling the function
 * @param img_dim the dimensions of the local and global data
 * @param old array to make the initial guess in and to calculate sawtooth
 */
void setup_reconstruct (MPI_Comm cart_comm, int rank, image_dimensions img_dim, real ** old){
    int i, j;

    /* set initial guess to white (255), including halos */
    for (i = 0; i < (img_dim.mp + 2); i++) {
        for (j = 0; j < (img_dim.np + 2); j++) {
            old[i][j] = 255.0;
        }
    }
    /* calculate the sawtooth halos */
    sawtooth(cart_comm, rank, img_dim, old);
}
    double CImplicitTriangle::get(double x, double y, double z, double w, double u, double v)
    {
        double val=m_source.get(x,y,z,w,u,v);
        double period=m_period.get(x,y,z,w,u,v);
        double offset=m_offset.get(x,y,z,w,u,v);

        if (offset>=1) return sawtooth(val, period);
        else if (offset<=0) return 1.0-sawtooth(val, period);
        else
        {
            double s1=(offset-sawtooth(val,period))>=0 ? 1.0 : 0.0;
            double s2=((1.0-offset)-(sawtooth(-val,period)))>=0 ? 1.0 : 0.0;
            return sawtooth(val,period) * s1/offset + sawtooth(-val,period)*s2/(1.0-offset);
        }
    }
Example #8
0
static void generate_wave(Waveform type, float *buf, size_t samples, double t,
   float frequency, float phase)
{
   switch (type) {
      case WAVEFORM_NONE:
         for (unsigned i = 0; i < samples; i++) {
            buf[i] = 0.0;
         }
         break;
      case WAVEFORM_SINE:
         sine(buf, samples, t, frequency, phase);
         break;
      case WAVEFORM_SQUARE:
         square(buf, samples, t, frequency, phase);
         break;
      case WAVEFORM_TRIANGLE:
         triangle(buf, samples, t, frequency, phase);
         break;
      case WAVEFORM_SAWTOOTH:
         sawtooth(buf, samples, t, frequency, phase);
         break;
   }
}
unsigned char frequencyrange(void)
{
unsigned char m;// represent adc convert value
unsigned int f;// represent frequency 
char msg1[16] =  "   START NOW?  ";//LCD LINE 1 message
char msg2[16] =  "  PRESS ANYKEY ";// LCD line 2 message
LCD_Reset();// initiliaze LCD

sprintf(msg1,"  Please choose  ");// chose frequency message
LCD_Line1(msg1);
sprintf(msg2,"Frequency");
LCD_Line2(msg2);
Delay10KTCYx(250);// delay 0.25s
Delay10KTCYx(250);//delay 0.25s
Delay10KTCYx(250);// delay0.25s
Delay10KTCYx(250);//delay0.25s



LCD_Reset();// initialize lCD
		switch(bo)
	{
		case 1:	
								do
								{
								sprintf(msg1,"Range:11~2277 Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// ADC convert value
								if (m==0) m=1;// let the least ADC value is 1 
								f=(unsigned int)1/(1/12600+m*0.00035+0.000089);;// caculate sine wave frequency
								if ((m<=60)&&(m>=30))f=f-1;// slightly adjust frequency
								if ((m<=20)&&(m>=10))f=f-4;// slightly adjust frequency
								if ((m>5)&&(m<10) )f=f-5;// slightly adjust frequency
								if(m==5) f=f-6;// slightly adjust frequency
								if(m==4) f=f-7;// slightly adjust frequency
								if(m==3) f=f-7;// slightly adjust frequency
								if (m==2) f=f+13;// slightly adjust frequency 
								sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
if (SWITCH_1==0)
{
switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }
								}
								while(SWITCH_0 == 1);
							    switch_release();//wait for RB0 release
								sinewave(m);//output sine wave
							    switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
	    break;
		case 2:
								do
								{
									sprintf(msg1,"Range:6~581 Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// ADC convert value
								if (m==0) m=1;// let the least ADC value is 1 
							 	f=(unsigned int) 1/ (1/847 + m*0.00057+0.001230); //caculate and slightly adjust triangle wave frequency
								if (m==1) f=f+26;//caculate and slightly adjust triangle wave frequency
								if (m==2) f=f+20;//caculate and slightly adjust triangle wave frequency
								if (m==3) f=f+12;//caculate and slightly adjust triangle wave frequency
								if (m==4) f=f+10;//caculate and slightly adjust triangle wave frequency
								if (m==5) f=f+7;//caculate and slightly adjust triangle wave frequency
								if ((m>=6)&&(m<=8)) f=f+5;//caculate and slightly adjust triangle wave frequency
								if (m==9) f=f+4;//caculate and slightly adjust triangle wave frequency
								if ((m>=10)&& (m<=13)) f=f+3;//caculate and slightly adjust triangle wave frequency
								if ((m>=13)&&(m<=17)) f=f+2;//caculate and slightly adjust triangle wave frequency
								if ((m>=18)&&(m<=50)) f=f+1;//caculate and slightly adjust triangle wave frequency
							sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
if (SWITCH_1==0)
{
	switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }
								}
								while(SWITCH_0 == 1);
								switch_release();//wait for RB0 release
								triwave(m);// output triangle wave
								switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
		break;
		case 3:
								do
								{
								sprintf(msg1,"Range:5~676 Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// ADC convert value
								if (m<=1) m=2;// let the least ADC value is 2
							 	f=(unsigned int) 1/ (1/15600 + m*0.000709+0.00007);//caculate  sawtooth wave frequency
								if ((m==2)||(m==3)) f=f+4;//caculate and slightly adjust sawtooth wave frequency
								if (m==4) f=f+1;//caculate and slightly adjust sawtooth wave frequency
							sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
							
if (SWITCH_1==0)
{
	switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }								
								}
								while(SWITCH_0 == 1);
								switch_release();//wait for RB0 release
								sawtooth(m);//output sawtooth wave
								switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
		break;
		case 4:
								do
								{
								sprintf(msg1,"Range:102~7690Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// adc convert value
								if (m==0) m=1;// let the least ADC value is 1
							 if ((m>=140)&&(m<=255)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-0.5;//caculate and slightly adjust square wave frequency
							 if ((m>=101)&&(m<=139)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-1.5;//caculate and slightly adjust square wave frequency
							if ((m>=70)&&(m<=100)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-2.5;//caculate and slightly adjust square wave frequency
							if ((m>=64)&&(m<=69)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-3.5;//caculate and slightly adjust square wave frequency
							if ((m>=55)&&(m<=63)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-4.5;//caculate and slightly adjust square wave frequency
							if ((m>=46)&&(m<=54)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-5.5;//caculate and slightly adjust square wave frequency
							if ((m>=45)&&(m<=43)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-6.5;//caculate and slightly adjust square wave frequency
							if ((m>=40)&&(m<=42)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-7.5;//caculate and slightly adjust square wave frequency
							if ((m>=30)&&(m<=40)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-9.5;//caculate and slightly adjust square wave frequency
							if ((m>=20)&&(m<=29)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-11.5;//caculate and slightly adjust square wave frequency
							if ((m>=10)&&(m<=19)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-2.5*m;//caculate and slightly adjust square wave frequency
							if (m==10) f=2131;//caculate and slightly adjust square wave frequency
							if (m==9) f=2313;//caculate and slightly adjust square wave frequency
							if (m==8) f=2540;//caculate and slightly adjust square wave frequency
							if (m==7) f=2810;//caculate and slightly adjust square wave frequency
							if (m==6) f=3140;//caculate and slightly adjust square wave frequency
							if (m==5) f=3570;//caculate and slightly adjust square wave frequency
							if (m==4) f=4130;//caculate and slightly adjust square wave frequency
							if (m==3) f=4900;//caculate and slightly adjust square wave frequency
							if (m==2) f=6020;//caculate and slightly adjust square wave frequency
							if (m==1) f=7690;	//caculate and slightly adjust square wave frequency
							sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
if (SWITCH_1==0)
{
	switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }									
								}
								while(SWITCH_0 == 1);
								switch_release();//wait for RB0 release
								squarewave(m);//output square wave
								switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
		break;
        default: 
		break;
	}

}
Example #10
0
int main() 
{
  //initial definition
  double nofphot,nofbins,probint,offset,theta,phi,L,d,noise;

  //initial parameters
  nofphot = 1000.; nofbins = 256; probint = 0.05; L = 50; d = 5;  offset = 0.5;
  theta = 0.3*PI; phi = 1.2*PI; noise = 10.;

  //other calculations and variable definitions
  nofphot *= 0.4;
  noise *= nofphot;
  double PIL_over_d = PI*L/d;
  double var = nofphot/nofbins;
  double var_n = noise/nofbins;
  int dim = 1/probint;
  double* prob = (double*) malloc(100*sizeof(double));
  double* prob_n = (double*) malloc(100*sizeof(double));
  int* randphot = (int*) malloc(nofbins*sizeof(int));
  int* randphot_n = (int*) malloc(nofbins*sizeof(int));
  int** count = (int**) calloc(5,sizeof(int*));
  for (int i=0; i<5; i++){count[i] = (int*) calloc(nofbins,sizeof(int));}
  double* rate = (double*) malloc(4*sizeof(double));
  double rnd;

  double check; 
  prob[0] = exp(-var); prob_n[0] = exp(-var_n);
  for(int i=0; i<100; i++){
    prob[i+1] = prob[i] + exp(-var)*pow(var,i+1)/factorial(i+1);
    prob_n[i+1] = prob_n[i] + exp(-var_n)*pow(var_n,i+1)/factorial(i+1);
  }
  for(int i=0; i<nofbins; i++){
    rnd = (double)rand()/RAND_MAX;
    for (int j=0; j<100; j++){
      check=prob[j];
      if(rnd < check){
	randphot[i] = j;  
	break;
      }
    }
    rnd = (double)rand()/RAND_MAX;
    for (int j=0; j<100; j++){
      check=prob_n[j];
      if(rnd < check){
	randphot_n[i] = j;  
	break;
      }
    }
  }
  for(int i=0; i<nofbins; i++){
    rate[0] = sawtooth(PIL_over_d*tan(theta)*cos(i*2*PI/nofbins-phi)+offset*PI,PI);
    rate[1] = rate[0] + sawtooth(PIL_over_d*tan(theta)*cos(i*2*PI/nofbins-phi)+(offset+1)*PI,PI);
    rate[2] = rate[1] + sawtooth(PIL_over_d*tan(theta)*cos(i*2*PI/nofbins-phi)+(offset+2)*PI,PI);
    rate[3] = rate[2] + sawtooth(PIL_over_d*tan(theta)*cos(i*2*PI/nofbins-phi)+(offset+3)*PI,PI);

    for(int j=0; j<200; j++){
      if(j==randphot[i]){
	break;
      }
      rnd = (double)rand()/RAND_MAX*2;
      if(rnd < rate[0]){
	count[0][i] += 1;
      } else if (rnd < rate[1]){
	count[1][i] += 1;
      } else if (rnd < rate[2]){
	count[2][i] += 1;
      } else if (rnd < rate[3]){
	count[3][i] += 1;
      } else {
	count[4][i] += 1;
      }
    }
    for(int j=0; j<200; j++){
      if(j==randphot_n[i]){
	break;
      }
      rnd = (double)rand()/RAND_MAX*5;
      count[(int)rnd][i] += 1;
    }
  }
  
  FILE* file;
  file = fopen("2-20real.txt","w+");
  for(int i=0; i<nofbins; i++){
    fprintf(file,"%d %d %d %d %d\n",count[0][i],count[1][i],count[2][i],count[3][i],count[4][i]);
  }  
  fclose(file);

  system("./2-20real.py");

  return 0;
}
Example #11
0
// Native triangle waveform generator
float triangle(float phase)
{
    return 2.0f * fabs(sawtooth(phase)) - 1.0f;
}
Example #12
0
// Poly-BLEP sawtooth
float blep_sawtooth(float phase, float dt)
{
    return sawtooth(phase) - poly_blep(phase, dt);
}
Example #13
0
int main()
{
  
  const double nofgrid = 256;
  const double nofbin = 256;

  double max_angle, L, d, offset;
  max_angle = PI/3; L = 50; d = 5; offset = 0.5;
  FILE* file;
  char fname[][10] = {"A.txt","B.txt"};
  float real_w[(int)nofbin][2]; float real_obs[(int)nofbin][2];
  double theta[(int)nofgrid][(int)nofgrid]; double phi[(int)nofgrid][(int)nofgrid];
  double sum[(int)nofbin];
  double max,min;
  double sc_fact[(int)nofgrid][(int)nofgrid];
  double ***model = (double***)malloc(nofgrid*sizeof(double**));
  for(int i=0; i<nofgrid; i++){
    model[i]=(double**)malloc(nofgrid*sizeof(double*));
    for(int j=0; j<nofbin; j++){
      model[i][j]=(double*)malloc(nofbin*sizeof(double));
    }
  }

  double k = PI*L/d;

  for (int i=0; i<nofgrid; i++){
    for (int j=0; j<nofgrid; j++){
      double posx = (i-nofgrid*0.5)*L*tan(max_angle)/(nofgrid*0.5)+L*tan(max_angle)/(nofgrid*0.5);
      double posy = (j-nofgrid*0.5)*L*tan(max_angle)/(nofgrid*0.5)+L*tan(max_angle)/(nofgrid*0.5);
      theta[i][j] = atan(sqrt((posx*posx+posy*posy)/(L*L)));
      if(posx < 0 && posy > 0){
	phi[i][j] = atan(posy/posx) + PI;
      }else if(posx < 0 && posy < 0){
	phi[i][j] = atan(posy/posx) - PI;
      } else {
	phi[i][j] = atan(posy/posx);
      }
    }
  }

  sum[0] = 0; sum[1] = 0;
  file = fopen("50real.txt","r");
  int ctr = 0;
  for (int i=0; i<nofbin; i++){
    fscanf(file,"%f %f\n",*(real_w+i),*(real_w+i)+1);
    sum[0] += **(real_w+i);
    sum[1] += *(*(real_w+i)+1);
  }
  fclose(file);
  for (int i=0; i<nofbin; i++){
    real_obs[i][0] = real_w[i][0] - sum[0]/nofbin;
    real_obs[i][1] = real_w[i][1] - sum[1]/nofbin;
  }

  for(int q=0; q<2; q++){
    for(int i=0; i<nofbin; i++){
      sum[i] = 0;
    }
    for(int i=0; i<nofgrid; i++){
      for(int j=0; j<nofgrid; j++){
	for(int l=0; l<nofbin; l++){
	  model[i][j][l] = sawtooth(k*tan(theta[i][j])*cos(l*2*PI/256.-phi[i][j])+(offset+q)*PI,PI);
	  sum[l] = sum[l] + model[i][j][l];
	}
      }
    }
    for(int i=0; i<nofgrid; i++){
      for(int j=0; j<nofgrid; j++){
	for(int l=0; l<nofbin; l++){
	model[i][j][l] = model[i][j][l] - sum[l]/nofbin;
	}
      }
    }
    
    file = fopen(fname[q],"w+");
    for(int i=0; i<nofgrid; i++){
      for(int j=0; j<nofgrid; j++){
	sc_fact[i][j] = 0;
      }
    }
    for(int i=0; i<nofgrid; i++){
      for(int j=0; j<nofgrid; j++){
	for(int l=0; l<nofbin; l++){
	  sc_fact[i][j] = sc_fact[i][j] + real_w[l][q]*real_obs[l][q]*model[i][j][l];
	}
	if(i==0 && j==0){
	  max = sc_fact[i][j];
	  min = sc_fact[i][j];
	} else {
	  if(sc_fact[i][j] > max){max = sc_fact[i][j];}
	  if(sc_fact[i][j] < min){min = sc_fact[i][j];}
	}
      }
    }
    for(int i=0; i<nofgrid; i++){
      for(int j=0; j<nofgrid; j++){
	fprintf(file,"%f ",2*(sc_fact[i][j]-min)/(max-min)-1);
      }
      fprintf(file,"\n");
    }
    fclose(file);
  }
}
Example #14
0
void validateFourSortBT() {  // validation on the Bentley bench test against heapsort
  printf("Entering validateFourSortBT Sawtooth ........\n");
  // printf("Entering validateFourSortBT Rand2 ........\n");
  // printf("Entering validateFourSortBT Plateau ........\n");
  // printf("Entering validateFourSortBT Shuffle ........\n");
  // printf("Entering validateFourSortBT Stagger ........\n");
  int sortcBTime, cut2Time, T;
  int seed =  666;
  int z;
  int siz = 1024*1024;
  // int limit = 1024 * 1024 * 16 + 1;
  // int seedLimit = 32 * 1024;
  int limit = siz + 1;
  // int seedLimit = 32;
  int seedLimit = 1;
  float frac;
  while (siz <= limit) {
    printf("%s %d %s %d %s", "siz: ", siz, " seedLimit: ", seedLimit, "\n");
    // int A[siz];
    struct intval *pi;
    void **A = myMalloc("compareAlgorithms0 1", sizeof(pi) * siz);
    void **B = myMalloc("compareAlgorithms0 3", sizeof(pi) * siz);
    // construct array
    int i;
    for (i = 0; i < siz; i++) {
      pi = myMalloc("compareAlgorithms0 2", sizeof (struct intval));
      A[i] = pi;
      pi = myMalloc("compareAlgorithms0 4", sizeof (struct intval));
      B[i] = pi;
    };
    // warm up the process
    fillarray(A, siz, seed);
    int TFill, m, tweak;
    int sortcBCnt, cut2Cnt; // , sortcBCntx, cut2Cntx;
    int sumQsortB, sumCut2; // , sumQsortBx, sumCut2x;
    // for (z = 0; z < 3; z++) { // repeat to check stability
    for (z = 0; z < 1; z++) { // repeat to check stability
      sortcBCnt = cut2Cnt = sumQsortB = sumCut2 = 0;
      // sortcBCntx = cut2Cntx = sumQsortBx = sumCut2x = 0;
      for (m = 1; m < 2 * siz; m = m * 2) {
      // m = 1024 * 1024; {
      // m = 1; {
      	for (tweak = 0; tweak <= 5; tweak++ ) {
	// tweak = 5; {
	  sortcBTime = 0; cut2Time = 0;
	  TFill = clock();
	  for (seed = 0; seed < seedLimit; seed++) 
	    sawtooth(A, siz, m, tweak);
	    // rand2(A, siz, m, tweak, seed);
	    // plateau(A, siz, m, tweak);
	    // shuffle(A, siz, m, tweak, seed);
	    // stagger(A, siz, m, tweak);
	  TFill = clock() - TFill;
	  T = clock();
	  for (seed = 0; seed < seedLimit; seed++) { 
	    sawtooth(A, siz, m, tweak);
	    // rand2(A, siz, m, tweak, seed);
	    // plateau(A, siz, m, tweak);
	    // shuffle(A, siz, m, tweak, seed);
	    // stagger(A, siz, m, tweak);
	    callHeapSort(A, siz, compareIntVal);
	  }
	  sortcBTime = sortcBTime + clock() - T - TFill;
	  sumQsortB += sortcBTime;
	  // if ( 4 != tweak ) sumQsortBx += sortcBTime;
	  T = clock();
	  for (seed = 0; seed < seedLimit; seed++) { 
	    sawtooth(B, siz, m, tweak);
	    // rand2(B, siz, m, tweak, seed);
	    // plateau(B, siz, m, tweak);
	    // shuffle(B, siz, m, tweak, seed);
	    // stagger(B, siz, m, tweak);
	    foursort(B, siz, compareIntVal, NUMTHREADS);  
	  }
	  cut2Time = cut2Time + clock() - T - TFill;
	  sumCut2 += cut2Time;
	  // if ( 4 != tweak ) sumCut2x += cut2Time;
	  printf("Size: %d m: %d tweak: %d ", siz, m, tweak);
	  printf("sortcBTime: %d ", sortcBTime);
	  printf("Cut2Time: %d ", cut2Time);
	  frac = 0;
	  if ( sortcBTime != 0 ) frac = cut2Time / ( 1.0 * sortcBTime );
	  printf("frac: %f \n", frac);
	  if ( sortcBTime < cut2Time ) sortcBCnt++;
	  else cut2Cnt++;
	  for (i = 0; i < siz; i++) {
	    if ( compareIntVal(A[i], B[i]) != 0 ) {
	      printf("***** validateFourSortBT m: %i tweak: %i at i: %i\n", 
		     m, tweak, i);
	      exit(0);
	    }
	  }
	}
	printf("sumQsortB:   %i sumCut2:  %i frac: %f", 
	       sumQsortB, sumCut2, (sumCut2/(1.0 * sumQsortB)));
	printf(" sortcBCnt:  %i cut2Cnt:  %i\n", sortcBCnt, cut2Cnt);
      }
      frac = 0;
      if ( sumQsortB != 0 ) frac = sumCut2 / ( 1.0 * sumQsortB );
      printf("Measurements:\n");
      printf("sumQsortB:   %i sumCut2:  %i frac: %f", 
	     sumQsortB, sumCut2, (sumCut2/(1.0 * sumQsortB)));
      printf(" sortcBCnt:  %i cut2Cnt:  %i\n", sortcBCnt, cut2Cnt);
      // printf("sumQsortBx:  %i sumCut2x: %i", sumQsortBx, sumCut2x);
      // printf(" sortcBCntx: %i cut2Cntx: %i\n", sortcBCntx, cut2Cntx);

    }
    // free array
    for (i = 0; i < siz; i++) {
      free(A[i]); free(B[i]);
    };
    free(A); free(B);
    siz = siz * 2;
    seedLimit = seedLimit / 2;
  }
} // end validateFourSortBT