grame-cncm / faustlibraries

The Faust libraries
https://faustlibraries.grame.fr
183 stars 59 forks source link

Stereo widener #170

Closed DBraun closed 7 months ago

DBraun commented 7 months ago

This allows us to exaggerate the stereoness of an input. Beware it can result in silence if the original input has no stereoness to begin with.

import("stdfaust.lib");

stereo_widener(w) = invSqrt2 : shuffle : *(midGain),*(stereoGain) : shuffle : invSqrt2
with {
    invSqrt2 = _/sqrt(2), _/sqrt(2);
    shuffle = _,_ <: +,-;
    midGain = 2*(1-w);
    stereoGain = 2*w;
};

width = hslider("width", 0.5, 0., 1., .001);
// drag a stereo input into the IDE and try these out:

// normal usage:
// process = _,_ : ef.stereo_width(width);
process = _,_ : stereo_widener(width);

// pretend left input is silence:
// `w=0` is NOT silence, and `w=1` is NOT silence.
// process = _,_ : 0*_,_ : stereo_widener(width);

// pretend input is mono:
// `w=1` is silence.
// process = _,_ :> _*.5 <: stereo_widener(width);

// process(L,R) = (L+R) <: _, _; // same when `w=0`
// process = _, _; // same when `w=0.5`
// process(L,R) = (L-R), (R-L); // same when `w=1`
DBraun commented 7 months ago

On second thought, the DSP is the same as stereo_width. We can just call stereo_width(2) to get the same stereo widening effect. This example below actually demonstrates their equivalence because the output is silence:

import("stdfaust.lib");

stereo_widener(w) = invSqrt2 : shuffle : *(midGain),*(stereoGain) : shuffle : invSqrt2
with {
    invSqrt2 = _/sqrt(2), _/sqrt(2);
    shuffle = _,_ <: +,-;
    midGain = 2*(1-w);
    stereoGain = 2*w;
};

width = hslider("width", 0.5, 0., 1., .001);
compare(x1, y1, x2, y2) = x1-x2,y1-y2;
process = _,_ <: ef.stereo_width(width*2.), stereo_widener(width) : compare;

So that sqrt(2) stuff is pointless 😆