BD1

sine wave oscillator
Author: Johannes Taelman
License: BSD
Github: sss/edrum/BD1.axo

Inlets

int32 rateM

int32 rateD

bool32.rising gate

frac32.bipolar pitch

frac32 env

frac32 amp

frac32 submix

Outlets

frac32buffer.bipolar sine wave

frac32 LFO

Parameters

frac32.s.map.pitch Pitch

frac32.s.map.pitch EnvPos

frac32.u.map Hit

frac32.u.map submix

frac32.u.map rate

frac32.u.map start

frac32.s.map.kdecaytime.exp d1

frac32.s.map.kdecaytime.exp d2

frac32.s.map.kdecaytime.exp dV

frac32.u.map.gain amp

int32.hradio waveform

int32.hradio destination

frac32.s.map width

Declaration
uint32_t Sub;
uint32_t Phase;
uint32_t Phrase;
int64_t ENV1;
int64_t ENV2;
int64_t ENV3;
int64_t envw;
int64_t envS;
int8_t stage1;
int8_t stage2;
int ntrig1;
int32_t val1;
int ntrig2;
int32_t val2;
int64_t ccomp;
int64_t decay;
int64_t wave;
int64_t pitwidth;
int64_t pithwidth;
int64_t rate;
int64_t srate;
int64_t dismix;
int32_t prev1;
int32_t step1;
int32_t ienv1;
int32_t prev2;
int32_t step2;
int32_t ienv2;
int32_t submix;

uint32_t Phose;
uint32_t R;
uint32_t H;
int32_t LFO;
int64_t MOd1;
int64_t MOd2;
int64_t MOd3;
int64_t MOd4;
int64_t MOd5;
int32_t dest;
int32_t Width;
int32_t sine;
int32_t slew;
int rateD;
Init
Phase = 0;
Sub = 0;
ntrig1 = 0;
val1 = 0;
ntrig2 = 0;
val2 = 0;
Phose = 0;
R = 1;
Control Rate
int32_t freq;
MTOFEXTENDED(param_Pitch + inlet_pitch + (MOd1 >> 2), freq);

int32_t t;
MTOF((1 << 27) - param_Hit, t);

int32_t frec;
MTOFEXTENDED(param_EnvPos, frec)

pitwidth = frec - freq;
outlet_LFO = LFO;

int64_t Rate = ___SMMUL(param_rate << 3, param_rate << 2);
Rate = ___SMMUL(Rate << 3, Rate << 2);
Rate = ___SMMUL(Rate << 3, param_rate << 2) << 2;
Audio Rate
ccomp = (1 << 31) - val1;
decay = param_d2 - param_d1;
decay = ___SMMUL(val1 >> 1, decay << 2);

// pitch envelope
if ((inlet_gate > 0) && !ntrig1) {
  ntrig1 = 1;
  stage1 = 1;
  Phase = 0;
  Sub = 0;
} else if (!(inlet_gate > 0)) {
  ntrig1 = 0;
}
if (stage1 == 0) {
  val1 = ___SMMUL(val1, param_d1 + decay + (1 << 17) + (1 << 15)) << 1;
} else {

  val1 = val1 + (t >> 2);
  if (val1 < 0) {
    val1 = 0x7FFFFFFF;
    stage1 = 0;
  }
}
ENV1 = val1 >> 4;

rateD = inlet_rateD > 0 ? inlet_rateD : 1;

// volume envelope
if ((inlet_gate > 0) && !ntrig2) {
  ntrig2 = 1;
  stage2 = 1;
} else if (!(inlet_gate > 0)) {
  ntrig2 = 0;
}
if (stage2 == 0) {
  val2 = ___SMMUL(val2, param_dV + (1 << 17) + (1 << 15)) << 1;
} else {

  val2 = val2 + (t >> 1);
  if (val2 < 0) {
    val2 = 0x7FFFFFFF;
    stage2 = 0;
  }
}
ENV2 = val2 >> 3;

{
  if (inlet_gate && !R) {
    Phose = param_start << 5;
    R = 1;
  } else {

    Phose += Rate * inlet_rateM / rateD;
  }
  if (!inlet_gate) {
    R = 0;
  }

  switch (param_waveform > 0 ? param_waveform : 0) {
  case 0:
    SINE2TINTERP(Phose, sine) LFO = (sine >> 5) + (1 << 26);
    break;
  case 1:
    LFO =
        (((Phose >> 4) - (1 << 27)) > (1 << 27) ? ((Phose >> 4) - (1 << 27))
                                                : -((Phose >> 4) - (1 << 27))) +
        (1 << 27);
    break;
  case 2:
    LFO = (Phose >> 5);
    break;
  case 3:
    LFO = (1 << 27) - (Phose >> 5);
    break;
  default:
    LFO = (((Phose >> 4) - (1 << 27)) > (1 << 27) ? (1 << 27) : 0);
    break;
  }
}
slew = slew + ___SMMUL((LFO - slew) << 3, Rate << 1);
dest = param_destination;
Width = param_width;
int32_t MODO = ___SMMUL(slew << 3, Width << 2);
switch (dest > 0 ? dest : 0) {
case 0:
  MOd1 = MODO;
  MOd2 = 0;
  MOd3 = 0;
  MOd4 = 0;
  MOd5 = 0;
  break;
case 1:
  MOd2 = MODO;
  MOd1 = 0;
  MOd3 = 0;
  MOd4 = 0;
  MOd5 = 0;
  break;
case 2:
  MOd3 = MODO;
  MOd1 = 0;
  MOd2 = 0;
  MOd4 = 0;
  MOd5 = 0;
  break;
case 3:
  MOd4 = MODO;
  MOd1 = 0;
  MOd2 = 0;
  MOd3 = 0;
  MOd5 = 0;
  break;
case 4:
  MOd5 = MODO;
  MOd1 = 0;
  MOd2 = 0;
  MOd3 = 0;
  MOd4 = 0;
  break;
default:
  MOd5 = MODO;
  MOd1 = 0;
  MOd2 = 0;
  MOd3 = 0;
  MOd4 = 0;
  break;
}

// extra volume envelope:
step1 = (inlet_env - prev1) >> 8;
ienv1 += step1;
prev1 = ienv1;

step2 = (((inlet_submix + param_submix + (MOd2 << 1)) >> 1) - prev2) >> 8;
submix += step2;
prev2 = submix;

envw = ___SMMUL((ENV1 + (ENV2 >> 6)) << 3, pitwidth << 2);
rate = freq + envw;
Phase += rate;
int32_t r;
int32_t s;

SINE2TINTERP(Phase << 1, r)
SINE2TINTERP(Phase + (1 < 30), s)

int32_t csub = (1 << 27) - param_submix;
int32_t oscmix = ___SMMUL(csub << 1, s) + ___SMMUL(submix << 1, r);
int32_t tscmix = oscmix;
dismix = __SSAT(___SMMUL(param_amp + (MOd3 << 3) + (inlet_amp << 3),
                         __SSAT(oscmix, 28) << 4)
                    << 1,
                28) >>
         2;
SINE2TINTERP((dismix + MOd5) << 5, s)
envS = ___SMMUL(((1 << 27) - ENV2) << 3, ienv1 << 2);
int64_t _1s = (s >> 5) + (tscmix);
int32_t MOdu = ___SMMUL(((1 << 27) - ENV2) << 3, MOd4 << 2);
wave = ___SMMUL(_1s, ENV2 << 3) + ___SMMUL(envS << 3, _1s) +
       ___SMMUL(MOdu << 3, _1s << 2);
outlet_wave = wave;

Privacy

© 2024 Zrna Research