averager synth

Hi nobody,

During our short trip to Heybeliada, I was trying to realize some silly process in SuperCollider.

I wrote it last week in S7 Scheme;


;calculate the average of two numbers;
(define (ortasi x y)
  (int (/ (+ x y) 2)))




;;removes an element from the list;;
(define (remove list element)
  (loop for i in list
        with lis = '()
        do 
        (when (not (equal? i element)) 
              (push i lis))
        finally (return (reverse lis))))


;output numbers...;
(define (orta ele low high) ;ele is the number of elements between the 'low' & 'high' values;
  (do ((i 0 (+ i 1))
       (an (make-list ele))
       (ranger (int (/ (- high low) ele)))
       (off low (+ off ranger)))
      ((= i ele) an)
    (list-set! an i (+ off (random ranger)))))



(define (orta-kes inl dur)
  (do ((ti 0 (+ ti 1)))
      ((= (list-ref inl (int (/ (length inl) 2)))
          (list-ref inl (- (int (/ (length inl) 2)) 1))
          (list-ref inl (+ (int (/ (length inl) 2)) 1))) inl)
    (do ((i 0 (+ i 1)))
        ((= i (length inl)) inl)
      (begin 
        (list-set! inl i (ortasi (list-ref inl i) (pick (remove inl (list-ref inl i)))))
        (send "mp:midi" :time ti :key (list-ref inl i) :dur dur)))))


(orta-kes (orta 12 20 120) 0.94)


First we create a series of number which are between the given ranges.
Every number represents a midi pitch number or frequency in Hz
Thereafter we run  the code and at each step every number updates its value by calculating the average with another pitch number in the network (randomly choosen node).
At some point, every values meets and the process stops.

Here is the SC code:

//this the synth, includes 20 sine wave oscilator

(
SynthDef("nam"
{arg lis = #[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var env;
env = EnvGen.ar(Env([0,1,1,0], [0.05, 0.05, 0.1]), doneAction:2);
Out.ar(0, Pan2.ar(Mix(SinOsc.ar(lis, mul: 0.1, add:0))*env, pos: 0, level: 1))}).play;
)

//this is the body of the code; which calculates the average values and 
//address them to synth, and stops at the end
(
var ortasi = {arg a, b; (a+b)/2};


var orta = {arg ele, low, high; var an=Array.newClear(ele), 
ranger=asInt((high-low)/ele),
off=low;
//i=-1;
block {|break| inf.do {|i| i; 
off=off+ranger;
an.put(i, rand(89)+off);
if (i == (ele-1)) {break.value(an)}};};};
//updates the value of 'il'th element of inlist//
var ortakes = {arg il, inlist; var inl = orta.value(20, 300, 5000);
inlist.put(il, ortasi.value(inlist.at(il), {remove(inlist, inl.at(il)); inlist.at(rand(inlist.size-1))}.value));};


//change the 2nd and 3rd argument of "orta.()" function for low and high range
var in = orta.(20, 20, 10000);
in.postln;
block {|out|
{inf.do({
//var in = inl;
if (in.at(9).asInteger == in.at(10).asInteger, {out.value.(true);});
20.do{arg rep; in = ortakes.(rep, in)}; 
Synth("nam", [\lis, in]);
in.postln;
0.19.wait;
});
false;
}.fork;
};
)




Comments

Popular Posts