lrec_new2

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/testing/lrec_new2.axo

Inlets

frac32.positive transport phase

frac32.positive recording fade-in time

frac32.positive recording fade-out time

bool32.risingfalling record,set tempo

int32 select slot to record to

bool32 sync on/off

frac32buffer audio in

Outlets

int32 length of recording in samples

bool32 record state

bool32 record state with fade-out

frac32.positive start of recording in fraction of the table

frac32.positive length of recording in fraction of the table

frac32.positive startpoint

frac32.positive remaining recording time in fraction of the slot's length

Parameters

frac32.s.map.kdecaytime.exp attack

frac32.s.map.kdecaytime.exp sets the fadeout-time of the overdub

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

bool32.tgl nofade

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 attack;
uint32_t release;
bool mode;

bool recstate;
uint32_t shold;
int32_t env;

int rtrig;

int syncshift;
Init
recpos = 0;
rec = 0;
start = 0;
rec_max = attr_table.LENGTH >> attr_slots;

syncshift = 1 << 14;

// set 'shift factor' for storing the recording length/the sync output
shift = (27 - attr_table.LENGTHPOW);
Control Rate
attack = inlet_attack + param_attack;
release = inlet_release + param_release;

if ((inlet_rec) && !rec) {
  rec = 1;
  recstate = 1;
  recpos = 0;
  start = inlet_phase;
  outlet_startpoint = 0;
  outlet_range = 0;
  outlet_smps = 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, attack) << 1);
  else
    env = ___SMMUL(env, release) << 1;
  if (env == 0)
    recstate = 0;
} else {
  recstate = rec;
  env = 1 << 27;
}

// rec stopped-> wait for rollover
if ((!inlet_rec) && rec) {
  if (mode) {
    if ((inlet_phase > (start - syncshift)) &&
        (inlet_phase < (start + syncshift))) {
      rec = 0;
      rtrig = 1;
    }
  } else {
    rec = 0;
    rtrig = 1;
  }
}
// rec done
if (rtrig) {
  shold = recpos;
  rtrig = 0;
}
if (!rec) {
  if (mode)
    outlet_startpoint = start;
  else
    outlet_startpoint = 0;
  outlet_range = shold << shift;
  outlet_smps = shold;
}
outlet_rec = rec;
outlet_state = recstate;
outlet_offset = offset;

if (rec)
  outlet_remain = ((rec_max - recpos) << shift) << attr_slots;
Audio Rate
// record

if (recstate) {
  recpos++;
  if (recpos >= rec_max)
    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;
}

Privacy

© 2024 Zrna Research