simsam4

Simple sampler with pitch, position, decay envelope and volume. Plus lp1 m lopass filter.
Author: Jaffasplaffa
License: BSD
Github: jaffa/sam/simsam4.axo

Inlets

bool32 trig

frac32.bipolar pitch modulation

frac32.positive start position in table

Outlets

frac32buffer wave

Parameters

bool32.tgl Decay envelope on

bool32.tgl Turns lp on (1pole)

bool32.tgl Turns hp on (1pole)

bool32.tgl Inverts audio signal

frac32.s.map.pitch Set pitch

frac32.u.map Position

frac32.u.map 1 pole lopass filter

frac32.u.map 1 pole hipass filter

frac32.u.map Volume Unity=32

frac32.s.map Decay length

Attributes

objref t

Declaration
// Table/Play //
int pstart;
int pstop;
uint64_t pos;

// Decay envelope //
int32_t prev;
int32_t step;

int32_t val;
int ntrig;

// lopass //
int32_t vallopass;
int32_t lopass;

// hipass //
int32_t valhipass;
int32_t hipass;
Init
// Table/Play //
pos = 0;
pstart = 0;
pstop = 1;

// Decay envelope //
val = 0;
ntrig = 0;

// lopass //
vallopass = 0;

// hipass //
valhipass = 0;
Control Rate
// Table/Play //
if ((inlet_trig > 0) && !pstart) {
  pstart = 1;
  pstop = 0;
  uint32_t asat = __USAT(inlet_pos + param_position, 27);
  pos = ((uint64_t)(asat >> (27 - attr_t.LENGTHPOW))) << 32;
} else if (!(inlet_trig > 0)) {
  pstart = 0;
}
if ((0) && !pstop) {
  pstop = 1;
  pstart = 0;
}
uint32_t f0;
MTOFEXTENDED(inlet_pitch + 0xFEC747D4 + param_pitch, f0);

// Vca //
step = (val - prev) >> 4;
int32_t i = prev;
prev = val;

// Env //
if ((inlet_trig > 0) && !ntrig) {
  val = 1 << 27;
  ntrig = 1;
} else {
  if (!(inlet_trig > 0))
    ntrig = 0;
  int32_t in = -param_decay;
  int32_t c;
  MTOFEXTENDED(in, c);
  c = 0x7FFFFFFF - (c >> 2);
  val = ___SMMUL(val, c) << 1;
}

// Lopass //

int32_t f2;
MTOF(param_lp, f2);

int32_t f3;
MTOF(param_hp, f3);
Audio Rate
int32_t table;
if (!pstop) {
  if ((pos >> 32) < attr_t.LENGTH) {
    uint32_t r = ___SMMUL(attr_t.array[pos >> 32] << attr_t.GAIN,
                          INT32_MAX - (((uint32_t)pos) >> 1));
    r = ___SMMLA(attr_t.array[(pos >> 32) + 1] << attr_t.GAIN,
                 (((uint32_t)pos) >> 1), r);
    table = r;
    pos += ((uint64_t)f0) << 8;
  } else
    table = 0;
} else
  table = 0;

// Env on //

int32_t envelopeon;
if (param_envon) {

  envelopeon = ___SMMUL(table, i) << 5;
  i += step;
} else {
  envelopeon = table;
};

// lopass filter //

if (param_lpon) {
  vallopass = ___SMMLA((envelopeon - vallopass) << 1, f2, vallopass);
  lopass = vallopass;
} else {
  lopass = envelopeon;
};

if (param_hpon) {
  valhipass = ___SMMLA((lopass - valhipass) << 1, f3, valhipass);
  hipass = lopass - valhipass;
} else {
  hipass = lopass;
}

// Invert //
int32_t invert;
if (param_inv) {
  invert = -hipass;
} else {
  invert = hipass;
}

outlet_out = ___SMMUL(invert << 3, param_vol << 3);

Privacy

© 2024 Zrna Research