contivari

Interpolated continously trans-morphing wavetable oscillator (or whatever) capable of sounding like LOTS of oscillators A function uses the internal table together with param_a, param_b and param_rate to edit itself in a continous loop. To make your own function, just embed the module, go over to K-rate code and follow the instructions. "function dependent controls": a=phase offset for sine-calculation for array-edit-position b=phase offset for sine-calculation for editting amplitude of array position "overall controls" pitch=oscillator pitch rate=changerate of wavetable->anti-clockwise=very slow morphing, clock-wise=fast morphing(=kinda noisy) mode=sets formula to use for transformation rst=when off, resets wavetable to zero, when on, resets wavetable to root-sine. (when reset input goes high)
Author: Remco van der Most
License: BSD
Github: sss/osc/contivari.axo

Inlets

frac32.bipolar pitch

frac32.bipolar rate

frac32.bipolar a

frac32.bipolar b

int32 mode

bool32 reset

Outlets

frac32buffer out

frac32buffer phase

Parameters

bool32.tgl rst

bool32.tgl disp

frac32.s.map.pitch pitch

frac32.s.map rate

frac32.s.map a

frac32.s.map b

int32 mode

Displays

int8array128.vbar scope

Declaration
int32_t T[128];
int32_t t[128];
int32_t r[128];
int D[128];
int i;
int32_t X;
int32_t Y;
int32_t tX;
int32_t tY;
bool cnt;
uint32_t Phase;
int32_t val;
int32_t LP;
int32_t TP;
bool rst;
Init
for (i = 0; i < 128; i++) {
  T[i] = 0;
  D[i] = 1;
}
Control Rate
if ((inlet_reset > 0) && !rst) {
  rst = 1;
  for (i = 0; i < 128; i++) {
    if (param_rst > 0) {
      int32_t R;
      SINE2TINTERP(i << 25, R)
      T[i] = R >> 1;
    } else {
      T[i] = 0;
    }
  }
} else if (inlet_reset <= 0) {
  rst = 0;
}
uint32_t rate;
MTOFEXTENDED(param_rate + inlet_rate, rate)
int32_t A = inlet_a + param_a;
int32_t B = inlet_b + param_b;
int mode = (inlet_mode + param_mode) & 3;
///// put your own code(s) overhere to update X and Y to tX and tY, output
///"should be" 32bit
///// so X and Y are your variables in a function that results in tX and tY as
///outputs.
///// tX controls the array-position (0-127) to edit and tY adds to the chosen
///array-position.
///// like: tX=X*X-Y*Y+param_a;
/////       tY=2*X*Y+param_b;

////code 1: every Krate update, X and Y are swapped between editting tX or tY
////        param_a and param_b are added as phase-offset in a sinewave

switch (mode > 0 ? mode : 0) {
case 0:
  cnt = (cnt + 1) & 1;
  SINE2TINTERP((cnt == 0 ? X : Y) + (A << 4), tX)
  SINE2TINTERP((cnt == 1 ? Y : X) + (B << 4), tY);
  break;

case 1:
  SINE2TINTERP(X + (A << 4), tX)
  SINE2TINTERP(Y + (B << 4), tY);
  break;

case 2:
  tX = (___SMMUL(X, (X > 0 ? X : -X)) - ___SMMUL(Y, Y > 0 ? Y : -Y) << 2) + A;
  tY = (___SMMUL(X, Y) << 1) * 2 + B;
  ;
  break;

case 3:
  tY = (___SMMUL(X, (X > 0 ? X : -X)) - ___SMMUL(Y, Y > 0 ? Y : -Y) << 2) + B;
  tX = (___SMMUL(X, Y) << 3) * 2 + (B << 4);
  ;
  break;

default:
  cnt = (cnt + 1) & 1;
  SINE2TINTERP((cnt == 0 ? X : Y) + (A << 4), tX)
  SINE2TINTERP((cnt == 1 ? Y : X) + (B << 4), tY);
  break;
}
/////

////leave this part alone, it will scale and use the tX and tY to edit the
///wavetable and to update tX and tY back to X and Y
X = tX;
tX = (tX >> 24) & 127;
int32_t tmp = T[tX] + (___SMMUL(tY, rate) << 1) * D[tX];
if ((tmp > (1 << 30)) || (tmp < (-1 << 30))) {
  D[tX] = -D[tX];
}
tmp = T[tX] + (___SMMUL(tY, rate)) * D[tX];
Y = T[tX] = tmp;

for (i = 0; i < 128; i++) {
  r[i] = T[i] + (T[(i + 1) & 127] + T[(i - 1) & 127] >> 1);
  TP = r[i] - TP >> 10;
  if (param_disp > 0) {
    disp_scope[i] = r[i] - TP >> 25;
  }
}

int32_t freq;
MTOFEXTENDED(param_pitch + inlet_pitch, freq)
freq = freq >> 3;
Audio Rate
int32_t out;
for (i = 0; i < 4; i++) {
  Phase += freq;
  uint32_t P1 = Phase - ((Phase >> 24) << 24) << 6;
  int32_t TMP1 = (r[(Phase >> 24) & 127]) >> 5;
  int32_t TMP2 = (r[((Phase >> 24) + 1) & 127]) >> 5;
  int32_t TMP3 = (r[((Phase >> 24) + 2) & 127]) >> 5;
  out = TMP1 + TMP2 + ___SMMUL(P1, TMP3 - TMP1 << 2);
  LP += out - LP >> 2;
  val += LP - val >> 11;
  out = LP - val;
}
outlet_out = out;
outlet_phase = Phase >> 4;

Privacy

© 2024 Zrna Research