<-- Vilbjørg

this is a growing collection of code examples for the sound programming environment ChucK,

ChucK its editor MiniAudicle can be obtained free at http://audicle.cs.princeton.edu/mini/



Quasicrystal Phase Function

sporbits-examples    

prime 1

curlicue fractal as sound 1

sin(kx) simple chaos

Gauss Iterated map
------------------------------------------------------
---------------------------------


//This is ChucK code for a sound mapping of the Quasicrystal Phasefunction
// download file QCphasefunction.ck
//It is intended for a samplerate of 44.1kHz
//Please refer to the implemented mathematics at:
// http://www.eyemaginary.com/Portfolio/QuasicrystalSampling.html

//this piece of code will walk you through the circle with an angle increment of pi/1000 for each step.
// you can vary function parameters beneath

Impulse im1 => Gain g1 => dac.right => dac.left;
0.5  => g1.gain;


class PhaseFunction
{
    2*pi*(7 + 3*Math.sqrt(5)) => float k; float k1; float k2; float k3; float k4;
    0.0 => float phase; 0.0 => float ph; float theta ;0.0 => float phase2;
    float zspeedx; float zspeedy;
    0.02788 => float x =>  float y; 0 => int i;

    fun float f(float thousandangle, float step, int steplength, float zspeed, float phscaling )
    {
        2*pi*thousandangle/1000 => theta;
        Math.cos(theta) * zspeed => zspeedx;
        Math.sin(theta) * zspeed => zspeedy;
        k* Math.cos(pi/5) => k1;
        k* Math.sin(pi/5) => k2;
        k* Math.cos(2*pi/5) => k3;
        k* Math.sin(2*pi/5) => k4;
        <<< zspeedx, zspeedy >>>;
       
        while (true)
        {
            phase=> phase2; // store previous value
            2*Math.cos(k*x) + 4*Math.cos(k1*x)*Math.cos(k2*y) + 4*Math.cos(k3*x)*Math.cos(k4*y) => phase; // Quasicrystal Phasefunction
           
            (((phase + 10)*phscaling ) + ph) % (2*pi) => ph; //raise and scale function output and add it to a phase - ph

            Math.sin(ph) => im1.next; // sound out

            if ((phase * phase2) < 0) //simple zerocrossing
            {
                i+1 => i;
            }
                 
            if (i > (steplength*100) && Math.fabs(phase) < 0.0001)
            {   
                thousandangle + step => thousandangle;
                2*pi*thousandangle/1000 => theta;
                Math.cos(theta) * zspeed => zspeedx;
                Math.sin(theta) * zspeed => zspeedy;
                <<< thousandangle, x, y >>>;

                0.02788 * Math.cos(theta) => x; // you can commnt out the reset of x and y and hear that it actually ->
                0.02788 * Math.sin(theta) => y; // does not change the sound, but x and y will be growing large
                //value chosen to minimize clicks by reset
               
                0 => i;
            }
           
            x + zspeedx => x;
            y + zspeedy => y;
            1::samp => now;
           
        }
    }
}

PhaseFunction pf;
pf.f(0.0, 0.5, 3, 0.0001, 0.02);
// 1st variable : float: thousandangle , the starting angle where 0.0 = 0 radians and 1000 = 2pi.
// 2nd variable : float : step  which is angle-increment per step  -> 1.0 = 2pi/1000
// 3rd variable : int : steplength is multiplied with 100 and measures zerocrossings between each step to give a bit of time variation instead of depending on a sample-clock
// 4th variable : float: the speed through the complex plane , the speed can be varied but do not let it exceed 0.01 
// 5th variable : float : phscaling : 0.05 is the max possible , you can set scaling lower for a narrower pitch range (deeper tones)
// end code


-----------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------

short stereo composition based on the quasicrystal phasefunction QC10.ck

-------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------





//This is an example of how to make periodic noise with Spread Polynomials
// Download file : SpreadPolynomialOrbits.ck

Impulse im1 => Gain g1 => HPF hp1 => dac.left;
Impulse im2 => Gain g2 => HPF hp2 => dac.right;
0.1 => g1.gain => g2.gain;
5 => hp1.freq => hp2.freq;

class PeriodicNoise
{
    int s1; int s0; int s2;
    0 => int i => float r0 => float r1 => float r => float t => float sf;
    0 => int ior => int ior1 => int sx;
   
