// Complex Division c = a / b
complex_t complex_div(complex_t a, complex_t b) {
  
  complex_t c;
  
  complex_t nu = complex_mul(a,complex_conj(b));
  complex_t dn = complex_mul(b,complex_conj(b));
  
  c.real = nu.real/dn.real;
  c.imag = nu.imag/dn.real;
  
  return c;
}
Ejemplo n.º 2
0
complex_float complex_arccos(complex_float c1){
	// arccos(z) = (pi/2) + i * log(i*z + sqrt(1 - z*z))
	complex_float zz = complex_mul(c1,c1);
	complex_float a = complex_make(1.0f);
	a = complex_sub(a,zz);                 // 1 - z*z
	a = complex_pow(a,complex_make(0.5f)); // sqrt(...)
	complex_float iz = complex_i(c1);      // i*z
	a = complex_add(iz,a);                 // i*z + sqrt(...)
	a = complex_ln(a);                     // log(...)
	a = complex_mul(complex_i(complex_make( 1.0f )),a); // i * log(...)
	complex_float r = complex_add( complex_make(1.57079632f), a); // pi/2 + ...
	return r;
}
Ejemplo n.º 3
0
static cut_result_t op_test(void) {
    complex_t a = { -1, 3 };
    complex_t b = { 4, 0 };
    CUT_ASSERT_COMPLEX(3, 3, complex_add(a, b));
    CUT_ASSERT_COMPLEX(3, 3, complex_add(b, a));
    CUT_ASSERT_COMPLEX(-5, 3, complex_sub(a, b));
    CUT_ASSERT_COMPLEX(5, -3, complex_sub(b, a));
    CUT_ASSERT_COMPLEX(-4, 12, complex_mul(a, b));
    CUT_ASSERT_COMPLEX(-4, 12, complex_mul(b, a));
    CUT_ASSERT_COMPLEX(-0.25, 0.75, complex_div(a, b));
    CUT_ASSERT_COMPLEX(-0.4, -1.2, complex_div(b, a));
    CUT_TEST_PASS();
}
Ejemplo n.º 4
0
complex_float complex_arcsin(complex_float c1){
	// Hopefully I got this right, from a paper called:
	// "Implementing the Complex Arcsine and Arccosine Functions Using Exception Handling"
	// arcsin(z) = -i* log(i*z + sqrt(1 - z*z))
	complex_float zz = complex_mul(c1,c1);
	complex_float a = complex_make(1.0f);
	a = complex_sub(a,zz);                 // 1 - z*z
	a = complex_pow(a,complex_make(0.5f)); // sqrt(...)
	complex_float iz = complex_i(c1);      // i*z
	a = complex_add(iz,a);                 // i*z + sqrt(...)
	a = complex_ln(a);                     // log(...)
	complex_float r = complex_mul(complex_i(complex_make( -1.0f )),a); // -i * log(...)
	return r;
}
Ejemplo n.º 5
0
complex_float complex_cos(complex_float c1){
	complex_float exp1 = complex_pow( complex_make(exp(1)), complex_i(c1) );
	complex_float exp2 = complex_pow( complex_make(exp(1)), complex_mul(complex_make(-1.0f),complex_i(c1)) );
	complex_float sum  = complex_add(exp1,exp2);
	complex_float r = complex_div( sum, complex_make(2.0f) );
	return r;
}
Ejemplo n.º 6
0
static void ifftx(complex_t data[], complex_t temp[], int n)
{
    int i;
    int h;
    int p;
    int t;
    int i2;
    complex_t wkt;

    if (n > 1)
    {
        h = n/2;
        for (i = 0;  i < h;  i++)
        {
            i2 = i*2;
            temp[i] = data[i2];         /* Even */
            temp[h + i] = data[i2 + 1]; /* Odd */
        }
        fftx(&temp[0], &data[0], h);
        fftx(&temp[h], &data[h], h);
        p = 0;
        t = MAX_FFT_LEN/n;
        for (i = 0;  i < h;  i++)
        {
            wkt = complex_mul(&icircle[p], &temp[h + i]);
            data[i] = complex_add(&temp[i], &wkt);
            data[h + i] = complex_sub(&temp[i], &wkt);
            p += t;
        }
    }
}
Ejemplo n.º 7
0
void FreqFilter::FilterChain::calculate(const complex* inbuf, complex *outbuf){
	for(int i=0; i<this->filterList.size(); i++){
		const complex *q = this->filterList[i]->getFqChar();
		if (!q) throw 1;
		for (int k=0; k<this->windowsize; k++){
			if (!k) 
				outbuf[k].re = q[k].re, outbuf[k].im = q[k].im;
			else 
				complex_mul(&q[k], &outbuf[k], &outbuf[k]);
		}

		for (int k=0; k<this->windowsize; k++){
			complex_mul(&inbuf[k], &outbuf[k], &outbuf[k]);
		}
	}
}
Ejemplo n.º 8
0
complex_float complex_sin(complex_float c1){
	// So... Euler said: exp(i*t) = cos(t) + i*sin(t) 
	// and then: sin(t) = (exp(i*t) - exp(-i*t)) / 2i 
	// and also: cos(t) = (exp(i*t) + exp(-i*t)) / 2  
	// Hm... I already have functions that raise complex numbers
	// to complex numbers so I'll use those for sin/code.
	complex_float exp1 = complex_pow( complex_make(exp(1)), complex_i(c1) );
	complex_float exp2 = complex_pow( complex_make(exp(1)), complex_mul(complex_make(-1.0f),complex_i(c1)) );
	complex_float diff = complex_sub(exp1,exp2);
	complex_float r = complex_div( diff, complex_i(complex_make(2.0f)) );
	return r;
}
Ejemplo n.º 9
0
void f0(void) {
  result = 1;
  
  bool_mul(bool_id(1));
  aggr_mul(aggr_id((AggrTy) { 2, 3, 5}));
  empty_mul(empty_id((EmptyTy) {}));
  scalar_mul(scalar_id(7));
  complex_mul(complex_id(11 + 13i));
  
  // This call should be eliminated.
  if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53)
    g0();
}
Ejemplo n.º 10
0
void
complex_fact (complex_t *dst, complex_t const *src)
{
	if (complex_real_p (src)) {
		complex_init (dst, gnm_fact (src->re), 0);
	} else {
		/*
		 * This formula is valid for all arguments except zero
		 * which we conveniently handled above.
		 */
		complex_t gz;
		complex_gamma (&gz, src);
		complex_mul (dst, &gz, src);
	}
}
Ejemplo n.º 11
0
int32_t main ( int32_t argc, char * argv[] )
{
    complex_t x,y,z;

    complex_init(x,1.0,0.0);
    complex_init(y,0.0,1.0);
    complex_mul(z,y,y);

    complex_exp(z,y,10);
    dbg_print("exp of");
    dbg_complex_print(y);
    dbg_print("is");
    dbg_complex_print(z);

    return 0;
}
Ejemplo n.º 12
0
void
complex_gamma (complex_t *dst, complex_t const *src)
{
	if (complex_real_p (src)) {
		complex_init (dst, gnm_gamma (src->re), 0);
	} else if (src->re < 0) {
		/* Gamma(z) = pi / (sin(pi*z) * Gamma(-z+1)) */
		complex_t a, b, mz;

		complex_init (&mz, -src->re, -src->im);
		complex_fact (&a, &mz);

		complex_init (&b,
			      M_PIgnum * gnm_fmod (src->re, 2),
			      M_PIgnum * src->im);
		/* Hmm... sin overflows when b.im is large.  */
		complex_sin (&b, &b);

		complex_mul (&a, &a, &b);

		complex_init (&b, M_PIgnum, 0);

		complex_div (dst, &b, &a);
	} else {
		complex_t zmh, zmhd2, zmhpg, f, f2, p, q, pq;
		int i;

		i = G_N_ELEMENTS(lanczos_num) - 1;
		complex_init (&p, lanczos_num[i], 0);
		complex_init (&q, lanczos_denom[i], 0);
		while (--i >= 0) {
			complex_mul (&p, &p, src);
			p.re += lanczos_num[i];
			complex_mul (&q, &q, src);
			q.re += lanczos_denom[i];
		}
		complex_div (&pq, &p, &q);

		complex_init (&zmh, src->re - 0.5, src->im);
		complex_init (&zmhpg, zmh.re + lanczos_g, zmh.im);
		complex_init (&zmhd2, zmh.re * 0.5, zmh.im * 0.5);
		complex_pow (&f, &zmhpg, &zmhd2);

		zmh.re = -zmh.re; zmh.im = -zmh.im;
		complex_exp (&f2, &zmh);
		complex_mul (&f2, &f, &f2);
		complex_mul (&f2, &f2, &f);

		complex_mul (dst, &f2, &pq);
	}
}
Ejemplo n.º 13
0
void clov_apply( char *name)
{
    /*
     * This marks the argument registers as defined by ABI as off limits
     * to us until they are freed by "getarg()";
     */
    int dum = defargcount(1);

    int retno;
    int branchsite;

    /*-------------------------------------------------------------------------------
     * registers used
     *-------------------------------------------------------------------------------
     */

    reg_array_1d(Chi ,Cregs,6); // 2 spionr      - 6 regs
    reg_array_1d(Psi ,Cregs,6); // 2 spinors     - 6 regs
    reg_array_1d(Clo ,Cregs,15); 
        
    offset_2d(PSIIMM,FourSpinType,6,2*nsimd());
    offset_2d(CLOIMM,CloverType,21,2*nsimd());

    /*
     * Integer registers
     */
    alreg(Clo_p,Iregs);    /*Pointer to the current cpt of gauge field    */
    alreg(Chi_p,Iregs);    /*Pointer to the input four spinor             */
    alreg(Psi_p,Iregs);    /*Pointer to current cpt output PSI field      */
    alreg(length,Iregs);   /*number of sites*/
    //alreg(tab,Iregs);      /*Pointer to current entry in offset table*/

    alreg(args,Iregs);

    /*Useful integer immediate constants, in units of Fsize*/
    def_off(ZERO_IMM,Byte,0);
    def_off(SPINOR, FourSpinType, 12*nsimd());
    def_off(CLOVER, CloverType, 42*nsimd());
    
    int Isize      = def_offset(PROC->I_size,Byte,"Isize");
    
    /*--------------------------------------------------------------------
     * Start of the "pseudo assembler proper.
     *--------------------------------------------------------------------
     */
    make_inst(DIRECTIVE,Enter_Routine,name);

    grab_stack(0);
    save_regs();

    /*     * Define our arguments     */
    getarg(args);  /*Pointer to arg list*/

    queue_iload(Chi_p, ZERO_IMM,args);
    queue_load_addr(args,Isize,args);
    queue_iload(Psi_p, ZERO_IMM,args);
    queue_load_addr(args,Isize,args);
    queue_iload(Clo_p,   ZERO_IMM,args);
    queue_load_addr(args,Isize,args);
    queue_iload(length,ZERO_IMM,args);

    for (int i =0; i<6; i++ )
    {
        need_constant(i*2*SizeofDatum(FourSpinType)*nsimd());
    }
    for (int i =0; i<21; i++ )
    {
        need_constant(i*2*SizeofDatum(CloverType)*nsimd());
    }
  
    retno = get_target_label(); /*Branch to exit if length <1*/
    check_iterations(length,retno);

    /*     * Site loop              */
    branchsite = start_loop(length);


    for(int pp=0; pp<6; pp++)
    {
        complex_load(Psi[pp],PSIIMM[pp][0],Psi_p,FourSpinType);
    } 
    for(int qq=0; qq<6; qq++)
    {
        complex_load(Clo[qq],CLOIMM[qq][0],Clo_p,CloverType);
    }

    for(int rr=0; rr<6; rr++)
    {
        complex_mul     (Chi[rr], Clo[rr],  Psi[rr]);
    }

    for(int ss=0; ss<15; ss++)
    {
        complex_load(Clo[ss],CLOIMM[ss+6][0],Clo_p,CloverType);
    }    

    complex_conjmadd(Chi[0], Clo[0],  Psi[1]);
    complex_conjmadd(Chi[0], Clo[1],  Psi[2]);
    complex_conjmadd(Chi[0], Clo[3],  Psi[3]);
    complex_conjmadd(Chi[0], Clo[6],  Psi[4]);
    complex_conjmadd(Chi[0], Clo[10], Psi[5]);

    complex_madd    (Chi[1], Clo[0],  Psi[0]);
    complex_conjmadd(Chi[1], Clo[2],  Psi[2]);
    complex_conjmadd(Chi[1], Clo[4],  Psi[3]);
    complex_conjmadd(Chi[1], Clo[7],  Psi[4]);
    complex_conjmadd(Chi[1], Clo[11], Psi[5]);

    complex_madd    (Chi[2], Clo[1],  Psi[0]);
    complex_madd    (Chi[2], Clo[2],  Psi[1]);
    complex_conjmadd(Chi[2], Clo[5], Psi[3]);
    complex_conjmadd(Chi[2], Clo[8], Psi[4]);
    complex_conjmadd(Chi[2], Clo[12], Psi[5]);

    complex_madd    (Chi[3], Clo[3],  Psi[0]);
    complex_madd    (Chi[3], Clo[4], Psi[1]);
    complex_madd    (Chi[3], Clo[5], Psi[2]);
    complex_conjmadd(Chi[3], Clo[9], Psi[4]);
    complex_conjmadd(Chi[3], Clo[13], Psi[5]);

    complex_madd    (Chi[4], Clo[6], Psi[0]);
    complex_madd    (Chi[4], Clo[7], Psi[1]);
    complex_madd    (Chi[4], Clo[8], Psi[2]);
    complex_madd    (Chi[4], Clo[9], Psi[3]);
    complex_conjmadd(Chi[4], Clo[14], Psi[5]);

    complex_madd    (Chi[5], Clo[10], Psi[0]);
    complex_madd    (Chi[5], Clo[11], Psi[1]);
    complex_madd    (Chi[5], Clo[12], Psi[2]);
    complex_madd    (Chi[5], Clo[13], Psi[3]);
    complex_madd    (Chi[5], Clo[14], Psi[4]);
  

    for(int sp=0; sp<6; sp++)
    {
         complex_store(Chi[sp],PSIIMM[sp][0],Chi_p,FourSpinType);
    }
    
    queue_iadd_imm(Psi_p,Psi_p,SPINOR);
    queue_iadd_imm(Chi_p,Chi_p,SPINOR);
    queue_iadd_imm(Clo_p,Clo_p,CLOVER);

    /* TERMINATION point of the loop*/
    stop_loop(branchsite,length);


    make_inst(DIRECTIVE,Target,retno);

    /*	     EPILOGUE               */

    restore_regs();
    free_stack();
    make_inst(DIRECTIVE,Exit_Routine,name);

    return;
}
Ejemplo n.º 14
0
int process( jack_nframes_t nframes, void* arg ) 
{
    // XXX: should we start at 0 or at 1 ??? it was 0, but I guess 1 is right
    static int processingBlockCounter = 1;

    SourceArray::iterator sourceIt;

    realtimeCommandEngine->evaluateCommands( ( wonder_frames_t ) 15 );

    // Get input samples from JACK, put the data into the delayline.
    // fill, zeropad and fft the padding buffer
    for( sourceIt = sourceArray->begin(); sourceIt != sourceArray->end(); ++sourceIt )
    {
        SourceAggregate* source = *sourceIt;

        source->inputLine->put( ( float* ) source->inputPort->getBuffer( nframes ), nframes );
        source->inputLine->get( source->paddingBuffer->getSamples(), nframes );

        source->paddingBuffer->zeroPad2ndHalf();

        source->paddingBuffer->fft();
    }

    // XXX: is this correct?
    // read samples into tailBuffer, but only when enough samples for whole tail partitionhave have been read
    if( fwonderConf->useTail  &&  ( processingBlockCounter % ( fwonderConf->tailPartitionSize / nframes ) ) == 0 )
    {
        for( sourceIt = sourceArray->begin(); sourceIt != sourceArray->end(); ++sourceIt )
        {
            SourceAggregate* source = *sourceIt;

            source->inputLine->get( source->tailPaddingBuffer->getSamples(), fwonderConf->tailPartitionSize );

            source->tailPaddingBuffer->zeroPad2ndHalf();
            source->tailPaddingBuffer->fft();
        }
    }

    
    // Do the multiplication in the frequence domain depending on which IR should be used
    // The transformed (fft) buffer of each source is multiplied with every partition of the IR.
    // 
    //	     XXX: I need a structure that maps the correct IRs.
    //	     something like HashMap< pair<Source, Output>, ImpulseResponseChannel >
    //
    //	     for now:
    //	     every source has a current IR and the channels correspond to the outputs.
    for( sourceIt = sourceArray->begin(); sourceIt != sourceArray->end(); ++sourceIt )
    {
        SourceAggregate* source = *sourceIt;

        if(      fwonderConf->doCrossfades 
            &&     source->crossfadeInbetweenIR 
            && ! ( source->crossfadeInbetweenIR->killed ) 
            &&   ( source->crossfadeInbetweenIR->getNoChannels() == 2 ) )
        {
            ImpulseResponse* thisIR = source->crossfadeInbetweenIR;

            for( int i = 0; i < thisIR->getNoChannels(); ++i )
            {
                ImpulseResponseChannel& impulseChannel = thisIR->getChannel( i );
        	ComplexDelayLine&       outputLine     = *( outputArray->at( i )->fadeIn2ComplexLine );

        	for( int j = 0; j < thisIR->getNoPartitions(); ++j )
                {
        	    FftwBuf* IRPartBuf    = impulseChannel [ j ];
        	    FftwBuf* outputBuffer = outputLine     [ j ];
        	    complex_mul( source->paddingBuffer->getSamples(), IRPartBuf->getSamples(), outputBuffer->getSamples(),
                                 source->paddingBuffer->getSSESize() ); 
        	}
            }

            thisIR = source->currentIR;

            if( thisIR && ( thisIR->getNoChannels() == 2 ) && ! ( thisIR->killed ) )
            {
                for( int i = 0; i < thisIR->getNoChannels(); ++i )
                {
                    ImpulseResponseChannel& impulseChannel = thisIR->getChannel( i );
                    ComplexDelayLine&       outputLine     = *( outputArray->at( i )->fadeOut2ComplexLine );

        	    for( int j = 0; j < thisIR->getNoPartitions(); ++j )
                    {
        		FftwBuf* IRPartBuffer = impulseChannel[ j ];
        		FftwBuf* outputBuffer = outputLine    [ j ];
        		complex_mul( source->paddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                     source->paddingBuffer->getSSESize() ); 
        	    }
        	}
            }

            source->oldIR                = source->currentIR;
            source->currentIR            = source->crossfadeInbetweenIR;
            source->crossfadeInbetweenIR = NULL;
          
        } // end of source->crossfadeInbetweenIR
        else if( source->newIR )
        {
            ImpulseResponse* thisIR = source->newIR;

            if( thisIR && ! ( thisIR->killed ) && ( thisIR->getNoChannels() == 2 ) )
            { 
                for( int i = 0; i < thisIR->getNoChannels(); ++i )
                {
                    ImpulseResponseChannel& impulseChannel = thisIR->getChannel( i );
                    ComplexDelayLine&       outLine        = *( outputArray->at( i )->fadeInComplexLine );

                    for( int j = 0; j < thisIR->getNoPartitions(); ++j ) 
                    {
                        FftwBuf* IRPartBuffer = impulseChannel[ j ];
                        FftwBuf* outputBuffer = outLine       [ j ];
                        complex_mul( source->paddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                     source->paddingBuffer->getSSESize() ); 
                    }
                }
            }

            thisIR = source->currentIR;

            if( thisIR && ! ( thisIR->killed ) && ( thisIR->getNoChannels() == 2 ) ) 
            {
                for( int i = 0; i < thisIR->getNoChannels(); ++i )
                {
                    ImpulseResponseChannel& impulseChannel = thisIR->getChannel( i );
                    ComplexDelayLine&       outLine     = *( outputArray->at( i )->fadeOutComplexLine );

                    for( int j = 0; j < thisIR->getNoPartitions(); ++j )
                    {
                	FftwBuf* IRPartBuffer = impulseChannel[ j ];
                	FftwBuf* outputBuffer = outLine       [ j ];
                	complex_mul( source->paddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                     source->paddingBuffer->getSSESize() ); 
                    }
                }
            }

            source->crossfadeInbetweenIR = source->newIR;
            source->newIR = NULL;
        } // end of source->newIR
        else // no newIR nor crossfadeInbetweenIR
        {
            ImpulseResponse* thisIR = source->currentIR;

            if( thisIR &&  ! ( thisIR->killed ) && ( thisIR->getNoChannels() == 2 ) )
            {
                for( int i = 0; i < thisIR->getNoChannels(); ++i )
                {
                    ImpulseResponseChannel& impulseChannel = thisIR->getChannel( i );

        	    for( int j = 0; j < thisIR->getNoPartitions(); ++j )
                    {
                        // second last partition of IR
                        if( fwonderConf->doTailCrossfades  &&  ( j == thisIR->getNoPartitions() - 2 ) )
                        {
                            ComplexDelayLine& outFadeOutLine = *( outputArray->at( i )->fadeOutComplexLine );

        		    FftwBuf* IRPartBuffer = impulseChannel[ j ];
        		    FftwBuf* outputBuffer = outFadeOutLine[ j ];

        		    complex_mul( source->paddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                         source->paddingBuffer->getSSESize() ); 

        		} // last partition of IR
                        else if( fwonderConf->doTailCrossfades && ( j == thisIR->getNoPartitions() - 1 ) )
                        {
                            ComplexDelayLine& outFadeOut2Line = *( outputArray->at( i )->fadeOut2ComplexLine );

        		    FftwBuf* IRPartBuffer = impulseChannel [ j ];
        		    FftwBuf* outputBuffer = outFadeOut2Line[ j ];

        		    complex_mul( source->paddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                         source->paddingBuffer->getSSESize() ); 
        		} 
                        else
                        {
                            ComplexDelayLine&  outLine = *( outputArray->at( i )->complexLine );

        		    FftwBuf* IRPartBuffer = impulseChannel[ j ];
        		    FftwBuf* outputBuffer = outLine       [ j ];

        		    complex_mul( source->paddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                         source->paddingBuffer->getSSESize() ); 
                        }
        	    }
        	}
            }
        } // end of no newIR nor crossfadeInbetweenIR

        if( fwonderConf->useTail )
        {
            ImpulseResponse* thisIR = source->tailIR;

            if( thisIR &&  ! ( thisIR->killed ) && ( thisIR->getNoChannels() == 2 ) ) 
            {
                for( int i = 0; i < thisIR->getNoChannels(); ++i ) 
                {
                    ImpulseResponseChannel& impulseChannel = thisIR->getChannel( i );
                    ComplexDelayLine&       outLine	   = *( outputArray->at( i )->tailComplexLine );
                    ComplexDelayLine&       outFadeInLine  = *( outputArray->at( i )->tailFadeInComplexLine );

                    int partsToCompute          = thisIR->getNoPartitions() - thisIR->getFirstPartition();
                    int periodsAvail            = fwonderConf->tailPartitionSize / nframes;
                    int step                    = ( processingBlockCounter % periodsAvail);
                    int partsToComputePerPeriod = ( partsToCompute - 1 ) / periodsAvail + 1; //XXX: check if he actually meant (x-1)/(y+1)
                    int startForNow             = thisIR->getFirstPartition() +   step       * partsToComputePerPeriod;
                    int stopBefore              = thisIR->getFirstPartition() + ( step + 1 ) * partsToComputePerPeriod;

                    if( stopBefore > thisIR->getNoPartitions() )
                        stopBefore = thisIR->getNoPartitions();

                    for( int j = startForNow; j < stopBefore; ++j ) 
                    {
                        if( fwonderConf->doTailCrossfades && ( j == thisIR->getFirstPartition() ) ) 
                        {
                            FftwBuf* IRPartBuffer = impulseChannel[ j ];
                            FftwBuf* outputBuffer = outFadeInLine [ j - 2 ];
                            complex_mul( source->tailPaddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                         source->tailPaddingBuffer->getSSESize() ); 
                        }
                        else 
                        {
                            FftwBuf* IRPartBuffer = impulseChannel[ j ];
                            FftwBuf* outputBuffer = outLine       [ j - 2 ];
                            complex_mul( source->tailPaddingBuffer->getSamples(), IRPartBuffer->getSamples(), outputBuffer->getSamples(),
                                         source->tailPaddingBuffer->getSSESize() ); 
                        }
                    }
                }
            }
        }
    }


    // convolution of the IRs with the input for this block has been done 
    // the results are still in the various complex delaylines. so get them out for each output
    OutputArray::iterator outputIt;
    for( outputIt = outputArray->begin(); outputIt != outputArray->end(); ++outputIt )
    {
        // get the output delayline for the current output
        DelayLine* outputLine = ( *outputIt )->outputLine;

        // get samples from the complex delayline to the normal delayline
        {
            ComplexDelayLine* outLine   = ( *outputIt )->complexLine;
            FftwBuf*          outBuffer = ( *outLine )[ 0 ];

            outBuffer->ifft();

            outputLine->accumulateAt( 0, outBuffer->getSamples(), outBuffer->getRealSize() );
            outLine->clearCurrentBufferAndAdvance();
        }

        if( fwonderConf->doCrossfades )
        {
            // fade Out
            {
                ComplexDelayLine* outLine   = ( *outputIt )->fadeOutComplexLine;
                FftwBuf*          outBuffer = ( *outLine )[ 0 ];

                outBuffer->ifft();
                outputLine->accumulateFadeOutAt( 0, outBuffer->getSamples(), outBuffer->getRealSize(), nframes );
                outLine->clearCurrentBufferAndAdvance();
            }

            // fade In
            {
                ComplexDelayLine* outLine   = ( *outputIt )->fadeInComplexLine;
                FftwBuf*          outBuffer = ( *outLine )[ 0 ];

                outBuffer->ifft();
                outputLine->accumulateFadeInAt( 0, outBuffer->getSamples(), outBuffer->getRealSize(), nframes );
                outLine->clearCurrentBufferAndAdvance();
            }

            // fade Out 2
            {
                ComplexDelayLine* outLine   = ( *outputIt )->fadeOut2ComplexLine;
                FftwBuf*          outBuffer = ( *outLine )[ 0 ];

                outBuffer->ifft();
                outputLine->accumulateFadeOut2At( 0, outBuffer->getSamples(), outBuffer->getRealSize(), nframes );
                outLine->clearCurrentBufferAndAdvance();
            }

            // fade In 2
            {
                ComplexDelayLine* outLine   = ( *outputIt )->fadeIn2ComplexLine;
                FftwBuf*          outBuffer = ( *outLine )[ 0 ];

                outBuffer->ifft();
                outputLine->accumulateFadeIn2At( 0, outBuffer->getSamples(), outBuffer->getRealSize(), nframes );
                outLine->clearCurrentBufferAndAdvance();
            }
        }

        if( fwonderConf->useTail )
        {
            int periods_avail = fwonderConf->tailPartitionSize / nframes;
            int step          = processingBlockCounter % periods_avail;

            if( step == ( periods_avail - 1 ) )
            {
                // tail
                {
                    ComplexDelayLine* outLine   = ( *outputIt )->tailComplexLine;
                    FftwBuf*          outBuffer = ( *outLine )[ 0 ];

                    outBuffer->ifft();
                    outputLine->accumulateAt( fwonderConf->tailOffset * nframes, outBuffer->getSamples(), outBuffer->getRealSize() );
                    outLine->clearCurrentBufferAndAdvance();
                }

                // tail fade In
                if( fwonderConf->doTailCrossfades )
                {
                    ComplexDelayLine* outLine   = ( *outputIt )->tailFadeInComplexLine;
                    FftwBuf*          outBuffer = ( *outLine )[ 0 ];

                    outBuffer->ifft();
                    outputLine->accumulateFadeInAt( fwonderConf->tailOffset * nframes, outBuffer->getSamples(), outBuffer->getRealSize(), nframes );
                    outLine->clearCurrentBufferAndAdvance();
                }
            }
        }

        // get the resulting samples from the delayline out to JACK
        float* outputBuffer = ( float* ) ( *outputIt )->outputPort->getBuffer( nframes );
        outputLine->getAndClearAndAdvance( outputBuffer, nframes );
    }
    
    ++processingBlockCounter;
    
    return 0;
}
Ejemplo n.º 15
0
	inline void update() {
		PhysParticle::update();
		orientation = complex_mul(orientation, angular_vel);
	}
