Example #1
0
static IPTR coolimage_draw(Class *cl, Object *o, struct impDraw *msg)
{
    struct CoolImageData    *data;
    WORD    	    	    x, y;
    
    data = INST_DATA(cl, o);
    
    x = IM(o)->LeftEdge + msg->imp_Offset.X;
    y = IM(o)->TopEdge  + msg->imp_Offset.Y;
    
    if (CyberGfxBase && (GetBitMapAttr(msg->imp_RPort->BitMap, BMA_DEPTH) >= 15))
    {
	data->pal[0] = data->bgcol;
	
	WriteLUTPixelArray((APTR)data->image->data,
			    0,
			    0,
			    data->image->width,
			    msg->imp_RPort,
			    data->pal,
			    x,
			    y,
			    data->image->width,
			    data->image->height,
			    CTABFMT_XRGB8);
        
    }
    	    
    return 0;
}
Example #2
0
mdct_info *faad_mdct_init(uint16_t N)
{
    uint16_t k;
#ifdef FIXED_POINT
    uint16_t N_idx;
    real_t cangle, sangle, c, s, cold;
#endif
	real_t scale;

    mdct_info *mdct = (mdct_info*)faad_malloc(sizeof(mdct_info));

    assert(N % 8 == 0);

    mdct->N = N;
    mdct->sincos = (complex_t*)faad_malloc(N/4*sizeof(complex_t));

#ifdef FIXED_POINT
    N_idx = map_N_to_idx(N);

    scale = const_tab[N_idx][0];
    cangle = const_tab[N_idx][1];
    sangle = const_tab[N_idx][2];
    c = const_tab[N_idx][3];
    s = const_tab[N_idx][4];
#else
    scale = (real_t)sqrt(2.0 / (real_t)N);
#endif

    /* (co)sine table build using recurrence relations */
    /* this can also be done using static table lookup or */
    /* some form of interpolation */
    for (k = 0; k < N/4; k++)
    {
#ifdef FIXED_POINT
        RE(mdct->sincos[k]) = c; //MUL_C_C(c,scale);
        IM(mdct->sincos[k]) = s; //MUL_C_C(s,scale);

        cold = c;
        c = MUL_F(c,cangle) - MUL_F(s,sangle);
        s = MUL_F(s,cangle) + MUL_F(cold,sangle);
#else
        /* no recurrence, just sines */
        RE(mdct->sincos[k]) = scale*(real_t)(cos(2.0*M_PI*(k+1./8.) / (real_t)N));
        IM(mdct->sincos[k]) = scale*(real_t)(sin(2.0*M_PI*(k+1./8.) / (real_t)N));
#endif
    }

    /* initialise fft */
    mdct->cfft = cffti(N/4);

#ifdef PROFILE
    mdct->cycles = 0;
    mdct->fft_cycles = 0;
#endif

    return mdct;
}
Example #3
0
/* C = A + B */
static void aadd(COMPLEX *C, COMPLEX *A, COMPLEX *B, int n)
{
     int i;

     for (i = 0; i < n; ++i) {
	  RE(C[i]) = RE(A[i]) + RE(B[i]);
	  IM(C[i]) = IM(A[i]) + IM(B[i]);
     }
}
Example #4
0
/* A = alpha * A  (complex, in place) */
static void ascale(COMPLEX *A, COMPLEX alpha, int n)
{
     int i;

     for (i = 0; i < n; ++i) {
	  COMPLEX a = A[i];
	  RE(A[i]) = RE(a) * RE(alpha) - IM(a) * IM(alpha);
	  IM(A[i]) = RE(a) * IM(alpha) + IM(a) * RE(alpha);
     }
}
Example #5
0
/* complex addition helper */
static void sig_caddsub(uint16 addsub,OPS op)
{
OP a,b,c,d,p1,p2;

a = ReadOp(RE(op[1].word), fp_f);                  /* read 1st op */
b = ReadOp(IM(op[1].word), fp_f);
c = ReadOp(RE(op[2].word), fp_f);                  /* read 2nd op */
d = ReadOp(IM(op[2].word), fp_f);
(void)fp_exec(addsub,&p1, a, c);                   /* add real */
(void)fp_exec(addsub,&p2, b, d);                   /* add imag */
WriteOp(RE(op[0].word), p1, fp_f);                 /* write result */
WriteOp(IM(op[0].word), p2, fp_f);                 /* write result */
}
static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][64],
                             uint8_t bd, uint8_t len)
{
    real_t r01r = 0, r01i = 0, r02r = 0, r02i = 0, r11r = 0;
    real_t temp1_r, temp1_i, temp2_r, temp2_i, temp3_r, temp3_i;
    real_t temp4_r, temp4_i, temp5_r, temp5_i;
    int8_t j;
    uint8_t offset = sbr->tHFAdj;
    const real_t rel = FRAC_CONST(0.999999); // 1 / (1 + 1e-6f);

    temp2_r = ACDET_PRE(QMF_RE(buffer[offset-2][bd]));
    temp2_i = ACDET_PRE(QMF_IM(buffer[offset-2][bd]));
    temp3_r = ACDET_PRE(QMF_RE(buffer[offset-1][bd]));
    temp3_i = ACDET_PRE(QMF_IM(buffer[offset-1][bd]));
    // Save these because they are needed after loop
    temp4_r = temp2_r;
    temp4_i = temp2_i;
    temp5_r = temp3_r;
    temp5_i = temp3_i;

    for (j = offset; j < len + offset; j++)
    {
        temp1_r = temp2_r;
        temp1_i = temp2_i;
        temp2_r = temp3_r;
        temp2_i = temp3_i;
        temp3_r = ACDET_PRE(QMF_RE(buffer[j][bd]));
        temp3_i = ACDET_PRE(QMF_IM(buffer[j][bd]));
        r01r += MUL_F(temp3_r, temp2_r) + MUL_F(temp3_i, temp2_i);
        r01i += MUL_F(temp3_i, temp2_r) - MUL_F(temp3_r, temp2_i);
        r02r += MUL_F(temp3_r, temp1_r) + MUL_F(temp3_i, temp1_i);
        r02i += MUL_F(temp3_i, temp1_r) - MUL_F(temp3_r, temp1_i);
        r11r += MUL_F(temp2_r, temp2_r) + MUL_F(temp2_i, temp2_i);
    }

    RE(ac->r12) = r01r - (MUL_F(temp3_r, temp2_r) + MUL_F(temp3_i, temp2_i)) +
                         (MUL_F(temp5_r, temp4_r) + MUL_F(temp5_i, temp4_i));
    IM(ac->r12) = r01i - (MUL_F(temp3_i, temp2_r) - MUL_F(temp3_r, temp2_i)) +
                         (MUL_F(temp5_i, temp4_r) - MUL_F(temp5_r, temp4_i));
    RE(ac->r22) = r11r - (MUL_F(temp2_r, temp2_r) + MUL_F(temp2_i, temp2_i)) +
                         (MUL_F(temp4_r, temp4_r) + MUL_F(temp4_i, temp4_i));
    RE(ac->r01) = r01r;
    IM(ac->r01) = r01i;
    RE(ac->r02) = r02r;
    IM(ac->r02) = r02i;
    RE(ac->r11) = r11r;

    ac->det = MUL_F(RE(ac->r11), RE(ac->r22)) - MUL_F((MUL_F(RE(ac->r12), RE(ac->r12)) + MUL_F(IM(ac->r12), IM(ac->r12))), rel);
    ac->det = ACDET_POST(ac->det);

}
Example #7
0
    unique_ptr<SharedLibrary> CompileCode(const std::vector<string> &codes, const std::vector<string> &link_flags )
    {
      static int counter = 0;
      static ngstd::Timer tcompile("CompiledCF::Compile");
      static ngstd::Timer tlink("CompiledCF::Link");
      string object_files;
      int i = 0;
      string prefix = "code" + ToString(counter++);
      for(string code : codes) {
        string file_prefix = prefix+"_"+ToString(i++);
        ofstream codefile(file_prefix+".cpp");
        codefile << code;
        codefile.close();
        cout << IM(3) << "compiling..." << endl;
        tcompile.Start();
#ifdef WIN32
        string scompile = "cmd /C \"ngscxx.bat " + file_prefix + ".cpp\"";
        object_files += file_prefix+".obj ";
#else
        string scompile = "ngscxx -c " + file_prefix + ".cpp -o " + file_prefix + ".o";
        object_files += file_prefix+".o ";
#endif
        int err = system(scompile.c_str());
        if (err) throw Exception ("problem calling compiler");
        tcompile.Stop();
      }

      cout << IM(3) << "linking..." << endl;
      tlink.Start();
#ifdef WIN32
        string slink = "cmd /C \"ngsld.bat /OUT:" + prefix+".dll " + object_files + "\"";
#else
        string slink = "ngsld -shared " + object_files + " -o " + prefix + ".so -lngstd -lngbla -lngfem";
        for (auto flag : link_flags)
            slink += " "+flag;
#endif
      int err = system(slink.c_str());
      if (err) throw Exception ("problem calling linker");      
      tlink.Stop();
      cout << IM(3) << "done" << endl;
      auto library = make_unique<SharedLibrary>();
#ifdef WIN32
      library->Load(prefix+".dll");
#else
      library->Load("./"+prefix+".so");
#endif
      return library;
    }