    fun float f( int spreadpol, int prime, int s, int  iteration, int orbitcount)
    {
        prime => float primef;
        iteration => float itp;
   
        while ( true)
        {
           
            if (i == 0){
                r1 => r0;
                if (spreadpol == 2){              // S2
                    4*s % prime => s0;
                    s0 * s % prime => s1;
                    ((s0 - s1) % prime ) + prime % prime => s => sf;
                 }else if(spreadpol ==3){        //S3
                    3-4*s => s0;
                    s0*s0 % prime => s0;
                    (s0*s % prime + prime) % prime  => s => sf;
                 }else if(spreadpol ==4){        //S4
                    1-2*s => s0;
                    s0*s0 % prime => s0;
                    s0*(1 - s) % prime => s0;
                    s0*s % prime => s0;
                    (16*s0 % prime + prime) % prime => s => sf;
                 }else if(spreadpol ==5){      //S5
                    s*s % prime => s0;
                    16*s0 % prime => s0;
                    (s0 - 20*s + 5) % prime => s0;
                    s0*s0 % prime => s0;
                    (s*s0 % prime + prime) % prime => s => sf;
                 }else if(spreadpol == 6){        //S6
                    (3- 4*s) % prime => s0;
                    s0*s0 % prime => s0;
                    (1-4*s) % prime => s1;
                    s1*s1 % prime => s1;
                    s0*s1 % prime => s1;
                    s1*(1-s) % prime => s1;
                    (4*s1*s  % prime + prime) % prime => s => sf;
                 }else if(spreadpol == 7){      //7
                    s*s % prime => s0;
                    s0*s % prime => s1;
                    64*s1 % prime => s1;
                    112*s0 % prime => s0;
                    (7 - 56*s) % prime => s2;
                    (s0 + s2 - s1) % prime => s0;
                    s0*s0 % prime => s0;
                    (s0*s % prime + prime) % prime  => s => sf;
                 }else {
                    <<< " this spread polynomial has not been coded yet, choose 2,3,4,5, 6 or 7">>>;
                    break;
                }
                (sf+1)/(primef+1) => r1;
               
                if (s == sx && ior > 0)
                {
                    <<< "orbit", ior, "    orbit length in samples:", ior* iteration >>>;
                    -1 => ior;
                    -1 => ior1;
                }
                   
                if (ior1 == orbitcount )
                {
                    s => sx;
                    0 => ior;
                    <<< s, " at ", orbitcount>>>;
                }
                if (ior1 == prime)
                {
                    s => sx;
                    0 => ior;
                    <<< s, " at prime " , prime>>>;
                }
                if (ior >= 0)
                {
                    (ior + 1 ) => ior;
                }
                if (ior1 >= 0)
                {
                    (ior1 + 1 ) => ior1;
                }
            }
        
        
            (i/ itp) *(r1 - r0) + r0 => r; // linear interpolation between rotation parameter and previous
        
            if (r*t == 1){ // caution for 0 in denominator
                -1000 => t;
                -1 => im1.next;
                0 => im2.next;
            }else{
                (t+r)/(1-t*r) => t; // calculating new circle parameter t
                (1 - t*t)/ (1+ t*t) => im1.next; // rational rotation output x y quarter phase
                2*t/ (1+ t*t) => im2.next;
            }
            
       
            (i+1) % iteration => i;
               
           
            1::samp => now;
        }
    }
}

PeriodicNoise pns;

pns.f(6, 15485581 , 93429, 3, 1000);
//pns.f(7,  10847  ,17043, 2095, 100);
//pns.f(5, 971 , 7, 11111, 10); //tones due to long iteration period

 // function variables (ints):
 
 //1: spreadpolynomial (2,3,4 ,5, 6 or 7)
 //2: prime - you want to avoid integer overflow , by 64 bit for sure safe up till around 20,000,000
 //  need to have 4 * prime * prime safe under signed 64bit integer , can not exceed size of signed due to way modulus works
 //3: seed , some times the seed is not part of an orbit, then it takes some iterations to fall into an orbit
 //4: iterationperiod
 //5 : iteration point when starting to look for orbit
 //  -if this value of s has not come back after prime iterations it is reset,
 //  but this may take long by large primes  better enlarge the value somewhat if you want to know orbit size



       
       



-----------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------

// code for sound programming environment Chuck, 1 file between double lines..
// code part of the Sporbits project
// download file : SpreadNoize.ck

Impulse im1 => Gain g1 => dac.left;
Impulse im2 => Gain g2 => dac.right;
0.2 => g1.gain => g2.gain;



class SpreadNoize
{
    0 => int ia => int ib => int isa => int isb;
    int ita; int itaa; int itb; int itbb;
    int sa; int sb;
    0 =>int icheck; 550 => int sss; float sssf;
    89 => int changea => int changeb;
    float ta; float tb; float ra; float rb; float t2a; float t2b;
    float sa0; float sa1; float sb0; float sb1;
    float xxa; float xxb;
    int a1; int a2; int b1; int b2; int b3;
    0 => float ampa => float amp0a => float amp1a;0 => float ampb => float amp0b => float amp1b;
    int ampinta; float ampfloata; int ampintb; float ampfloatb;
    float ampscalea; float ampscaleb;
    1 => float is2;
    int scalea; int scaleb;
    1 => float iampa => float iampb;
    float sfa; float sfb;
    1 => float m; 0 => int timing; 120  => int lll;
    1015829  => int end;
   
