lpr

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/lpr/lpr.axo

Inlets

frac32buffer audio in

int32 select slot to record into

bool32.risingfalling record,set tempo

bool32.risingfalling sync

int32.positive playmode

frac32.positive position inlet for sync-mode

Outlets

frac32.positive remaining recording-time for the selected slot

bool32.pulse recstart

bool32 recording state,pre - fadeout

bool32 postrec

bool32 recording state,post - fadeout

int32.positive recslot

Parameters

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

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

Attributes

objref table to record to

combo number of slots in the table

Declaration
bool rec;
bool recstate;
bool mode;
bool postrec;

uint8_t shift;

uint32_t recstart;
uint32_t recpos;
uint32_t rec_max;

uint32_t start;
int32_t _ap;
int32_t phase;

int32_t env;

uint8_t recslot;

static const uint8_t LENGTH = (1 << attr_slots) << 2;
uint32_t slotlen = attr_table.LENGTH >> attr_slots;
uint32_t array[LENGTH];

void stopMainRec() {
  rec = 0;
  rec_max = recpos;
  array[(recslot << 2) + 1] = (recpos + recstart);
  recpos = 0;
  postrec = 0;
  return;
}
Init
shift = (27 - attr_table.LENGTHPOW);
Control Rate
outlet_recstart = 0;

if ((inlet_rec) && !rec) {
  outlet_recstart = 1;
  rec_max = slotlen;
  recslot = inlet_slot % (1 << attr_slots);
  start = inlet_phase;
  mode = inlet_sync;
  recstart = (__USAT((((inlet_slot << 21) >> attr_slots) << 6), 27) >> shift);
  recpos = 0;
  array[recslot << 2] = recstart;
  array[(recslot << 2) + 2] = (inlet_playmode) ? inlet_playmode : 1;
  array[(recslot << 2) + 3] = __SSAT(inlet_phase, 28);
  rec = 1;
  recstate = 1;
}
// fades
if (rec)
  env = (1 << 27) - (___SMMUL((1 << 27) - env, param_attack) << 1);
else
  env = ___SMMUL(env, param_release) << 1;
recstate = env;
// rec stopped-> wait for rollover if sync is on
if ((!inlet_rec) && rec) {
  if (mode) {
    postrec = 1;
    phase = (inlet_phase - start) & ((1 << 27) - 1);
    if ((phase - _ap) <= 0) {
      recpos -= 16;
      stopMainRec();
    }
    _ap = phase;
  } else {
    stopMainRec();
  }
}
outlet_recstate = rec;
outlet_fadestate = recstate;
outlet_recslot = recslot;
outlet_postrec = postrec;

if (rec)
  outlet_remain = ((slotlen - recpos) << shift) << attr_slots;
else
  outlet_remain = ((slotlen - rec_max) << shift) << attr_slots;
Audio Rate
// record
if (recstate) {
  if (recpos >= rec_max)
    recpos = 0;
  if (rec)
    attr_table.array[recpos + recstart] =
        __SSAT((___SMMUL((inlet_wave), env) << 5), 28) >> attr_table.GAIN;
  else
    attr_table.array[recpos + recstart] =
        (__SSAT(___SMMUL((inlet_wave), env) << 5, 28) >> attr_table.GAIN) +
        attr_table.array[recpos + recstart];
  recpos++;
}

Privacy

© 2024 Zrna Research