Example #8
0
    virtual void Update ()
    {
      // delete inverse;
      if (GetTimeStamp() == bfa->GetTimeStamp()) return;
      timestamp = bfa->GetTimeStamp();
      
      cout << IM(3) << "Update Direct Solver Preconditioner" << flush;
      
      try
	{                                          
          auto have_sparse_fact = dynamic_pointer_cast<SparseFactorization> (inverse);
          if (have_sparse_fact && have_sparse_fact -> SupportsUpdate())
            {
              if (have_sparse_fact->GetAMatrix() == bfa->GetMatrixPtr())
                {
                  // cout << "have the same matrix, can update factorization" << endl;
                  have_sparse_fact->Update();
                  return;
                }
            }
          
	  bfa->GetMatrix().SetInverseType (inversetype);
	  shared_ptr<BitArray> freedofs = 
	    bfa->GetFESpace()->GetFreeDofs (bfa->UsesEliminateInternal());
	  inverse = bfa->GetMatrix().InverseMatrix(freedofs);
	}
      catch (exception & e)
	{
	  throw Exception (string("caught exception in DirectPreconditioner: \n") +
                           e.what() + 
                           "\nneeds a sparse matrix (or has memory problems)");
	}
    }
TEST(PeelOuterHullLayers, CubeWithFold) {
    Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> V;
    Eigen::MatrixXi F;
    test_common::load_mesh("cube_with_fold.ply", V, F);

    typedef CGAL::Exact_predicates_exact_constructions_kernel K;
    typedef K::FT Scalar;
    typedef Eigen::Matrix<Scalar,
            Eigen::Dynamic,
            Eigen::Dynamic> MatrixXe;

    MatrixXe Vs;
    Eigen::MatrixXi Fs, IF;
    Eigen::VectorXi J, IM;
    igl::copyleft::cgal::RemeshSelfIntersectionsParam param;
    igl::copyleft::cgal::remesh_self_intersections(V, F, param, Vs, Fs, IF, J, IM);

    std::for_each(Fs.data(),Fs.data()+Fs.size(),
            [&IM](int & a){ a=IM(a); });
    MatrixXe Vt;
    Eigen::MatrixXi Ft;
    igl::remove_unreferenced(Vs,Fs,Vt,Ft,IM);

    Eigen::VectorXi I, flipped;
    size_t num_peels = igl::copyleft::cgal::peel_outer_hull_layers(Vt, Ft, I, flipped);
}
Example #10
0
VOID AROSCycle__GM_RENDER(Class *cl, Object *o, struct gpRender *msg)
{
    struct CycleData *data = INST_DATA(cl, o);

    /* Full redraw: clear and draw border */
    DrawImageState(msg->gpr_RPort,IM(EG(o)->GadgetRender),
                   EG(o)->LeftEdge, EG(o)->TopEdge,
                   EG(o)->Flags&GFLG_SELECTED?IDS_SELECTED:IDS_NORMAL,
                   msg->gpr_GInfo->gi_DrInfo);

    if (data->font)
    	SetFont(msg->gpr_RPort, data->font);
    else
	SetFont(msg->gpr_RPort, msg->gpr_GInfo->gi_DrInfo->dri_Font);

    if (data->labels)
        renderlabel(EG(o), data->labels[data->active],
                    msg->gpr_RPort, msg->gpr_GInfo);
		    
    /* Draw disabled pattern */
    if (G(o)->Flags & GFLG_DISABLED)
        drawdisabledpattern(msg->gpr_RPort,
                            msg->gpr_GInfo->gi_DrInfo->dri_Pens[SHADOWPEN],
                            G(o)->LeftEdge, G(o)->TopEdge,
                            G(o)->Width, G(o)->Height);

}
Example #11
0
  int EnterTaskManager ()
  {
    if (task_manager)
      {
        // no task manager started
        return 0;
      }

    task_manager = new TaskManager();

    cout << IM(3) << "task-based parallelization (C++11 threads) using "<< task_manager->GetNumThreads() << " threads" << endl;

#ifdef USE_NUMA
    numa_run_on_node (0);
#endif

#ifndef WIN32
    // master has maximal priority !
    int policy;
    struct sched_param param;
    pthread_getschedparam(pthread_self(), &policy, &param);
    param.sched_priority = sched_get_priority_max(policy);
    pthread_setschedparam(pthread_self(), policy, &param);
#endif // WIN32

    
    task_manager->StartWorkers();

    ParallelFor (Range(100), [&] (int i) { ; });    // startup
    return task_manager->GetNumThreads();
  }
