syncKing

Oscillator with lots of sync options and modulation: -two waveform functions, each with their own "PWM" control mode. -control inlets for FM and AM width (eg for envelopes). FM is linear FM with frequency dependent modulation-index-width. -independent audio inlets for phase, FM, AM and sync (of course you can all feed them the same signal). -hardsync: resets phase to 0 immediately -direcsync: reverses playdirection at sync -bitsync: syncs phase to && bit of sync input -softsync: syncs phase to 0, but with LP filter. -swapsync: inverses output polarity -possync: depending on phase position, soft-syncs phase forwards or backwards. -stepsync: at sync moves phase at the amount of the "RespPo" setting. -"grit" parameter feeds output back to phase position.
Author: Remco van der Most
License: BSD
Github: sss/osc/syncKing.axo

Inlets

bool32 waveform

bool32 hardsync

bool32 direcsync

bool32 bitsync

bool32 softsync

bool32 swapsync

bool32 possync

bool32 stepsync

bool32 Ring

bool32 active

frac32buffer phase

frac32buffer phase increment

frac32buffer syncsource

frac32buffer am

frac32 pitch

frac32 PWM

frac32 PM

frac32 AM

frac32.bipolar FM

Outlets

frac32buffer.positive phasor wave

Parameters

frac32.s.map FM

frac32.s.map PM

frac32.s.map AM

frac32.s.map Grit

frac32.s.map Stepsize

bool32.tgl Waveform

bool32.tgl restarts phase at zero

bool32.tgl (inverses play direction

bool32.tgl Bitsync

bool32.tgl Swapsync

bool32.tgl Softsync

bool32.tgl Possync

bool32.tgl Stepsync

frac32.s.map.pitch pitch

frac32.s.map.pitch RespSo

frac32.s.map.pitch RespPo

Declaration
uint32_t Phase;

int hard;
int soft;
int32_t val1;
int32_t smooth1;
int sync;
int async;
int direction;
int dir;
int swap;
int32_t swp;
int32_t val2;
int position;
int32_t val3;
int32_t smooth2;
int step;
int32_t stphase;
int32_t phrase;
int32_t phasu;
int32_t phasU;
int32_t wa;
int32_t wb;
int32_t wc;
int waveform;
int32_t FMW;
int bit;
int32_t stAM;
int32_t PosAM;
int32_t InvAM;
int32_t AM;
int32_t feed;
int32_t afeed;
int32_t bfeed;
int32_t FW;
int32_t phaswidth;
int32_t phsw;
uint32_t freq;
int32_t f1;
int32_t f2;
int32_t f3;
Init
Phase = 0;
dir = 1;
swp = 1;
val1 = 0;
val2 = 1;
val3 = 0;
Control Rate
if (inlet_active > 0) {

  MTOFEXTENDED(param_pitch + inlet_pitch, freq);

  MTOF(param_RespSo, f1);

  MTOF(param_pitch + (1 << 21) * 24, f2);

  MTOF(param_RespPo, f3);

  step = inlet_stepsync + param_Stepsync;
  soft = inlet_softsync + param_Softsync;
  position = inlet_possync + param_Possync;
  direction = inlet_direcsync + param_Direcsync;
  hard = inlet_hardsync + param_Hardsync;
  swap = inlet_swapsync + param_Swapsync;
  waveform = inlet_waveform + param_Waveform;
  bit = inlet_bitsync + param_Bitsync;
  FW = param_FM + inlet_FM;

  PosAM = param_AM + inlet_AM;
  PosAM = (PosAM > (1 << 27)) ? (1 << 27) : PosAM;
  PosAM = (PosAM < (-1 << 27)) ? (-1 << 27) : PosAM;
  stAM = (PosAM >= 0) ? PosAM : -PosAM;
  InvAM = (1 << 27) - stAM;

  phaswidth = (inlet_PM + param_PM) << 3;
}
Audio Rate
if (inlet_active > 0) {
  phsw = ___SMMUL(inlet_phase << 3, phaswidth << 2);

  sync = inlet_syncsource;

  if (step > 0) {
    if (sync > 0 && async <= 0)
      stphase += param_Stepsize << 5;
  }

  if (soft > 0) {
    if (sync > 0 && async <= 0) {
      smooth1 = Phase - val1 + val2 + stphase;
    }
    val1 = ___SMMLA((smooth1 - val1) << 1, f1, val1);
  }

  if (position > 0) {
    if (sync > 0 && async <= 0) {
      if (Phase > (1 << 31)) {
        smooth2 = (1 << 32 - (Phase - val1 + val2));
      } else {
        smooth2 = -(Phase - val1 + val2 + stphase);
      }
    }
    val3 = ___SMMLA((smooth2 - val3) << 1, f3, val3);
  }

  if (val3 == (1 << 32)) {
    val3 = 0;
    smooth2 = 0;
  }

  if (direction > 0) {
    if (sync > 0 && async <= 0)
      dir = -dir;
  }

  if (hard > 0) {
    if (sync > 0 && async <= 0)
      Phase = 0;
  }

  if (bit > 0) {
    Phase = (Phase | sync);
  }

  if (swap > 0) {
    if (sync > 0 && async <= 0) {
      swp = -swp;
    }
  }

  feed = ___SMMUL(outlet_out << 4, param_Grit << 4);
  afeed = ___SMMLA((feed - afeed) << 1, f2, afeed);
  val2 = ___SMMLA((afeed - val2) << 1, f2, val2);
  FMW = ___SMMUL(inlet_freq << 3, freq << 5);
  Phase += ((freq) + ___SMMUL((FW) << 3, FMW << 2)) * dir;
  phrase = (((Phase - val1 + val3 + stphase) >> 5) * swp + phsw + val2) &
           ((1 << 27) - 1);
  async = sync;

  switch (waveform > 0 ? 1 : 0) {
  case 0:
    int32_t temp;
    SINE2TINTERP((phrase + phsw) << 5, temp)
    phasU = ___SMMUL(inlet_PWM << 3, temp >> 3);
    SINE2TINTERP((phasU + phrase) << 5, phasu);
    phasu = (phasu >> 5) + (1 << 26);
    break;

  case 1:
    wa = (phrase) & ((1 << 27) - 1);
    wb = (inlet_PWM >> 1) + (1 << 26);
    wc = (1 << 27) - (wb);
    if (wa < wb) {
      phasu = wa * ((1 << 30) / (wb)) >> 3;
    } else {
      phasu = (1 << 27) - ((wa - (wb)) * ((1 << 30) / wc) >> 3);
    }
    break;
  }

  AM = ___SMMUL(inlet_am << 3, phasu << 2);
  outlet_out = ___SMMUL((phasu - (1 << 26)) << 3, InvAM << 2) +
               ___SMMUL(PosAM << 3, AM << 2);

} else {
  outlet_out = 0;
}

Privacy

© 2024 Zrna Research