lrec

records audio to a table with nice fade-ins and -outs. the table can be divided into 1,2,4 or 8 slots. when 'sync' is enabled,recording will be synced to phase of the signal connected to 'pos', and after 'rec' is zero,recording will continue until the starting point is reached. after recording is done,the length if the recording in samples is sent out, as well as the length of the recording (in fraction of the table's size). meanwhile,the input signal is overdubbed and faded out ,so NO CLICKS! set the length of the fade-out/overdub period with 'release', the length of the fade-in of the recording with 'attack'.
Author: Robert Schirmer
License: BSD
Github: rbrt/looper/lrec.axo

Inlets

int32 select slot to record into

frac32buffer audio in

frac32.positive position inlet for sync-mode

bool32.risingfalling record,set tempo

bool32.risingfalling sync

Outlets

frac32 startpoint when recording in sync

int32 length of recording in samples

bool32 recording state,pre - fadeout

bool32 recording state,post - fadeout

frac32.positive offset inside the table

frac32.positive length of recording in fraction of the table

frac32.positive remaining recording-time for the selected slot

Parameters

frac32.s.map.kdecaytime.exp fade-in time

frac32.s.map.kdecaytime.exp fade-out time

bool32.tgl if 'hard' is on,there will be NO fade-in

bool32.tgl disable fades

Attributes

objref table to record to

combo number of slots in the table

Declaration
bool rec;
uint32_t recpos;
uint32_t offset;
uint32_t rec_offset;
uint32_t rec_max;
uint8_t shift;
uint32_t start;
uint32_t starthold;
bool mode;

bool recstate;
uint32_t shold;
uint32_t rhold;
int32_t env;

int32_t _ap;
int32_t phase;
Init
rec_max = attr_table.LENGTH >> attr_slots;
shift = (27 - attr_table.LENGTHPOW);
Control Rate
if ((inlet_rec) && !rec) {
  recpos = 0;
  rec = 1;
  recstate = 1;
  start = inlet_phase;
  shold = 1 << 27;
  rhold = 1 << 27;
  starthold = 0;
  mode = inlet_sync;
  offset = (((inlet_slot) << 21) >> attr_slots) << 6;
  rec_offset = (__USAT(offset, 27) >> (27 - attr_table.LENGTHPOW));
}

// fades
if (!param_nofade) {
  if (rec)
    env = (param_hard)
              ? (1 << 27)
              : (1 << 27) - (___SMMUL((1 << 27) - env, param_attack) << 1);
  else
    env = ___SMMUL(env, param_release) << 1;
  recstate = env;
} else {
  recstate = rec;
  env = rec << 27;
}

// rec stopped-> wait for rollover if sync is on
if ((!inlet_rec) && rec) {
  if (mode) {
    phase = (inlet_phase - start) & ((1 << 27) - 1);
    if ((phase - _ap) <= 0) {
      rec = 0;
      shold = recpos - 16;
      rhold = shold << shift;
      recpos = 0;
      starthold = start;
    }
    _ap = phase;
  } else {
    rec = 0;
    shold = recpos;
    rhold = shold << shift;
    recpos = 0;
    starthold = 0;
  }
}

outlet_rec = rec;
outlet_fade = recstate;
outlet_offset = offset;
outlet_range = rhold;
outlet_smps = shold;
outlet_startpoint = starthold;
if (rec)
  outlet_remain = ((rec_max - recpos) << shift) << attr_slots;
Audio Rate
// record

if (recstate) {
  if ((recpos >= rec_max) || (recpos >= shold))
    recpos = 0;

  if (rec)
    attr_table.array[recpos + rec_offset] =
        __SSAT((___SMMUL((inlet_wave), env) << 5), 28) >> attr_table.GAIN;
  else
    attr_table.array[recpos + rec_offset] =
        (__SSAT((___SMMUL((inlet_wave), env) << 5), 28) +
         (attr_table.array[recpos + rec_offset] << attr_table.GAIN)) >>
        attr_table.GAIN;

  recpos++;
}

Privacy

© 2024 Zrna Research