コード例 #1
0
ファイル: elem_func_gw.cpp プロジェクト: scitao/scilab
types::Double* trigo(types::Double* in, func_real func_r, func_complex func_c, bool forceComplex)
{
    bool isComplex = in->isComplex() || forceComplex;
    types::Double* out = new types::Double(in->getDims(), in->getDimsArray(), isComplex);

    int size = in->getSize();
    double* pInR = in->get();
    double* pOutR = out->get();

    if (isComplex)
    {
        double* pInI = in->getImg();
        double* pOutI = out->getImg();
        std::complex<double> d;
        for (int i = 0; i < size; ++i)
        {
            d.real(pInR[i]);
            d.imag(pInI[i]);
            std::complex<double> res = func_c(d);
            pOutR[i] = res.real();
            pOutI[i] = res.imag();
        }
    }
    else
    {
        for (int i = 0; i < size; ++i)
        {
            pOutR[i] = func_r(pInR[i]);
        }
    }

    return out;
}
コード例 #2
0
ファイル: scale.c プロジェクト: amithash/spectro
unsigned int *generate_scale_table(unsigned int nbands, scale_t scale)
{
	unsigned int *out;
	forward_t func_f;
	reverse_t func_r;
	float sc_max;
	float sc_min;
	float sc_step;
	float i;
	int j;

	if(scale < 0 || scale >= MAX_SCALE)
	      return NULL;
	if(nbands < 2)
	      return NULL;

	/* Technically nbands can be anything, but it is nice to have sanity bounds on
	 * input parameters */
	if(nbands > 20000)
	      return NULL;

	out = calloc(nbands, sizeof(unsigned int));
	if(!out)
	      return NULL;

	func_f = forward[scale];
	func_r = reverse[scale];

	sc_max = func_r(MAX_FREQ);
	sc_min = func_r(MIN_FREQ);
	sc_step = (sc_max - sc_min) / (float)(nbands);

	for(i = sc_min + sc_step, j = 0; i <= sc_max + sc_step && j < nbands; i += sc_step, j++) {
		out[j] = func_f(i);
	}

	return out;
}