Ejemplo n.º 16
0
struct signal* fft(struct signal* p_signal)
{
	struct signal*  p_input_signal = \
	(struct signal*) malloc(sizeof(struct complex_number)*(p_signal->size) + sizeof(p_signal->size));

	struct signal*  p_out_put_signal = \
 	(struct signal*)malloc(sizeof(struct complex_number)*(p_signal->size) + sizeof(p_signal->size));

	*p_input_signal   = *p_signal;
	*p_out_put_signal = *p_signal;

	int tmp   = 0;
	int index = 0;
	int bits  = 0;

	int layyer= 0;
	int selected_point = 0;
	int pre_half	   = 0;	

	int    r  = 0;
	double x  = 0;
	struct complex_number W_rN ;
	struct complex_number complex_tmp ;

	/*
	**	We caculate how many bits should be used to 
	** represent the size of the number of input signal.
	*/
	for(tmp = p_signal->size-1;tmp > 0;tmp>>=1)
	{
		bits++;
	}

	/*
	**	We should re-sequence the input signal
	** by bit-reverse.
	*/
	for(tmp = 0;tmp < p_signal->size;tmp++)
	{
		index = reverse_bits(tmp,bits);
		p_input_signal->points[tmp] = p_signal->points[index];
#ifdef DEBUG
		printf(" tmp:%5d index:%5d  ",tmp,index);
		show_complex_number(&p_signal->points[index]);
#endif
	}