    fun float f(int prime, int s, int it, int scale, int change, int iittt)
    {
        s => sa => sb;
        scale => scalea => scaleb;
        it => ita => itaa => itb => itbb;
       
        while(true)
        {
            if(ia == 0)// S6 :  4s*(1-s)*(1-4s)^2*(3-4s)^2
            {
               
               
                sa1 => sa0;
               
                (3- 4*sa) % prime => a1;
                a1*a1 % prime => a1;
                (1-4*sa)*(1-4*sa) % prime => a2;
                a1*a2 % prime => a2;
                a2*(1-sa) % prime => a2;
                ((4*a2*sa % prime) + prime) % prime => sa;
               
                sa => sfa;
               
                sfa/(scalea*prime) => ra; 
                if (isa ==  changea)
                {
                    if (timing > lll)
                    {
                        ampa => amp0a;
                        0 => amp1a;
                        end => ampscalea;
                        2* end => changea;
                        0 => isa;
                        1 => iampa;
                    } else{
                        (sa % iittt + 5) *3 => itbb;
                        sa + 1 => sa;
                        sa / 5 + 29   => ampscalea;
                        sa %  change + 1  => changea;
                        sa % 109 + 3 => scalea;
                        ampa => amp0a;
                        (sa % 7) + 1 => ampinta;
                        ampinta => ampfloata;
                        ampfloata / 8 => amp1a;
                        0 => isa;
                        1 => iampa;
                        itaa => ita;
                    }
                }
                isa + 1 => isa;
            }
           
            if(ib == 0)// S7 :  s*(7-56s +112s^2 -64s^3)^2
            {
                sb1 => sb0;
               
                sb*sb % prime => b1;
                b1*sb % prime => b2;
                64*b2 % prime => b2;
                112*b1 % prime => b1;
                (7 - 56*sb) % prime => b3;
                (b3 + b1 - b2) % prime => b3;
                b3*b3 % prime => b3;
                (b3*sb % prime + prime) % prime => sb;
               
                sb => sfb;
               
                sfb/(scaleb*prime) => rb; 
                if (isb == changeb)
                {
                    if (timing >lll)
                    {
                        ampb => amp0b;
                        0 => amp1b;
                        end => ampscaleb;
                        2*end => changeb;
                        0 => isb;
                        1 => iampb;
                    }else{
                                             
                        (sb % iittt + 5) *3 => itaa;
                        sb + 1 => sb;
                        sb / 5 + 29  => ampscaleb;
                        sb %  change  + 1 => changeb;
                        sa % 109 + 3 => scaleb;
                        ampb => amp0b;
                        (sb % 7) + 1 => ampintb;
                        ampintb => ampfloatb;
                        ampfloatb / 8 => amp1b;
                        0 => isb;
                        1 => iampb;
                        itbb => itb;
                    }
                }
                isb + 1 => isb;
               
               
               
            }
           
           
            Math.min(1,iampa /ampscalea )  * (amp1a - amp0a) + amp0a => ampa;
            Math.min(1,iampb /ampscaleb)  * (amp1b - amp0b) + amp0b => ampb;
            if(ampa+ampb < 0.001 & timing > lll)
            {
                break; // THE END
            }
           
           
            if( ra*ta ==1)// rotations are done without use of transcendentals
            { // refer to the great mathematics of Norman Wildberger
                -10000 => ta;
                -1 *ampa  => xxa => im1.next;
            } else {
                (ta + ra)/(1- ta*ra) => ta;
                ta*ta => t2a;
                ampa * (1-t2a)/(1+t2a) => xxa => im1.next;
            }
           
            if( rb*tb ==1)
            {
                -10000 => tb;
                -1 *ampb  => xxb => im2.next;
            } else {
                (tb + rb)/(1- tb*rb) => tb;
                tb*tb => t2b;
                ampb * (1-t2b)/(1+t2b) => xxb => im2.next;
            }
           
            if(icheck == 0)
            {
                timing + 1 => timing;
               
                if (timing < 100)
                {
                    if (change > 300)
                    {
                        change - 233 => change;
                    }
                    iittt + 7 => iittt;
                }else if(timing > 99)
                {
                    if (iittt > 50)
                    {
                        iittt - 41 => iittt;
                    }
                }
               
            }
           
            (ia+ 1) % ita => ia;
            (ib+ 1) % itb => ib;
           
            (icheck + 1) % 89779 => icheck;
            iampa + 1 => iampa;
            iampb + 1 => iampb;
            1::samp => now;
        }
    }
}







SpreadNoize sn;

sn.f(14901941, 296345, 30, 30, 14087, 11); //changing the first number, = finite field,  to another prime
// of similar size will make different variations
// or changing the second number, = the initial input, will also give a different piece



