Esempio n. 1
0
  inline mopo_float Filter::tick(int i) {
    mopo_float input = inputs_[kAudio]->at(i);
    mopo_float cutoff = inputs_[kCutoff]->at(i);
    mopo_float resonance = inputs_[kResonance]->at(i);

    if (cutoff != current_cutoff_ || resonance != current_resonance_)
      computeCoefficients(current_type_, cutoff, resonance);

    mopo_float out = input * in_0_ + past_in_1_ * in_1_ + past_in_2_ * in_2_ -
                     past_out_1_ * out_0_ - past_out_2_ * out_1_;
    past_in_2_ = past_in_1_;
    past_in_1_ = input;
    past_out_2_ = past_out_1_;
    past_out_1_ = out;
    return out;
  }
Esempio n. 2
0
  void Filter::process() {
    current_type_ = static_cast<Type>(inputs_[kType]->at(0));
    computeCoefficients(current_type_, inputs_[kCutoff]->at(0),
                                       inputs_[kResonance]->at(0));

    int i = 0;
    if (inputs_[kReset]->source->triggered &&
        inputs_[kReset]->source->trigger_value == kVoiceReset) {
      int trigger_offset = inputs_[kReset]->source->trigger_offset;
      for (; i < trigger_offset; ++i)
        outputs_[0]->buffer[i] = tick(i);

      reset();
    }
    for (; i < buffer_size_; ++i)
      outputs_[0]->buffer[i] = tick(i);
  }
Esempio n. 3
0
  void DcFilter::process() {
    computeCoefficients();

    const mopo_float* source = input(kAudio)->source->buffer;
    mopo_float* dest = output()->buffer;
    int i = 0;
    if (inputs_->at(kReset)->source->triggered &&
        inputs_->at(kReset)->source->trigger_value == kVoiceReset) {
      int trigger_offset = inputs_->at(kReset)->source->trigger_offset;
      for (; i < trigger_offset; ++i)
        tick(i, dest, source);

      reset();
    }
    for (; i < buffer_size_; ++i)
      tick(i, dest, source);
  }
Esempio n. 4
0
  /* @brief get coefficient associates to a l1norm value.
   *  @param l1norm is the norm value for which we want values of coefficient
   *  @return a vector containing pair<int,double>=(index of non zero coefficient,coefficient)
   */
  STK::Array1D< pair<int,Real> > Path::coeff(Real l1norm) const
  {
    STK::Array1D< pair<int,Real> > coeff;
    if(l1norm!=0)
    {
      //search off the interval of m_l1norm containing l1norm
      int indexl1norm=0;
      while( ( states_[indexl1norm].l1norm() < l1norm ) && ( indexl1norm < (int) states_.size()-1 ) )
        indexl1norm++;

      if(l1norm==states_[indexl1norm].l1norm())//if l1norm is equal to an actual l1norm
        coeff=states_[indexl1norm].coefficients();
      else
      {
        if( indexl1norm == (int) states_.size()-1 )//last m_l1norm, we return the last coefficient
          coeff=states_[indexl1norm].coefficients();
        else
          coeff=computeCoefficients(states_[indexl1norm-1],states_[indexl1norm],evolution_[indexl1norm-1],l1norm);
      }
    }
    return coeff;
  }
