Exemple #1
0
int32_t make_FM4Op(CSOUND *csound, FM4OP *p)
{
    MYFLT       tempCoeffs[2] = {FL(0.0), -FL(1.0)};
    FUNC        *ftp;

    if (!FM_tabs_built) build_FM(); /* Ensure tables exist */

    make_ADSR(&p->adsr[0]);
    make_ADSR(&p->adsr[1]);
    make_ADSR(&p->adsr[2]);
    make_ADSR(&p->adsr[3]);
    make_TwoZero(&p->twozero);
    if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->vifn)) == NULL))
      goto err1;
    p->vibWave = ftp;
    p->baseFreq = csound->A4;
    p->ratios[0] = FL(1.0);
    p->ratios[1] = FL(1.0);
    p->ratios[2] = FL(1.0);
    p->ratios[3] = FL(1.0);
    p->gains[0] = FL(1.0);
    p->gains[1] = FL(1.0);
    p->gains[2] = FL(1.0);
    p->gains[3] = FL(1.0);
    TwoZero_setZeroCoeffs(&p->twozero, tempCoeffs);
    p->twozero.gain = FL(0.0);
    return OK;
 err1:
/* Expect sine wave */
    return csound->PerfError(csound, p->h.insdshead,
                             Str("No table for VibWaveato"));
}
Exemple #2
0
int bowedbarset(CSOUND *csound, BOWEDBAR *p)
{
    int32 i;
    MYFLT amplitude = *p->amp * AMP_RSCALE;

    p->modes[0] = FL(1.0);
    p->modes[1] = FL(2.756);
    p->modes[2] = FL(5.404);
    p->modes[3] = FL(8.933);

    make_BiQuad(&p->bandpass[0]);
    make_BiQuad(&p->bandpass[1]);
    make_BiQuad(&p->bandpass[2]);
    make_BiQuad(&p->bandpass[3]);
    make_ADSR(&p->adsr);
    ADSR_setAllTimes(csound, &p->adsr, FL(0.02), FL(0.005), FL(0.9), FL(0.01));

    if (*p->lowestFreq>=FL(0.0)) {      /* If no init skip */
      if (*p->lowestFreq!=FL(0.0))
        p->length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0));
      else if (*p->frequency!=FL(0.0))
        p->length = (int32) (CS_ESR / *p->frequency + FL(1.0));
      else {
        csound->Warning(csound,
                        Str("unknown lowest frequency for bowed bar -- "
                            "assuming 50Hz\n"));
        p->length = (int32) (CS_ESR / FL(50.0) + FL(1.0));
      }
    }

    p->nr_modes = NR_MODES;
    for (i = 0; i<NR_MODES; i++) {
      make_DLineN(csound, &p->delay[i], p->length);
      DLineN_setDelay(csound, &p->delay[i], (int)(p->length/p->modes[i]));
      BiQuad_clear(&p->bandpass[i]);
    }
/*     p->gains[0] = FL(0.0); */
/*     p->gains[1] = FL(0.0); */
/*     p->gains[2] = FL(0.0); */
/*     p->gains[3] = FL(0.0); */
    p->adsr.target = FL(0.0);
    p->adsr.value = FL(0.0);
    p->adsr.rate = amplitude * FL(0.001);
    p->adsr.state = ATTACK;
    p->lastBowPos = FL(0.0);
    p->bowTarg = FL(0.0);
    p->freq = -FL(1.0);
    p->lastpos = -FL(1.0);
    p->lastpress = p->bowvel = p->velinput = FL(0.0);
    p->kloop = 0;
    p->bowTabl.offSet = p->bowTabl.slope = FL(0.0);
    return OK;
}
Exemple #3
0
int brassset(CSOUND *csound, BRASS *p)
{
    FUNC        *ftp;
    MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */

    if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->vibr = ftp;
    else {                                      /* Expect sine wave */
      return csound->InitError(csound, Str("No table for Brass"));
    }
    p->frq = *p->frequency;     /* Remember */
    if (*p->lowestFreq>=FL(0.0)) {
      if (*p->lowestFreq!=FL(0.0)) {
        p->length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0));
        p->limit = *p->lowestFreq;
      }
      else if (p->frq!=FL(0.0)) {
        p->length = (int32) (CS_ESR / p->frq + FL(1.0));
        p->limit = p->frq;
      }
      else {
        csound->Warning(csound, Str("No base frequency for brass "
                                    "-- assumed to be 50Hz\n"));
        p->length = (int32) (CS_ESR / FL(50.0) + FL(1.0));
        p->limit = FL(50.0);
      }
      make_DLineA(csound, &p->delayLine, p->length);
      make_LipFilt(&p->lipFilter);
      make_DCBlock(&p->dcBlock);
      make_ADSR(&p->adsr);
      ADSR_setAllTimes(csound, &p->adsr, FL(0.005), FL(0.001), FL(1.0), FL(0.010));