------------------------------------------------------------
---------------------------------------------------------------------

endless composition based on Spread polynomials MusicForComputer.ck


------------------------------------------------------------------------------------

------------------------------------------------------------------------------


// code for sound programming environment Chuck, 1 file between double lines..
// PrimeCircle -  [quadratic residue]

//download file primeCircle.ck



Impulse im1 => Gain g1 => dac.left;
Impulse im2 => Gain g2 => dac.right;
Impulse im3 => Gain g3 => dac.left;
Impulse im4 => Gain g4 => dac.right;
0.5 => g1.gain => g2.gain;
0.5 => g3.gain => g4.gain;
Impulse im5 => Gain g5  => dac.left;
Impulse im6 => Gain g6 => dac.right;

0.9 => g5.gain => g6.gain;

//dac => WvOut2 w => blackhole;
//"recp10" => w.wavFilename;
//null @=> w;
class Sqmod
{
    0.0 => float i; 0.0 => float i2;
    0.0 => float a;
    0.0 => float a10;  float a11; float a12;
    0.0 => float a20;  float a21; float a22;
    0.0 => float a30;  float a31; float a32;
    0.0 => float a40;  float a41; float a42;
    0.0 => float a50;  float a51; float a60; float a61; float m; float ph; float ph1;

    0.3 => float zmag;0.3 => float zmagx;
    0 => int ii; 0 => int ii2 ;
   
   
    fun float f(float n1, float n2,float n3, float n4, int itp, int inp)
    {
      
        while (true)
        {
            if (ii == 0)
            {
               
                i * i   => a;
                if (i>n1){a10=>a10;}
                else{Math.fmod(a,n1) => a10;}
                if(i>n2){a20=>a20;}
                else{Math.fmod(a,n2) => a20;}
                if(i>n3){a30=>a30;}
                else{Math.fmod(a,n3) => a30;}
                if(i>n4){a40=>a40;}
                else{Math.fmod(a,n4) => a40;}
               
                (a10 - a40)/n1 => a50;
                a50*a50 => a50;                // differences between twins control amp -
                (a20 - a30)/n1 => a60;  // for rhythm  
                a60* a60 => a60;        
                Math.pow(2, a10* 6 /n1)*0.0076937   => a11;        //*54*pi/22050        
                Math.pow(2, a20 * 6 / n1)*0.0076937   => a21;
                Math.pow(2, a30* 6 /n1)*0.0076937   => a31;                
                Math.pow(2, a40 * 6 / n1)*0.0076937   => a41;

                i+ 1 => i;
               
               
            }

           
            if(ii2==0){
                Math.fmod(i2 * i2 , n1) => m;
                Math.pow(2, 2*m/n1) *0.0076937  => ph; //;*0.0076937
            }
           
            a50 * 0.9998  => a50;
            a60 * 0.9998 => a60;
           
            if (i > n1)
            {zmag*0.99999 => zmag;
            0.0 => a51 => a61;}
           
            if(i>n2){ zmagx*0.99999 => zmagx;}
            if (zmag< 0.00001)
            {break;}
           
            if (i ==1){ 0.0 => ph1;}
            else{ph1 + ph => ph1;}
            a50*Math.sin(ph1)=> im5.next;
            a60*Math.sin(ph1)=> im6.next; 
               
            Math.fmod(a12 + a11, 2* pi) => a12; 
            zmag*Math.cos(a12)=> im1.next;             
           
           
            Math.fmod(a22 + a21, 2* pi) => a22;                
            zmag*Math.cos(a22)=> im2.next;
           
            Math.fmod(a32 + a31, 2* pi) => a32;                
            zmagx*Math.cos(a32)=> im3.next;
           
            Math.fmod(a42 + a41, 2* pi) => a42;                
            zmagx*Math.cos(a42)=> im4.next;
                      
            (ii + 1 ) % itp => ii;
            (ii2 + 1 ) % inp => ii2;
            i2 + 1.0 => i2;
            1::samp => now;
        }
    }
}
Sqmod pm;

pm.f(433.0, 421.0, 431.0, 419.0, 7877, 29);


--------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------

// code for sound programming environment Chuck, 1 file between double lines..

// download file primePop.ck
// PrimePop -  [cubic residue]

Impulse im1 => Gain g1 => dac.left;
Impulse im2 => Gain g2 => dac.right;
Impulse im3 => Gain g3 => dac.left;
Impulse im4 => Gain g4 => dac.right;
0.5 => g1.gain => g2.gain;
0.5 => g3.gain => g4.gain;
Impulse im5 => Gain g5  => dac.left;
Impulse im6 => Gain g6 => dac.right;
Impulse im7 => Gain g7  => dac.left;
Impulse im8 => Gain g8 => dac.right;
0.6 => g5.gain => g6.gain => g7.gain => g8.gain;