Example #12
0
test_report benchmark_test_with_external_configuration(std::string test_casename, const std::string function_name, int flag){
	std::cout << "test case: " << test_casename << " starts with external configuration" << std::endl;

	general_configuration ext_conf_file("configuration_"+function_name+".txt");

	Overall_Optimisation_Configuration_Settings myConf2(test_casename,
			ext_conf_file,
			"reference_point_"+function_name+".txt",
			"penalty_point_"+function_name+".txt",
			"lower_bound_"+function_name+".txt",
			"upper_bound_"+function_name+".txt",
			"starting_point_"+function_name+".txt",
			"current_step_"+function_name+".txt");

	const unsigned int n_of_variables=myConf2.getExternalConfigurationFile().getVar();
	const unsigned int n_of_objectives=myConf2.getExternalConfigurationFile().getObj();

	objective_function_formulae obj_function(n_of_objectives);

	ObjectiveFunctionBasic<double> TS_ObjFunc(myConf2, obj_function);

	Container2 MTM(n_of_variables, n_of_objectives, "MTM","./memories");
	Container2 IM(n_of_variables, n_of_objectives, "IM","./memories");
	Container2 HISTORY(n_of_variables, n_of_objectives, "HISTORY","./memories");

	STM_Container2 STM(myConf2.getExternalConfigurationFile().getStmSize(), n_of_variables, "STM", "./memories");
	LTM_Container2Basic2<double> LTM( n_of_variables ,  myConf2.getExternalConfigurationFile().getRegions(), myConf2.get_lower_bound(), myConf2.get_upper_bound(),"LTM", "./memories");
	std::cout << "Memories done!" << std::endl;

	TabuSearch TS(myConf2, flag, TS_ObjFunc, MTM, IM, HISTORY, STM, LTM);

	double hyper_volume_indicator=TS.search2();

	return test_report(myConf2.getCaseName(), TS.getDatumPnt(), hyper_volume_indicator) ;
}
	virtual void UpdatePotentialData(typename blitz::Array<cplx, Rank> data, typename Wavefunction<Rank>::Ptr psi, cplx timeStep, double curTime)
	{
		typedef CombinedRepresentation<Rank> CmbRepr;
		typedef SphericalHarmonicBasisRepresentation SphHarmRepr;

		typename CmbRepr::Ptr repr = boost::static_pointer_cast< CmbRepr >(psi->GetRepresentation());
		SphHarmRepr::Ptr angRepr = boost::static_pointer_cast< SphHarmRepr >(repr->GetRepresentation(this->AngularRank));
	
		int rCount = data.extent(this->RadialRank);
		int angCount = data.extent(this->AngularRank);

		blitz::Array<double, 1> localr = psi->GetRepresentation()->GetLocalGrid(this->RadialRank);

		BasisPairList angBasisPairs = GetBasisPairList(this->AngularRank);

		if (data.extent(this->RadialRank) != rCount) throw std::runtime_error("Invalid r size");
		if (data.extent(this->AngularRank) != angBasisPairs.extent(0)) throw std::runtime_error("Invalid ang size");

		cplx IM(0,1.0);
		blitz::TinyVector<int, Rank> index;
		data = 0;

		for (int angIndex=0; angIndex<angCount; angIndex++)
		{
			index(AngularRank) = angIndex;

			int leftIndex = angBasisPairs(angIndex, 0);
			int rightIndex = angBasisPairs(angIndex, 1);
	
			LmIndex left = angRepr->Range.GetLmIndex(leftIndex);
			LmIndex right = angRepr->Range.GetLmIndex(rightIndex);

			//"Left" quantum numbers
			int l = left.l;
			int m = left.m;
			
			//"Right" quantum numbers
			int lp = right.l;
			int mp = right.m;

			//Selection rules
			if (m != mp) continue;
			if (std::abs(l - lp) != 1) continue;

			double E = LaserHelper::E(lp, m) * LaserHelper::kronecker(l, lp+1);
			double F = LaserHelper::F(lp, m) * LaserHelper::kronecker(l, lp-1);

			double coupling = (E + F);


			for (int ri=0; ri<rCount; ri++)
			{
				index(RadialRank) = ri;
				data(index) = - IM* coupling;

				//Charge scaling from config
				data(index) *= (-1.0) * Charge;
			}
		}
	}
