loop_multi_stereo

records audio to a table. 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 tempo if the recording in hz is sent out, as well as the length of the recording (in fraction of the table's size).
Author: Robert Schirmer
License: who cares
Github: rbrt/old/loop_multi_stereo.axo

Inlets

frac32buffer audio in L

frac32buffer audio in R

frac32buffer sync position in

bool32.risingfalling record,set tempo

int32 select slot to record to

bool32 sync on/off

Outlets

frac32 offset of the selected slot in the table

frac32 tempo in hz

frac32 recording offset when recording in sync

frac32.positive length of recording in fraction of the slot

bool32 record state

Attributes

objref table to record to

objref table to record to

combo number of slots in the table

Declaration
bool rec;
int recpos;
int offset;
int rec_offset;
int rec_max;
int shift;
int spos;
int csample;
int start;
int mode;
Init
recpos = 0;
rec = 0;
start = 0;
rec_max = attr_tableL.LENGTH >> attr_slots;

// set 'shift factor' for storing the recording length/the sync output
if (attr_tableL.LENGTH == 2048) {
  shift = 16;
}
if (attr_tableL.LENGTH == 4096) {
  shift = 15;
}
if (attr_tableL.LENGTH == 8192) {
  shift = 14;
}
if (attr_tableL.LENGTH == 16384) {
  shift = 13;
}
if (attr_tableL.LENGTH == 32768) {
  shift = 12;
}
if (attr_tableL.LENGTH == 65536) {
  shift = 11;
}
if (attr_tableL.LENGTH == 131072) {
  shift = 10;
}
if (attr_tableL.LENGTH == 262144) {
  shift = 9;
}
if (attr_tableL.LENGTH == 524288) {
  shift = 8;
}
if (attr_tableL.LENGTH == 1048576) {
  shift = 7;
}
if (attr_tableL.LENGTH == 2097152) {
  shift = 6;
}
if (attr_tableL.LENGTH == 4194304) {
  shift = 5;
}
Audio Rate
csample = (inlet_pos >> 7);

if ((inlet_rec) && !rec) {
  rec = 1;
  recpos = 0;
  spos = csample;
  start = inlet_pos;
  outlet_range = 0;
  outlet_freq = 0;
  outlet_start = 0;
  mode = inlet_sync;
  offset = (((inlet_slot) << 21) >> attr_slots) << 6;
  rec_offset = (__USAT(offset, 27) >> (27 - attr_tableL.LENGTHPOW));

}

// rec stopped-wait for rollover
else if (!(inlet_rec)) {
  if (mode) {
    if ((csample > (spos - 12)) && (csample < (spos + 12))) {
      rec = 0;
    }
  } else
    rec = 0;

  // record
  if (rec) {
    recpos++;
    attr_tableL.array[(recpos + rec_offset)] =
        __SSAT(inlet_waveL, 28) >> attr_tableL.GAIN;
    attr_tableR.array[(recpos + rec_offset)] =
        __SSAT(inlet_waveR, 28) >> attr_tableR.GAIN;
    if (recpos >= rec_max) {
      recpos = 0;
    }
  }

  // rec done

  if (!rec) {
    outlet_range = (recpos << shift);

    if (recpos) {
      outlet_freq = (int)(281474976710656.f / (recpos * (128 << 3)));
    } else
      outlet_freq = 0;

    if (mode)
      outlet_start = start;
  }

  outlet_rec = rec;
  outlet_offset = offset;

Privacy

© 2024 Zrna Research