Tuning Experiments

Exploring tunings in supercollider.

s.boot;

(
SynthDef(\sinePerc, {|freq, amp=0.3, dur=1|
    var sig;
    sig = SinOsc.ar(freq)*amp;
    sig = sig * EnvGen.kr(Env([1, 0], [dur], 1.2), doneAction: Done.freeSelf);
    Out.ar(0, sig!2);
}).add;
)

(
SynthDef(\sawPerc, {|freq, amp=0.3, dur=1|
    var sig;
    sig = Saw.ar(freq)*amp;
    sig = sig * EnvGen.kr(Env([1, 0], [dur], 1.2), doneAction: Done.freeSelf);
    Out.ar(0, sig!2);
}).add;
)

(
~exp_row = {|n_tones=12, n_tones_divisor=12, multiplier=1, start_freq=200, repeats=1, dur=0.15|
    // postf("% in % over %\n", n_tones, n_tones_divisor, multiplier);
    x = start_freq*((multiplier+1) ** ((0..n_tones) / n_tones_divisor ));
    x.postln;
    Pdef(\a, Pbind(\instrument, \sawPerc, \dur, dur, \freq, Pseq(x, repeats: repeats))).play;
}
)

(
{
    4.do({|i|
        11.do({|j|
            ~exp_row.value(
                n_tones: j+1,
                n_tones_divisor: j+1,
                multiplier: i+1,
                repeats: 4,
                dur: (1.0)/(j+1),
            );
            (4*(j+2)*(1.0)/(j+1)).wait; // we add +1 in func ;/
        });
    })
}.fork;
)


(
~pythagoras = {|start_freq=200, num_steps=12, step=(3/2), sorted=true, repeats=1, dur=0.15|
// pythagoras
    //var start_freq = 400;
    //var num_steps = 200;  // num of fifths we want to go
    var x = Array.fill(num_steps-1, {|i|  // base freq not included
        var j = (step) ** (i+1);
        while({j>2}){
            j=j*1/2 // stay within one octave
        };
        j;
    });
    x = start_freq * (x.insert(0, 1)); // add base freq
    if(sorted){x = x.sort};
    x.postln;
    Pdef(\a, Pbind(\instrument, \sinePerc, \dur, dur, \freq, Pseq(x, repeats: repeats))).play;
}
)


(
{
    7.do({|i|
        i = i+2; // start at 2
        (i-1).do({|j|
            var counter, denominator;
            counter = i+j+1;
            denominator = i;
            postf("% / %\n", counter, denominator);
            ~pythagoras.value(
                sorted: true,
                step: (counter/denominator),
                dur: 0.1,
                repeats: 4,
            );
            (4*12*0.1).wait;
        });
    })
}.fork;
)

// harry partch 43 scale
// https://en.wikipedia.org/wiki/Harry_Partch%27s_43-tone_scale

(
~harryPartch29 = [
    1/1, 12/11, 11/10, 10/9, 9/8, 8/7, 7/6, 6/5, 11/9, 5/4, 14/11, 9/7, 4/3, 11/8, 7/5,
    10/7, 16/11, 3/2, 14/9, 11/7, 8/5, 18/11, 5/3, 12/7, 7/4, 16/9, 9/5, 20/11, 11/6, 2/1,
];
~harryPartch14 = [
    81/80, 33/32, 21/20, 16/15,
    32/27,
    21/16, 27/20,
    40/27, 32/21,
    27/16,
    40/21, 64/33, 160/81,
];
~harryPartch43 = (~harryPartch29 ++ ~harryPartch14).sort;
)
~harryPartch43.plot

(
Pdef(\b, Pbind(\instrument, \sawPerc, \dur, 0.15, \freq, Pseq(~harryPartch43 * 200, repeats: 4))).play;
)

// bohlen pierce scala
~exp_row.value(13, 13, 2, repeats:4)


// schichtungen
(
{
    ~octaves = 4;
    ~denominatorRange = (2..6);
    ~steps = 6;
    ~soundTime = 0.5;
    ~startFreq = 200;
    (1..(~octaves+1)).do{|octave|
        ~denominatorRange.do({|denominator|
            postf("% Oktave(n) mit ((1..%) / %) Schichtung\n", octave, ~steps, denominator);
            ~steps.do({|step|
                x = ~startFreq*((octave+1) ** ((0..step) / denominator ));
                {
                    NumChannels.ar(
                        SinOsc.ar(x, mul:0.8/x.size) * EnvGen.kr(Env(times: [~soundTime/2, ~soundTime/2]), doneAction: Done.freeSelf))
                }.play;
                ~soundTime.wait;
            })
        })
    }
}.fork;
)