Example #14
0
static double verify_impulse(fftd_func *dft,
			    int n, int veclen,
			   COMPLEX *inA,
			   COMPLEX *inB,
			   COMPLEX *inC,
			   COMPLEX *outA,
			   COMPLEX *outB,
			   COMPLEX *outC,
			   COMPLEX *tmp,
			   int rounds)
{
     int N = n * veclen;
     COMPLEX impulse;
     int i;
     double e, maxerr = 0.0;

     /* test 2: check that the unit impulse is transformed properly */
     RE(impulse) = 1.0;
     IM(impulse) = 0.0;
     
     for (i = 0; i < N; ++i) {
	  /* impulse */
	  RE(inA[i]) = 0.0;
	  IM(inA[i]) = 0.0;
	  
	  /* transform of the impulse */
	  outA[i] = impulse;
     }
     for (i = 0; i < veclen; ++i)
	  inA[i * n] = impulse;

     /* a simple test first, to help with debugging: */
     dft((double *)outB, (double *)inA);
     e = acmp(outB, outA, N);
     if(e > maxerr) maxerr = e;

     for (i = 0; i < rounds; ++i) {
	  fill_random(inB, N);
	  asub(inC, inA, inB, N);
   	  dft((double *)outB, (double *)inB);
   	  dft((double *)outC, (double *)inC);
	  aadd(tmp, outB, outC, N);
	  e = acmp(tmp, outA, N);
	  if(e > maxerr) maxerr = e;
     }
     return maxerr;
}
Example #15
0
static void fill_random(COMPLEX *a, int n)
{
     int i;

     /* generate random inputs */
     for (i = 0; i < n; ++i) {
	  RE(a[i]) = double_rand();
	  IM(a[i]) = double_rand();
     }
}
Example #16
0
static void auto_correlation(sbr_info *sbr, acorr_coef *ac, qmf_t buffer[MAX_NTSRHFG][32],
                             uint8_t bd, uint8_t len)
{
    real_t r01r = 0, r01i = 0, r02r = 0, r02i = 0, r11r = 0;
    const real_t rel = 1 / (1 + 1e-6f);
    int8_t j;
    uint8_t offset = sbr->tHFAdj;


    for (j = offset; j < len + offset; j++)
    {
        r01r += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-1][bd]) +
            QMF_IM(buffer[j][bd]) * QMF_IM(buffer[j-1][bd]);
        r01i += QMF_IM(buffer[j][bd]) * QMF_RE(buffer[j-1][bd]) -
            QMF_RE(buffer[j][bd]) * QMF_IM(buffer[j-1][bd]);
        r02r += QMF_RE(buffer[j][bd]) * QMF_RE(buffer[j-2][bd]) +
            QMF_IM(buffer[j][bd]) * QMF_IM(buffer[j-2][bd]);
        r02i += QMF_IM(buffer[j][bd]) * QMF_RE(buffer[j-2][bd]) -
            QMF_RE(buffer[j][bd]) * QMF_IM(buffer[j-2][bd]);
        r11r += QMF_RE(buffer[j-1][bd]) * QMF_RE(buffer[j-1][bd]) +
            QMF_IM(buffer[j-1][bd]) * QMF_IM(buffer[j-1][bd]);
    }

    RE(ac->r01) = r01r;
    IM(ac->r01) = r01i;
    RE(ac->r02) = r02r;
    IM(ac->r02) = r02i;
    RE(ac->r11) = r11r;

    RE(ac->r12) = r01r -
        (QMF_RE(buffer[len+offset-1][bd]) * QMF_RE(buffer[len+offset-2][bd]) + QMF_IM(buffer[len+offset-1][bd]) * QMF_IM(buffer[len+offset-2][bd])) +
        (QMF_RE(buffer[offset-1][bd]) * QMF_RE(buffer[offset-2][bd]) + QMF_IM(buffer[offset-1][bd]) * QMF_IM(buffer[offset-2][bd]));
    IM(ac->r12) = r01i -
        (QMF_IM(buffer[len+offset-1][bd]) * QMF_RE(buffer[len+offset-2][bd]) - QMF_RE(buffer[len+offset-1][bd]) * QMF_IM(buffer[len+offset-2][bd])) +
        (QMF_IM(buffer[offset-1][bd]) * QMF_RE(buffer[offset-2][bd]) - QMF_RE(buffer[offset-1][bd]) * QMF_IM(buffer[offset-2][bd]));
    RE(ac->r22) = r11r -
        (QMF_RE(buffer[len+offset-2][bd]) * QMF_RE(buffer[len+offset-2][bd]) + QMF_IM(buffer[len+offset-2][bd]) * QMF_IM(buffer[len+offset-2][bd])) +
        (QMF_RE(buffer[offset-2][bd]) * QMF_RE(buffer[offset-2][bd]) + QMF_IM(buffer[offset-2][bd]) * QMF_IM(buffer[offset-2][bd]));

    ac->det = RE(ac->r11) * RE(ac->r22) - rel * (RE(ac->r12) * RE(ac->r12) + IM(ac->r12) * IM(ac->r12));
}
Example #17
0
  void Preconditioner :: Timing () const
  {
    cout << IM(1) << "Timing Preconditioner ... " << flush;
    const BaseMatrix & amat = GetAMatrix();
    const BaseMatrix & pre = GetMatrix();

    clock_t starttime;
    double time;
    starttime = clock();

    BaseVector & vecf = *pre.CreateVector();
    BaseVector & vecu = *pre.CreateVector();

    vecf = 1;
    int steps = 0;
    do
      {
	vecu = pre * vecf;
	steps++;
	time = double(clock() - starttime) / CLOCKS_PER_SEC;
      }
    while (time < 2.0);

    cout << IM(1) << " 1 step takes " << time / steps << " seconds" << endl;


    starttime = clock();
    steps = 0;
    do
      {
	vecu = amat * vecf;
	steps++;
	time = double(clock() - starttime) / CLOCKS_PER_SEC;
      }
    while (time < 2.0);

    cout << IM(1) << ", 1 matrix takes "
	 << time / steps << " seconds" << endl;
  }
