Ejemplo n.º 1
0
Archivo: wt.c Proyecto: srejv/dspmusic
inline fixedp dLinTerp(fixedp x1, fixedp x2, fixedp y1, fixedp y2, fixedp x)
{
	fixedp dx, result, denom;
	denom = qsub(x2, x1);
	if(denom == 0)
		return y1; // should not ever happen

	// calculate decimal position of x
	dx = qdiv(qsub(x, x1), denom);

	// use weighted sum method of interpolating
	result = qadd( qmul( dx, y2 ), qmul( qsub( short2q(1), dx ), y1 ));

	return result;
}
Ejemplo n.º 2
0
void
subtract_numbers(void)
{
	double a, b;

	if (isrational(stack[tos - 1]) && isrational(stack[tos - 2])) {
		qsub();
		return;
	}

	save();

	p2 = pop();
	p1 = pop();

	if (isdouble(p1))
		a = p1->u.d;
	else
		a = convert_rational_to_double(p1);

	if (isdouble(p2))
		b = p2->u.d;
	else
		b = convert_rational_to_double(p2);

	push_double(a - b);

	restore();
}
Ejemplo n.º 3
0
fixedp do_3band(EQSTATE* es, fixedp sample)
{
  // Locals

  fixedp  l,m,h;      // Low / Mid / High - Sample Values

  // Filter #1 (lowpass)

  es->f1p0  = qadd(es->f1p0, qmul(es->lf, qsub(sample,   es->f1p0)));//  + vsa; might need this but i dont think so. who knows?
  es->f1p1  = qadd(es->f1p1, qmul(es->lf, qsub(es->f1p0, es->f1p1)));
  es->f1p2  = qadd(es->f1p2, qmul(es->lf, qsub(es->f1p1, es->f1p2)));
  es->f1p3  = qadd(es->f1p3, qmul(es->lf, qsub(es->f1p2, es->f1p3)));

  l          = es->f1p3;

  // Filter #2 (highpass)
  
  es->f2p0  = qadd(es->f2p0,qmul(es->hf, qsub(sample   , es->f2p0))); // + vsa;
  es->f2p1  = qadd(es->f2p1,qmul(es->hf, qsub(es->f2p0 , es->f2p1)));
  es->f2p2  = qadd(es->f2p2,qmul(es->hf, qsub(es->f2p1 , es->f2p2)));
  es->f2p3  = qadd(es->f2p3,qmul(es->hf, qsub(es->f2p2 , es->f2p3)));

  h          = qsub(es->sdm3, es->f2p3);

  // Calculate midrange (signal - (low + high))

  m          = qsub(es->sdm3, qadd(h, l));

  // Scale, Combine and store

  l         = qmul(l, es->lg);
  m         = qmul(m, es->mg);
  h         = qmul(h, es->hg);

  // Shuffle history buffer 

  es->sdm3   = es->sdm2;
  es->sdm2   = es->sdm1;
  es->sdm1   = sample;                

  // Return result

  return(qadd(l, qadd(m, h)));
}
/*
 * Subtract two complex numbers.
 */
COMPLEX *
csub(COMPLEX *c1, COMPLEX *c2)
{
	COMPLEX *r;

	if ((c1->real == c2->real) && (c1->imag == c2->imag))
		return clink(&_czero_);
	if (ciszero(c2))
		return clink(c1);
	r = comalloc();
	if (!qiszero(c1->real) || !qiszero(c2->real)) {
		qfree(r->real);
		r->real = qsub(c1->real, c2->real);
	}
	if (!qiszero(c1->imag) || !qiszero(c2->imag)) {
		qfree(r->imag);
		r->imag = qsub(c1->imag, c2->imag);
	}
	return r;
}
/*
 * Multiply two complex numbers.
 * This saves one multiplication over the obvious algorithm by
 * trading it for several extra additions, as follows.	Let
 *	q1 = (a + b) * (c + d)
 *	q2 = a * c
 *	q3 = b * d
 * Then (a+bi) * (c+di) = (q2 - q3) + (q1 - q2 - q3)i.
 */
