コード例 #1
1
ファイル: apf.c プロジェクト: arulk77/gpu.evrc
void    apf(short *in, short *coeff, short *out, long delayi, short alpha,
	    short beta, short u, short agc, short ltgain, short order, short length, short br)
{

	static int FirstTime = 1;

	static short FIRmem[ORDER];	/* FIR filter memory */
	static short IIRmem[ORDER];	/* IIR filter memory */
	static short last;
	static short Residual[ACBMemSize + SubFrameSize];	/* local residual */

	short   wcoef1[ORDER];
	short   wcoef2[ORDER];
	short   scratch[SubFrameSize];
	short   temp[SubFrameSize];
	short   mem[ORDER];
	long	sum1, sum2;
	long    gamma, APFgain;
	short   i, j, n, best;
	short	Stemp, shift1, shift2;
	long	Ltemp;


	/* initialization -- should be done in init routine for implementation */
	if (FirstTime)
	{
		FirstTime = 0;
		for (i = 0; i < ORDER; i++)
			FIRmem[i] = 0;
		for (i = 0; i < ORDER; i++)
			IIRmem[i] = 0;
		for (i = 0; i < ACBMemSize; i++)
			Residual[i] = 0;
		last = 0;
	}

	/* Compute weighted LPC coefficients */
	weight(wcoef1, coeff, alpha, order);
	weight(wcoef2, coeff, beta, order);


	/* Tilt speech  */

	/*...no tilt in non-voiced regions...*/
	for (i = 0, sum2 = 0; i < length - 1; i++)
		sum2 = L_mac(sum2, in[i], in[i + 1]);
	if (sum2 < 0)
		u = 0;		/*...no tilt...*/

	for (i = 0; i < length; i++)
	{
		scratch[i] = msu_r(L_deposit_h(in[i]), u, last);
		last = in[i];
	}

	/* Compute  residual */
	fir(scratch, scratch, wcoef1, FIRmem, order, length);

	for (i = 0; i < SubFrameSize ; i++)
	  Residual[ACBMemSize+i] = scratch[i];

	/* long term filtering */
	/* Find best integer delay around delayi */
	j = extract_h(L_add(delayi, 32768));
	sum1 = 0;
        shift1 = 1;
	best = j;
	for (i = Max(DMIN, j - 3); i <= Min(DMAX, j + 3); i++)
	{
                shift2 = 1;
		for (n = ACBMemSize, sum2 = 0; n < ACBMemSize + length; n++)
		{
			Ltemp = L_mult(Residual[n], Residual[n - i]);
			Ltemp = L_shr(Ltemp, shift2);
			sum2 = L_add(sum2, Ltemp);
			if (sum2 >= 0x40000000)
			{
				sum2 = L_shr(sum2, 1);
				shift2++;
			}
		}

                if( ((shift1 >= shift2) && (L_shr(sum2,sub(shift1,shift2)) > sum1))
                   || ((shift1 < shift2) && (sum2 > L_shr(sum1,sub(shift2,shift1)))))
		{
			sum1 = sum2;
			shift1 = shift2;
			best = i;
		}
	}

	/* Get beta for delayi */
	shift1 = 1;
	for (i = ACBMemSize, sum1 = 0; i < ACBMemSize + length; i++)
	{
		Ltemp = L_mult(Residual[i - best], Residual[i - best]);
		Ltemp = L_shr(Ltemp, shift1);
		sum1 = L_add(sum1, Ltemp);
		if (sum1 >= 0x40000000)
		{
			sum1 = L_shr(sum1, 1);
			shift1++;
		}
	}
	shift2 = 1;
	for (i = ACBMemSize, sum2 = 0; i < ACBMemSize + length; i++)
	{
		Ltemp = L_mult(Residual[i], Residual[i - best]);
		Ltemp = L_shr(Ltemp, shift2);
		sum2 = L_add(sum2, Ltemp);
		if (sum2 >= 0x40000000)
		{
			sum2 = L_shr(sum2, 1);
			shift2++;
		}
	}
	if (shift1 > shift2)
	{
		shift1 = sub(shift1, shift2);
		sum2 = L_shr(sum2, shift1);
	}
	else if (shift1 < shift2)
	{
		shift2 = sub(shift2, shift1);
		sum1 = L_shr(sum1, shift2);
	}

	if ((sum2 == 0) || (sum1 == 0) || (br == 1))
		for (i = 0; i < length; i++)
			temp[i] = Residual[i + ACBMemSize];
	else
	{
		if (sum2 >= sum1)
			gamma = 0x7fffffff;		/* Clip gamma at 1.0 */
		else if (sum2 < 0)
			gamma = 0;
		else
		{
			shift1 = norm_l(sum1);
			sum1 = L_shl(sum1, shift1);
			sum2 = L_shl(sum2, shift1);
			gamma = L_divide(sum2, sum1);
		}

		if (gamma < 0x40000000)
			for (i = 0; i < length; i++)
				temp[i] = Residual[i + ACBMemSize];
		else
		{
			/* Do actual filtering */
			for (i = 0; i < length; i++)
			{
				Ltemp = L_mpy_ls(gamma, ltgain);
				Ltemp = L_mpy_ls(Ltemp, Residual[ACBMemSize + i - best]);
				temp[i] = add(Residual[ACBMemSize + i], round(Ltemp));
			}
		}

	}


	/* iir short term filter - first run */
	for (i = 0; i < length; i++)
		scratch[i] = temp[i];
	for (i = 0; i < order; i++)
		mem[i] = IIRmem[i];
	iir(scratch, scratch, wcoef2, mem, order, length);


	/* Get filter gain */
	shift1 = 1;
	for (i = 0, sum1 = 0; i < length; i++)
	{
		Ltemp = L_mult(in[i], in[i]);
		Ltemp = L_shr(Ltemp, shift1);
		sum1 = L_add(sum1, Ltemp);
		if (sum1 >= 0x40000000)
		{
			sum1 = L_shr(sum1, 1);
			shift1++;
		}
	}
	shift2 = 1;
	for (i = 0, sum2 = 0; i < length; i++)
	{
		Ltemp = L_mult(scratch[i], scratch[i]);
		Ltemp = L_shr(Ltemp, shift2);
		sum2 = L_add(sum2, Ltemp);
		if (sum2 >= 0x40000000)
		{
			sum2 = L_shr(sum2, 1);
			shift2++;
		}
	}
	if (shift1 > shift2)
	{
		shift1 = sub(shift1, shift2);
		sum2 = L_shr(sum2, shift1);
	}
	else if (shift1 < shift2)
	{
		shift2 = sub(shift2, shift1);
		sum1 = L_shr(sum1, shift2);
	}

	if (sum2 != 0)
	{
		shift1 = norm_l(sum2);
		sum2 = L_shl(sum2, shift1);
		shift1 = sub(shift1, 2);	/* For (1. < APFgain < 2.) */
		sum1 = L_shl(sum1, shift1);
		Ltemp = L_divide(sum1, sum2);
		shift1 = norm_l(Ltemp);
		Ltemp = L_shl(Ltemp, shift1);
		Stemp = sqroot(Ltemp);
		if (shift1 & 1)
			APFgain = L_mult(0x5a82, Stemp);
		else
			APFgain = L_deposit_h(Stemp);
		shift1 = shr(shift1, 1);
		APFgain = L_shr(APFgain, shift1);

		/* Re-normalize the speech signal */
		for (i = 0; i < length; i++)
		{
			Ltemp = L_mpy_ls(APFgain, temp[i]);
			Ltemp = L_shl(Ltemp, 1);  /* For (1. < APFgain < 2.) */
			temp[i] = round(Ltemp);
		}
	}
	else
		APFgain = 0x40000000;


	/* iir short term filter - second run */
	iir(out, temp, wcoef2, IIRmem, order, length);

	/* Update residual buffer */
	for (i = 0; i < ACBMemSize; i++)
		Residual[i] = Residual[i + length];
}
コード例 #2
0
ファイル: main.cpp プロジェクト: 3eggert/mbed
int main() {
    Sine_f32 sine_1KHz(  1000, SAMPLE_RATE, 1.0);
    Sine_f32 sine_15KHz(15000, SAMPLE_RATE, 0.5);
    FIR_f32<NUM_TAPS> fir(firCoeffs32);
    
    float32_t buffer_a[BLOCK_SIZE];
    float32_t buffer_b[BLOCK_SIZE];
    for (float32_t *sgn=output; sgn<(output+TEST_LENGTH_SAMPLES); sgn += BLOCK_SIZE) {
        sine_1KHz.generate(buffer_a);           // Generate a 1KHz sine wave
        sine_15KHz.process(buffer_a, buffer_b); // Add a 15KHz sine wave
        fir.process(buffer_b, sgn);             // FIR low pass filter: 6KHz cutoff
    }
    
    sine_1KHz.reset();
    for (float32_t *sgn=expected_output; sgn<(expected_output+TEST_LENGTH_SAMPLES); sgn += BLOCK_SIZE) {
        sine_1KHz.generate(sgn);        // Generate a 1KHz sine wave
    }
    
    float snr = arm_snr_f32(&expected_output[DELAY-1], &output[WARMUP-1], TEST_LENGTH_SAMPLES-WARMUP);
    printf("snr: %f\n\r", snr);
    if (snr < SNR_THRESHOLD_F32) {
        printf("Failed\n\r");
    } else {
        printf("Success\n\r");
    }
}
コード例 #3
0
ファイル: test.c プロジェクト: kinhoa122345/virtualsoc-wcdma
int main()
{
	//Local variables (declared in wcdma_signal_fixed.h)
	//int Signal_I [(SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR]
	//int Signal_Q [(SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR]
	//int FIR_COEFF[FILTER_NB_CELL]
	//int symbole_flow_user1[NB_SYMBOL]
	//int ovsf_code_user1[SF]

	//local variables (others)
	int Signal_I_symb[SF/2*SAMPLING_FACTOR];
	int Signal_Q_symb[SF/2*SAMPLING_FACTOR];

	int Signal_I_filtered[(SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR] ;
	int Signal_Q_filtered[(SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR] ;
	
	int Signal [ (SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR * 2 ] ;
	int amplitude ;

	//Other variables
	int b,i;


	//Inits
	fir ( FIR_COEFF, FILTER_NB_CELL, Signal_I, (SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR, Signal_I_filtered ) ;
	fir ( FIR_COEFF, FILTER_NB_CELL, Signal_Q, (SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR, Signal_Q_filtered ) ;
	
	QPSKinv ( Signal_I_filtered, Signal_Q_filtered, (SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR, Signal, &amplitude ) ; 
		
	for ( i = 0 ; i < (SF/2*NB_SYMBOL+DELAY_MAX/2)*SAMPLING_FACTOR*2 ; i++ )
	{
		printf ( "%d ", Signal[i] ) ;
		
		if ( i % 8 == 0 )
			printf ( "\n" ) ; 
	}	
	printf ( "\n" ) ; 
		
	//Check results
	
	//End
	return(0);
}
コード例 #4
0
ファイル: FIR_vst.cpp プロジェクト: kaktus3000/HighGain
void
FIR_vst::processReplacing (float** inputs, float** outputs, VstInt32 nSamples)
{
    float* pIn  =  *inputs;
    float* pOut = *outputs;

	const float	vol = powf(10.0f, (m_afParameters[PORT_VOL] * 80.0f - 60.0f) / 20.0f);
	uint model = (uint) MAX(m_afParameters[PORT_MODEL] * NUM_MODELS, NUM_MODELS - 1);

	fir(&m_State, pIn, pOut, nSamples, (uint)getSampleRate(), model, vol);
}
コード例 #5
0
ファイル: fir.c プロジェクト: chisophugis/itsp
int main() {
  int i;
  double x;
  double y;
  double h[4] = {1.,1.,1.,1.};
  double w[4] = {0};

  while (fscanf(stdin, "%lf", &x) == 1) {
    y = fir(M, h, w, x);
    fprintf(stdout, "%lf\n", y);
  }

  /* Input-off transient. */
  for (i = 0; i < M; i++) {
    y = fir(M, h, w, 0.);
    fprintf(stdout, "%lf\n", y);
  }

  return 0;
}
コード例 #6
0
ファイル: ref13.c プロジェクト: ABratovic/open-watcom-v2
void test(
    INHERIT *ip,                // - pointer to INHERIT structure
    BASE& br,                   // - reference to BASE of INHERIT structure
    INHERIT& ir )               // - reference to INHERITE structure
{
    BASE *bp;

// 4.7
    init_inherit( ip );
    if( ip->b != 1 ) fail(__LINE__);
    fir( ir );
    if( ip->a != -1 ) fail(__LINE__);
    if( ip->b != -1 ) fail(__LINE__);
    init_inherit( ip );
    fbr( br );
    if( ip->a != -1 ) fail(__LINE__);
    if( ip->b != 1 ) fail(__LINE__);

    init_inherit( &i );
    fir( i );
    if( i.a != -1 ) fail(__LINE__);
    if( i.b != -1 ) fail(__LINE__);
    init_inherit( &i );
    bp = &i;
    fbr( *bp );
    if( i.a != -1 ) fail(__LINE__);
    if( i.b != 1 ) fail(__LINE__);

// 5
    init_inherit( &i );
    br.a++;
    ir.a += 5;
    ir.b *= 3;
    if( i.a != 7 ) fail(__LINE__);
    if( i.b != 3 ) fail(__LINE__);

// 5.2.2
    static_int = 0;
    return_int_ref() = 7;
    if( static_int != 7 ) fail(__LINE__);
}
コード例 #7
0
ファイル: testfir.c プロジェクト: martin-etchart/c
/** \fn main()
 * \brief Prueba de los módulos implementados.
 * @return No tiene salida.
*/
int main() {

    /// Señal de entrada.
    sample_t u[SIGNAL_LENGTH]; 					//señal de entrada
    /// Señal de salida.
    sample_t y[SIGNAL_LENGTH]; 					//señal de salida del filtro


    sample_t ma = 1.0/TAP_LENGTH; 				//moving average

    /// Coeficientes del FIR.
    sample_t coefs[TAP_LENGTH] = {ma,ma,ma,ma};	//coeficientes de media movil

    /// Retardo de la señal de entrada (en muestras).
    int retardo = 4;							//retardo
    /// Altura de la señal de entrada
    sample_t altura = 4;						//altura

    printf("\n");
    printf("************** Filtrado FIR ***************\n");
    printf("*                                         *\n");
    printf("*                _________                *\n");
    printf("*        U      |         |    Y          *\n");
    printf("*      -------->|   FIR   |------->       *\n");
    printf("*               |_________|               *\n");
    printf("*                                         *\n");
    printf("*******************************************\n");
    printf("\n");

    /*Generar señal de entrada*/
    step(&u[0],retardo,altura);
    //impulso(&u[0],retardo,altura);

    /*Imprimir señal de entrada*/
    printf("Señal de entrada al filtro:\n");
    for (int i=0; i<SIGNAL_LENGTH; printf("%1.1f ",u[i]),i++);
    printf("\n\n");

    /*Inicialización del filtro*/
    ini_fir(coefs);  //printf("Coeficientes del filtro: %1.1f\n",c[0]);

    /*Filtrado de la señal*/
    for (int i=0; i<SIGNAL_LENGTH; i++) {
        //printf("Taps disponibles: %d\n",taps);
        y[i] = fir(&u[i]); //printf("Señal de salida: %f\n",y[i]);
    };

    /*Imprimir señal de salida*/
    printf("Señal de salida al filtro:\n");
    for (int i=0; i<SIGNAL_LENGTH; printf("%1.1f ",y[i]),i++);
    printf("\n\n");

}
コード例 #8
0
void forest (int n) //N - количество елочек в лесу
{
 int h0=150;
 int i,a,b,h;
 int col;
 for (i=1; i<=n; i++)
    {
      h=rand()%h0+10;           // высота треугольника от 10 до h0 точек
      a=rand()%700;  // координата x вершины елочки - от 20 до ширины окна
      b=rand()%500;  // координата y вершины елочки - от 5 до высоты окна
      col=rand()%15+1;           // цвет линий
      fir(a,b,h,col); 	// ќбращение к процедуре рисовани¤ елочки
    }
}
コード例 #9
0
int main () {
  const int SAMPLES=600;
  FILE *fp;

  data_t signal, output;
  coef_t taps[11] = {0,-10,-9,23,56,63,56,23,-9,-10,0,};

  int i, ramp_up;
  signal = 0;
  ramp_up = 1;

  fp=fopen("out.dat","w");
  for (i=0;i<=SAMPLES;i++) {
   if (ramp_up == 1)
    signal = signal + 1;
   else
    signal = signal - 1;


    fir(&output,taps,signal);

    if ((ramp_up == 1) && (signal >= 75))
     ramp_up = 0;
    else if ((ramp_up == 0) && (signal <= -75))
     ramp_up = 1;


    fprintf(fp,"%i %d %d\n",i,signal,output);
  }
  fclose(fp);

  printf ("Comparing against output data \n");
  if (system("diff -w out.dat out.gold.dat")) {

 fprintf(stdout, "*******************************************\n");
 fprintf(stdout, "FAIL: Output DOES NOT match the golden output\n");
 fprintf(stdout, "*******************************************\n");
     return 1;
  } else {
 fprintf(stdout, "*******************************************\n");
 fprintf(stdout, "PASS: The output matches the golden output!\n");
 fprintf(stdout, "*******************************************\n");
     return 0;
  }
}
コード例 #10
0
ファイル: main.c プロジェクト: ecomptiago/EmbarcadosLab1
int main()
{
  int size_i = 10;
  int size_coef = 3;

  int s_in[10]= {1, 2, 3, 4, 5, 1, 2, 5, 6, 10};
  int coef[3] = {2, 8, 9};
  int out[8];
  int outc[8];

  int firReturn = fir(s_in, size_i, coef, size_coef, out);
  printf("FIR filter in assembly returned %d.\n",firReturn);
  
  firFilterInC(s_in, size_i, coef, size_coef, outc);
  
  printArray(out,8,"out");
  printArray(outc,8,"outc");
  
  return 0;
}
コード例 #11
0
int main (void)
{
    check_vect ();
    int i, j;
    float diff;

    for (i = 0; i < M; i++)
        coeff[i] = i;
    for (i = 0; i < N+M; i++)
        in[i] = i;

    foo ();
    fir ();

    for (i = 0; i < N; i++) {
        if (out[i] != fir_out[i])
            abort ();
    }

    return 0;
}
コード例 #12
0
 // (p/q) fractional resampler
 // * length of the used FIR filter is q*l
 // * consumes q*num_blocks samples and
 // * produces p*num_blocks samples per call to process
 fractional_resampler(int p,
                      int q,
                      int l,
                      int num_blocks=1)
   : p_(p)
   , q_(q)
   , l_(l)
   , num_blocks_(num_blocks)
   , counter_(0)
   , history_(2*q*l_, 0)
   , b_(p*q*l_, 0)
   , out_(p*num_blocks, 0) {
   typedef filter::fir::lowpass<float> fir_type;
   fir_type fir(p*q*l_);
   fir.design(1.0f/p, 0.1f/p);
   for (int i=0; i<q*l; ++i) {
     for (int j=0; j<p; ++j) {
       b_[q*l-1-i + j*q*l] = p*fir.coeff()[i*p + j];
     }
   }
 }
コード例 #13
0
ファイル: firdemo.cpp プロジェクト: Haggui/fir1
int main (int,char**)
{
	// inits the filter
	Fir1 fir("coefficients.dat");

	// resets the delay line to zero
	fir.reset ();
      
	// gets the number of taps
	int taps = fir.getTaps();

	printf("taps = %d\n",taps);

	FILE *fimpulse = fopen("impulse.dat","wt");
	for(int i=0;i<taps*2;i++) 
	{
		float a=0;
		if (i==10) a = 1;
		float b = fir.filter(a);
		fprintf(fimpulse,"%f\n",b);
	}
	fclose(fimpulse);
	fprintf(stderr,"Written the impulse response to 'impulse.dat'\n");
}
コード例 #14
0
ファイル: graph-shortestpath.cpp プロジェクト: manish05/TCR
vvi floydwarshall(vvi &g)
{
   vvi f=g; int n=f.si;
   fkr(n) fir(n) fjr(n) f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
   return f;
}
コード例 #15
0
ファイル: main1.c プロジェクト: MasterPauli/EEE8091
void main(void)
{	
	// Local variables
    int i,k;
	unsigned char preamble=0;
	unsigned char datachar=0;
    unsigned char count_bits=0;
    unsigned char count_bytes=0;
	unsigned char trig=0;
	unsigned char led_cnt = 0;
	
	
    // Setup 21364 board    
	Setup21364();	
	
	for (k=0;k < N_bp+1; k++)
		{
		state_bp[k] = 0.0;
		}
	
	for (k=0; k< N_mf ; k++)
		{
			x2[k]=0.0;
		}

	for (k=0;k < N_mf+1; k++)
		{
			state_mf[k]=0.0;
		}
		
//Initialise buffer contents
	for (k=0;k < N_mf; k++)
		{
			x5[k]=0.0;
		}
		
		
    for(;;)
    {
     	while(blockReady)
     	{
     		//Clear the Block Ready Semaphore
    		blockReady = 0;
    
    		//Set the Processing Active Semaphore before starting processing
    		isProcessing = 1;
					
    		// Pointer to input samples
    		unsigned int * sample_in=src_pointer[int_cntr];
     		
    		// Pointer to output ssamples
    		unsigned int * sample_out=src_pointer[int_cntr];
    		
			
			for(i=0;i<NUM_SAMPLES/2;i++)
     		{      
     		     			
     		 	/*	
     		 	 	Important Notes:
     		 		1. Conversion from 24 to 32 bit and input scaling  
     		 		2. Index [2*i+1] corresponds to ADC channel 1, [2*i] to ADC channel 2
     		 		3. The differential input range for the ADC is ~2.8Vpp
     		 		4. Do not overdrive the ADC with the signal generator (see point 3 for range)
     		 		5. C-language elements implemented: bit-shifting, pointer casting, array indexing   
     		 	*/	   		 		
    			x0=(float)((int)(sample_in[2*i+1]<<8)*scale_in);
    			x1=fir(x0,h_bp,state_bp,N_bp);
    			
				//demodulator
    			x3=x1*x2[19];			       	
				for(k=N_mf-1;k>0;k--)          
				{
					x2[k]=x2[k-1];		
				}
				x2[0]=x1;

				//low pass filter
				x4=fir(x3, h_mf, state_mf, N_mf);
				

				
				//x5 input by shifting
				for(k=0;k<N_mf-1;k++)
				{
					x5[k]=x5[k+1];        
				}
				x5[N_mf-1]=x4;    
		   
		   
				Nc0=Nc0+1; //define Nc0
		   
				if(Nc0 == Nc1)
				{
					Ee=0;
					El=0;
					for (k=0;k<10;k++)
					{
						Ee= Ee + x5[k]*x5[k];
						El = El + x5[k+10]*x5[k+10];
					}
			


										//set nc2 to vary nc1
			        if(Ee > El)
			        Nc2=Nc2+1;
	    		    else if(Ee < El)
					Nc2=Nc2-1;
		            else
            		Nc2=Nc2; 
			
					//set nc1 to control shifting of X5
            		if(Nc2 == 10) 
            		{
	          			Nc2=0;
	          			Nc1=19;
	        		}	
	        		else if (Nc2 == -10)
			        {
			          Nc2=0;
			          Nc1=21;
		        	}
			        else
			        	Nc1=20;


	        
			        Nc0=0; //reset the counter for X5shifting
			        
			        
	        		Em=0.5*(x5[9]+x5[10]);			
	    		//Frame synchronisation Search ++++
				if(trig == 0)
	    		{
		    		preamble=preamble>>1;
					if(Em<0)
					{
						preamble=preamble+0x80000000;
					}
			
			    	if(preamble == 0x2B2B2B2B)
			    	{
			    		trig=1;
			    		preamble=0;
			    		led_cnt=led_cnt%2;
			    		LED_ON(led_cnt++);
			     	}
	    		}
	    		//Frame synchronisation get info
				else     // data detection should happened in next bits!!!
				{
					datachar>>=1;
					if(Em<0)
					{
						datachar+=0x80;
					}
					count_bits++;

				
					if(count_bits == 8)
					{
						count_bits=0;
						data[count_bytes] = datachar;
						count_bytes++;
						datachar=0;
						if(count_bytes>71)
						{
							count_bytes = 0;
							trig=0;
						}
					}

					
				}
	     	
	     	
	     	
	     	
	       		}
	 
    			// Buffer ADC 1 output for inspection after DSP is halted
    			scope1[k]=x0;
    			scope2[k++]=x0;
    			
    			/*
    				Important Notes: the code below implements:
    			    1. 32-to-24 bit convesion and output to DAC 1 & 2
     		 	    2. Index 2*i+1 corresponds to DAC channel 1, 2i to DAC channel 2
     		 	   	3. Full-Scale Output Voltage at Each Pin (Single-Ended) 1 Vrms or 2.8Vpp.
     		 	       Current setup: DACVOL_MAX in init1835viaSPI.c gives ~ 2.8Vpp
			       	4. Depending on the input signal strength additional scaling is required.
     		 	   	5. The code below sends x0 and -x0 to the DAC outputs.
			*/
				sample_out[2*i+1]=(unsigned int)(((int)(Em*scale_out))>>8);	// DAC 1				
     			sample_out[2*i]=(unsigned int)(((int)(x4*scale_out))>>8);	// DAC 2
     		}
コード例 #16
0
ファイル: pitch.c プロジェクト: jeonggunlee/6.375-labs
int main(int argc, char* argv[])
{
    if (argc != 3) {
        fprintf(stderr, "usage: inputpcm outputpcm\n");
        return 1;
    }

    const char* iname = argv[1];
    const char* oname = argv[2];

    FILE* fin = fopen(iname, "rb");
    FILE* fout = fopen(oname, "wb");

    // Set up the FFT.
    fftw_complex* infft = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    fftw_complex* outfft = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    fftw_plan forward = fftw_plan_dft_1d(N, infft, outfft, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_plan reverse = fftw_plan_dft_1d(N, infft, outfft, FFTW_BACKWARD, FFTW_ESTIMATE);

    // window - holds the window samples.
    // We shift through from right to left S samples at a time.
    short window[N] = {0};

    // outblock - holds the output samples we shift out from right to left.
    short outblock[N] = {0};

    int i;
    while (!feof(fin)) {

        // Read in the next S samples
        short samples[S];
        fread(samples, sizeof(short), S, fin);

        // Pass the samples through the fir filter.
        for (i = 0; i < S; i++) {
            samples[i] = fir(samples[i]);
        }

        // Shift input samples left by S and copy in the next S sample values.
        // (Oversampling)
        memmove(window, window + S, sizeof(short) * (N-S));
        memcpy(window + (N-S), samples, sizeof(short)*S); 

        // Convert audio samples to complex numbers
        for (i = 0; i < N; i++) {
            infft[i] = (double complex)window[i];
        }

        // Forward FFT
        fftw_execute(forward);

        // Pitch Adjustment.
        pitchadjust(outfft, infft);

        // Inverse FFT
        // We have to scale down by N because fftw doesn't for us.
        fftw_execute(reverse);
        for (i = 0; i < N; i++) {
            outfft[i] /= (double)N;
        }

        // Average in new samples with output block and shift out ready
        // samples. (Overlayer)
        for (i = 0; i < N; i++) {
            outblock[i] += (short)(creal(outfft[i])*S/(double)(N));
        }
        fwrite(outblock, sizeof(short), S, fout);
        memmove(outblock, outblock+S, sizeof(short) * (N-S));
        for (i = N-S; i < N; i++) {
            outblock[i] = 0;
        }
    }

    fftw_destroy_plan(forward);
    fftw_destroy_plan(reverse);
    fftw_free(infft);
    fftw_free(outfft);

    fclose(fin);
    fclose(fout);
}
コード例 #17
0
ファイル: apt.cpp プロジェクト: la1k/wxfetch
int apt_decode(apt_t *apt, buffer_t *sound_buffer, float *pixels_out)
{
    double corr, ecorr, lcorr;
    float pixelv[APT_IMG_WIDTH + SyncFilterLen] = {};
    int res;
    int npv = apt->num_leftover_pixels;
    if (apt->num_leftover_pixels > 0) {
	memmove(pixelv, apt->leftover_pixels, npv * sizeof(float));
	apt->num_leftover_pixels = 0;
    }
    if (npv < SyncFilterLen + 2) {
	res = getpixelv(sound_buffer, apt, &(pixelv[npv]), SyncFilterLen + 2 - npv);
	npv += res;
	if (npv < SyncFilterLen + 2)
	    return (0);
    }

    /* test sync */
    corr = fir(&(pixelv[1]), Sync, SyncFilterLen);
    ecorr = fir(pixelv, Sync, SyncFilterLen);
    lcorr = fir(&(pixelv[2]), Sync, SyncFilterLen);
    apt->FreqLine = 1.0 + (ecorr - lcorr) / corr / APT_IMG_WIDTH / 4.0;
    if (corr <= 0.75 * apt->last_max_correlation) {
	apt->synced = 0;
	apt->FreqLine = 1.0;
    }
    apt->last_max_correlation = corr;
    if (apt->synced < 8) {
	int shift, mshift;

	if (npv < APT_IMG_WIDTH + SyncFilterLen) {
	    res =
		getpixelv(sound_buffer, apt, &(pixelv[npv]), APT_IMG_WIDTH + SyncFilterLen - npv);
	    npv += res;
	    if (npv < APT_IMG_WIDTH + SyncFilterLen)
		return (0);
	}

	/* lookup sync start */
	mshift = 0;
	for (shift = 1; shift < APT_IMG_WIDTH; shift++) {
	    double corr;

	    corr = fir(&(pixelv[shift + 1]), Sync, SyncFilterLen);
	    if (corr > apt->last_max_correlation) {
		mshift = shift;
		apt->last_max_correlation = corr;
	    }
	}
	if (mshift != 0) {
	    memmove(pixelv, &(pixelv[mshift]),
		    (npv - mshift) * sizeof(float));
	    npv -= mshift;
	    apt->synced = 0;
	    apt->FreqLine = 1.0;
	} else
	    apt->synced += 1;
    }
    if (npv < APT_IMG_WIDTH) {
	res = getpixelv(sound_buffer, apt, &(pixelv[npv]), APT_IMG_WIDTH - npv);
	npv += res;
	if (npv < APT_IMG_WIDTH)
	    return (0);
    }
    if (npv == APT_IMG_WIDTH) {
	npv = 0;
    } else {
	memmove(apt->leftover_pixels, &(pixelv[APT_IMG_WIDTH]),
		(npv - APT_IMG_WIDTH) * sizeof(float));
	apt->num_leftover_pixels = npv - APT_IMG_WIDTH;
    }
    
    memcpy(pixels_out, pixelv, APT_IMG_WIDTH*sizeof(float));

    return (1);
}
コード例 #18
0
ファイル: BASE.cpp プロジェクト: RTcmix/RTcmix
/* ------------------------------------------------------------------ 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;
}
コード例 #19
0
ファイル: MBASE.cpp プロジェクト: eriser/RTcmix-1
/* ------------------------------------------------------------------ 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;
}
コード例 #20
0
ファイル: dsp.c プロジェクト: bkerler/aptdec
int getpixelrow(float *pixelv)
{
    static float pixels[PixelLine + SyncFilterLen];
    static int npv = 0;
    static int synced = 0;
    static double max = 0.0;

    double corr, ecorr, lcorr;
    int res;

    if (npv > 0)
	memmove(pixelv, pixels, npv * sizeof(float));
    if (npv < SyncFilterLen + 2) {
	res = getpixelv(&(pixelv[npv]), SyncFilterLen + 2 - npv);
	npv += res;
	if (npv < SyncFilterLen + 2)
	    return (0);
    }

    /* test sync */
    ecorr = fir(pixelv, Sync, SyncFilterLen);
    corr = fir(&(pixelv[1]), Sync, SyncFilterLen);
    lcorr = fir(&(pixelv[2]), Sync, SyncFilterLen);
    FreqLine = 1.0+((ecorr-lcorr) / corr / PixelLine / 4.0);
    if (corr < 0.75 * max) {
	synced = 0;
	FreqLine = 1.0;
    }
    max = corr;
    if (synced < 8) {
	int shift, mshift;

	if (npv < PixelLine + SyncFilterLen) {
	    res =
		getpixelv(&(pixelv[npv]), PixelLine + SyncFilterLen - npv);
	    npv += res;
	    if (npv < PixelLine + SyncFilterLen)
		return (0);
	}

	/* lookup sync start */
	mshift = 0;
	for (shift = 1; shift < PixelLine; shift++) {
	    double corr;

	    corr = fir(&(pixelv[shift + 1]), Sync, SyncFilterLen);
	    if (corr > max) {
		mshift = shift;
		max = corr;
	    }
	}
	if (mshift != 0) {
	    memmove(pixelv, &(pixelv[mshift]),
		    (npv - mshift) * sizeof(float));
	    npv -= mshift;
	    synced = 0;
	    FreqLine = 1.0;
	} else
	    synced += 1;
    }
    if (npv < PixelLine) {
	res = getpixelv(&(pixelv[npv]), PixelLine - npv);
	npv += res;
	if (npv < PixelLine)
	    return (0);
    }
    if (npv == PixelLine) {
	npv = 0;
    } else {
	memmove(pixels, &(pixelv[PixelLine]),
		(npv - PixelLine) * sizeof(float));
	npv -= PixelLine;
    }

    return (1);
}
コード例 #21
0
ファイル: wcdma.c プロジェクト: kinhoa122345/virtualsoc-wcdma
int main(int argc, char** argv, char** envp)
{
	//int num_proc = get_proc_id();
	unsigned myId;
	start_metric();


	register int a, iSymbol, iBuffer, iPosCode ;  
	const int bufferSize = SF/2*SAMPLING_FACTOR;
	int Signal_I_symb[80]  ;
	int Signal_Q_symb[80]  ;
	register int bit ;
	int Signal_I_filtered[bufferSize]  ;
	int Signal_Q_filtered[bufferSize] ;
	int Signal [ 16 ] ;	


	for ( a = 0 ; a < 80 ; a++ )
	{
		Signal_I_symb[a] = 0 ;
		Signal_Q_symb[a] = 0 ;
	}
	
	for ( a = 0 ; a < bufferSize ; a++ )
	{
		Signal_I_filtered[a] = 0 ;
		Signal_Q_filtered[a] = 0 ;
	}
	
	for ( a = 0 ; a < 16 ; a++ )
	{
		Signal[a] = 0 ;
	}
	
	//if(num_proc==1)
	//{	
		//For each symbol
		for(iSymbol=0;iSymbol<NB_SYMBOL;iSymbol++)
		{
			//Get first symbol
			for(iBuffer=0;iBuffer<bufferSize;iBuffer++) 
			{
				// Shifting the old values at the beginning of the buffer
				Signal_I_symb[iBuffer]	= Signal_I_symb[iBuffer+16] ; 
				Signal_Q_symb[iBuffer]	= Signal_Q_symb[iBuffer+16] ; 
				
				Signal_I_symb[iBuffer+16]	= Signal_I_symb[iBuffer+32] ;
				Signal_Q_symb[iBuffer+16]	= Signal_Q_symb[iBuffer+32] ; 
				 
				Signal_I_symb[iBuffer+32]	= Signal_I_symb[iBuffer+48] ; 
				Signal_Q_symb[iBuffer+32]	= Signal_Q_symb[iBuffer+48] ; 
				
				Signal_I_symb[iBuffer+48]	= Signal_I_symb[iBuffer+64] ; 
				Signal_Q_symb[iBuffer+48]	= Signal_Q_symb[iBuffer+64] ;			
			
				// Put the new values at the end of the buffer	
				Signal_I_symb[iBuffer+64]		= Signal_I[iBuffer+iSymbol*SF/2*SAMPLING_FACTOR];	 
				Signal_Q_symb[iBuffer+64]		= Signal_Q[iBuffer+iSymbol*SF/2*SAMPLING_FACTOR];
			}

			//-------------------------------------- FIRST STAGE -----------------------------------------------
			//FIR for I and Q
			pr("Time before FIR = ", 0x10, PR_STRING | PR_TSTAMP | PR_NEWL);
			#pragma omp parallel
			{
				fir ( FIR_COEFF, FILTER_NB_CELL, Signal_I_symb, Signal_Q_symb, bufferSize, Signal_I_filtered, Signal_Q_filtered ) ; 
			}
			//fir ( FIR_COEFF, FILTER_NB_CELL, Signal_Q_symb, bufferSize, Signal_Q_filtered ) ;  	
//			pr("Time after FIR = ", 0x10, PR_STRING | PR_TSTAMP | PR_NEWL);
//						
//			//------------------------------------- SECOND STAGE -----------------------------------------------		
//			//---- QPSK-1 (parallel to serial)
//			pr("Time before QPSK = ", 0x10, PR_STRING | PR_TSTAMP | PR_NEWL);
//			for ( iBuffer = 0 ; iBuffer < bufferSize/2 ; iBuffer+=2 ) 
//			{
//				Signal[iBuffer] = Signal[iBuffer+bufferSize/2] ;
//				/*Signal[iBuffer+bufferSize/2] = Signal_I_filtered[iBuffer*4] ;
//
//				Signal[iBuffer+1] = Signal[iBuffer+1+bufferSize/2] ;
//				Signal[iBuffer+1+bufferSize/2] = Signal_Q_filtered[iBuffer*4] ;	*/			
//
//			}
//			QPSKinv ( Signal_I_filtered, Signal_Q_filtered, bufferSize/2, &Signal[8] ) ;
//			pr("Time after QPSK = ", 0x10, PR_STRING | PR_TSTAMP | PR_NEWL);		
//			
//			//-------------------------------------- THIRD STAGE -----------------------------------------------		
//			if ( iSymbol != 0 )
//			{
//				//---- Rake receiver
//				pr("Time before RakeReceiver = ", 0x10, PR_STRING | PR_TSTAMP | PR_NEWL) ;
//
//				bit = 0 ;
//
//				for ( iPosCode = 0 ; iPosCode < SF ; iPosCode++ )
//				{
//					bit += Signal[iPosCode]*ovsf_code_user1[iPosCode] + Signal[iPosCode+1]*ovsf_code_user1[iPosCode] + Signal[iPosCode+2]*ovsf_code_user1[iPosCode] + Signal[iPosCode+3]*ovsf_code_user1[iPosCode] + Signal[iPosCode+4]*ovsf_code_user1[iPosCode] + Signal[iPosCode+5]*ovsf_code_user1[iPosCode] ;
//				}			
//				pr("Time after RakeReceiver = ", 0x10, PR_STRING | PR_TSTAMP | PR_NEWL);
//				_printdecn("Bit ", (int) ( (bit > 0) ? 1 : 0) ) ;
//				pr("", 0x10, PR_NEWL);
//			}
		
		}

	/*}
	else
	{
		_printstrn("Only 1 processor is supported!");
	}*/
	
	stop_metric();
	//Stop metrics
	_printstrn("Done");
	//Check results
		
	//End
	return(0);
}
コード例 #22
0
void Hrtf::hrtf(const unsigned channel_idx, s16 *dst, const s16 *src, int src_ch, int src_n, int idt_offset, const kemar_ptr& kemar_data, int kemar_idx, float freq_decay) {
	assert(channel_idx < 2);

	//LOG_DEBUG(("channel %d: window %d: adding %d, buffer size: %u, decay: %g", channel_idx, window, WINDOW_SIZE, (unsigned)result.get_size(), freq_decay));

	if (channel_idx <= 1) {
		bool left = channel_idx == 0;
		if (!left && idt_offset > 0) {
			idt_offset = 0;
		} else if (left && idt_offset < 0) {
			idt_offset = 0;
		}
		if (idt_offset < 0)
			idt_offset = - idt_offset;
	} else 
		idt_offset = 0;

	assert(std::min(0, idt_offset) >= 0);
	assert(std::max(0, idt_offset) + WINDOW_SIZE <= src_n);

	for(int i = 0; i < WINDOW_SIZE; ++i) {
		//-1 0 1 2 3
		int p = idt_offset + i;
		assert(p >= 0 && p < src_n);
		//printf("%d of %d, ", p, src_n);
		int v = src[p * src_ch];
		_mdct.data[i] = v / 32768.0f;
		//fprintf(stderr, "%g ", _mdct.data[i]);
	}
	
	_mdct.apply_window();
	_mdct.mdct();
	{
		for(size_t i = 0; i < mdct_type::M; ++i)
		{
			const int kemar_sample = i * 257 / mdct_type::M;
			std::complex<float> fir(kemar_data[kemar_idx][0][kemar_sample][0], kemar_data[kemar_idx][0][kemar_sample][1]);
			//_mdct.data[i] *= std::abs(fir); TODO: fix HRTF
		}
	}

	//LOG_DEBUG(("kemar angle index: %d\n", kemar_idx));
	assert(freq_decay >= 1);
	
	_mdct.imdct();
	_mdct.apply_window();

	{
		//stupid msvc
		int i;
		for(i = 0; i < WINDOW_SIZE / 2; ++i) {
			float v = _mdct.data[i] + overlap_data[channel_idx][i];
			
			if (v < -1) {
				LOG_DEBUG(("clipping %f", v));
				v = -1;
			} else if (v > 1) {
				LOG_DEBUG(("clipping %f", v));
				v = 1;
			}
			*dst++ = (int)(v * 32767);
		}
		for(; i < WINDOW_SIZE; ++i) {
			overlap_data[channel_idx][i - WINDOW_SIZE / 2] = _mdct.data[i];
		}
	}
}