Example #18
0
static double verify_linear(fftd_func *dft, 
			  int N,
			  COMPLEX *inA,
			  COMPLEX *inB,
			  COMPLEX *inC,
			  COMPLEX *outA,
			  COMPLEX *outB,
			  COMPLEX *outC,
			  COMPLEX *tmp,
			  int rounds)
{
    int i; double maxerr = 0.0; double e;

    /* test 1: check linearity */
    for (i = 0; i < rounds; ++i) {
	COMPLEX alpha, beta;
	RE(alpha) = double_rand();
	IM(alpha) = double_rand();
	RE(beta) = double_rand();
	IM(beta) = double_rand();
	fill_random(inA, N);
	fill_random(inB, N);
	dft((double *)outA, (double *)inA);
	dft((double *)outB, (double *)inB);

	ascale(outA, alpha, N);
	ascale(outB, beta, N);
	aadd(tmp, outA, outB, N);
	ascale(inA, alpha, N);
	ascale(inB, beta, N);
	aadd(inC, inA, inB, N);
	dft((double *)outC, (double *)inC);

	e = acmp(outC, tmp, N);
	if(e > maxerr) maxerr = e;
    }
    return maxerr;
}
Example #19
0
static double verify_shift(fftd_func *dft,
			 int N, 
			 COMPLEX *inA,
			 COMPLEX *inB,
			 COMPLEX *outA,
			 COMPLEX *outB,
			 COMPLEX *tmp,
			 int rounds)
{
    const double twopin = 2 * M_PI / (double) N;
    int i, j;
    double e, maxerr = 0.0;

    /* test 3: check the time-shift property */
    /* the paper performs more tests, but this code should be fine too */

    for (i = 0; i < rounds; ++i) {
	  
	fill_random(inA, N);
	arol(inB, inA, N, 1);

	dft((double *)outA, (double *)inA);
	dft((double *)outB, (double *)inB);

	for (j = 0; j < N; ++j) {
	    double s = SIGN * sin(j * twopin);
	    double c = cos(j * twopin);
	    int index = j;
	    RE(tmp[index]) = RE(outB[index]) * c - IM(outB[index]) * s;
	    IM(tmp[index]) = RE(outB[index]) * s + IM(outB[index]) * c;
	}
	e = acmp(tmp, outA, N);
	if(e > maxerr) maxerr = e;
    }
    return maxerr;
}
Example #20
0
static double compute_error(COMPLEX *A, COMPLEX *B, int n)
{
     /* compute the relative error */
     double error = 0.0;
     double tol = TOLERANCE;
     int i;

     for (i = 0; i < n; ++i) {
	  double a;
	  double mag;
	  a = hypot(RE(A[i]) - RE(B[i]), IM(A[i]) - IM(B[i]));
	  mag = 0.5 * (hypot(RE(A[i]), IM(A[i])) +
		       hypot(RE(B[i]), IM(B[i]))) + tol;

	  a /= mag;
	  if (a > error)
	       error = a;

#ifdef HAVE_ISNAN
	  FFTW_ASSERT(!isnan(a));
#endif
     }
     return error;
}
Example #21
0
void system_init(){

    // Estructura de configuración para la UART.
    uart_cfg_t uart_config;

    // Configura los aprametros de la UART.
    uart_config.baudrate    = UART_BAUDRATE_9600;   // Baudaje a 1200.
    uart_config.stop_bits   = UART_STOP_BITS_1;     // 1 bit de parada.
    uart_config.parity      = UART_PARITY_NONE;     // Sin paridad
    uart_config.word_length = UART_WORD_LENGTH_8;   // Dato de 8 bits
    uart_config.interrupt   = UART_INTERRUPT_RX;    // Interrupción por dato recibido activada.

    // Inicializa la UART con su configuración.
    uart_init(&uart_config);

    IM(1);  // Modo de interrupcion 1 en el Z80.
    EI();   // Habilita la interrupción INT en el Z80
    
}
Example #22
0
static void passf2pos_sse(const uint16_t l1, const complex_t *cc,
                          complex_t *ch, const complex_t *wa)
{
    uint16_t k, ah, ac;

    for (k = 0; k < l1; k++)
    {
        ah = 2*k;
        ac = 4*k;

        RE(ch[ah])    = RE(cc[ac]) + RE(cc[ac+1]);
        IM(ch[ah])    = IM(cc[ac]) + IM(cc[ac+1]);

        RE(ch[ah+l1]) = RE(cc[ac]) - RE(cc[ac+1]);
        IM(ch[ah+l1]) = IM(cc[ac]) - IM(cc[ac+1]);
    }
}
TEST(copyleft_cgal_peel_outer_hull_layers, TwoCubes) {
    Eigen::MatrixXd V;
    Eigen::MatrixXi F;
    test_common::load_mesh("two-boxes-bad-self-union.ply", V, F);
    ASSERT_EQ(486, V.rows());
    ASSERT_EQ(708, F.rows());

    typedef CGAL::Exact_predicates_exact_constructions_kernel K;
    typedef K::FT Scalar;
    typedef Eigen::Matrix<Scalar,
            Eigen::Dynamic,
            Eigen::Dynamic> MatrixXe;

    MatrixXe Vs;
    Eigen::MatrixXi Fs, IF;
    Eigen::VectorXi J, IM;
    igl::copyleft::cgal::RemeshSelfIntersectionsParam param;
    igl::copyleft::cgal::remesh_self_intersections(V, F, param, Vs, Fs, IF, J, IM);

    std::for_each(Fs.data(),Fs.data()+Fs.size(),
            [&IM](int & a){ a=IM(a); });
    MatrixXe Vt;
    Eigen::MatrixXi Ft;
    igl::remove_unreferenced(Vs,Fs,Vt,Ft,IM);
    const size_t num_faces = Ft.rows();

    Eigen::VectorXi I, flipped;
    size_t num_peels = igl::copyleft::cgal::peel_outer_hull_layers(Vt, Ft, I, flipped);

    Eigen::MatrixXd vertices(Vt.rows(), Vt.cols());
    std::transform(Vt.data(), Vt.data() + Vt.rows() * Vt.cols(),
            vertices.data(), [](Scalar v) { return CGAL::to_double(v); });
    igl::writeOBJ("debug.obj", vertices, Ft);

    ASSERT_EQ(num_faces, I.rows());
    ASSERT_EQ(0, I.minCoeff());
    ASSERT_EQ(1, I.maxCoeff());
}
Example #24
0
static void passf3(const uint16_t ido, const uint16_t l1, const complex_t *cc,
                   complex_t *ch, const complex_t *wa1, const complex_t *wa2,
                   const int8_t isign)
{
    static real_t taur = FRAC_CONST(-0.5);
    static real_t taui = FRAC_CONST(0.866025403784439);
    uint16_t i, k, ac, ah;
    complex_t c2, c3, d2, d3, t2;

    if (ido == 1)
    {
        if (isign == 1)
        {
            for (k = 0; k < l1; k++)
            {
                ac = 3*k+1;
                ah = k;

                RE(t2) = RE(cc[ac]) + RE(cc[ac+1]);
                IM(t2) = IM(cc[ac]) + IM(cc[ac+1]);
                RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),taur);
                IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),taur);

                RE(ch[ah]) = RE(cc[ac-1]) + RE(t2);
                IM(ch[ah]) = IM(cc[ac-1]) + IM(t2);

                RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+1])), taui);
                IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+1])), taui);

                RE(ch[ah+l1]) = RE(c2) - IM(c3);
                IM(ch[ah+l1]) = IM(c2) + RE(c3);
                RE(ch[ah+2*l1]) = RE(c2) + IM(c3);
                IM(ch[ah+2*l1]) = IM(c2) - RE(c3);
            }
        } else {
            for (k = 0; k < l1; k++)
            {
                ac = 3*k+1;
                ah = k;

                RE(t2) = RE(cc[ac]) + RE(cc[ac+1]);
                IM(t2) = IM(cc[ac]) + IM(cc[ac+1]);
                RE(c2) = RE(cc[ac-1]) + MUL_F(RE(t2),taur);
                IM(c2) = IM(cc[ac-1]) + MUL_F(IM(t2),taur);

                RE(ch[ah]) = RE(cc[ac-1]) + RE(t2);
                IM(ch[ah]) = IM(cc[ac-1]) + IM(t2);

                RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+1])), taui);
                IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+1])), taui);

                RE(ch[ah+l1]) = RE(c2) + IM(c3);
                IM(ch[ah+l1]) = IM(c2) - RE(c3);
                RE(ch[ah+2*l1]) = RE(c2) - IM(c3);
                IM(ch[ah+2*l1]) = IM(c2) + RE(c3);
            }
        }
    } else {
        if (isign == 1)
        {
            for (k = 0; k < l1; k++)
            {
                for (i = 0; i < ido; i++)
                {
                    ac = i + (3*k+1)*ido;
                    ah = i + k * ido;

                    RE(t2) = RE(cc[ac]) + RE(cc[ac+ido]);
                    RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),taur);
                    IM(t2) = IM(cc[ac]) + IM(cc[ac+ido]);
                    IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),taur);

                    RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2);
                    IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2);

                    RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+ido])), taui);
                    IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+ido])), taui);

                    RE(d2) = RE(c2) - IM(c3);
                    IM(d3) = IM(c2) - RE(c3);
                    RE(d3) = RE(c2) + IM(c3);
                    IM(d2) = IM(c2) + RE(c3);