COMPLEX *
cmul(COMPLEX *c1, COMPLEX *c2)
{
	COMPLEX *r;
	NUMBER *q1, *q2, *q3, *q4;

	if (ciszero(c1) || ciszero(c2))
		return clink(&_czero_);
	if (cisone(c1))
		return clink(c2);
	if (cisone(c2))
		return clink(c1);
	if (cisreal(c2))
		return cmulq(c1, c2->real);
	if (cisreal(c1))
		return cmulq(c2, c1->real);
	/*
	 * Need to do the full calculation.
	 */
	r = comalloc();
	q2 = qqadd(c1->real, c1->imag);
	q3 = qqadd(c2->real, c2->imag);
	q1 = qmul(q2, q3);
	qfree(q2);
	qfree(q3);
	q2 = qmul(c1->real, c2->real);
	q3 = qmul(c1->imag, c2->imag);
	q4 = qqadd(q2, q3);
	qfree(r->real);
	r->real = qsub(q2, q3);
	qfree(r->imag);
	r->imag = qsub(q1, q4);
	qfree(q1);
	qfree(q2);
	qfree(q3);
	qfree(q4);
	return r;
}
/*
 * Subtract a real number from a complex number.
 */
COMPLEX *
csubq(COMPLEX *c, NUMBER *q)
{
	COMPLEX *r;

	if (qiszero(q))
		return clink(c);
	r = comalloc();
	qfree(r->real);
	qfree(r->imag);
	r->real = qsub(c->real, q);
	r->imag = qlink(c->imag);
	return r;
}
Ejemplo n.º 7
0
  void
    job_service_cpi_impl::sync_run_job_noio (saga::job::job     & ret,
                                             std::string          cmd,
                                             std::string          host)
  {
    saga::job::description jd;
    if (helper::create_saga_job_description(jd, cmd, host)
	== false) {
      SAGA_ADAPTOR_THROW("Could not parse command.", saga::BadParameter);
    }

    instance_data data(this);

    // create new job. state == saga::job::New
    saga::job::job job = saga::adaptors::job(data->rm_.get_url(),
                                             jd, proxy_->get_session());
    std::string pbsid;
    std::ostringstream os;

	std::string bin_pth;
	adaptor_data_type ad(this);
    bin_pth = ad->get_binary_path();
    cli::qsub qsub(localhost, bin_pth);

    //cli::qsub qsub(localhost);

    if (qsub.execute(jd, pbsid, os) == false) {
      std::string msg = os.str();
      // please check user@host
      SAGA_ADAPTOR_THROW(msg, saga::NoSuccess);
    }

    std::string sagaid = jobid_converter.convert_jobid(pbsid);
    saga::adaptors::attribute attr(job);
    attr.set_attribute(sja::jobid, sagaid);

//    adaptor_data_type ad(this);
    ad->register_job(pbsid, jd);
    // set current state
    job.get_state();
    ret = job;
  }
/*
 * Square a complex number.
 */
COMPLEX *
csquare(COMPLEX *c)
{
	COMPLEX *r;
	NUMBER *q1, *q2;

	if (ciszero(c))
		return clink(&_czero_);
	if (cisrunit(c))
		return clink(&_cone_);
	if (cisiunit(c))
		return clink(&_cnegone_);
	r = comalloc();
	if (cisreal(c)) {
		qfree(r->real);
		r->real = qsquare(c->real);
		return r;
	}
	if (cisimag(c)) {
		qfree(r->real);
		q1 = qsquare(c->imag);
		r->real = qneg(q1);
		qfree(q1);
		return r;
	}
	q1 = qsquare(c->real);
	q2 = qsquare(c->imag);
	qfree(r->real);
	r->real = qsub(q1, q2);
	qfree(q1);
	qfree(q2);
	qfree(r->imag);
	q1 = qmul(c->real, c->imag);
	r->imag = qscale(q1, 1L);
	qfree(q1);
	return r;
}
Ejemplo n.º 9
0
/*
 * Add an opcode to the current function being compiled.
 * Note: This can change the curfunc global variable when the
 * function needs expanding.
 */
