KarplusStrong

Karplus-strong synthesis delay -pitch tuned to the same pitch of a normal oscillator. (5=440hz) -tailtime sets the fade-out time of the feedback, with "strength" set to zero, this can take up to 40 seconds or maybe even longer! -damp sets the frequency of the internal lowpass filtering -strength sets the filtering strength (ratio between non-filtered and filtered signal, the higher the strength, the stronger the dampening) -influence sets the amount of influence the pitch has on the damping control. if set to zero, damping will stay the same, when fully open, dampening frequency will increase corresponding to the pitch. Normal string-behavior would be higher then zero, but not fully open.
Author: Remco van der Most
License: BSD
Github: sss/delay/KarplusStrong.axo

Inlets

frac32 pitch

frac32 damp

frac32 strength

frac32 influence

frac32buffer delay time (fraction of total delayline size)

Outlets

frac32buffer wave

Parameters

frac32.s.map.pitch pitch

frac32.s.map.pitch damp

frac32.u.map tailtime

frac32.u.map strength

frac32.s.map influence

Declaration
static const uint32_t LENGTHPOW = (13);
static const uint32_t LENGTH = (1 << 13);
static const uint32_t LENGTHMASK = ((1 << 13) - 1);
int32_t *array;
uint32_t writepos;
int32_t feed;
int32_t Time;
int32_t val1;
int32_t val2;
int32_t T1ime;
Init
static int32_t _array[attr_poly][1 << 13] __attribute__((section(".sdram")));
array = &_array[parent->polyIndex][0];
int i;
writepos = 0;
for (i = 0; i < LENGTH; i++)
  array[i] = 0;
Control Rate
int32_t pitch = inlet_pitch + 95860818 + param_pitch;
int32_t damp;
MTOF(param_damp +
         ___SMMUL(pitch << 3, (__USAT(param_influence + inlet_influence, 27))
                                  << 2) +
         inlet_damp,
     damp)
int32_t strength = __USAT(param_strength + inlet_strength, 27);
float32_t fratio = -pitch;
fratio = powf(2, (fratio / ((float32_t)(12 << 21))));
Time = (((int32_t)((1 << 25) * fratio)) >> 27 - LENGTHPOW);
int32_t tailtime = param_tailtime >> 5;
float32_t ratio = (float32_t)(Time) / (float32_t)(tailtime);
float32_t dB = (float32_t)(-10) * ratio;
dB = powf(2, dB);
int32_t TIME = (int32_t)((1 << 25) * fratio);
uint32_t tmp_w1 = (TIME << (LENGTHPOW + 3)) & 0x3FFFFFFF;
uint32_t tmp_w2 = (1 << 30) - tmp_w1;
Audio Rate
writepos = (writepos + 1) & LENGTHMASK;
uint32_t tmp_di1 = writepos - (Time)-1;
int32_t tmp_a1 = array[tmp_di1 & LENGTHMASK];
int32_t tmp_a2 = array[(tmp_di1 + 1) & LENGTHMASK];
int32_t tmp_r = ___SMMUL(tmp_a1, tmp_w1);
tmp_r = ___SMMLA(tmp_a2, tmp_w2, tmp_r);
int32_t lp = tmp_r * dB * 4;
val1 = ___SMMLA((((int32_t)(lp)) - val1) << 1, damp, val1);
feed = ___SMMUL(((1 << 27) - strength) << 3, lp << 2) +
       ___SMMUL(strength << 3, val1 << 2);
array[writepos] = -feed + inlet_in;
//+___SMMUL(-feed>>4,(feed>0?feed:-feed)>>4);
outlet_out = -feed + inlet_in >> 1;

Privacy

© 2024 Zrna Research