class Sqmod
{
    0.0 => float i; 0.0 => float i2; float i3;float i4;
    0.0 => float a;
    0.0 => float a10;  float a11; float a12;
    0.0 => float a20;  float a21; float a22;
    0.0 => float a30;  float a31; float a32;
    0.0 => float a40;  float a41; float a42;
    0.0 => float a50;  float a51; float a60; float a61;
    0.0 => float a70;  float a71; float a80; float a81;
    float m; float t;
    float ph10; float ph11;float ph20; float ph21; float ph1p;float ph2p;float ph13; float ph23;

    0.3 => float zmag;0.3 => float zmagx;
    0 => int ii; 0.0 => float ii2 ;
   
   
    fun float f(float n1, float n2,float n3, float n4, int itp, float inp, int c)
    {
      
        while (true)
        {
            if (ii == 0)
            {
               
                i * i* i=> a;  //   * i
                if (i>n1*c){a10=>a10;}
                else{Math.fmod(a,n1) => a10;}
                if(i>n2*c){a20=>a20;}
                else{Math.fmod(a,n2) => a20;}
                if(i>n3*c){a30=>a30;}
                else{Math.fmod(a,n3) => a30;}
                if(i>n4*c){a40=>a40;}
                else{Math.fmod(a,n4) => a40;}
               
                (a10 - a40)/n1 => a50;
                Math.min(a50*a50, 0.5) => a51;                -
                (a20 - a30)/n1 => a60; 
                Math.min(a60*a60, 0.5) => a61;
                (a10 - a30)/n1 => a70;
                Math.min(a70*a70, 0.5) => a71;                -
                (a20 - a40)/n1 => a80; 
                Math.min(a80*a80, 0.5) => a81;         
                Math.pow(2, a10* 6 /n1)*0.0076937   => a11;        //*54*pi/22050        
                Math.pow(2, a20 * 6 / n1)*0.0076937   => a21;
                Math.pow(2, a30* 6 /n1)*0.0076937   => a31;                
                Math.pow(2, a40 * 6 / n1)*0.0076937   => a41;

                i+ 1 => i;
               
                0 => i3;
              
               
               
            }

           
            if(ii2==0){
                ph10 => ph1p; ph20 => ph2p;
                Math.fmod(i2 * i2* i2, n1) => m;  //*0.0076937
                Math.pow(2, 3*m/n1)*0.0153874  => ph10;
                Math.pow(2, 4*m/n1)*0.0153874 => ph20;//*0.0076937
                Math.fmod(i2 + 1.0, n1)  => i2;
               
               
               
            }
           
                      
            if (i > n1*c)
            {zmag*0.99999 => zmag;
            0.0 => a51 => a61;}
           
            if(i> n2*c){ zmagx*0.99999 => zmagx;}
            if (zmag< 0.001)
            {break;}
           
            (ii2/inp* ph10) +  (1- (ii2/inp))* ph1p => ph13;
            (ii2/inp* ph20) +  (1- (ii2/inp))* ph2p => ph23;
           
            if(i3 == 0){
                0.0 =>ph11 =>ph21;
            }
            else{
                ph11 + ph13 => ph11;
                ph21 + ph23 => ph21;
            }
           
            if(i3 > 443){
                a51 * 0.995 => a51;
                a61 * 0.995 => a61;
                a71 * 0.995 => a71;
                a81 * 0.995 => a81;
            }

           
            a51*Math.sin(ph11)=> im5.next;
            a61*Math.sin(ph11)=> im6.next;
            a71*Math.sin(ph21)=> im7.next;
            a81*Math.sin(ph21)=> im8.next;
          
          
            Math.fmod(a12 + a11, 2* pi) => a12; 
            zmag*Math.cos(a12)=> im1.next;             
           
           
            Math.fmod(a22 + a21, 2* pi) => a22;                
            zmag*Math.cos(a22)=> im2.next;
           
            Math.fmod(a32 + a31, 2* pi) => a32;                
            zmagx*Math.cos(a32)=> im3.next;
           
            Math.fmod(a42 + a41, 2* pi) => a42;                
            zmagx*Math.cos(a42)=> im4.next;
                      
            (ii + 1 ) % itp => ii;
            Math.fmod(ii2 + 1.0, inp ) => ii2;
            i3 + 1 => i3;
           
            1::samp => now;
        }
    }
}
Sqmod pm;
//pm.f(1031.0, 1021.0, 1033.0, 1019.0, 233, 113, 13);
pm.f(1031.0, 1021.0, 1033.0, 1019.0, 10009, 113, 1);
//pm.f(389.0, 373.0, 383.0, 379.0, 7877, 151, 1);


-------------------------------------------------------------------
--------------------------------------------------------------------