void
addop(long op)
{
    register FUNC *fp;		/* current function */
    NUMBER *q, *q1, *q2;
    unsigned long count;
    BOOL cut;
    int diff;

    fp = curfunc;
    count = fp->f_opcodecount;
    cut = TRUE;
    diff = 2;
    q = NULL;
    if ((count + 5) >= maxopcodes) {
        maxopcodes += OPCODEALLOCSIZE;
        fp = (FUNC *) malloc(funcsize(maxopcodes));
        if (fp == NULL) {
            math_error("cannot malloc function");
            /*NOTREACHED*/
        }
        memcpy((char *) fp, (char *) curfunc,
               funcsize(curfunc->f_opcodecount));
        if (curfunc != functemplate)
            free(curfunc);
        curfunc = fp;
    }

    /*
     * Check the current opcode against the previous opcode and try to
     * slightly optimize the code depending on the various combinations.
     */
    switch (op) {
    case OP_GETVALUE:
        switch (oldop) {
        case OP_NUMBER:
        case OP_ZERO:
        case OP_ONE:
        case OP_IMAGINARY:
        case OP_GETEPSILON:
        case OP_SETEPSILON:
        case OP_STRING:
        case OP_UNDEF:
        case OP_GETCONFIG:
        case OP_SETCONFIG:
            return;
        case OP_DUPLICATE:
            diff = 1;
            oldop = OP_DUPVALUE;
            break;
        case OP_FIADDR:
            diff = 1;
            oldop = OP_FIVALUE;
            break;
        case OP_GLOBALADDR:
            diff = 1 + PTR_SIZE;
            oldop = OP_GLOBALVALUE;
            break;
        case OP_LOCALADDR:
            oldop = OP_LOCALVALUE;
            break;
        case OP_PARAMADDR:
            oldop = OP_PARAMVALUE;
            break;
        case OP_ELEMADDR:
            oldop = OP_ELEMVALUE;
            break;
        default:
            cut = FALSE;

        }
        if (cut) {
            fp->f_opcodes[count - diff] = oldop;
            return;
        }
        break;
    case OP_POP:
        switch (oldop) {
        case OP_ASSIGN:
            fp->f_opcodes[count-1] = OP_ASSIGNPOP;
            oldop = OP_ASSIGNPOP;
            return;
        case OP_NUMBER:
        case OP_IMAGINARY:
            q = constvalue(fp->f_opcodes[count-1]);
            qfree(q);
            break;
        case OP_STRING:
            sfree(findstring((long)fp->f_opcodes[count-1]));
            break;
        case OP_LOCALADDR:
        case OP_PARAMADDR:
            break;
        case OP_GLOBALADDR:
            diff = 1 + PTR_SIZE;
            break;
        case OP_UNDEF:
            fp->f_opcodecount -= 1;
            oldop = OP_NOP;
            oldoldop = OP_NOP;
            return;
        default:
            cut = FALSE;
        }
        if (cut) {
            fp->f_opcodecount -= diff;
            oldop = OP_NOP;
            oldoldop = OP_NOP;
            fprintf(stderr,
                    "Line %ld: unused value ignored\n",
                    linenumber());
            return;
        }
        break;
    case OP_NEGATE:
        if (oldop == OP_NUMBER) {
            q = constvalue(fp->f_opcodes[count-1]);
            fp->f_opcodes[count-1] = addqconstant(qneg(q));
            qfree(q);
            return;
        }
    }
    if (oldop == OP_NUMBER) {
        if (oldoldop == OP_NUMBER) {
            q1 = constvalue(fp->f_opcodes[count - 3]);
            q2 = constvalue(fp->f_opcodes[count - 1]);
            switch (op) {
            case OP_DIV:
                if (qiszero(q2)) {
                    cut = FALSE;
                    break;
                }
                q = qqdiv(q1,q2);
                break;
            case OP_MUL:
                q = qmul(q1,q2);
                break;
            case OP_ADD:
                q = qqadd(q1,q2);
                break;
            case OP_SUB:
                q = qsub(q1,q2);
                break;
            case OP_POWER:
                if (qisfrac(q2) || qisneg(q2))
                    cut = FALSE;
                else
                    q = qpowi(q1,q2);
                break;
            default:
                cut = FALSE;
            }
            if (cut) {
                qfree(q1);
                qfree(q2);
                fp->f_opcodes[count - 3] = addqconstant(q);
                fp->f_opcodecount -= 2;
                oldoldop = OP_NOP;
                return;
            }
        } else if (op != OP_NUMBER) {
            q = constvalue(fp->f_opcodes[count - 1]);
            if (op == OP_POWER) {
                if (qcmpi(q, 2L) == 0) {
                    fp->f_opcodecount--;
                    fp->f_opcodes[count - 2] = OP_SQUARE;
                    qfree(q);
                    oldop = OP_SQUARE;
                    return;
                }
                if (qcmpi(q, 4L) == 0) {
                    fp->f_opcodes[count - 2] = OP_SQUARE;
                    fp->f_opcodes[count - 1] = OP_SQUARE;
                    qfree(q);
                    oldop = OP_SQUARE;
                    return;
                }
            }
            if (qiszero(q)) {
                qfree(q);
                fp->f_opcodes[count - 2] = OP_ZERO;
                fp->f_opcodecount--;
            } else if (qisone(q)) {
                qfree(q);
                fp->f_opcodes[count - 2] = OP_ONE;
                fp->f_opcodecount--;
            }
        }
    }
    /*
     * No optimization possible, so store the opcode.
     */
    fp->f_opcodes[fp->f_opcodecount] = op;
    fp->f_opcodecount++;
    oldoldop = oldop;
    oldop = op;
}
/*
 * Divide two complex numbers.
 */
