~ubuntu-branches/ubuntu/precise/csound/precise

« back to all changes in this revision

Viewing changes to Opcodes/ugsc.c

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2012-04-19 09:26:46 UTC
  • mfrom: (3.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20120419092646-96xbj1n6atuqosk2
Tags: 1:5.17.6~dfsg-1
* New upstream release
 - Do not build the wiimote opcodes (we need wiiuse).
* Add new API function to symbols file
* Disable lua opcodes, they were broken. Requires OpenMP to be enabled.
* Backport fixes from upstream:
  - Link dssi4cs with dl. Backport
  - Fix building of CsoundAC

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
    /* pole values taken from Bernie Hutchins, "Musical Engineer's Handbook" */
108
108
    double poles[12] = {0.3609, 2.7412, 11.1573, 44.7581, 179.6242, 798.4578,
109
109
                        1.2524, 5.5671, 22.3423, 89.6271, 364.7914, 2770.1114};
110
 
    double polefreq[12], rc[12], alpha[12], beta[12];
 
110
    double polefreq, rc, alpha, beta;
111
111
    /* calculate coefficients for allpass filters, based on sampling rate */
112
112
    for (j=0; j<12; j++) {
113
113
      /*      p->coef[j] = (1 - (15 * PI * pole[j]) / csound->esr) /
114
114
              (1 + (15 * PI * pole[j]) / csound->esr); */
115
 
      polefreq[j] = poles[j] * 15.0;
116
 
      rc[j] = 1.0 / (2.0 * PI * polefreq[j]);
117
 
      alpha[j] = 1.0 / rc[j];
118
 
      beta[j] = (1.0 - (alpha[j] * 0.5 * (double)csound->onedsr)) /
119
 
                (1.0 + (alpha[j] * 0.5 * (double)csound->onedsr));
 
115
      polefreq = poles[j] * 15.0;
 
116
      rc = 1.0 / (2.0 * PI * polefreq);
 
117
      alpha = 1.0 / rc;
 
118
      alpha = alpha * 0.5 * (double)csound->onedsr;
 
119
      beta = (1.0 - alpha) / (1.0 + alpha);
120
120
      p->xnm1[j] = p->ynm1[j] = FL(0.0);
121
 
      p->coef[j] = -(MYFLT)beta[j];
 
121
      p->coef[j] = -(MYFLT)beta;
122
122
    }
123
123
    return OK;
124
124
}
125
125
 
126
126
static int hilbert(CSOUND *csound, HILBERT *p)
127
127
{
128
 
    MYFLT xn1 = FL(0.0), yn1 = FL(0.0), xn2 = FL(0.0), yn2 = FL(0.0);
 
128
    MYFLT xn1, yn1, xn2, yn2;
129
129
    MYFLT *out1, *out2, *in;
130
 
    MYFLT *xnm1, *ynm1, *coef;
 
130
    MYFLT *coef;
131
131
    int n, nsmps = csound->ksmps;
132
132
    int j;
133
133
 
134
 
    xnm1 = p->xnm1;
135
 
    ynm1 = p->ynm1;
136
134
    coef = p->coef;
137
135
    out1 = p->out1;
138
136
    out2 = p->out2;
344
342
{
345
343
    MYFLT xn = FL(0.0), yn = FL(0.0);
346
344
    MYFLT *out, *in;
347
 
    MYFLT *xnm1, *ynm1, feedback;
 
345
    MYFLT feedback;
348
346
    MYFLT coef = *p->kcoef, fbgain = *p->fbgain;
349
347
    MYFLT beta, wp;
350
348
    int nsmps = csound->ksmps;
351
349
    int i, j;
352
350
 
353
 
    xnm1 = p->xnm1;
354
 
    ynm1 = p->ynm1;
355
351
    feedback = p->feedback;
356
352
    out = p->out;
357
353
    in = p->in;
385
381
 
386
382
static int phaser2set(CSOUND *csound, PHASER2 *p)
387
383
{
388
 
    int modetype, j;
 
384
    int modetype;
389
385
    int loop;
390
386
 
391
387
    p->modetype = modetype = (int)*p->mode;
399
395
    csound->AuxAlloc(csound, (size_t)loop*sizeof(MYFLT), &p->aux2);
400
396
    p->nm1 = (MYFLT *) p->aux1.auxp;
401
397
    p->nm2 = (MYFLT *) p->aux2.auxp;
402
 
    for (j=0; j< loop; j++)
403
 
      p->nm1[j] = p->nm2[j] = FL(0.0);
 
398
    /* *** This is unnecessary as AuxAlloc zeros *** */
 
399
    /* for (j=0; j< loop; j++) */
 
400
    /*   p->nm1[j] = p->nm2[j] = FL(0.0); */
404
401
    return OK;
405
402
}
406
403
 
433
430
      ksep = -ksep;
434
431
 
435
432
    for (n=0; n<nsmps; n++) {
 
433
      MYFLT kk = FL(1.0);
436
434
      xn = in[n] + feedback * fbgain;
437
435
      /* The following code is used to determine
438
436
       * how the frequencies of the notches are calculated.
443
441
      for (j=0; j < p->loop; j++) {
444
442
        if (p->modetype == 1)
445
443
          freq = kbf + (kbf * ksep * j);
446
 
        else
447
 
          freq = kbf * csound->intpow(ksep,(int32)j);
 
444
        else {
 
445
          freq = kbf * kk;
 
446
          kk *= ksep;
 
447
          //freq = kbf * csound->intpow(ksep,(int32)j);
 
448
        }
448
449
        /* Note similarities of following equations to
449
450
         * equations in resonr/resonz. The 2nd-order
450
451
         * allpass filter used here is similar to the
460
461
        /* Difference equations for implementing canonical
461
462
         * 2nd order section. (Direct Form II)
462
463
         */
463
 
        temp = xn - b * p->nm1[j] - a * p->nm2[j];
464
 
        yn = a * temp + b * p->nm1[j] + nm2[j];
465
 
        p->nm2[j] = p->nm1[j];
466
 
        p->nm1[j] = temp;
 
464
        temp = xn - b * nm1[j] - a * nm2[j];
 
465
        yn = a * temp + b * nm1[j] + nm2[j];
 
466
        nm2[j] = nm1[j];
 
467
        nm1[j] = temp;
467
468
        xn = yn;
468
469
      }
469
470
      out[n] = yn;