// code for sound programming environment Chuck, 1 file between double lines..

//download file primeOrder.ck

//PrimeOrder

Impulse im1 => Gain g1 => dac.left;
Impulse im2 => Gain g2 => dac.right;
Impulse im3 => Gain g3 => dac.left;
Impulse im4 => Gain g4 => dac.right;

0.5 => g1.gain => g2.gain;
0.5 => g3.gain => g4.gain;


class Sqmod
{
    0.0 => float u1 => float u2 => float u3 => float u4 ; 1.0 => float u11 => float u21 => float u31 => float u41;
    float l1; float l2;float l3; float l4;
    0.0 => float a10;  float a11; float a12;
    0.0 => float a20;  float a21; float a22;
    0.0 => float a30;  float a31; float a32;
    0.0 => float a40;  float a41; float a42;

    5.0 => float m11 => float m21 => float m31 => float m41;
    float m1 => float m2 => float m3 => float m4;float m12 => float m22 => float m32 => float m42;

    0.3 => float zmag1;
    0.0076937 => float a111 => float a211 => float a311 => float a411;
    0.0076937 => float a112 => float a212 => float a312 => float a412;
   
    fun float f(float n1, float n2, float n3, float n4, float k1, float k2, float k3, float k4,float t, int c)
    {
      
        while (true)
        {
            if (u1 == m11)
            {
                u11 * u11=> l1;
                //u11 * u11 * u11=> l1;  //   
                if (u11>n1*c){a10=>a10;}
                else{Math.fmod(l1,n1) => a10;}
               
                Math.pow(2, a10* 6 /n1)*0.0076937   => a11; //*54*pi/22050
              
                Math.fmod(l1,k1) => m1;
                Math.max(m1,3) * t => m11;
               
                0.0 => u1;
                u11 + 1=> u11;
               
            }
           
            if (u2 == m21)
            {
                u21 * u21=> l2;
                //u21 * u21 * u21=> l2; //
                if(u21>n2*c){a20=>a20;}
                else{Math.fmod(l2,n2) => a20;}
               
                Math.pow(2, a20 * 6 / n1)*0.0076937   => a21;
               
                Math.fmod(l2  ,k2)  => m2;
                Math.max(m2,3) * t => m21;
               
                0.0 => u2;
                u21+ 1 => u21;
               
            }
           
            if (u3 == m31)
            {
                u31 * u31=> l3;
                //u31 * u31 * u31=> l3; //
                if(u31>n3*c){a30=>a30;}
                else{Math.fmod(l3,n3) => a30;}
               
                Math.pow(2, a30 * 6 / n1)*0.0076937   => a31;
               
                Math.fmod(l3 ,k3) => m3;
                Math.max(m3, 3) * t=> m31;
               
                0.0 => u3;
                u31+ 1 => u31;
               
            }
           
            if (u4 == m41)
            {
                u41 * u41=> l4;
                //u41 * u41 * u41=> l4; //
                if(u41>n4*c){a40=>a40;}
                else{Math.fmod(l4,n4) => a40;}
               
                Math.pow(2, a40 * 6 / n1)*0.0076937   => a41;
               
                Math.fmod(l4,k4)   => m4;
                Math.max(m4, 3) * t => m41;
               
                0.0 => u4;
                u41+ 1 => u41;
               
               
            }
           
                    
            if (u11 > n1*c)
            {zmag1*0.99999 => zmag1;}
           
               
            if(zmag1<0.001)
            {break;}
                   
           
            (a11+ a112)/2  =>  a112;
            (a111+ a112)/2  =>  a111;      
            Math.fmod(a12 + a111, 2* pi) => a12; 
            zmag1*Math.cos(a12)=> im1.next;             
            
            (a21+ a212)/2  =>  a212;
            (a211+ a212)/2  =>  a211;           
            Math.fmod(a22 + a211, 2* pi) => a22;                
            zmag1*Math.cos(a22)=> im2.next;
           
            (a31+ a312)/2  =>  a312;
            (a311+ a312)/2  =>  a311;
            Math.fmod(a32 + a311, 2* pi) => a32;                
            zmag1*Math.cos(a32)=> im3.next;
           
            (a41+ a412)/2  =>  a412;
            (a411+ a412)/2  =>  a411;
            Math.fmod(a42 + a411, 2* pi) => a42;                
            zmag1*Math.cos(a42)=> im4.next;

            u1+1 => u1;
            u2+1 => u2;
            u3+1 => u3;
            u4+1 => u4;

            1::samp => now;
        }
    }
}
Sqmod pm;
pm.f(821, 809, 811, 819, 419, 433, 421, 431, 43, 1);
//pm.f(1033, 1019, 1031, 1021, 419, 433, 421, 431, 37, 1);
//pm.f(3931, 3917, 3929, 3919  ,419, 433, 421, 431 ,29 , 1);
//pm.f(277, 263, 271, 269 , 101, 109, 103, 107, 157, 8);
//pm.f(433, 419, 421, 431 , 101, 109, 103, 107, 157, 2);
//pm.f(1033, 1019, 1031, 1021  ,101, 109, 103, 107 ,151, 1);
//pm.f(3931, 3917, 3929, 3919  ,101, 109, 103, 107 ,157 , 1);