#if 1
                    ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]),
                        IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i]));
                    ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]),
                        IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i]));
#else
                    ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]),
                        RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i]));
                    ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]),
                        RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i]));
#endif
                }
            }
        } else {
            for (k = 0; k < l1; k++)
            {
                for (i = 0; i < ido; i++)
                {
                    ac = i + (3*k+1)*ido;
                    ah = i + k * ido;

                    RE(t2) = RE(cc[ac]) + RE(cc[ac+ido]);
                    RE(c2) = RE(cc[ac-ido]) + MUL_F(RE(t2),taur);
                    IM(t2) = IM(cc[ac]) + IM(cc[ac+ido]);
                    IM(c2) = IM(cc[ac-ido]) + MUL_F(IM(t2),taur);

                    RE(ch[ah]) = RE(cc[ac-ido]) + RE(t2);
                    IM(ch[ah]) = IM(cc[ac-ido]) + IM(t2);

                    RE(c3) = MUL_F((RE(cc[ac]) - RE(cc[ac+ido])), taui);
                    IM(c3) = MUL_F((IM(cc[ac]) - IM(cc[ac+ido])), taui);

                    RE(d2) = RE(c2) + IM(c3);
                    IM(d3) = IM(c2) + RE(c3);
                    RE(d3) = RE(c2) - IM(c3);
                    IM(d2) = IM(c2) - RE(c3);

#if 1
                    ComplexMult(&RE(ch[ah+l1*ido]), &IM(ch[ah+l1*ido]),
                        RE(d2), IM(d2), RE(wa1[i]), IM(wa1[i]));
                    ComplexMult(&RE(ch[ah+2*l1*ido]), &IM(ch[ah+2*l1*ido]),
                        RE(d3), IM(d3), RE(wa2[i]), IM(wa2[i]));
#else
                    ComplexMult(&IM(ch[ah+l1*ido]), &RE(ch[ah+l1*ido]),
                        IM(d2), RE(d2), RE(wa1[i]), IM(wa1[i]));
                    ComplexMult(&IM(ch[ah+2*l1*ido]), &RE(ch[ah+2*l1*ido]),
                        IM(d3), RE(d3), RE(wa2[i]), IM(wa2[i]));
#endif
                }
            }
        }
    }
}
Example #25
0
static void passf2neg(const uint16_t ido, const uint16_t l1, const complex_t *cc,
                      complex_t *ch, const complex_t *wa)
{
    uint16_t i, k, ah, ac;

    if (ido == 1)
    {
        for (k = 0; k < l1; k++)
        {
            ah = 2*k;
            ac = 4*k;

            RE(ch[ah])    = RE(cc[ac]) + RE(cc[ac+1]);
            RE(ch[ah+l1]) = RE(cc[ac]) - RE(cc[ac+1]);
            IM(ch[ah])    = IM(cc[ac]) + IM(cc[ac+1]);
            IM(ch[ah+l1]) = IM(cc[ac]) - IM(cc[ac+1]);
        }
    } else {
        for (k = 0; k < l1; k++)
        {
            ah = k*ido;
            ac = 2*k*ido;

            for (i = 0; i < ido; i++)
            {
                complex_t t2;

                RE(ch[ah+i]) = RE(cc[ac+i]) + RE(cc[ac+i+ido]);
                RE(t2)       = RE(cc[ac+i]) - RE(cc[ac+i+ido]);

                IM(ch[ah+i]) = IM(cc[ac+i]) + IM(cc[ac+i+ido]);
                IM(t2)       = IM(cc[ac+i]) - IM(cc[ac+i+ido]);

#if 1
                ComplexMult(&RE(ch[ah+i+l1*ido]), &IM(ch[ah+i+l1*ido]),
                    RE(t2), IM(t2), RE(wa[i]), IM(wa[i]));
#else
                ComplexMult(&IM(ch[ah+i+l1*ido]), &RE(ch[ah+i+l1*ido]),
                    IM(t2), RE(t2), RE(wa[i]), IM(wa[i]));
#endif
            }
        }
    }
}
Example #26
0
void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
{
    uint16_t k;

    complex_t x;
    ALIGN complex_t Z1[512];
    complex_t *sincos = mdct->sincos;

    uint16_t N  = mdct->N;
    uint16_t N2 = N >> 1;
    uint16_t N4 = N >> 2;
    uint16_t N8 = N >> 3;

#ifndef FIXED_POINT
	real_t scale = REAL_CONST(N);
#else
	real_t scale = REAL_CONST(4.0/N);
#endif

#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
    /* detect non-power of 2 */
    if (N & (N-1))
    {
        /* adjust scale for non-power of 2 MDCT */
        /* *= sqrt(2048/1920) */
        scale = MUL_C(scale, COEF_CONST(1.0327955589886444));
    }
#endif
#endif

    /* pre-FFT complex multiplication */
    for (k = 0; k < N8; k++)
    {
        uint16_t n = k << 1;
        RE(x) = X_in[N - N4 - 1 - n] + X_in[N - N4 +     n];
        IM(x) = X_in[    N4 +     n] - X_in[    N4 - 1 - n];

        ComplexMult(&RE(Z1[k]), &IM(Z1[k]),
            RE(x), IM(x), RE(sincos[k]), IM(sincos[k]));

        RE(Z1[k]) = MUL_R(RE(Z1[k]), scale);
        IM(Z1[k]) = MUL_R(IM(Z1[k]), scale);

        RE(x) =  X_in[N2 - 1 - n] - X_in[        n];
        IM(x) =  X_in[N2 +     n] + X_in[N - 1 - n];

        ComplexMult(&RE(Z1[k + N8]), &IM(Z1[k + N8]),
            RE(x), IM(x), RE(sincos[k + N8]), IM(sincos[k + N8]));

        RE(Z1[k + N8]) = MUL_R(RE(Z1[k + N8]), scale);
        IM(Z1[k + N8]) = MUL_R(IM(Z1[k + N8]), scale);
    }

    /* complex FFT, any non-scaling FFT can be used here  */
    cfftf(mdct->cfft, Z1);

    /* post-FFT complex multiplication */
    for (k = 0; k < N4; k++)
    {
        uint16_t n = k << 1;
        ComplexMult(&RE(x), &IM(x),
            RE(Z1[k]), IM(Z1[k]), RE(sincos[k]), IM(sincos[k]));

        X_out[         n] = -RE(x);
        X_out[N2 - 1 - n] =  IM(x);
        X_out[N2 +     n] = -IM(x);
        X_out[N  - 1 - n] =  RE(x);
    }
}
Example #27
0
void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
{
    uint16_t k;

    complex_t x;
#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
    real_t scale, b_scale = 0;
#endif
#endif
    ALIGN complex_t Z1[512];
    complex_t *sincos = mdct->sincos;

    uint16_t N  = mdct->N;
    uint16_t N2 = N >> 1;
    uint16_t N4 = N >> 2;
    uint16_t N8 = N >> 3;

#ifdef PROFILE
    int64_t count1, count2 = faad_get_ts();
#endif

#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
    /* detect non-power of 2 */
    if (N & (N-1))
    {
        /* adjust scale for non-power of 2 MDCT */
        /* 2048/1920 */
        b_scale = 1;
        scale = COEF_CONST(1.0666666666666667);
    }
#endif
#endif

    /* pre-IFFT complex multiplication */
    for (k = 0; k < N4; k++)
    {
        ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
            X_in[2*k], X_in[N2 - 1 - 2*k], RE(sincos[k]), IM(sincos[k]));
    }

