audio2pitchfreq

audio-rate pitch detector module with "average" function for krate signals. "damp" dampens the input signal to remove higher harmonics from interfering with the detection. "avg" sets the "averager" length->records all zero-crossings into an array and takes the average to send to both pitch and frqAvg outputs.
Author: Remco van der Most
License: BSD
Github: sss/conv/audio2pitchfreq.axo

Inlets

frac32buffer input

Outlets

frac32 pitch

frac32 frqAvg

frac32buffer freq

Parameters

frac32.s.map.pitch damp

int32 avg

Declaration
int32_t val;
int32_t prev;
bool ZT;
uint64_t timer;
bool GT;
uint64_t cnt;
uint32_t ct;
int32_t ar[1024];
uint64_t hl = (1 << 31);
int32_t out;
int32_t LOG(int32_t in) {
  Float_t f;
  f.f = in;
  int32_t r1 = ((f.parts.exponent & 0x7F) - 18) << 24;
  int32_t r3 = logt[f.parts.mantissa >> 15] << 10;
  out = r1 + r3;
}
Init
val = 0;
cnt = 1;
prev = 0;
Control Rate
int i;
int32_t f;
MTOF(param_damp, f);
int64_t avg = 0;
int32_t mid;
MTOFEXTENDED(0, mid);
LOG(mid);
mid = out;

for (i = 0; i < (param_avg << 4); i++) {
  avg += ar[i];
}
avg = (avg / (param_avg << 4));

int32_t to;
LOG(avg);
to = out;
outlet_pitch = (to - mid >> 1) * 3;

outlet_frqAvg = avg >> 4;
Audio Rate
int32_t diff = inlet_in - prev >> 4;

for (i = 0; i < 16; i++) {

  prev += diff;
  val += ___SMMUL((prev - val), f) >> 2;
  cnt += 1;
  if ((prev > 0) && !GT) {

    timer = hl / (cnt);
    ct += 1;
    ct = ct >= (param_avg << 4) ? 0 : ct;
    ar[ct] = timer >> 28;
    cnt = 0;
    GT = 1;
  } else if (prev < 0) {
    GT = 0;
  }
}

outlet_freq = timer >> 28;

prev = inlet_in;

Privacy

© 2024 Zrna Research