I didnt get it work with hilbert and pospass ( cause I dont understand
either ),
so I used allpass chains with coefficients by Oli Niemital ( I think).
I also made a version with heterodyne filtering, but the response gets too
long,
it seems you need a cutoff < 3 hz (?)
I got something that works, but its quite sluggish, and prefers lower notes.
BUT it works with polyphonic input, which is amazing to me
Mabye someone has ideas how to improve it, the best place to start may be
the integrations which are home baked.
It works like this
adaptive bandpass -> hilbertt transform > phase difference
this goes to a refernce oscillator, whos pitch is compared and updated
similar to phase locked loop but in pitch
and sorry, I dont know how to send unformatted plain text from gmail nor
how to respond so
that the list topics sty intact 8 but I try)
// frequency tracker test 9f
//
import("stdfaust.lib");
drywet = (hslider("[1]DryWet[style:knob]", 0.71, 0, 1, 0.01)) ;
filterS = (hslider("[2]filer samples[style:knob]", 20, 2, 48, 1)) ;
filterF = (hslider("[3]filter F[style:knob]", 3, 0.5, 20, 0.5)) ;
//readout = hbargraph("[5]f [style:numerical]", 0, 1);
freqtrack(x) =
(_,x:prefilt:track)~_:_,(x@(filterS*2)<:_,_:*:an.amp_follower_ar(1/8,
1/8):max(0):sqrt)
with {
fwmin = 27.5 / ma.SR; // min. frequency
fwmax = 3520 / ma.SR; // max. frequency
octave = 1;
prefilt(fw, x) = x:fi.svf.hp( fwmin * ma.SR,
0.707):fi.svf.lp( fwmax * ma.SR, 0.707):
bfilt4(fw/octave):hil;
bfilt4( fw, x) = x: fi.svf.lp(fw*ma.SR*0.7, 0.541):
fi.svf.lp(fw*ma.SR*0.7, 1.307):
fi.svf.hp(fw*ma.SR*1.19, 0.541):
fi.svf.hp(fw*ma.SR *1.19, 1.307);
bfilt6( fw, x) = x<:
fi.svf.hp(fw*ma.SR*1.19, 0.518): fi.svf.hp(fw*ma.SR *1.19,
0.707): fi.svf.hp(fw*ma.SR *1.19, 1.932):
fi.svf.lp(fw*ma.SR*0.7, 0.518): fi.svf.lp(fw*ma.SR*0.7,
0.707): fi.svf.lp(fw*ma.SR*0.7, 1.932);
hil(x) = x<:
fi.allpassn1m(4, ( 0.6923878, 0.9360654323,
0.9882295227, 0.9987488453)),
fi.allpassn1m(4, ( 0.4021921162, 0.8561710882,
0.9722909546, 0.9952884791));
track( x, y) = (x,y,_:wtrack)~_
with{
wtrack(x, y, fw) = (y,x:norm:qatan2:diph),
(fw:phacc:diph):
w2p,(w2p
<:_,_):_-_,_:(integ(filterS):integ(filterS)),_:+:p2w:
max(fwmin, min(fwmax, _)):
integ(filterS):
_;
norm( x, y) = x * x, y * y: +: sqrt:max(
1e-7):0.5/_<: _ *x,_*y;
integ(del, x) =
x<:_,_@del:_,_*tresp(del):-:lpw(avat)
with{
avat = filterF/ ma.SR;
tresp( smp) = ma.E^(- 2*ma.PI *
avat) <:_,_:1-_,_^del: * ;
};
reff = 440;
// fw to pitch ref. 440 hz
w2p( w) = w*(ma.SR/reff):max(1e-12):ma.log2:_+12;
// pitch to w ref 440 hz
p2w( po) =
po*(1/12):2^_:_*(reff/ma.SR):min(ma.SR/4);
// freq ratio a / b
ffab( fw1, fw2) = (fw1:max( 0.0004)) / (fw2:max(
0.0004)) ;
// delta pitch octave to freq. ratio
dpo2ff( dpo) = dpo:min(12):2^_;
};
// phase accumulation
phacc( dph) = dph: mphasor;
// approx. atan2 , normalized output -0.5...0.5
qatan2(y, x) = ba.if(x > 0, qatn(y, x), (ba.if(y > 0 ,
qatn(y, x) + 0.5, qatn(y, x) - 0.5))):
max(-0.5, min( 0.5, _))
with{
qatn(y, x) = y,(ba.if(x>0, x + 1e-14 ,
x-1e-14) ):
_/ _: _<:_,_,_:_,(_*_<:_,_):_*(1-_ *(
(1/3-0.2*_)));
};
atan2n(y, x) = y, x: ba.if( x != 0, atan2, 0):_/(2*ma.PI);
// wraps between -0.5..0.5
wrap(x) = x-( floor( x +0.5)) ;
// unwraps delta phase
uwr1(dw) = dw:ba.if( dw< -0.25, dw- (dw'+dw) , _): ba.if(
dw> 0.25, dw + (dw'-dw), _);
// phase difference
diph(ph) = ph <:_,_':-:uwr1;
// approx sine -0.5...0.5
qsin(x) = x+(0.5): wrap <:
(abs:-(0.25):qsincurve),_:ma.copysign
with { qsincurve(x) = 1 - ( (x*x)<:
*(1.2253517*16),(_<:*:* (-3.60562732*16)):>_ );};
// phasor / accumulator -0.5...0.5
mphasor(fw) = (+(fw) :(wrap))~_;
lpw( fw, x)= x : fi.pole(lpp)*(1-lpp)
with { lpp = ma.E^(- 2*ma.PI * fw); };
};
testsaw(fw, amp) = os.saw2( fw * ma.SR ) : fi.svf.lp(700, 0.707)*amp;
//readout
process = +: _<:_*(1-drywet)@(filterS*2), (freqtrack<:testsaw) * drywet :>_
<:_,_ ;
_______________________________________________
Faudiostream-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/faudiostream-users