#ifdef PROFILE
    count1 = faad_get_ts();
#endif

    /* complex IFFT, any non-scaling FFT can be used here */
    cfftb(mdct->cfft, Z1);

#ifdef PROFILE
    count1 = faad_get_ts() - count1;
#endif

    /* post-IFFT complex multiplication */
    for (k = 0; k < N4; k++)
    {
        RE(x) = RE(Z1[k]);
        IM(x) = IM(Z1[k]);
        ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
            IM(x), RE(x), RE(sincos[k]), IM(sincos[k]));

#ifdef ALLOW_SMALL_FRAMELENGTH
#ifdef FIXED_POINT
        /* non-power of 2 MDCT scaling */
        if (b_scale)
        {
            RE(Z1[k]) = MUL_C(RE(Z1[k]), scale);
            IM(Z1[k]) = MUL_C(IM(Z1[k]), scale);
        }
#endif
#endif
    }

    /* reordering */
    for (k = 0; k < N8; k+=2)
    {
        X_out[              2*k] =  IM(Z1[N8 +     k]);
        X_out[          2 + 2*k] =  IM(Z1[N8 + 1 + k]);

        X_out[          1 + 2*k] = -RE(Z1[N8 - 1 - k]);
        X_out[          3 + 2*k] = -RE(Z1[N8 - 2 - k]);

        X_out[N4 +          2*k] =  RE(Z1[         k]);
        X_out[N4 +    + 2 + 2*k] =  RE(Z1[     1 + k]);

        X_out[N4 +      1 + 2*k] = -IM(Z1[N4 - 1 - k]);
        X_out[N4 +      3 + 2*k] = -IM(Z1[N4 - 2 - k]);

        X_out[N2 +          2*k] =  RE(Z1[N8 +     k]);
        X_out[N2 +    + 2 + 2*k] =  RE(Z1[N8 + 1 + k]);

        X_out[N2 +      1 + 2*k] = -IM(Z1[N8 - 1 - k]);
        X_out[N2 +      3 + 2*k] = -IM(Z1[N8 - 2 - k]);

        X_out[N2 + N4 +     2*k] = -IM(Z1[         k]);
        X_out[N2 + N4 + 2 + 2*k] = -IM(Z1[     1 + k]);

        X_out[N2 + N4 + 1 + 2*k] =  RE(Z1[N4 - 1 - k]);
        X_out[N2 + N4 + 3 + 2*k] =  RE(Z1[N4 - 2 - k]);
    }

#ifdef PROFILE
    count2 = faad_get_ts() - count2;
    mdct->fft_cycles += count1;
    mdct->cycles += (count2 - count1);