COMPLEX *
cdiv(COMPLEX *c1, COMPLEX *c2)
{
	COMPLEX *r;
	NUMBER *q1, *q2, *q3, *den;

	if (ciszero(c2)) {
		math_error("Division by zero");
		/*NOTREACHED*/
	}
	if ((c1->real == c2->real) && (c1->imag == c2->imag))
		return clink(&_cone_);
	r = comalloc();
	if (cisreal(c1) && cisreal(c2)) {
		qfree(r->real);
		r->real = qqdiv(c1->real, c2->real);
		return r;
	}
	if (cisimag(c1) && cisimag(c2)) {
		qfree(r->real);
		r->real = qqdiv(c1->imag, c2->imag);
		return r;
	}
	if (cisimag(c1) && cisreal(c2)) {
		qfree(r->imag);
		r->imag = qqdiv(c1->imag, c2->real);
		return r;
	}
	if (cisreal(c1) && cisimag(c2)) {
		qfree(r->imag);
		q1 = qqdiv(c1->real, c2->imag);
		r->imag = qneg(q1);
		qfree(q1);
		return r;
	}
	if (cisreal(c2)) {
		qfree(r->real);
		qfree(r->imag);
		r->real = qqdiv(c1->real, c2->real);
		r->imag = qqdiv(c1->imag, c2->real);
		return r;
	}
	q1 = qsquare(c2->real);
	q2 = qsquare(c2->imag);
	den = qqadd(q1, q2);
	qfree(q1);
	qfree(q2);
	q1 = qmul(c1->real, c2->real);
	q2 = qmul(c1->imag, c2->imag);
	q3 = qqadd(q1, q2);
	qfree(q1);
	qfree(q2);
	qfree(r->real);
	r->real = qqdiv(q3, den);
	qfree(q3);
	q1 = qmul(c1->real, c2->imag);
	q2 = qmul(c1->imag, c2->real);
	q3 = qsub(q2, q1);
	qfree(q1);
	qfree(q2);
	qfree(r->imag);
	r->imag = qqdiv(q3, den);
	qfree(q3);
	qfree(den);
	return r;
}
Ejemplo n.º 11
0
int
main ()
{
  int (*fun1) (qcmplx *, qcmplx *);
  qcmplx z, w;
  /*  char num[128]; */
  int i, k, errs, tests;
  union
    {
      double d;
      unsigned short s[4];
    }  u;

  errs = 0;
  tests = 0;
  i = 0;
  for (;;)
    {
      fun1 = test1[i].func;
      if (fun1 == NULL)
	break;

      /* Convert tabulated values to binary.  */
      asctoq (test1[i].real_arg_str, real_arg);
      asctoq (test1[i].imag_arg_str, imag_arg);
      asctoq (test1[i].real_ans_str, real_ans);
      asctoq (test1[i].imag_ans_str, imag_ans);

      /* Construct the complex argument.  */
      qmov (real_arg, z.r);
      qmov (imag_arg, z.i);

      /* Call the function under test.  */
      k = (*(fun1)) (&z, &w);

      /* Estimate the error of the result.  */
      qsub (w.r, real_ans, real_err);
      if (real_ans[1] != 0)
	qdiv (real_ans, real_err, real_err);
      qtoe (real_err, u.s);
      d_real_err = u.d;

      qsub (w.i, imag_ans, imag_err);
      if (imag_ans[1] != 0)
	qdiv (imag_ans, imag_err, imag_err);
      qtoe (imag_err, u.s);
      d_imag_err = u.d;


#if 1
      if ((fabs (d_real_err) > ERR_THRESH) || (fabs (d_imag_err) > ERR_THRESH))
	{
	  errs += 1;
	  printf ("Line %d: %s error = %.3e ", i + 1, test1[i].name,
		  d_real_err);
	  if (d_imag_err >= 0.0)
	    printf ("+ ");
	  printf ("%.3e i\n", d_imag_err);
	}
#else
      if ((qcmp (w.r, real_ans) != 0) || (qcmp (w.i, imag_ans) != 0))
	{
	  errs += 1;
	  qtoasc (w.r, num, 70);
	  printf ("Line %d: %s\n", i + 1, num);
	  qtoasc (w.i, num, 70);
	  printf ("%si\n", num);
	  qtoasc (real_ans, num, 70);
	  printf ("s.b. %s\n", num);
	  qtoasc (imag_ans, num, 70);
	  printf ("%si\n", num);
	  /*	  
	  printf ("Line %d: %.9e %9e, s.b. %.9e %.9e\n", i + 1,
		  creal(w), cimag(w), test1[i].real_ans, test1[i].imag_ans);
	  */
	}
#endif
      i += 1;
      tests += 1;
    }
  printf ("%d errors in %d tests\n", errs, tests);
  exit (0);
}
Ejemplo n.º 12
0
main(int ac, char **av)
{
    int i;
    FILE *ifp;
    char line[LINE_SIZE];

    prog = av[0];
    flt_scale = (double)1.0;
    flags = 0;
	d_path = NULL;
    process_options(ac, av);
    if (flags & VERBOSE)
        fprintf(ofp, 
	    "-- TPC %s Parameter Substitution (Version %d.%d.%d%s)\n",
            NAME, VERSION, RELEASE, MODIFICATION, PATCH);

    setup();

    if (!(flags & DFLT))        /* perturb the RNG */
	    {
	    if (!(flags & SEED))
                rndm = (long)((unsigned)time(NULL) * DSS_PROC);
		if (rndm < 0)
			rndm += 2147483647;
		Seed[0].value = rndm;
		for (i=1; i <= QUERIES_PER_SET; i++)
			{
			Seed[0].value = NextRand(Seed[0].value);
			Seed[i].value = Seed[0].value;
			}
		printf("-- using %ld as a seed to the RNG\n", rndm);
		}
    else
        printf("-- using default substitutions\n");
    
    if (flags & INIT)           /* init stream with ifile */
        {
        ifp = fopen(ifile, "r");
	OPEN_CHECK(ifp, ifile);
        while (fgets(line, LINE_SIZE, ifp) != NULL)
            fprintf(stdout, "%s", line);
        }

    if (snum >= 0)
        if (optind < ac)
            for (i=optind; i < ac; i++)
                {
                char qname[10];
                sprintf(qname, "%d", SEQUENCE(snum, atoi(av[i])));
                qsub(qname, flags);
                }
        else
            for (i=1; i <= QUERIES_PER_SET; i++)
                {
                char qname[10];
                sprintf(qname, "%d", SEQUENCE(snum, i));
                qsub(qname, flags);
                }
    else
        if (optind < ac)
            for (i=optind; i < ac; i++)
                qsub(av[i], flags);   
        else
            for (i=1; i <= QUERIES_PER_SET; i++)
                {
                char qname[10];
                sprintf(qname, "%d", i);
                qsub(qname, flags);
                }
    
    if (flags & TERMINATE)      /* terminate stream with tfile */
        {
        ifp = fopen(tfile, "r");
        if (ifp == NULL)
	OPEN_CHECK(ifp, tfile);
        while (fgets(line, LINE_SIZE, ifp) != NULL)
            fprintf(stdout, "%s", line);
        }

    return(0);
}
Ejemplo n.º 13
0
main()
{
char s[80];
double fabs(), floor();
#if EXPSCALE || EXPSC2
double exp();
#endif
double sqrt();	/* required to compute rms error */
int i, j, k;
long m, n;

dprec();	/* set up floating point coprocessor */
merror = 0;
/*aiconf = -1;*/	/* configure Airy function */
x = 1.0;
z = x * x;
qclear( qmax );
qtoasc( qmax, strmax, 4 );
qclear( qrmsa );
qclear( qave );

#if 1
printf(" Start at random number #:" );
gets( s );
sscanf( s, "%ld", &n );
printf("%ld\n", n );
#else
n = 0;
#endif

for( m=0; m<n; m++ )
	drand( &x );
n = 0;
m = 0;
x = floor( x );

loop:

for( i=0; i<100; i++ )
{
n++;
m++;

/* make random number in desired range */
drand( &x );
x = WIDTH *  ( x - 1.0 )  +  LOW;
#if EXPSCALE
x = exp(x);
drand( &a );
a = 1.0e-13 * x * a;
if( x > 0.0 )
	x -= a;
else
	x += a;
#endif
#if ONEINT
k = x;
x = k;
#endif
etoq( &x, q1 );		/* double number to q type */

/* do again if second argument required */

#if TWOARG || THREEARG || FOURARG
drand( &a );
a = WIDTHA *  ( a - 1.0 )  +  LOWA;
/*a /= 50.0;*/
#if EXPSC2
a = exp(a);
drand( &y2 );
y2 = 1.0e-13 * y2 * a;
if( a > 0.0 )
	a -= y2;
else
	a += y2;
#endif
#if TWOINT || THREEINT
k = a + 0.25;
a = k;
#endif
etoq( &a, qy4 );
#endif


#if THREEARG || FOURARG
drand( &b );
#if PROB
/*
b = b - 1.0;
b = a * b;
*/
b = WIDTHA *  ( b - 1.0 )  +  LOWA;

/* Half-integer a and b */
/*a = 0.5*floor(2.0*a+1.0);*/
a = 0.5;
b = 0.5*floor(2.0*b+1.0);
etoq( &a, qy4 );
/*x = (a / (a+b));*/

#else
b = WIDTHA *  ( b - 1.0 )  +  LOWA;
#endif
#if THREEINT
j = b + 0.25;
b = j;
#endif
etoq( &b, qb );
#endif

#if FOURARG
drand( &c );
c = WIDTHA *  ( c - 1.0 )  +  LOWA;
/* for hyp2f1 to ensure c-a-b > -1 */
/*
z = c-a-b;
if( z < -1.0 )
	c -= 1.6 * z;
*/
etoq( &c, qc );
#endif

/*printf("%.16E %.16E\n", a, x);*/

/* compute function under test */
#if ONEARG
#if FOURANS
/*FUNC( x, &z, &y2, &y3, &y4 );*/
FUNC( x, &y4, &y2, &y3, &z );
#else
#if TWOANS
FUNC( x, &z, &y2 );
/*FUNC( x, &y2, &z );*/
#else
#if ONEINT
z = FUNC( k );
#else
z = FUNC( x );
#endif
#endif
#endif
#endif

#if TWOARG
#if TWOINT
/*z = FUNC( k, x );*/
/*z = FUNC( x, k );*/
z = FUNC( a, x );
#else
#if FOURANS
FUNC( a, x, &z, &y2, &y3, &y4 );
#else
z = FUNC( a, x );
#endif
#endif
#endif

#if THREEARG
#if THREEINT
z = FUNC( j, k, x );
#else
z = FUNC( a, b, x );
#endif
#endif

#if FOURARG
z = FUNC( a, b, c, x );
#endif

etoq( &z, q2 );

/* handle detected overflow */
if( (z == MAXNUM) || (z == -MAXNUM) )
	{
	printf("detected overflow ");
#if FOURARG
	printf("%.4E %.4E %.4E %.4E %.4E %6ld \n",
		a, b, c, x, y, n);
#else
	printf("%.16E %.4E %.4E %6ld \n", x, a, z, n);
#endif
	e = 0.0;
	m -= 1;
	goto endlup;
	}
/* Skip high precision if underflow.  */
if( merror == UNDERFLOW )
  goto underf;

/* compute high precision function */
#if ONEARG
#if FOURANS
/*QFUNC( q1, qz, qy2, qy3, qy4 );*/
QFUNC( q1, qy4, qy2, qy3, qz );
#else
#if TWOANS
QFUNC( q1, qz, qy2 );
/*QFUNC( q1, qy2, qz );*/
#else
/*qclear( qy4 );*/
/*qmov( qone, qy4 );*/
/*QFUNC( qy4, q1, qz );*/
/*QFUNC( 1, q1, qz );*/
QFUNC( q1, qz );  /* normal */
#endif
#endif
#endif

#if TWOARG
#if TWOINT
/*QFUNC( k, q1, qz );*/
/*QFUNC( q1, qy4, qz );*/
QFUNC( qy4, q1, qz );
#else
#if FOURANS
QFUNC( qy4, q1, qz, qy2, qy3, qc );
#else
/*qclear( qy4 );*/
/*qmov( qone, qy4 );*/
QFUNC( qy4, q1, qz );
#endif
#endif
#endif

#if THREEARG
#if THREEINT
QFUNC( j, k, q1, qz );
#else
QFUNC( qy4, qb, q1, qz );
#endif
#endif

#if FOURARG
QFUNC( qy4, qb, qc, q1, qz );
#endif

qtoe( qz, &y ); /* correct answer, in double precision */


/* get absolute error, in extended precision */
qsub( qz, q2, qe );
qtoe( qe, &e );		/* the error in double precision */

/*  handle function result equal to zero
    or underflowed. */
if( qz[1] < 3 || merror == UNDERFLOW || fabs(z) < underthresh )
	{
underf:
	  merror = 0;
/* Don't bother to print anything.  */
#if 0
	printf("ans 0 ");
#if ONEARG
	printf("%.8E %.8E %.4E %6ld \n", x, y, e, n);
#endif

#if TWOARG
#if TWOINT
	printf("%d %.8E %.8E %.4E %6ld \n", k, x, y, e, n);
#else
	printf("%.6E %.6E %.6E %.4E %6ld \n", a, x, y, e, n);
#endif
#endif

#if THREEARG
	printf("%.6E %.6E %.6E %.6E %.4E %6ld \n", a, b, x, y, e, n);
#endif

#if FOURARG
	printf("%.4E %.4E %.4E %.4E %.4E %.4E %6ld \n",
		a, b, c, x, y, e, n);
#endif
#endif /* 0 */
	qclear( qe );
	e = 0.0;
	m -= 1;
	goto endlup;
	}

else

/*	relative error	*/

/* comment out the following two lines if absolute accuracy report */

#if RELERR
	qdiv( qz, qe, qe );
#else
	{
	qmov( qz, q2 );
	q2[0] = 0;
	if( qcmp( q2, qone ) > 0 )
		qdiv( qz, qe, qe );
	}
#endif

qadd( qave, qe, qave );
/* absolute value of error */
qe[0] = 0;

/* peak detect the error */
if( qcmp(qe, qmax) > 0 )
	{
	qmov( qe, qmax );
	qtoasc( qmax, strmax, 4 );
#if ONEARG
	printf("%.8E %.8E %s %6ld \n", x, y, strmax, n);
#endif
#if TWOARG
#if TWOINT
	printf("%d %.8E %.8E %s %6ld \n", k, x, y, strmax, n);
#else
	printf("%.6E %.6E %.6E %s %6ld \n", a, x, y, strmax, n);
#endif
#endif
#if THREEARG
	printf("%.6E %.6E %.6E %.6E %s %6ld \n", a, b, x, y, strmax, n);
#endif
#if FOURARG
	printf("%.4E %.4E %.4E %.4E %.4E %s %6ld \n",
		a, b, c, x, y, strmax, n);
#endif
	}

/* accumulate rms error	*/
/* rmsa += e * e;  accumulate the square of the error */
qmul( qe, qe, q2 );
qadd( q2, qrmsa, qrmsa );
endlup:
	;
}

/* report every 100 trials */
/* rms = sqrt( rmsa/m ); */
ltoq( &m, q1 );
qdiv( q1, qrmsa, q2 );
qsqrt( q2, q2 );
qtoasc( q2, strrms, 4 );

qdiv( q1, qave, q2 );
qtoasc( q2, strave, 4 );
/*
printf("%6ld   max = %s   rms = %s  ave = %s \n", m, strmax, strrms, strave );
*/
printf("%6ld   max = %s   rms = %s  ave = %s \r", m, strmax, strrms, strave );
fflush(stdout);
goto loop;
}
void two_ch_filtering(const Int32 *pQmf_r,
                      const Int32 *pQmf_i,
                      Int32 *mHybrid_r,
                      Int32 *mHybrid_i)
{

    Int32 cum0;
    Int32 cum1;
    Int32 cum2;
    Int32 tmp1;
    Int32 tmp2;

#ifndef ANDROID_DEFAULT_CODE
    tmp1 = qadd(pQmf_r[ 1], pQmf_r[11]);
    tmp2 = qadd(pQmf_i[ 1], pQmf_i[11]);
#else
    tmp1 = pQmf_r[ 1] + pQmf_r[11];
    tmp2 = pQmf_i[ 1] + pQmf_i[11];
#endif

    cum1 =   fxp_mul32_Q31(Qfmt31(0.03798975052098f), tmp1);
    cum2 =   fxp_mul32_Q31(Qfmt31(0.03798975052098f), tmp2);

#ifndef ANDROID_DEFAULT_CODE
    tmp1 = qadd(pQmf_r[ 3], pQmf_r[9]);
    tmp2 = qadd(pQmf_i[ 3], pQmf_i[9]);
#else    
    tmp1 = pQmf_r[ 3] + pQmf_r[ 9];
    tmp2 = pQmf_i[ 3] + pQmf_i[ 9];
#endif
    
    cum1 =   fxp_msu32_Q31(cum1, Qfmt31(0.14586278335076f), tmp1);
    cum2 =   fxp_msu32_Q31(cum2, Qfmt31(0.14586278335076f), tmp2);

#ifndef ANDROID_DEFAULT_CODE
    tmp1 = qadd(pQmf_r[ 5], pQmf_r[7]);
    tmp2 = qadd(pQmf_i[ 5], pQmf_i[7]);
#else    
    tmp1 = pQmf_r[ 5] + pQmf_r[ 7];
    tmp2 = pQmf_i[ 5] + pQmf_i[ 7];
#endif
    
    cum1 =   fxp_mac32_Q31(cum1, Qfmt31(0.61193261090336f), tmp1);
    cum2 =   fxp_mac32_Q31(cum2, Qfmt31(0.61193261090336f), tmp2);

    cum0 = pQmf_r[HYBRID_FILTER_DELAY] >> 1;  /* HYBRID_FILTER_DELAY == 6 */

#ifndef ANDROID_DEFAULT_CODE
    mHybrid_r[0] = qadd(cum0, cum1);
    mHybrid_r[1] = qsub(cum0, cum1);
#else
    mHybrid_r[0] = (cum0 + cum1);
    mHybrid_r[1] = (cum0 - cum1);
#endif

    cum0 = pQmf_i[HYBRID_FILTER_DELAY] >> 1;  /* HYBRID_FILTER_DELAY == 6 */

#ifndef ANDROID_DEFAULT_CODE
    mHybrid_i[0] = qadd(cum0, cum2);
    mHybrid_i[1] = qsub(cum0, cum2);
#else
    mHybrid_i[0] = (cum0 + cum2);
    mHybrid_i[1] = (cum0 - cum2);
#endif    

}
Ejemplo n.º 15
0
void process_overdrive(Distortion *t, fixedp *x) {
	
	Uint32 n;
	fixedp denom, tmp, a, b, numerator, denom1, denom2;

	// kom ihåg förra processens sampel?
	/*if(t->fdb) {
		for(n = 0; n < PROCESS_SIZE; n++) {
			t->prev = qadd( qmul( x[n],t->gain ), qmul( qmul(t->prev, t->gain), t->fdb ) );
			
	
			// 6554 = 0.2
			numeratorLvl1 = qmul(t->lvl1, qexp(qmul(t->prev, qadd(Q1, qmul(6554, qsub(Q1, t->lvl1))))));
			numeratorLvl2 = qmul(t->lvl2, qexp(qmul(-t->prev, qadd(Q1, qmul(6554, qsub(Q1, t->lvl2))))));
			denom = qadd(qexp(t->prev), qexp(-t->prev));
			x[n] = qdiv(qsub(numeratorLvl1, numeratorLvl2), denom);
		}
	} 
	else {*/
		for(n = 0; n < PROCESS_SIZE; n++) {

			t->prev = qmul(x[n],t->gain);
			


			a = qadd(Q1,qmul(3254,qsub(Q1,t->lvl1)));
			b = qadd(Q1,qmul(3254,qsub(Q1,t->lvl2)));
			tmp = qmul(-t->prev, qadd(a,b));
			
			if(tmp > short2q(32)) tmp = short2q(32);
			if(tmp < short2q(-32)) tmp = short2q(-32);
			
			tmp = qexp(tmp);
			numerator = qsub(t->lvl1, qmul(t->lvl2, tmp));
			
			tmp = qmul(t->prev, qsub(Q1, a));

			if(tmp > short2q(32)) tmp = short2q(32);
			if(tmp < short2q(-32)) tmp = short2q(-32);
			denom1 = qexp(tmp);

			tmp = qmul(-t->prev, qadd(Q1, a));

			if(tmp > short2q(32)) tmp = short2q(32);
			if(tmp < short2q(-32)) tmp = short2q(-32);
			denom2 = qexp(tmp);
			
			denom = qadd(denom1, denom2);
			tmp = qdiv(numerator, denom);
			
			if (tmp > AUDIOMAX) {
				// nu är tmp större än 32767
				tmp = AUDIOMAX;
			} else if (tmp < AUDIOMIN) {
				tmp = AUDIOMIN;
			}

			x[n] = tmp;
		}
	//}
}
Ejemplo n.º 16
0
	filter->xz1 = short2q(0);
	filter->xz2 = short2q(0);
	filter->yz1 = short2q(0);
	filter->yz2 = short2q(0);
}

// Do the filter: given input xn, calculate output yn and return it
fixedp BiQuad_do(BiQuad* this, fixedp xn) {
	// just do the difference equation: y(n) = a0x(n) + a1x(n-1) + a2x(n-2) - b1y(n-1) - b2y(n-2)
	fixedp a0 = qmul(this->a0, xn);
	fixedp a1 = qmul(this->a1, this->xz1);
	fixedp yn = qadd(a0, a1);
	a1 = qmul(this->a2, this->xz2);
	yn = qadd(yn, a1);
	a1 = qmul(this->b1, this->yz1);
	yn = qsub(yn, a1);
	a1 = qmul(this->b2, this->yz2);
	yn = qsub(yn, a1);
	//float yn = this->a0*xn + this->a1*this->xz1 + this->a2*this->xz2 - this->b1*this->yz1 - this->b2*this->yz2;

	// underflow check
	
	if(yn > 0.0 && yn < FLT_MIN_PLUS) yn = 0;
	if(yn < 0.0 && yn > FLT_MIN_MINUS) yn = 0;

	// shuffle the delays
	// Y delays
	this->yz2 = this->yz1;
	this->yz1 = yn;

	// X delays