tap_tempo

Tap tempo, mul/div as inputs
Author: Are Leistad
License: BSD
Github: drj/seq/tap_tempo.axo

IO Variants: 3


Variant: 1

Inlets

bool32.rising Tap input

int32.positive Tempo multiplier

int32.positive Tempo divisor

Outlets

bool32.pulse Clock output

frac32.positive Phasor output

Parameters

bool32.mom tap

Declaration
uint32_t ktimer;
uint32_t last_ktime;
uint32_t phase;
float base_freq;
uint32_t mul;
uint32_t div;
uint32_t old_phase;
uint32_t old_inlet_tap;
uint32_t old_param_tap;
Init
ktimer = 0;
last_ktime = 0;
phase = 0;
base_freq = 64.0f * (double)(1 << 30) * 1.0f / (SAMPLERATE * 1.0f);
old_phase = 0;
old_inlet_tap = 0;
old_param_tap = 0;
Control Rate
if ((inlet_tap && !old_inlet_tap) || (param_tap && !old_param_tap)) {
  float period = (ktimer - last_ktime);
  if (period < 15000) // 5 seconds at most between taps
  {
    period = period * 16;
    if (period < 1.0f) {
      period = 1.0f;
    }
    float f_clock = SAMPLERATE / period;
    base_freq = 64.0f * (float)(1 << 30) * f_clock / (SAMPLERATE * 1.0f);
    phase = 0;
  }
  last_ktime = ktimer;
}

if (inlet_mul < 1) {
  mul = 1;
} else {
  mul = inlet_mul;
}
if (inlet_div < 1) {
  div = 1;
} else {
  div = inlet_div;
}
float freq = (base_freq * (float)mul) / (float)div;
phase += (uint32_t)freq;

outlet_clock = 0;
if (phase < old_phase) {
  outlet_clock = 1;
}

outlet_phasor = (phase >> 5);

old_phase = phase;
old_inlet_tap = inlet_tap;
old_param_tap = param_tap;

ktimer++;

Variant: 2

Inlets

bool32.rising Tap input

Outlets

bool32.pulse Clock output

frac32.positive Phasor output

Parameters

int32 clockmul

int32 clockdiv

bool32.mom tap

Declaration
uint32_t ktimer;
uint32_t last_ktime;
uint32_t phase;
float base_freq;
uint32_t old_phase;
uint32_t old_inlet_tap;
uint32_t old_param_tap;
Init
ktimer = 0;
last_ktime = 0;
phase = 0;
base_freq = 64.0f * (double)(1 << 30) * 1.0f / (SAMPLERATE * 1.0f);
old_phase = 0;
old_inlet_tap = 0;
old_param_tap = 0;
Control Rate
if ((inlet_tap && !old_inlet_tap) || (param_tap && !old_param_tap)) {
  float period = (ktimer - last_ktime);
  if (period < 15000) // 5 seconds at most between taps
  {
    period = period * 16;
    if (period < 1.0f) {
      period = 1.0f;
    }
    float f_clock = SAMPLERATE / period;
    base_freq = 64.0f * (float)(1 << 30) * f_clock / (SAMPLERATE * 1.0f);
    phase = 0;
  }
  last_ktime = ktimer;
}

float freq = (base_freq * (float)param_clockmul) / (float)param_clockdiv;
phase += (uint32_t)freq;

outlet_clock = 0;
if (phase < old_phase) {
  outlet_clock = 1;
}

outlet_phasor = (phase >> 5);

old_phase = phase;
old_inlet_tap = inlet_tap;
old_param_tap = param_tap;

ktimer++;

Variant: 3

Inlets

bool32.rising Tap input

Outlets

frac32.positive Phasor output

bool32.pulse Clock output

Parameters

bool32.mom tap

Attributes

spinner clockmul

spinner clockdiv

Declaration
uint32_t ktimer;
uint32_t last_ktime;
uint32_t phase;
int32_t clock_freq;
uint32_t old_phase;
uint32_t old_inlet_tap;
uint32_t old_param_tap;
Init
ktimer = 0;
last_ktime = 0;
phase = 0;
clock_freq = 64 * (uint32_t)((float)(1 << 30) * 1.0f / (SAMPLERATE * 1.0f));
old_phase = 0;
old_inlet_tap = 0;
old_param_tap = 0;
Control Rate
if ((inlet_tap && !old_inlet_tap) || (param_tap && !old_param_tap)) {
  float period = (ktimer - last_ktime);
  if (period < 15000) // 5 seconds at most between taps
  {
    period = period * 16;
    if (period < 1.0f) {
      period = 1.0f;
    }
    float f_clock = SAMPLERATE / period;
    float freq = 64.0f * (float)(1 << 30) * f_clock / (SAMPLERATE * 1.0f);
    freq = (freq * (float)attr_clockmul) / (float)attr_clockdiv;
    clock_freq = (uint32_t)freq;
    phase = 0;
  }
  last_ktime = ktimer;
}

phase += clock_freq;

outlet_clock = 0;
if (phase < old_phase) {
  outlet_clock = 1;
}

outlet_phasor = (phase >> 5);

old_phase = phase;
old_inlet_tap = inlet_tap;
old_param_tap = param_tap;

ktimer++;

Privacy

© 2024 Zrna Research