view yeti/panplots.yeti @ 14:e587ae0e4d75 freq

Tidy up direct calculation; use linear interpolation
author Chris Cannam
date Wed, 10 Jun 2015 14:28:34 +0100
parents a3c1f0b0ab85
children
line wrap: on
line source
program panplots;

vector = load may.vector;
matrix = load may.matrix;
complex = load may.complex;
plot = load may.plot;
vamp = load may.vamp;

panof ix = (ix / 10) - 1;

gains ix =
   (p = panof ix;
    if p > 0 then
        { left = 1 - p, right = 1 }
    else
        { left = 1, right = p + 1 }
    fi);

sqr x = x * x;

cancelled l r ix =
    case gains ix of
    { left, right }:
        abs
        if left < right then 
            ratio = left / right; 
            l - ratio * r;
        else
            ratio = right / left; 
            r - ratio * l;
        fi;
    esac;

cancelledCplx l r ix =
    case gains ix of
    { left, right }:
        complex.magnitude
        if left < right then 
            ratio = left / right; 
            complex.subtract l (complex.scale ratio r);
        else
            ratio = right / left; 
            complex.subtract r (complex.scale ratio l);
        fi;
    esac;

cancelledVect l r ix =
    case gains ix of
    { left, right }:
        vector.rms
        if left < right then 
            ratio = left / right; 
            vector.subtract l (vector.scaled ratio r);
        else
            ratio = right / left; 
            vector.subtract r (vector.scaled ratio l);
        fi;
    esac;

range = [0..20];

plotForRange f cap =
    \() (plot.plot [ Caption cap, Vector (vector.fromList (map f range)) ]);

plotForRange (cancelled 1 1) "Left 1, right 1: perceived as centred";
plotForRange (cancelled 1 0) "Left 1, right 0: perceived as full left";
plotForRange (cancelled 0 1) "Left 0, right 1: perceived as full right";
plotForRange (cancelled 0.5 1) "Left 0.5, right 1";
plotForRange (cancelled 0.5 0.2) "Left 0.5, right 0.2";
/*
c mag phase = complex.fromPolar mag phase;

plotForRange (cancelledCplx (c 1 0) (c 1 0)) "Left 1, right 1, in phase";
plotForRange (cancelledCplx (c 0.5 0) (c 1 0)) "Left 0.5, right 1, in phase";
plotForRange (cancelledCplx (c 1 0) (c 1 pi)) "Left 1, right 1, opposite phase";
plotForRange (cancelledCplx (c 1 0) (c 1 0.1)) "Left 1, right 1, phases 0.1 out";
plotForRange (cancelledCplx (c 1 0) (c 1 0.2)) "Left 1, right 1, phases 0.2 out";
plotForRange (cancelledCplx (c 1 0) (c 1 0.8)) "Left 1, right 1, phases 0.8 out";
plotForRange (cancelledCplx (c 0.5 0) (c 0.2 0.2)) "Left 0.5, right 0.2, phases 0.2 out";
*/
sinv offset = vector.fromList 
   (map do i: sin ((i + offset) * 2 * pi / 100) done [0..100]);

//\() (plot.plot [ Vector (sinv 0), Vector (sinv 40) ]);

plotForRange (cancelledVect (sinv 0) (sinv 10)) "Sine vectors slightly out of phase";