Esempio n. 1
0
void Luce(double x, double y, double z,double dimensione,float r,float g,float b,float iox,float ioy,float ioz,int Tex)
{
	Vector Position;
	Vector MyPosition;
	Position.x = x;
	Position.y = y;
	Position.z = z;

	MyPosition.x=iox;
	MyPosition.y=ioy;
	MyPosition.z=ioz;
	Vector sight = VectorDiff(MyPosition, Position);

	Vector cz;
	cz.x = 0;
	cz.y = 0;
	cz.z = 1;

	Vector cross1 = VectorMultiply( sight, cz );
	Vector cross2 = VectorMultiply( sight, cross1 );

	cross1 = VectorNormalize(cross1);
	cross2 = VectorNormalize(cross2);

	cross1 = VectorScalarMultiply(cross1, dimensione);
	cross2 = VectorScalarMultiply(cross2, dimensione);

	glColor3f(r,g,b);
	glEnable(GL_TEXTURE_2D);
	glEnable (GL_BLEND);
	glBlendFunc( (1,1,1,1), (1,1,1,1));
	glDepthMask (GL_FALSE);

	glBindTexture( GL_TEXTURE_2D, texture[Tex] );
	glBegin(GL_QUADS);
		glTexCoord2d( 0.0, 0.0 );
		glVertex3d( Position.x + cross1.x, Position.y + cross1.y, Position.z + cross1.z);
		glTexCoord2d( 1.0, 0.0 );
		glVertex3d( Position.x - cross2.x, Position.y - cross2.y, Position.z - cross2.z);
		glTexCoord2d( 1.0, 1.0 );
		glVertex3d( Position.x - cross1.x, Position.y - cross1.y, Position.z - cross1.z);
		glTexCoord2d( 0.0, 1.0 );
		glVertex3d( Position.x + cross2.x, Position.y + cross2.y, Position.z + cross2.z);
	glEnd();

	glDisable(GL_TEXTURE_2D);
	glDisable (GL_BLEND);
	glDepthMask (GL_TRUE);
}
Esempio n. 2
0
TEST(DSPSingle, TestVectorScalarMultiply)
{
    float out[10];
    VectorScalarMultiply(out, ramp, 2.0, 10);
    for (unsigned i = 0; i < 10; ++i)
    {
        ASSERT_FLOAT_EQ(2.0 * ramp[i], out[i]);
    }
}
Esempio n. 3
0
/* UpsamplerProcess ****************************************************/
Error_t
UpsamplerProcess(Upsampler      *upsampler,
                 float          *outBuffer,
				 const float    *inBuffer,
				 unsigned       n_samples)
{
    float tempbuf[n_samples];
    if (upsampler && outBuffer)
    {
        for (unsigned filt = 0; filt < upsampler->factor; ++filt)
        {
            FIRFilterProcess(upsampler->polyphase[filt], tempbuf, inBuffer, n_samples);
            CopyBufferStride(outBuffer+filt, upsampler->factor, tempbuf, 1, n_samples);
        }

        VectorScalarMultiply(outBuffer, (const float*)outBuffer,
                             upsampler->factor, n_samples * upsampler->factor);
        return NOERR;
    }
    else
    {
        return NULL_PTR_ERROR;
    }
}
Esempio n. 4
0
static Error_t
RBJFilterUpdate(RBJFilter* filter)
{
    filter->cosOmega = cos(filter->omega);
    filter->sinOmega = sin(filter->omega);

    switch (filter->type)
    {
    case LOWPASS:
        filter->alpha = filter->sinOmega / (2.0 * filter->Q);
        filter->b[0] = (1 - filter->cosOmega) / 2;
        filter->b[1] = 1 - filter->cosOmega;
        filter->b[2] = filter->b[0];
        filter->a[0] = 1 + filter->alpha;
        filter->a[1] = -2 * filter->cosOmega;
        filter->a[2] = 1 - filter->alpha;
        break;

    case HIGHPASS:
        filter->alpha = filter->sinOmega / (2.0 * filter->Q);
        filter->b[0] = (1 + filter->cosOmega) / 2;
        filter->b[1] = -(1 + filter->cosOmega);
        filter->b[2] = filter->b[0];
        filter->a[0] = 1 + filter->alpha;
        filter->a[1] = -2 * filter->cosOmega;
        filter->a[2] = 1 - filter->alpha;
        break;

    case BANDPASS:
        filter->alpha = filter->sinOmega * sinhf(logf(2.0) / 2.0 * \
            filter->Q * filter->omega/filter->sinOmega);
        filter->b[0] = filter->sinOmega / 2;
        filter->b[1] = 0;
        filter->b[2] = -filter->b[0];
        filter->a[0] = 1 + filter->alpha;
        filter->a[1] = -2 * filter->cosOmega;
        filter->a[2] = 1 - filter->alpha;
        break;

    case ALLPASS:
        filter->alpha = filter->sinOmega / (2.0 * filter->Q);
        filter->b[0] = 1 - filter->alpha;
        filter->b[1] = -2 * filter->cosOmega;
        filter->b[2] = 1 + filter->alpha;
        filter->a[0] = filter->b[2];
        filter->a[1] = filter->b[1];
        filter->a[2] = filter->b[0];
        break;

    case NOTCH:
        filter->alpha = filter->sinOmega * sinhf(logf(2.0) / 2.0 * \
            filter->Q * filter->omega/filter->sinOmega);
        filter->b[0] = 1;
        filter->b[1] = -2 * filter->cosOmega;
        filter->b[2] = 1;
        filter->a[0] = 1 + filter->alpha;
        filter->a[1] = filter->b[1];
        filter->a[2] = 1 - filter->alpha;
        break;

    case PEAK:
        filter->alpha = filter->sinOmega * sinhf(logf(2.0) / 2.0 * \
            filter->Q * filter->omega/filter->sinOmega);
        filter->b[0] = 1 + (filter->alpha * filter->A);
        filter->b[1] = -2 * filter->cosOmega;
        filter->b[2] = 1 - (filter->alpha * filter->A);
        filter->a[0] = 1 + (filter->alpha / filter->A);
        filter->a[1] = filter->b[1];
        filter->a[2] = 1 - (filter->alpha / filter->A);
        break;

    case LOW_SHELF:
        filter->alpha = filter->sinOmega / 2.0 * sqrt( (filter->A + 1.0 / \
            filter->A) * (1.0 / filter->Q - 1.0) + 2.0);
        filter->b[0] = filter->A * ((filter->A + 1) - ((filter->A - 1) *       \
            filter->cosOmega) + (2 * sqrtf(filter->A) * filter->alpha));
        filter->b[1] = 2 * filter->A * ((filter->A - 1) - ((filter->A + 1) *   \
            filter->cosOmega));
        filter->b[2] = filter->A * ((filter->A + 1) - ((filter->A - 1) *       \
            filter->cosOmega) - (2 * sqrtf(filter->A) * filter->alpha));
        filter->a[0] = ((filter->A + 1) + ((filter->A - 1) *                   \
            filter->cosOmega) + (2 * sqrtf(filter->A) * filter->alpha));
        filter->a[1] = -2 * ((filter->A - 1) + ((filter->A + 1) *              \
            filter->cosOmega));
        filter->a[2] = ((filter->A + 1) + ((filter->A - 1) *                   \
            filter->cosOmega) - (2 * sqrtf(filter->A) * filter->alpha));
        break;

    case HIGH_SHELF:
        filter->alpha = filter->sinOmega / 2.0 * sqrt( (filter->A + 1.0 / \
            filter->A) * (1.0 / filter->Q - 1.0) + 2.0);
        filter->b[0] = filter->A * ((filter->A + 1) + ((filter->A - 1) *       \
            filter->cosOmega) + (2 * sqrtf(filter->A) * filter->alpha));
        filter->b[1] = -2 * filter->A * ((filter->A - 1) + ((filter->A + 1) *  \
            filter->cosOmega));
        filter->b[2] = filter->A * ((filter->A + 1) + ((filter->A - 1) *       \
            filter->cosOmega) - (2 * sqrtf(filter->A) * filter->alpha));
        filter->a[0] = ((filter->A + 1) - ((filter->A - 1) *                   \
            filter->cosOmega) + (2 * sqrtf(filter->A) * filter->alpha));
        filter->a[1] = 2 * ((filter->A - 1) - ((filter->A + 1) *               \
            filter->cosOmega));
        filter->a[2] = ((filter->A + 1) - ((filter->A - 1) *                   \
            filter->cosOmega) - (2 * sqrtf(filter->A) * filter->alpha));
        break;

    default:
        return ERROR;
        break;
    }

    // Normalize filter coefficients
    float factor = 1.0 / filter->a[0];
    float norm_a[2];
    float norm_b[3];
    VectorScalarMultiply(norm_a, &filter->a[1], factor, 2);
    VectorScalarMultiply(norm_b, filter->b, factor, 3);
    BiquadFilterUpdateKernel(filter->biquad, norm_b, norm_a);
    return NOERR;
}