sb rec

'arm' will arm the recorder, 'rec' will start recording to the selected slot or, when already recording,start another recording in a selected slot. when 'arm' is 0 again,recording will stop,and the recorded slots can be played back. you cannot record into a slot that already contains sample data. if already recording,recording will continue in the slot you were recording to before. sample start-and endpoints can be accessed 'from the outside' as a table named as the recorder-object.
Author: Robert Schirmer
License: BSD
Github: rbrt/looper/sb rec.axo

Inlets

bool32.risingfalling arm the recorder or stop recording

bool32.rising a pulse will start a recording a sample in the selected slot if 'arm' is 1 and the selected slot doesn't already contain a sample

bool32.rising delete the current slot

bool32.rising defragment the sample-table

bool32.rising clear

bool32.rising re-initialize 'sb rec' after loading a 'set'

frac32buffer audio in

int32.positive select a slot to record into (0 - 127)

Outlets

bool32 '1' if a slot already contains a sample

bool32 recording status

bool32.pulse issues a pulse when a new slot is recorded

frac32.positive remaining recording-time

Attributes

objref table to record to

Declaration
bool rec;
uint32_t recpos;
uint32_t rec_max;
uint8_t shift;

static const uint32_t LENGTHPOW = 8;
static const uint32_t LENGTH = 1 << 8;
static const uint32_t LENGTHMASK = (1 << 8) - 1;
static const uint32_t BITS = 32;
static const uint32_t GAIN = 0;
uint32_t array[LENGTH];

int8_t preslot;
uint8_t chunks;
uint8_t chunk[128];
uint32_t lchunk[128];

uint32_t del[256];
uint8_t delcount;

bool rtrig;
bool ntrig;
bool full;
bool ctrig;
uint32_t sstart;
uint32_t send;
uint32_t slength;
uint32_t end;
bool dtrig;
bool gtrig;
Init
rec_max = attr_table.LENGTH;
shift = (27 - attr_table.LENGTHPOW);
preslot = -1;
Control Rate
full = array[(inlet_slot << 1) + 1];

if (inlet_arm && !full) {
  if ((inlet_rec && !ntrig) && (inlet_slot < 127)) {
    ntrig = 1;
    array[inlet_slot << 1] = recpos;
    if (preslot > -1) {
      lchunk[preslot] = recpos;
      array[(preslot << 1) + 1] = 1;
    }
    chunk[chunks] = inlet_slot;
    preslot = inlet_slot;
    chunks += 1;
    rec = 1;
  }
}
if (!inlet_rec)
  ntrig = 0;

if (!inlet_arm) {
  if (rec) {
    rec = 0;
    lchunk[preslot] = recpos;
    array[255] = recpos;
  }
  preslot = -1;
  int i;
  for (i = 0; i < chunks; i++)
    array[(chunk[i] << 1) + 1] = lchunk[chunk[i]];
  chunks = 0;
}

// clear
if (inlet_clear && !rtrig) {
  rtrig = 1;
  recpos = 0;
  preslot = -1;
  delcount = 0;
  int i;
  for (i = 0; i < 256; i++)
    array[i] = 0;
}
if (!inlet_clear)
  rtrig = 0;

// delete
if (inlet_delete && !dtrig) {
  if (array[(inlet_slot << 1) + 1]) {
    dtrig = 1;
    del[delcount] = array[inlet_slot << 1];
    del[delcount + 1] = array[(inlet_slot << 1) + 1];
    array[inlet_slot << 1] = 0;
    array[(inlet_slot << 1) + 1] = 0;
    delcount += 2;
  }
}
if (!inlet_delete && !ctrig)
  dtrig = 0;

// compact
if (inlet_defrag && !ctrig) {
  ctrig = 1;
  int ii;
  for (ii = 0; ii < delcount; ii += 2) {
    sstart = del[ii];
    send = del[ii + 1];
    slength = (del[ii + 1] - del[ii]);

    int shift_index;
    for (shift_index = 0; shift_index < 256; shift_index += 2)
      if (array[shift_index] >= send) {
        array[shift_index] -= slength;
        array[shift_index + 1] -= slength;
      }

    int move_samples;
    for (move_samples = send; move_samples < recpos; move_samples += 1)
      attr_table.array[move_samples - slength] = attr_table.array[move_samples];

    int shift_chunks;
    for (shift_chunks = 0; shift_chunks < delcount; shift_chunks += 2)
      if (del[shift_chunks] >= send) {
        del[shift_chunks] -= slength;
        del[shift_chunks + 1] -= slength;
      }

    recpos -= slength;
  }
  delcount = 0;
  array[255] = recpos;
}
if (!inlet_defrag && !delcount)
  ctrig = 0;

// re-init
if (inlet_reinit && !gtrig) {
  preslot = -1;
  delcount = 0;
  recpos = array[255];
  gtrig = 1;
}
if (!inlet_reinit)
  gtrig = 0;

outlet_rec = ntrig;
outlet_active = full;
outlet_remain = (rec_max - recpos) << shift;
outlet_state = rec;
Audio Rate
// record

if (rec) {
  attr_table.array[recpos] = __SSAT(inlet_wave, 28) >> attr_table.GAIN;
  recpos++;
}

Privacy

© 2024 Zrna Research