/*        ADSR_setAll(&p->adsr, 0.02f, 0.05f, FL(1.0), 0.001f); */

      ADSR_setAttackRate(csound, &p->adsr, amp * FL(0.001));

      p->maxPressure = amp;
      ADSR_keyOn(&p->adsr);

      /* Set frequency */
      /*      p->slideTarget = (CS_ESR / p->frq * FL(2.0)) + 3.0f; */
      /* fudge correction for filter delays */
      /*      DLineA_setDelay(&p->delayLine, p->slideTarget);*/
      /* we'll play a harmonic  */
      p->lipTarget = FL(0.0);
/*        LipFilt_setFreq(csound, &p->lipFilter, p->frq); */
      /* End of set frequency */
      p->frq = FL(0.0);         /* to say we do not know */
      p->lipT = FL(0.0);
      /*     LipFilt_setFreq(csound, &p->lipFilter, */
      /*                     p->lipTarget * (MYFLT)pow(4.0,
                                                       (2.0* p->lipT) -1.0)); */
      {
        int relestim = (int)(CS_EKR * FL(0.1));
        /* 1/10th second decay extention */
        if (relestim > p->h.insdshead->xtratim)
          p->h.insdshead->xtratim = relestim;
      }
      p->kloop = (int) ((int32) (p->h.insdshead->offtim * CS_EKR)
                        - (int32) (CS_EKR * *p->dettack));
    }
    return OK;
}
Exemple #4
0
int bowedset(CSOUND *csound, BOWED *p)
{
    int32        length;
    FUNC        *ftp;
    MYFLT       amp = (*p->amp)*AMP_RSCALE; /* Normalise */

    if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->vibr = ftp;
    else {                                      /* Expect sine wave */
      return csound->InitError(csound, Str("No table for wgbow vibrato"));
    }
    if (*p->lowestFreq>=FL(0.0)) {      /* If no init skip */
      if (*p->lowestFreq!=FL(0.0)) {
        length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0));
        p->limit = *p->lowestFreq;
      }
      else if (*p->frequency!=FL(0.0)) {
        length = (int32) (CS_ESR / *p->frequency + FL(1.0));
        p->limit = *p->frequency;
      }
      else {
        csound->Warning(csound, Str("unknown lowest frequency for bowed string "
                                    "-- assuming 50Hz\n"));
        length = (int32) (CS_ESR / FL(50.0) + FL(1.0));
        p->limit = FL(50.0);
      }
      make_DLineL(csound, &p->neckDelay, length);
      length = length >> 1; /* Unsure about this; seems correct in later code */
      make_DLineL(csound, &p->bridgeDelay, length);

      /*  p->bowTabl.offSet = FL(0.0);*/
      /* offset is a bias, really not needed unless */
      /* friction is different in each direction    */

      /* p->bowTabl.slope contrls width of friction pulse, related to bowForce */
      p->bowTabl.slope = FL(3.0);
      make_OnePole(&p->reflFilt);
      make_BiQuad(&p->bodyFilt);
      make_ADSR(&p->adsr);

      DLineL_setDelay(&p->neckDelay, FL(100.0));
      DLineL_setDelay(&p->bridgeDelay, FL(29.0));

      OnePole_setPole(&p->reflFilt, FL(0.6) - (FL(0.1) * RATE_NORM));
      OnePole_setGain(&p->reflFilt, FL(0.95));

      BiQuad_setFreqAndReson(p->bodyFilt, FL(500.0), FL(0.85));
      BiQuad_setEqualGainZeroes(p->bodyFilt);
      BiQuad_setGain(p->bodyFilt, FL(0.2));

      ADSR_setAllTimes(csound, &p->adsr, FL(0.02), FL(0.005), FL(0.9), FL(0.01));
