Example #1
0
void YSE::DSP::FastFadeOut(YSE::DSP::buffer & s, UInt length) {
  Clamp(length, 1u, s.getLength());
  Flt step = 1.0f / static_cast<Flt>(length);
  Flt multiplier = 1.0f;
  Flt * ptr = s.getPtr();
  for (UInt i = 0; i < length; i++) {
    *ptr++ *= multiplier;
    multiplier -= step;
  }
  UInt leftOvers = s.getLength() - length;
  while (leftOvers--) *ptr++ = 0.0f;
}
Example #2
0
void YSE::DSP::FastFadeIn(YSE::DSP::buffer & s, UInt length) {
  Clamp(length, 1u, s.getLength());
  Flt step = 1.0f / static_cast<Flt>(length);
  Flt multiplier = 0.0f;
  Flt * ptr = s.getPtr();
  for (UInt i = 0; i < length; i++) {
    *ptr++ *= multiplier;
    multiplier += step;
  }
}
Example #3
0
void YSE::DSP::ChangeGain(YSE::DSP::buffer & s, Flt currentGain, Flt newGain, UInt length) {
  if (currentGain == newGain) {
    s *= newGain;
    return;
  }

  Clamp(length, 1u, s.getLength());
  Flt step = (newGain - currentGain) / static_cast<Flt>(length);
  Flt multiplier = currentGain;
  Flt * ptr = s.getPtr();
  for (UInt i = 0; i < length; i++) {
    *ptr++ *= multiplier;
    multiplier += step;
  }
  UInt leftOvers = s.getLength() - length;
  for (; leftOvers > 7; leftOvers -= 8, ptr += 8) {
    ptr[0] *= newGain; ptr[1] *= newGain; ptr[2] *= newGain; ptr[3] *= newGain;
    ptr[4] *= newGain; ptr[5] *= newGain; ptr[6] *= newGain; ptr[7] *= newGain;
  }
  while (leftOvers--) *ptr++ *= newGain;
}
Example #4
0
void YSE::DSP::readInterpolated(YSE::DSP::buffer & ctrl, YSE::DSP::buffer& out, YSE::DSP::buffer & buffer, UInt &pos) {
  Flt * input = ctrl.getPtr();
  Flt * output = out.getPtr();
  Int n = ctrl.getLength();
  Int nsamps = buffer.getLength();
  Flt limit = nsamps - n - 1.0f;
  Flt fn = n - 1.0f;

  Flt * vp = buffer.getPtr();
  Flt *bp = nullptr;
  Flt *wp = vp + pos;

  while (n--) {
    Flt delsamps = SAMPLERATE * *input++, frac;
    Int idelsamps;
    Flt a, b, c, d, cminusb;
    if (delsamps < 1.00001f) delsamps = 1.00001f;
    if (delsamps > limit) delsamps = limit;
    delsamps += fn;
    fn = fn - 1.0f;
    idelsamps = (Int)delsamps;
    frac = delsamps - static_cast<Flt>(idelsamps);
    bp = wp - idelsamps;
    if (bp < vp + 4) bp += nsamps;
    d = bp[-3];
    c = bp[-2];
    b = bp[-1];
    a = bp[0];
    cminusb = c - b;
    *output++ = b + frac * (
      cminusb - 0.1666667f * (1.0f - frac) * (
      (d - a - 3.0f * cminusb) * frac + (d + 2.0f * a - 3.0f * b)
      )
      );

  }
  pos = (UInt)(bp - vp);
}
Example #5
0
void YSE::DSP::fftStats::operator()(YSE::DSP::buffer & real, YSE::DSP::buffer & imaginary) {
  if (real.getLength() != imaginary.getLength()) {
    assert(false);
  }

  int n = real.getLength();
  int n2 = (n >> 1);

  if (n < 4) {
    assert(false);
    return;
  }

  Flt * inReal = real.getPtr();
  Flt * inImag = imaginary.getPtr();
  Flt * freq = frequencies.getPtr();
  Flt * amp = amplitudes.getPtr();

  Flt lastReal = 0, currentReal = inReal[0], nextReal = inReal[1];
  Flt lastImag = 0, currentImag = inImag[0], nextImag = inImag[1];
  int m = n2 + 1;
  Flt fbin = 1, oneOverN2 = 1.f / ((Flt)n2 * (Flt)n2);

  inReal += 2;
  inImag += 2;

  *amp++ = *freq++ = 0;

  n2 -= 2;

  while (n2--) {
    Flt re, im, pow, fr;
    
    lastReal = currentReal;
    currentReal = nextReal;
    nextReal = *inReal++;

    lastImag = currentImag;
    currentImag = nextImag;
    nextImag = *inImag++;

    re = currentReal - 0.5f * (lastReal + nextReal);
    im = currentImag - 0.5f * (lastImag + nextImag);
    pow = re * re + im * im;

    if (pow > 1e-19) {
      Flt detune = ((lastReal + nextReal) * re + (lastImag - nextImag) * im) / (2.f * pow);
      if (detune > 2 || detune < -2) fr = pow = 0;
      else fr = fbin + detune;
    }
    else {
      fr = pow = 0;
    }

    *freq++ = fr;
    *amp++ = oneOverN2 * pow;
    fbin += 1.f;
  }
  while (m--) *amp++ = *freq++ = 0;

  YSE::DSP::sqrtFunc(frequencies.getPtr(), frequencies.getPtr(), n >> 1);
}