0x k f

Detects the number of samples between zero crossings, and when a zero crossing occurs trig outputs a pulse. Frequency output in axoloti frequency format.
Author: Sputnki
License: BSD
Github: sptnk/detect/0x k f.axo

Inlets

frac32.bipolar in

Outlets

int32 number of samples at k-rate sample rate

bool32.pulse a pulse is fired when the zero crossing occurs

frac32.positive frequency

Declaration
float count = 0;
float output = 0;

bool sign_old = 0;
bool sign = 0;
int32_t in_prev = 0;
Control Rate
count += 1.0f;
sign = inlet_in > 0 ? 1 : 0;
float intercept = ((float)inlet_in) / ((float)(in_prev - inlet_in));

bool trig = 0;

if (sign != sign_old) {
  output = count + intercept;
  count = -intercept;
  trig = 1;
}

in_prev = inlet_in;
outlet_smp = output;
outlet_trig = trig;
sign_old = sign;
outlet_f = 2147483648.0f / output;

Privacy

© 2024 Zrna Research