Esempio n. 5
0
Coord computeBezierPoint(const vector<Coord> &controlPoints, const float t) {

  size_t nbControlPoints = controlPoints.size();

  computeCoefficients(t, nbControlPoints);

  Vector<double, 3> bezierPoint;
  bezierPoint[0] = bezierPoint[1] = bezierPoint[2] = 0;
  double curCoeff = 1.0;
  double r = static_cast<double>(nbControlPoints);

  for (size_t i = 0 ; i < controlPoints.size() ; ++i) {
    Vector<double, 3> controlPoint;
    controlPoint[0] = controlPoints[i][0];
    controlPoint[1] = controlPoints[i][1];
    controlPoint[2] = controlPoints[i][2];
    bezierPoint += controlPoint * curCoeff * tCoeffs[static_cast<double>(t)][i] * sCoeffs[static_cast<double>(t)][nbControlPoints - 1 - i];
    double c = static_cast<double>(i+1);
    curCoeff *= (r -c)/c;
  }

  return Coord(bezierPoint[0], bezierPoint[1], bezierPoint[2]);
}
// function definitions
int coeffSelectUpdateAlgorithm3D(Vec3D<int> * v, int d, int n, int * failedGridList, 
	int failedGridCounter, double * listCoeffs, int verbose) {
	// n: level (definition varies)
	// d: dimension ,e.g., 3D

        int globalRank, ng = 0;
        MPI_Comm_rank(MPI_COMM_WORLD, &globalRank);

	if (d == 2) { //2D
	    ng = 4*(n+1) - 6;
	}
	else if(d == 3) { //3D
	    ng = (2*(n+1)*(n+1) - 4*(n+1) + 4);
	}
	else {
	    if(globalRank == 0)
		printf("Only supports 2D and 3D at the moment. Abort.\n");
	    exit(1);
	}

	int* grids = new int[d*ng];
	int ind = 0;
	#pragma omp parallel for default(shared)
	for (int i = 0; i < ng; ++i) {
	    grids[ind++] = v[i].x;
	    grids[ind++] = v[i].y;
	    grids[ind++] = v[i].z;
	}

	// optionally print the grids
	if (verbose > 0 && globalRank == 0) {
	    printf("Grids: (%d)\n", ng);
	    #pragma omp parallel for default(shared)
	    for (int i = 0; i < ng; ++i) {
		printf("\t");
		for (int k = 0; k < d; ++k) 
		    printf("%d ",grids[i*d+k]);
		printf("\n");
	    }
	}

	// initialise coefficient and status array
	double* coef = new double[ng];
	int* stat = new int[ng];
	
	for (int i = 0; i < ng; ++i) {
	    if (not isFailedGrid(i, failedGridList, failedGridCounter))
		stat[i] = 0; // grid is not failed
	    else
		stat[i] = 1; // grid is failed
	}
       
	// call wrapper to compute coefficients
	computeCoefficients(grids, ng, d, stat, coef);

	// copy the coefficients to return to the calle function  
	for (int i = 0; i < ng; ++i) {
	    listCoeffs[i] = coef[i];
	}

	// cleanup
	delete[] grids;
	delete[] coef;
	delete[] stat;

	return 0;
}
Esempio n. 7
0
void _SnacRemesher_InterpolateElements( void* _context ) {
	Snac_Context*			context = (Snac_Context*)_context;
	SnacRemesher_Context*	contextExt = ExtensionManager_Get( context->extensionMgr, 
																   context, 
																   SnacRemesher_ContextHandle );
	Mesh*					mesh = context->mesh;
	SnacRemesher_Mesh*		meshExt = ExtensionManager_Get( context->meshExtensionMgr,
															mesh, 
															SnacRemesher_MeshHandle );
	HexaMD*					decomp = (HexaMD*)mesh->layout->decomp;
	Element_LocalIndex		element_lI;
	Tetrahedra_Index		tet_I;

	Element_DomainIndex	neldI =  decomp->elementDomain3DCounts[0];
	Element_DomainIndex	neldJ =  decomp->elementDomain3DCounts[1];
	Element_DomainIndex	neldK =  decomp->elementDomain3DCounts[2];

	void createBarycenterGrids( void* _context );
	void computeCoefficients( void* _context );
	void computeBaryCoords( void* _context );

	unsigned int 	have_xneg_shadow, have_xpos_shadow;
	unsigned int 	have_yneg_shadow, have_ypos_shadow;
	unsigned int 	have_zneg_shadow, have_zpos_shadow;
	int     		rankPartition[3];

	/* Decompose rank into partitions in each axis */
	rankPartition[2] = context->rank/(decomp->partition3DCounts[0]*decomp->partition3DCounts[1]);
	rankPartition[1] = (context->rank-rankPartition[2]*decomp->partition3DCounts[0]*decomp->partition3DCounts[1]) / decomp->partition3DCounts[0];
	rankPartition[0] = context->rank-rankPartition[2]*decomp->partition3DCounts[0]*decomp->partition3DCounts[1] - rankPartition[1] * decomp->partition3DCounts[0];
	
	have_xneg_shadow = (((decomp->partition3DCounts[0]>1)&&(rankPartition[0]>0))?1:0);
	have_xpos_shadow = (((decomp->partition3DCounts[0]>1)&&(rankPartition[0]<(decomp->partition3DCounts[0]-1)))?1:0);
	have_yneg_shadow = (((decomp->partition3DCounts[1]>1)&&(rankPartition[1]>0))?1:0);
	have_ypos_shadow = (((decomp->partition3DCounts[1]>1)&&(rankPartition[1]<(decomp->partition3DCounts[1]-1)))?1:0);
	have_zneg_shadow = (((decomp->partition3DCounts[2]>1)&&(rankPartition[2]>0))?1:0);
	have_zpos_shadow = (((decomp->partition3DCounts[2]>1)&&(rankPartition[2]<(decomp->partition3DCounts[2]-1)))?1:0);

	meshExt->local_range_min[0] = (have_xneg_shadow?decomp->shadowDepth:0);
	meshExt->local_range_max[0] = (have_xpos_shadow?(neldI-1-decomp->shadowDepth):(neldI-1));
	meshExt->local_range_min[1] = (have_yneg_shadow?decomp->shadowDepth:0);
	meshExt->local_range_max[1] = (have_ypos_shadow?(neldJ-1-decomp->shadowDepth):(neldJ-1));
	meshExt->local_range_min[2] = (have_zneg_shadow?decomp->shadowDepth:0);
	meshExt->local_range_max[2] = (have_zpos_shadow?(neldK-1-decomp->shadowDepth):(neldK-1));

	/* Create old and new grids of barycenters */
	createBarycenterGrids( context );
	
	/*
	** Free any owned arrays that may still exist from the last node interpolation.
	*/
	FreeArray( meshExt->externalElements );
	meshExt->nExternalElements = 0;
	
	/* Compute coefficients for barycentric coordinates. */
	computeCoefficients( context );

	/* Compute barycentric coordinates of a new local grid w.r.t. the old domain grid. */
	computeBaryCoords( context );

	/* Finally, interpolate on each node in the new local barycenter mesh. */
	for( element_lI = 0; element_lI < mesh->elementLocalCount; element_lI++ )
		for(tet_I=0;tet_I<Tetrahedra_Count;tet_I++) 
			SnacRemesher_InterpolateElement( context, contextExt,
							element_lI, tet_I,
							meshExt->newElements,
							meshExt->barcord[element_lI].elnum,
							meshExt->barcord[element_lI].tetnum );
	
	/* Copy interpolated element variables stored in newElements
	   to the origianl element array. */
	for( element_lI = 0; element_lI < mesh->elementLocalCount; element_lI++ )
		for(tet_I=0;tet_I<Tetrahedra_Count;tet_I++) 
			SnacRemesher_CopyElement( context, contextExt, element_lI, tet_I, 
									  meshExt->newElements ); 
			/* _SnacRemesher_CopyElement( context, element_lI, tet_I, */
			/* 						  meshExt->newElements ); */

}
bool AMVariableIntegrationTime::variableTime(double *times) const
{
	// If all the data is good already, just copy it.
	if (isValid_ && !variableTimes_.isEmpty()){

		QVector<double> data = variableTimes_.values().toVector();
		memcpy(times, data.constData(), data.size()*sizeof(double));

		return true;
	}

	if (!isValid_ && !computeCoefficients())
		return false;

	if (kStep_ <= 0.0 || k0_ > kf_)
		return false;

	variableTimes_.clear();

	switch(equation_){

	case Constant:{

		int points = int(round((kf_-k0_)/kStep_));
		double k = k0_;

		for (int i = 0; i < points; i++){

			variableTimes_.insert(k, t0_);
			k += kStep_;
		}

		break;
	}

	case Linear:{

		int points = int(round((kf_-k0_)/kStep_));
		double k = k0_;

		for (int i = 0; i < points; i++){

			variableTimes_.insert(k, a0_ + a1_*k);
			k += kStep_;
		}

		break;
	}

	case Quadratic:{

		int points = int(round((kf_-k0_)/kStep_));
		double k = k0_;

		for (int i = 0; i < points; i++){

			variableTimes_.insert(k, a0_ + a1_*k*k);
			k += kStep_;
		}

		break;
	}

	case Geometric:{

		int points = int(round((kf_-k0_)/kStep_));
		double k = k0_;

		for (int i = 0; i < points; i++){

			variableTimes_.insert(k, a0_ + a1_*pow(k, a2_));
			k += kStep_;
		}

		break;
	}

	case Exponential:{

		int points = int(round((kf_-k0_)/kStep_));
		double k = k0_;

		for (int i = 0; i < points; i++){

			variableTimes_.insert(k, a0_ + a1_*exp(a2_*k));
			k += kStep_;
		}

		break;
	}

	case Logarithmic:{

		int points = int(round((kf_-k0_)/kStep_));
		double k = k0_;

		for (int i = 0; i < points; i++){

			variableTimes_.insert(k, a0_ + a1_*log10(fabs(k + a2_)));
			k += kStep_;
		}

		break;
	}

	case SmoothStep:{

		int points = int(round((kf_-k0_)/kStep_));
		double k = k0_;

		for (int i = 0; i < points; i++){

			variableTimes_.insert(k, a0_ + a1_/(1 + exp(-1.0*a2_*(k - kf_/2)/2)));
			k += kStep_;
		}

		break;
	}
	}

	QVector<double> data = variableTimes_.values().toVector();
	memcpy(times, data.constData(), data.size()*sizeof(double));

	return true;
}