--------------------------------------------------------------------
-------------------------------------------------------------------------


// code for sound programming environment Chuck, 1 file between double lines.. Vilbjørg Broch 2013.

//download file curlicue.ck

// curlicue fractal as sound - choose constant and iteration frequency beneath.. there is a reverb, but the mix is all down.

Impulse i1 => JCRev r1 => dac.left;
Impulse i2 => JCRev r2 => dac.right;
0.5 => i1.gain => i2.gain;
0.0 => r1.mix => r2.mix;
0.9 => r1.gain => r2.gain;
class curlicue
{
    0.0 => float theta;
    0.0 => float phi; // starting value not 0 (sin(0) = 0 , its a static point)
    0.0 => float zphase => float zphaseprevious => float zphaseinterpolated => float zphaseincrement;
    
    0.3 => float zmag; // determines amplitude of waveform
    0.3 => float zmag1;
    0 => int i; // sample counter
    #(0, 0) => complex zz;
    %(0, 0) => polar pp;
    float mu;
    float mu2;

    
    fun float f(float s, int itp, int inp)
    {
        while (true)
        {
            if (i == 0)
            {
                zphase => zphaseprevious;
                0.0 => mu;
                
                Math.fmod((phi + theta), (2*pi)) => phi;
                Math.fmod((theta + (2*pi*s)),(2*pi)) => theta;
                
              
                %(1, phi) => polar one;
                one $ complex  => complex zx;
                zx + zz => zz;
                
                zz $ polar => polar pp;
                Math.fmod((pp.phase + zphase), 2*pi)=> zphase;
                
                Math.min( pp.mag* pp.mag / 300000, 0.5) => zmag;
                
            }
            else
            {
                zphase => zphase;
                
            }
            Math.fmod((1/inp + mu),1.0) => mu;
            (1- Math.cos(mu*pi) )/2=> mu2;
            zphaseprevious*(1-mu2) + zphase*mu2 => zphaseinterpolated;
            %(zmag , zphaseinterpolated) => polar zpolar;
            zpolar $ complex =>  complex z;
            z.re => i1.next;
            z.im => i2.next;
            (i + 1) % itp => i;
            1::samp => now;
            
        }
    }


}


curlicue curl;// curlicue lives off irrational constants, choose one of these or look for others
// th 2 numerbers are itp : iteration freq. in samples and inp:interpolation; can very well be the same..

//curl.f(1.414213562373095, 15, 15);// sqr 2
//curl.f(0.7642236535892206629, 10, 10);//Landau-Ramanujan constant
//curl.f(1.6180339887498948482, 60, 30);//phi golden ratio
curl.f(1.4513692348833810502, 60, 30);//Ramanujan-Soldner constant
//curl.f(1.4513692348833810502, 10, 10);//Ramanujan-Soldner constant
//curl.f(4.6692116609102990671, 10, 10); //The prime constant


--------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

//download file GaussIteration.ck

// code for sound programming environment Chuck, 1 file between double lines.. Vilbjørg Broch 2013.

// Gauss Iterated map : x[n+1] = exp(-a * x[n]^2)  + b  ... (x, a, b are all complex)
// code is set to break if the orbit escapes, the presets beneath all converges to something periodic
// rather quickly, if you find interesting presets then I would be pleased to know.


Impulse i1 => Gain g1 => dac.left;
Impulse i2 => Gain g2 => dac.right;
0.3 => g1.gain => g2.gain;



class GaussIt
{
    float p1; float p2; float xmagp; float xphasep; float phase; complex z;complex z2;
    0 => int i; float phad; 0 => float mag; float mag1; float magp;
    0 => int ii;
    fun float f(float xre, float xim, float are, float aim, float bre, float bim, int itp, float k)
    {
        while(true)
        {
       
            if(i == 0)
            {
                2*xre*xim => p1;
                xim*xim - xre*xre => p2;
                Math.exp(p1*aim + p2*are) => xmagp;
                aim*p2 - are*p1 => xphasep;
                xmagp * Math.cos(xphasep) + bre => xre;
                xmagp * Math.sin(xphasep) + bim => xim;
                #(xre, xim) => z;
                z $ polar => polar zpol;
                (zpol.mag + pi)/itp * k => phad;
                mag => magp;
                Math.min(zpol.mag * 0.5, 0.8) => mag;
               
                if(Math.fabs(xre) > 10){break;}
                (ii + 1) % 3000 => ii;
                if(ii==0){<<< xre, "  ", xim, "  ", zpol.mag, "  ", zpol.phase>>>;}
               
            }
            magp*(itp-i)/itp  + mag*i/itp => mag1;
            phase + phad => phase;
            %(mag1 , phase) => polar z2pol;
            z2pol $ complex => z2;
            z2.re => i1.next;
            z2.im => i2.next;
            (i + 1) % itp => i;
            1::samp => now;
         }
    }
}
GaussIt gi; // x-real, x-imag, a-real, a-imag, b-real, b-imag, iteration-freqency, interpolation..

