simsam3

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

Inlets

bool32 trig

frac32.bipolar pitch modulation

frac32.positive start position in table

Outlets

frac32buffer wave

Parameters

frac32.s.map Decay length

bool32.tgl Decay envelope on

bool32.tgl lpon

frac32.s.map.pitch Set pitch

frac32.u.map Position

frac32.u.map 1 pole lopass filter

frac32.u.map Volume Unity=32

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;
Init
// Table/Play //
pos = 0;
pstart = 0;
pstop = 1;

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

// lopass //
vallopass = 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_d;
  int32_t c;
  MTOFEXTENDED(in, c);
  c = 0x7FFFFFFF - (c >> 2);
  val = ___SMMUL(val, c) << 1;
}

// Lopass //

int32_t f2;
MTOF(param_freq, f2);
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 //
int32_t lopass;
if (param_lpon) {
  vallopass = ___SMMLA((envelopeon - vallopass) << 1, f2, vallopass);
  lopass = vallopass;
} else {
  lopass = envelopeon;
};

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

Privacy

© 2024 Zrna Research