#endif
}
Example #28
0
File: main.cpp Project: Vort/VortOS
// ----------------------------------------------------------------------------
void Entry()
{
	// Move cursor off-screen
	_outpw(0x3D4, 0x070E);
	_outpw(0x3D4, 0xD00F);

	CKernelHeader* KH = (CKernelHeader*)CMemMap::c_KernelImageBase;
	dword* BootInfo = (dword*)(*(dword*)(CMemMap::c_KernelImageBase + 0x100));

	RawOutString("Checking Kernel...", 0, 0, 0xA);
	if (IsKernelOK(*KH, BootInfo))
	{
		RawOutString("OK", 18, 0, 0xA);
	}
	else
	{
		RawOutString("Fail", 18, 0, 0xC);
		ErrIf(true);
	}

	dword BootType = BootInfo[1];
	dword DriversCount = BootInfo[2] - 1;
	CDriverInfo DriverInfos[12];

	for (dword i = 0; i < DriversCount; i++)
	{
		DriverInfos[i].m_BytesSize = BootInfo[3 + (i + 1) * 3];
		DriverInfos[i].m_LoadPage  = BootInfo[4 + (i + 1) * 3];
		char* Name = PC(BootInfo[5 + (i + 1) * 3]);

		for (int j = 0;; j++)
		{
			DriverInfos[i].m_Name[j] = Name[j];
			if (Name[j] == 0)
				break;
		}
	}

	InitPIT();

	CPhysMemManager PMM;
	PMM.AllocBlockAt(KH->GetKernelCodeBase(), KH->m_KernelCodePageCount, false);
	PMM.AllocBlockAt(KH->GetKernelRDataBase(), KH->m_KernelRDataPageCount, false);
	PMM.AllocBlockAt(KH->GetKernelDataBase(), KH->m_KernelDataPageCount, true);
	PMM.AllocBlockAt((byte*)CMemMap::c_VideoRamTextBase, 8, true);
	__writecr3(CMemMap::c_PmmPageDirectory);
	SetupCR0();

	for (dword i = 0; i < DriversCount; i++)
	{
		PMM.AllocBlockAt(
			DriverInfos[i].GetImageBase(),
			DriverInfos[i].GetImagePageCount(), false);
	}

	CGDT GDT(PMM);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0x92, 1);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0x98, 1);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0xF2, 1);
	GDT.CreateNewDescriptor(0, 0xFFFFF, 0xF8, 1);

	static const dword HeapPageCount = 32;
	void* HeapBlock = PMM.AllocBlock(HeapPageCount);
	CHeap SysHeap(PB(HeapBlock), HeapPageCount * 4096);
	g_SysHeap = &SysHeap;

	CTask KernelTask(GDT, true, 0, 0, 0, 0, CMemMap::c_PmmPageDirectory);
	KernelTask._setActive();

	CIntManager IM(PMM, KernelTask.GetTSS().GetSelector());

	CKernel K(KernelTask, PMM, IM, GDT, IM.GetIDT(),
		BootType, DriverInfos, DriversCount);
}
Example #29
0
void hf_generation(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
                   qmf_t Xhigh[MAX_NTSRHFG][64]
#ifdef SBR_LOW_POWER
                   ,real_t *deg
#endif
                   ,uint8_t ch)
{
    uint8_t l, i, x;
    ALIGN complex_t alpha_0[64], alpha_1[64];
#ifdef SBR_LOW_POWER
    ALIGN real_t rxx[64];
#endif

    uint8_t offset = sbr->tHFAdj;
    uint8_t first = sbr->t_E[ch][0];
    uint8_t last = sbr->t_E[ch][sbr->L_E[ch]];

    calc_chirp_factors(sbr, ch);

#ifdef SBR_LOW_POWER
    memset(deg, 0, 64*sizeof(real_t));
#endif

    if ((ch == 0) && (sbr->Reset))
        patch_construction(sbr);

    /* calculate the prediction coefficients */
#ifdef SBR_LOW_POWER
    calc_prediction_coef_lp(sbr, Xlow, alpha_0, alpha_1, rxx);
    calc_aliasing_degree(sbr, rxx, deg);
#endif

    /* actual HF generation */
    for (i = 0; i < sbr->noPatches; i++)
    {
        for (x = 0; x < sbr->patchNoSubbands[i]; x++)
        {
            real_t a0_r, a0_i, a1_r, a1_i;
            real_t bw, bw2;
            uint8_t q, p, k, g;

            /* find the low and high band for patching */
            k = sbr->kx + x;
            for (q = 0; q < i; q++)
            {
                k += sbr->patchNoSubbands[q];
            }
            p = sbr->patchStartSubband[i] + x;

#ifdef SBR_LOW_POWER
            if (x != 0 /*x < sbr->patchNoSubbands[i]-1*/)
                deg[k] = deg[p];
            else
                deg[k] = 0;
#endif

            g = sbr->table_map_k_to_g[k];

            bw = sbr->bwArray[ch][g];
            bw2 = MUL_C(bw, bw);

            /* do the patching */
            /* with or without filtering */
            if (bw2 > 0)
            {
                real_t temp1_r, temp2_r, temp3_r;
#ifndef SBR_LOW_POWER
                real_t temp1_i, temp2_i, temp3_i;
                calc_prediction_coef(sbr, Xlow, alpha_0, alpha_1, p);
#endif

                a0_r = MUL_C(RE(alpha_0[p]), bw);
                a1_r = MUL_C(RE(alpha_1[p]), bw2);
#ifndef SBR_LOW_POWER
                a0_i = MUL_C(IM(alpha_0[p]), bw);
                a1_i = MUL_C(IM(alpha_1[p]), bw2);
#endif

                temp2_r = QMF_RE(Xlow[first - 2 + offset][p]);
                temp3_r = QMF_RE(Xlow[first - 1 + offset][p]);
#ifndef SBR_LOW_POWER
                temp2_i = QMF_IM(Xlow[first - 2 + offset][p]);
                temp3_i = QMF_IM(Xlow[first - 1 + offset][p]);
#endif
                for (l = first; l < last; l++)
                {
                    temp1_r = temp2_r;
                    temp2_r = temp3_r;
                    temp3_r = QMF_RE(Xlow[l + offset][p]);
#ifndef SBR_LOW_POWER
                    temp1_i = temp2_i;
                    temp2_i = temp3_i;
                    temp3_i = QMF_IM(Xlow[l + offset][p]);
#endif

#ifdef SBR_LOW_POWER
                    QMF_RE(Xhigh[l + offset][k]) = temp3_r +
                                (MUL_R(a0_r, temp2_r) + MUL_R(a1_r, temp1_r));
#else
                    QMF_RE(Xhigh[l + offset][k]) = temp3_r +
                                (MUL_R(a0_r, temp2_r) - MUL_R(a0_i, temp2_i) +
                                 MUL_R(a1_r, temp1_r) - MUL_R(a1_i, temp1_i));
                    QMF_IM(Xhigh[l + offset][k]) = temp3_i +
                                (MUL_R(a0_i, temp2_r) + MUL_R(a0_r, temp2_i) +
                                 MUL_R(a1_i, temp1_r) + MUL_R(a1_r, temp1_i));
#endif
                }
            } else {
                for (l = first; l < last; l++)
                {
                    QMF_RE(Xhigh[l + offset][k]) = QMF_RE(Xlow[l + offset][p]);
#ifndef SBR_LOW_POWER
                    QMF_IM(Xhigh[l + offset][k]) = QMF_IM(Xlow[l + offset][p]);
#endif
                }
            }
        }
    }

    if (sbr->Reset)
    {
        limiter_frequency_table(sbr);
    }
}
Example #30
0
static void calc_prediction_coef(sbr_info *sbr, qmf_t Xlow[MAX_NTSRHFG][64],
                                 complex_t *alpha_0, complex_t *alpha_1, uint8_t k)
{
    real_t tmp, mul;
    acorr_coef ac;

    auto_correlation(sbr, &ac, Xlow, k, sbr->numTimeSlotsRate + 6);

    if (ac.det == 0)
    {
        RE(alpha_1[k]) = 0;
        IM(alpha_1[k]) = 0;
    } else {
        mul = DIV_R(REAL_CONST(1.0), ac.det);
        tmp = (MUL_R(RE(ac.r01), RE(ac.r12)) - MUL_R(IM(ac.r01), IM(ac.r12)) - MUL_R(RE(ac.r02), RE(ac.r11)));
        RE(alpha_1[k]) = MUL_R(tmp, mul);
        tmp = (MUL_R(IM(ac.r01), RE(ac.r12)) + MUL_R(RE(ac.r01), IM(ac.r12)) - MUL_R(IM(ac.r02), RE(ac.r11)));
        IM(alpha_1[k]) = MUL_R(tmp, mul);
    }

    if (RE(ac.r11) == 0)
    {
        RE(alpha_0[k]) = 0;
        IM(alpha_0[k]) = 0;
    } else {
        mul = DIV_R(REAL_CONST(1.0), RE(ac.r11));
        tmp = -(RE(ac.r01) + MUL_R(RE(alpha_1[k]), RE(ac.r12)) + MUL_R(IM(alpha_1[k]), IM(ac.r12)));
        RE(alpha_0[k]) = MUL_R(tmp, mul);
        tmp = -(IM(ac.r01) + MUL_R(IM(alpha_1[k]), RE(ac.r12)) - MUL_R(RE(alpha_1[k]), IM(ac.r12)));
        IM(alpha_0[k]) = MUL_R(tmp, mul);
    }

    if ((MUL_R(RE(alpha_0[k]),RE(alpha_0[k])) + MUL_R(IM(alpha_0[k]),IM(alpha_0[k])) >= REAL_CONST(16)) ||
        (MUL_R(RE(alpha_1[k]),RE(alpha_1[k])) + MUL_R(IM(alpha_1[k]),IM(alpha_1[k])) >= REAL_CONST(16)))
    {
        RE(alpha_0[k]) = 0;
        IM(alpha_0[k]) = 0;
        RE(alpha_1[k]) = 0;
        IM(alpha_1[k]) = 0;
    }
}