vcf4pole

Four pole VCF The cutoff frequency is limited to 9.4kHz. For higher cutoff frequencies, use the vcf4pole2x version.
Author: Johannes Taelman
License: GPL
Github: jt/filter/vcf4pole.axo

Inlets

frac32buffer in

frac32.bipolar pitch

frac32.positive reso

Outlets

frac32buffer out

Parameters

frac32.u.map reso

frac32.s.map.pitch pitch

Declaration
/* based on
https://github.com/ddiakopoulos/MoogLadders/blob/master/src/RKSimulationModel.h
*
Copyright (c) 2015, Miller Puckette. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

int32_t cutoff = 0;
int32_t resonance = 0;

int32_t clip(int32_t x) { return __SSAT(x, 28); }

int32_t state[4];

int32_t MultCutoff_A(int32_t x) { return ___SMMUL(x, cutoff); }

void calculateDerivatives_A(int32_t input, int32_t *dstate, int32_t *sstate) {
  int32_t satstate0 = clip(sstate[0]);
  int32_t satstate1 = clip(sstate[1]);
  int32_t satstate2 = clip(sstate[2]);
  int32_t satstate3 = clip(sstate[3]);

  dstate[0] = MultCutoff_A(clip(input - (___SMMUL(resonance, sstate[3]) << 4)) -
                           satstate0);
  dstate[1] = MultCutoff_A(satstate0 - satstate1);
  dstate[2] = MultCutoff_A(satstate1 - satstate2);
  dstate[3] = MultCutoff_A(satstate2 - satstate3);
}

void rungekutteSolver_A(int32_t input) {
  int i;
  int32_t deriv1[4], deriv2[4], deriv3[4], deriv4[4], tempState[4];

  calculateDerivatives_A(input, deriv1, state);

  for (i = 0; i < 4; i++)
    tempState[i] = state[i] + (deriv1[i]);

  calculateDerivatives_A(input, deriv2, tempState);

  for (i = 0; i < 4; i++)
    tempState[i] = state[i] + (deriv2[i]);

  calculateDerivatives_A(input, deriv3, tempState);

  for (i = 0; i < 4; i++)
    tempState[i] = state[i] + (deriv3[i] << 1);

  calculateDerivatives_A(input, deriv4, tempState);

  for (i = 0; i < 4; i++)
    state[i] = ___SMMLA(deriv1[i] + deriv4[i] + ((deriv2[i] + deriv3[i]) << 1),
                        (int)(0xFFFFFFFFu / 3u), state[i]);
}

int32_t MultCutoff_B(int32_t x) { return ___SMMLA(x, cutoff, x); }

void calculateDerivatives_B(int32_t input, int32_t *dstate, int32_t *sstate) {
  int32_t satstate0 = clip(sstate[0]);
  int32_t satstate1 = clip(sstate[1]);
  int32_t satstate2 = clip(sstate[2]);
  int32_t satstate3 = clip(sstate[3]);

  dstate[0] = MultCutoff_B(clip(input - (___SMMUL(resonance, sstate[3]) << 4)) -
                           satstate0);
  dstate[1] = MultCutoff_B(satstate0 - satstate1);
  dstate[2] = MultCutoff_B(satstate1 - satstate2);
  dstate[3] = MultCutoff_B(satstate2 - satstate3);
}

void rungekutteSolver_B(int32_t input) {
  int i;
  int32_t deriv1[4], deriv2[4], deriv3[4], deriv4[4], tempState[4];

  calculateDerivatives_B(input, deriv1, state);

  for (i = 0; i < 4; i++)
    tempState[i] = state[i] + (deriv1[i]);

  calculateDerivatives_B(input, deriv2, tempState);

  for (i = 0; i < 4; i++)
    tempState[i] = state[i] + (deriv2[i]);

  calculateDerivatives_B(input, deriv3, tempState);

  for (i = 0; i < 4; i++)
    tempState[i] = state[i] + (deriv3[i] << 1);

  calculateDerivatives_B(input, deriv4, tempState);

  for (i = 0; i < 4; i++)
    state[i] = ___SMMLA(deriv1[i] + deriv4[i] + ((deriv2[i] + deriv3[i]) << 1),
                        (int)(0xFFFFFFFFu / 3u), state[i]);
}
Control Rate
int pitch1 = param_pitch + inlet_pitch + 0x01000000;
if (pitch1 > 0x08400000)
  pitch1 = 0x08400000;
int32_t freq;
MTOFEXTENDED(pitch1, freq);
cutoff = (freq << 1);
resonance = __USAT(param_reso + inlet_reso, 28) << 3;
resonance += resonance >> 6;

if (cutoff > 0) {
  // case A
  int i;
  for (int i = 0; i < BUFSIZE; i++) {
    rungekutteSolver_A(inlet_in[i]);
    outlet_out[i] = state[3];
  }
} else {
  // case B
  int i;
  for (int i = 0; i < BUFSIZE; i++) {
    rungekutteSolver_B(inlet_in[i]);
    outlet_out[i] = state[3];
  }
}

Privacy

© 2024 Zrna Research