//gi.f(0.3, -0.623112422, -0.5683118109, -0.580119702, -1.696157202, -0.10102301, 10000, 200.0);
//gi.f(0.3, -0.623112423, -0.5683118109, -0.580119703, -1.696157203, -0.10102302, 10000, 200.0);
//gi.f(-0.21, 0.3, 0.1, -0.8, 0.2, -0.2, 10000, 200.0);
//gi.f(-0.4, 0.5, 0.22, -0.27, 0.36, -1.12, 10000, 200.0);
gi.f(-0.5, 0.5, 0.225, -0.27, 0.36, -1.137, 10000, 200.0);

-----------------------------------------------------------------------------------------------------------------------------------      
------------------------------------------------------------------------------------------------------------------------------------------       


// code for sound programming environment Chuck, 1 file between double lines.. Vilbjørg Broch 2013.

//download file sinKx.ck

// SINKX -  simple chaos generator ::: x(n+1) = sin ( k * x(n))  --- Chugen for ChucK
// mono

class SinKX extends Chugen
{
    0.3 => float x; // starting value != 0 (sin(0) = 0 , its a static point)
    3.09287 => float k; //takes you through the bifurcation diagram;
    25 => int itp; // iteration period
    25 => int inp; // interpolation period
    0.0 => float zphase => float zphaseprevious => float zphaseinterpolated => float zphaseincrement;
    0.2 => float zmag; // determines amplitude of waveform
    0 => int i;
      
    fun float tick(float in)
    {
       
        if (i == 0)
        {
            zphase => zphaseprevious;
            Math.sin(k*x) => x;
            (x + zphase) % 2*pi - pi => zphase;
            (zphase-zphaseprevious)/inp => zphaseincrement;
            //<<< in >>>;
        }
        else
        {
            zphase => zphase;
            zphaseincrement => zphaseincrement;
        }
        zphaseincrement + zphaseinterpolated => zphaseinterpolated;
        %(zmag , zphaseinterpolated) => polar zpolar;
        zpolar $ complex =>  complex z;
       
        (i + 1) % itp => i;

      return z.re;
    }
}

SinKX skx => Gain  g => dac;
0.3 => g.gain;

0 => int ii;
while(true)
{
    if (ii == 0)
    {
        8.301345 => skx.k; 3000 => skx.itp; 30 => skx.inp;
        <<< skx.x, skx.k, skx.itp, skx.inp, skx.zphase, skx.zphaseprevious, skx.zphaseincrement >>>;
    }
    if (ii == 6)
    {
        7.789123 => skx.k; 8 => skx.itp; 8 => skx.inp;
        <<< skx.x, skx.k, skx.itp, skx.inp, skx.zphase, skx.zphaseprevious, skx.zphaseincrement  >>>;
    }
    if (ii == 8)
    {
        6.08 => skx.k; 1200 => skx.itp; 12 => skx.inp;
        <<< skx.x, skx.k, skx.itp, skx.inp, skx.zphase, skx.zphaseprevious, skx.zphaseincrement  >>>;
    }
   
    if (ii == 12)
    {
       5.011345 => skx.k; 100 => skx.itp; 100 => skx.inp;
        <<< skx.x, skx.k, skx.itp, skx.inp, skx.zphase, skx.zphaseprevious, skx.zphaseincrement  >>>;
    }
    if (ii == 18)
    {
        7.789123 => skx.k; 500 => skx.itp; 50 => skx.inp;
        <<< skx.x, skx.k, skx.itp, skx.inp, skx.zphase, skx.zphaseprevious, skx.zphaseincrement >>>;
    }
    if (ii == 24)
    {
        5.78916 => skx.k;  40 => skx.itp; 40 => skx.inp;
        <<< skx.x, skx.k, skx.itp, skx.inp, skx.zphase, skx.zphaseprevious, skx.zphaseincrement >>>;
    }
    if (ii == 30)
    {
        5.78916 => skx.k;  5000 => skx.itp, 50 => skx.inp;
        <<< skx.x, skx.k, skx.itp, skx.inp, skx.zphase, skx.zphaseprevious, skx.zphaseincrement >>>;
    }

   
   
    ii++;
    Math.random2f(0.5, 2.0)::second=>now;
}

----------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------------------------------