/*        ADSR_setAll(&p->adsr, 0.002f,0.01f,0.9f,0.01f); */

      p->adsr.target = FL(1.0);
      p->adsr.rate = p->adsr.attackRate;
      p->adsr.state = ATTACK;
      p->maxVelocity = FL(0.03) + (FL(0.2) * amp);

      p->lastpress = FL(0.0);   /* Set unknown state */
      p->lastfreq = FL(0.0);
      p->lastbeta = FL(0.0);    /* Remember states */
      p->lastamp = amp;
    }
    return OK;
}
Exemple #5
0
int fluteset(CSOUND *csound, FLUTE *p)
{
    FUNC        *ftp;
    int32        length;

    if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->vibr = ftp;
    else {                                   /* Expect sine wave */
      return csound->InitError(csound, Str("No table for Flute"));
    }
    if (*p->lowestFreq>=FL(0.0)) {      /* Skip initialisation?? */
      if (*p->lowestFreq!=FL(0.0)) {
        length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0));
        p->limit = *p->lowestFreq;
      }
      else if (*p->frequency!=FL(0.0)) {
        length = (int32) (CS_ESR / *p->frequency + FL(1.0));
        p->limit = *p->frequency;
      }
      else {
        csound->Warning(csound, Str("No base frequency for flute "
                                    "-- assumed to be 50Hz\n"));
        length = (int32) (CS_ESR / FL(50.0) + FL(1.0));
        p->limit = FL(50.0);
      }
      make_DLineL(csound, &p->boreDelay, length);
      length = length >> 1;        /* ??? really; yes from later version */
      make_DLineL(csound, &p->jetDelay, length);
      make_OnePole(&p->filter);
      make_DCBlock(&p->dcBlock);
      make_Noise(p->noise);
      make_ADSR(&p->adsr);
                                /* Clear */
/*     OnePole_clear(&p->filter); */
/*     DCBlock_clear(&p->dcBlock); */
                                /* End Clear */
/*       DLineL_setDelay(&p->boreDelay, 100.0f); */
/*       DLineL_setDelay(&p->jetDelay, 49.0f); */

      OnePole_setPole(&p->filter, FL(0.7) - (FL(0.1) * RATE_NORM));
      OnePole_setGain(&p->filter, -FL(1.0));
      ADSR_setAllTimes(csound, &p->adsr, FL(0.005), FL(0.01), FL(0.8), FL(0.010));
/*        ADSR_setAll(&p->adsr, 0.02f, 0.05f, 0.8f, 0.001f); */
    /* Suggested values */
    /*    p->endRefl = 0.5; */
    /*    p->jetRefl = 0.5; */
    /*    p->noiseGain = 0.15; */ /* Breath pressure random component   */
    /*    p->vibrGain = 0.05;  */ /* breath periodic vibrato component  */
    /*    p->jetRatio = 0.32;  */
      p->lastamp = FL(1.0);       /* Remember */
                                  /* This should be controlled by attack */
      ADSR_setAttackRate(csound, &p->adsr, FL(0.02));
      p->maxPress = FL(2.3) / FL(0.8);
      p->outputGain = FL(1.001);
      ADSR_keyOn(&p->adsr);
      p->kloop = (MYFLT)((int)(p->h.insdshead->offtim*CS_EKR -
                               CS_EKR*(*p->dettack)));

      p->lastFreq = FL(0.0);
      p->lastJet = -FL(1.0);
      /* freq = (2/3)*p->frequency as we're overblowing here */
      /* but 1/(2/3) is 1.5 so multiply for speed */
    }
    return OK;
}