lrec fade alt

records audio to a table.after recording is done,the length of the recording in samples is sent out, as well as the length of the recording (in fraction of the table's size). 'lrec fade alt' is writing the fade-out to an alternative buffer.
Author: Robert Schirmer
License: BSD
Github: rbrt/old/lrec fade alt.axo

Inlets

frac32buffer audio in

bool32.risingfalling record

Outlets

frac32.positive length of recording in fraction of the table

int32 length in samples

bool32 state

Parameters

frac32.s.map.kdecaytime.exp attack

frac32.s.map.kdecaytime.exp release

bool32.tgl hard

Attributes

objref main

objref fade

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

uint32_t shold;
uint32_t rhold;
int32_t env;
Init
recpos = 0;
rec = 0;

// set 'shift factor' for storing the recording length/the sync output
if (attr_main.LENGTH == 2048) {
  shift = 16;
}
if (attr_main.LENGTH == 4096) {
  shift = 15;
}
if (attr_main.LENGTH == 8192) {
  shift = 14;
}
if (attr_main.LENGTH == 16384) {
  shift = 13;
}
if (attr_main.LENGTH == 32768) {
  shift = 12;
}
if (attr_main.LENGTH == 65536) {
  shift = 11;
}
if (attr_main.LENGTH == 131072) {
  shift = 10;
}
if (attr_main.LENGTH == 262144) {
  shift = 9;
}
if (attr_main.LENGTH == 524288) {
  shift = 8;
}
if (attr_main.LENGTH == 1048576) {
  shift = 7;
}
if (attr_main.LENGTH == 2097152) {
  shift = 6;
}
if (attr_main.LENGTH == 4194304) {
  shift = 5;
}
Control Rate
if (rec)
  env = (param_hard)
            ? -(1 << 27)
            : (1 << 27) - (___SMMUL((1 << 27) - env, param_attack) << 1);
else
  env = ___SMMUL(env, param_release) << 1;

if (env == 0)
  recstate = 0;

outlet_state = recstate;
outlet_range = rhold;
outlet_smps = shold;
Audio Rate
if ((inlet_rec) && !rec) {
  rec = 1;
  recstate = 1;
  recpos = 0;
}
if ((!inlet_rec) && rec) {
  rhold = (recpos << shift);
  shold = recpos;
  rec = 0;
  recpos = 0;
}

// record
if (recstate) {
  recpos++;
  if (recpos >= attr_main.LENGTH)
    recpos = 0;
  if (rec)
    attr_main.array[recpos] =
        __SSAT((___SMMUL((inlet_wave), env) << 5), 28) >> attr_main.GAIN;
  else
    attr_fade.array[recpos] = (__SSAT((___SMMUL((inlet_wave), env) << 5), 28) +
                               (attr_fade.array[recpos] << attr_fade.GAIN)) >>
                              attr_fade.GAIN;
}

Privacy

© 2024 Zrna Research