slicer

Sample slicer. This object is to be used in conjunction with table/read and such objects. It produces two ramp signals (phase can be fed inside a window object, pos can go into a conv/interp and then into table/read interp to enable playback), and is easily chainable. The object is programmed to play the sample at the correct speed, based on the sized of the sample (hence the size menu). You can specify the start position and the (relative) length of the slice. Speed allows to tune the sample playback speed (not chromatically, unfortunately), reverse enables reversed playback. In case you want to chain several object, you can select the sample to play by feeding an integer (0, 1, 2 ...) inside sel inlet.
Author: Sputnki
License: BSD
Github: sptnk/table/slicer.axo

Inlets

bool32.rising trig

frac32.positive defphase

frac32.positive defpos

int32 sel

Outlets

int32 sel

bool32.pulse trig

frac32.positive phase

frac32.positive pos

Parameters

frac32.s.map speed

bool32.tgl reverse

frac32.u.map.ratio start

frac32.u.map.ratio len

Attributes

combo size

Declaration
bool ttrig;
bool env;
int32_t freq;
uint32_t phase;
uint32_t phase_old;
int32_t pos;

int32_t sample_len;
Init
ttrig = 0;
env = 0;
freq = 0;
phase_old = 0;
phase = 0;
pos = 0;

sample_len = 1 << attr_size;
Control Rate
freq = (4294967296 /
        (___SMMUL(___SMMUL((1 << 27) - param_start << 3, param_len << 3),
                  sample_len << 4) +
         1)) *
       16;
freq += ___SMMUL(freq, param_speed) << 5;

if (inlet_trig && !ttrig && !inlet_sel) // se viene premuto il tasto
{
  ttrig = 1;
  env = 1;
  phase = 0;
} else if (inlet_trig && !ttrig && inlet_sel) // se viene premuto il tasto
{
  ttrig = 1;
  env = 0;
  phase = 0;
} else if (!inlet_trig) // se viene rilasciato il tasto
  ttrig = 0;

if (!env) // se non siamo in fase di inviluppo
{
  outlet_phase = inlet_defphase;
  outlet_pos = inlet_defpos;
} else {
  phase += freq;          // il contatore avanza di un tot
  if (phase >= phase_old) // se il contatore non ha resettato
  {
    phase_old = phase; // ok, continuiamo a contare
    if (!param_reverse)
      pos = param_start +
            ___SMMUL(phase >> 1,
                     ___SMMUL((1 << 27) - param_start << 3,
                              param_len << 3)); // calcoliamo la nuova posizione
    else
      pos = param_start +
            ___SMMUL((1 << 27) - param_start << 3, param_len << 2) -
            ___SMMUL(phase >> 1,
                     ___SMMUL((1 << 27) - param_start << 3, param_len << 3));
  } else // se invece il contatore ha resettato
  {
    ttrig = 0; // rendiamo di nuovo disponibile il campione
    env = 0;   // non siamo più in fase di inviluppo
    phase = 0;
    phase_old = 0;
  }

  outlet_pos = pos;
  outlet_phase = phase >> 5;
}

outlet_trig = inlet_trig;
outlet_sel = inlet_sel - 1;

Privacy

© 2024 Zrna Research