void overdrive_run(void *obj, sound_t *out, sound_t *in)
{
	overdrive_t *overdrive = (overdrive_t *)obj;

	// Zona de ganancia lineal
	if( ((*in) <= fixedpt_rconst(1/3)) && ((*in) > fixedpt_rconst(-1/3)) )
	{
		// Calculo la salida
		*out = fixedpt_mul(*in, 2);
	}
	// Zona de ganancia cuadratica en primer cuadrante
	else if( ((*in) <= fixedpt_rconst(2/3)) && ((*in) > fixedpt_rconst(1/3)) )
	{
		// Calculo la salida
		*out = fixedpt_rconst(+2) - fixedpt_mul(*in, +3);
		*out = fixedpt_rconst(+3) - fixedpt_mul(*out, *out);
		*out = fixedpt_div(*out, 3);
	}
	// Zona de ganancia cuadratica en primer cuadrante
	else if( ((*in) <= fixedpt_rconst(-1/3)) && ((*in) > fixedpt_rconst(-2/3)) )
	{
		// Calculo la salida
		*out = fixedpt_rconst(-2) + fixedpt_mul(*in, -3);
		*out = fixedpt_rconst(-3) + fixedpt_mul(*out, *out);
		*out = fixedpt_div(*out, 3);
	}
	// Zona sin ganancia
	else
	{
		// Calculo la salida
		*out = *in;
	}

}
Beispiel #2
0
void wah_run(void *obj, sound_t *out, sound_t *in)
{
	wah_t *wah = (wah_t *)obj;
	static fixedpt fc;
	fixedpt q1;
	fixedpt f1;

	FILE * fd;
	fd = fopen("Dump.csv","a+");

	// Calculo la constante de damping del filtro
	q1  = fixedpt_mul(damp, FIXEDPT_TWO);

	// Calculo el siguiente valor de t para la triangular
	fc += fixedpt_div(wahf, fss);
	fc %= FIXEDPT_TWO;

	// Calcular el valor de la onda triangular
	f1  = fixedpt_tri(fc);
	f1  = f1 + FIXEDPT_ONE;
	f1  = fixedpt_div(f1, FIXEDPT_TWO);
	f1  = fixedpt_mul(f1, maxf - minf) + minf;

	// Calcular el valor de la senoidal que modula
	f1  = fixedpt_mul(f1, FIXEDPT_PI);
	f1  = fixedpt_div(f1, fss);
	f1  = fixedpt_sin(f1);
	f1  = fixedpt_mul(f1, FIXEDPT_TWO);

	// Calcular el wah
	wah->yh = *in - wah->yl - fixedpt_mul(wah->yb, q1);
	wah->yb =       wah->yb + fixedpt_mul(wah->yh, f1);
	wah->yl =       wah->yl + fixedpt_mul(wah->yb, f1);

	wah->yh = fixedpt_div(wah->yh, fixedpt_rconst(3));
	wah->yb = fixedpt_div(wah->yb, fixedpt_rconst(2));
	wah->yl = fixedpt_div(wah->yl, fixedpt_rconst(2));

	fprintf(fd, "%d\t%d\t%d\n", wah->yl, wah->yb, wah->yh);

	*out = wah->yb;

	fclose(fd);
}
Beispiel #3
0
void echo_run(void *obj, sound_t *out, sound_t *in)
{
	echo_t  *echo = (echo_t *)obj;
	sound_t fbk;

	// Saco la muestra mas vieja de la cadena de delay
	delay_pull(echo->delay, &fbk);

	// Calculo el valor que ingresa a la cadena de delay
	fbk = *in + fixedpt_mul(fbk, feedback);

	// Guardo la señal realimentada
	delay_push(echo->delay, &fbk);

	// Calculo la salida
	*out = fixedpt_mul(*in, fixedpt_rconst(1) - mix) + fixedpt_mul(fbk, mix);
}
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <locale.h>

//#define FIXEDPT_WBITS 16
#include "fixedptc.h"

/* This test program verifies the fixedpt precision, comparing it to
 * float and double precision results. */

static const float pi_f = 3.14159265358979323846264338;
static const double pi_d = 3.14159265358979323846264338;
static const fixedpt pi_x = fixedpt_rconst(3.14159265358979323846264338);

static const float e_f = 2.71828182845904523536028747;
static const double e_d = 2.71828182845904523536028747;
static const fixedpt e_x = fixedpt_rconst(2.71828182845904523536028747);
/*
void
verify_numbers()
{
	printf("pi as string:\t3.14159265358979323846264338\n");
	printf("pi as float:\t%0.6f\n", pi_f);
	printf("pi as double:\t%0.15lf\n", pi_d);
	printf("pi as fixedpt:\t%s\n", fixedpt_cstr(pi_x, -1));
	printf("  delta fixedpt-double:\t%0.10lf\n", atof(fixedpt_cstr(pi_x, -1)) - pi_d);
	printf("pi as fixedpt converted to float: %0.6f\n", fixedpt_tofloat(pi_x));

	printf("e as string:\t2.71828182845904523536028747\n");
Beispiel #5
0
int main() {

	fixedpt A, B, C;
	
	printf("fixedptc library version: %s\n", FIXEDPT_VCSID);
	printf("Using %d-bit precision, %d.%d format\n\n", FIXEDPT_BITS, FIXEDPT_WBITS, FIXEDPT_FBITS);

	printf("The most precise number: ");
	fixedpt_print(1);
	printf("The biggest number: ");
	fixedpt_print(0x7fffff00);
	printf("Here are some example numbers:\n");

	printf("Random number: ");
	fixedpt_print(fixedpt_rconst(143.125));
	printf("PI: ");
	fixedpt_print(FIXEDPT_PI);
	printf("e: ");
	fixedpt_print(FIXEDPT_E);
	puts("");

	A = fixedpt_rconst(2.5);
	B = fixedpt_fromint(3);

	fixedpt_print(A);
	puts("+");
	fixedpt_print(B);
	C = fixedpt_add(A, B);
	puts("=");
	fixedpt_print(C);
	puts("");

	fixedpt_print(A);
	puts("*");
	fixedpt_print(B);
	puts("=");
	C = fixedpt_mul(A, B);
	fixedpt_print(C);
	puts("");

	A = fixedpt_rconst(1);
	B = fixedpt_rconst(4);
	C = fixedpt_div(A, B);

	fixedpt_print(A);
	puts("/");
	fixedpt_print(B);
	puts("=");
	fixedpt_print(C);

	printf("exp(1)=");
	fixedpt_print(fixedpt_exp(FIXEDPT_ONE));

	puts("");
	puts("sqrt(pi)=");
	fixedpt_print(fixedpt_sqrt(FIXEDPT_PI));
	
	puts("");
	puts("sqrt(25)=");
	fixedpt_print(fixedpt_sqrt(fixedpt_rconst(25)));

	puts("");
	puts("sin(pi/2)=");
	fixedpt_print(fixedpt_sin(FIXEDPT_HALF_PI));

	puts("");
	puts("sin(3.5*pi)=");
	fixedpt_print(fixedpt_sin(fixedpt_mul(fixedpt_rconst(3.5), FIXEDPT_PI)));

	puts("");
	puts("4^3.5=");
	fixedpt_print(fixedpt_pow(fixedpt_rconst(4), fixedpt_rconst(3.5)));

	puts("");
	puts("4^0.5=");
	fixedpt_print(fixedpt_pow(fixedpt_rconst(4), fixedpt_rconst(0.5)));

	return (0);
}