lmangle

drives a phasor (saw-wave) for reading/writing data. phase always stays inside the range defined by 'offset' and 'range'
Author: robert schirmer
License: BSD
Github: rbrt/old/lmangle.axo

Inlets

frac32.positive offset inside the table

frac32.positive length of the area to index,or loop end

frac32.positive start position on 'reset' inside 'range'

frac32.bipolar speed modulation

frac32buffer.positive looplength

frac32buffer.positive loopstart inside 'range'

bool32.risingfalling play or dont

bool32.rising reset to 'startpoint'

Outlets

int32 loop count since reset

int32 lenght of the loop in samples

frac32buffer.positive phase

Parameters

bool32.tgl loop changes direction when it reaches the boundaries

frac32.s.map speed,+ 64 normal speed forward, - 64 backward

Attributes

objref table

Declaration
float32_t index;
bool play;
int direction;
int dir1;
int dir2;
uint32_t pos;
int shift;
int range;
int startpoint;
int loopstart;
int looplength;
int count;
int edge;
int r;
bool add;
int max_pos;
Init
play = 0;

// set 'shift factor' for storing the recording length/the sync output
if (attr_table.LENGTH == 2048) {
  shift = 16;
}
if (attr_table.LENGTH == 4096) {
  shift = 15;
}
if (attr_table.LENGTH == 8192) {
  shift = 14;
}
if (attr_table.LENGTH == 16384) {
  shift = 13;
}
if (attr_table.LENGTH == 32768) {
  shift = 12;
}
if (attr_table.LENGTH == 65536) {
  shift = 11;
}
if (attr_table.LENGTH == 131072) {
  shift = 10;
}
if (attr_table.LENGTH == 262144) {
  shift = 9;
}
if (attr_table.LENGTH == 524288) {
  shift = 8;
}
if (attr_table.LENGTH == 1048576) {
  shift = 7;
}
if (attr_table.LENGTH == 2097152) {
  shift = 6;
}
if (attr_table.LENGTH == 4194304) {
  shift = 5;
}
Audio Rate
int t_speed = (inlet_speed + param_speed);
range = (inlet_range >> shift);
looplength = ((___SMMUL(inlet_range, inlet_looplength) << 5) >> shift);
loopstart = ((___SMMUL(inlet_range, inlet_loopstart) << 5) >> shift);
max_pos = (range < (loopstart + looplength)) ? range : (loopstart + looplength);
dir1 = (t_speed < 0) ? 1 : -1;
dir2 = (t_speed > 0) ? 1 : -1;

if (inlet_reset && r) {
  index = 0;
  r = 0;
} else if (!inlet_reset)
  r = 1;

if (inlet_play && (!play)) {
  play = 1;
  edge = 0;
  count = 0;
  direction = 1;
  add = range;
  startpoint = ((___SMMUL(inlet_range, inlet_startpoint) << 5) >> shift);
  if (param_palindromic && (t_speed < 0)) {
    index = (max_pos);
    startpoint = 1;
  } else
    index = 0;

} else {
  if (!inlet_play) {
    play = 0;
    outlet_pos = 0;
  }

  index += ((t_speed * direction) * (float)(1.0f / (1 << 27)));
  pos = (index + startpoint);

  // limit indexing to a range
  if (play) {
    if (pos >= max_pos) {
      if (param_palindromic) {
        direction = dir1;
        if (!edge)
          index = (max_pos - loopstart);
      } else
        index = 0;
      count += add;
      edge = 1;
    }
    if (pos <= startpoint) {
      if (param_palindromic) {
        direction = dir2;
      } else
        index = (max_pos - startpoint);
      count += add;
      edge = 1;
    }
    if (edge) {
      startpoint = loopstart;
    }
    outlet_pos = ((pos << shift) + inlet_offset);
  }
}
outlet_count = count;
outlet_smps = (max_pos - loopstart);

Privacy

© 2024 Zrna Research