/*
Meier Crossfeed - for Headphone listening to 'hard panned' stereo records
-------------------------------------------------------------------------------------

Implementation of the 'simple' passive crossfeed circuit by Jan Meier.
See also: http://www.meier-audio.homepage.t-online.de/passivefilter.htm

Applies crossfeed to the stereo signal.

Crossfeed is a process where listening over two speakers is simulated.
This is good for old hard panned stereo records,
which might be quite fatiguing to listen to
on headphones with no crossfeed.

Note:
Doing crossfeedback on headphones just makes the sound more mono.
But not if you simulate the delay between ears...
...which has not been implemented in this plugin yet...
(also some filtering has to be applied ???) 
*/

slider1:10<1,100,1>Strength (%)

in_pin:L in
in_pin:R in
out_pin:L out
out_pin:R out

@init
vcl = vcr = vdiff = 0;

@slider
strength = slider1*100;

coef1 = (2128 / srate); // Left/right filter coef
coef2 = strength / srate; // Crossfeed filter coef

@sample
vcl = spl0;
vcr = spl1;

lout = (buf[0] + vcl);
rout = (buf[1] + vcr);
buf[0] = lout;
buf[1] = rout;
// update filter state
common = vdiff * coef2;
vcl -= (vcl * coef1) + common; // Left filter output
vcr -= (vcr * coef1) - common; // Right filter output
vdiff = lout - rout; // L-R difference signal
buf += 2;

spl0 = vcl;
spl1 = vcr;