	for(layyer = 1;layyer <= bits;layyer++)
	{

		
		#ifdef DEBUG
			printf("layyer %d input\n",layyer);
			show_signal(p_input_signal);
		#endif

		for(selected_point = 0;selected_point < p_signal->size;selected_point += 1<<(layyer))
		{
			for(pre_half = selected_point,r = 0,x = 0;
			    pre_half < (selected_point + (1<<(layyer-1)));
			    pre_half++)
			{
				r = get_r_in_Wn(pre_half,layyer,bits);

				#ifdef DEBUG
					printf("r: %d\n",r);
				#endif
	
				x = -2*PI*r/((double)(p_input_signal->size));
				W_rN.real    = cos(x);
				W_rN.imagine = sin(x);

				complex_tmp = complex_mul(&W_rN , &(p_input_signal->points[pre_half + (1<<(layyer-1))])  );

				#ifdef DEBUG
					show_complex_number(&complex_tmp);
				#endif

				p_out_put_signal->points[pre_half] = \
				complex_add(&p_input_signal->points[pre_half],&complex_tmp);

				p_out_put_signal->points[pre_half + (1<<(layyer-1))] = \
				complex_sub(&p_input_signal->points[pre_half],&complex_tmp);

			}
			
		}

		#ifdef DEBUG
			printf("layyer%d output\n",layyer);
			show_signal(p_out_put_signal);
		#endif

		for(tmp = 0;tmp < p_out_put_signal->size;tmp++)
		{
			p_input_signal->points[tmp] = p_out_put_signal->points[tmp];
		}

	}

	free(p_input_signal);
	return p_out_put_signal;
}
Ejemplo n.º 17
0
bool collideCircleRectangle(vec2 circle_position, float circle_radius, vec2 rect_size, vec2 rect_orientation) {
	vec2 rotated_circle = complex_mul(circle_position, complex_conjugate(rect_orientation));
	return collideCircleAARectangle(rotated_circle, circle_radius, rect_size);
}