Saturday, 12 November 2016

Patching


Inserting a new unit generator on demand.
   from http://soundlab.cs.princeton.edu/publications/chuck_nime2005.pdf

 // inserting a new unit generator 
 if( switch_hit )
   { 
        // disconnect foo from bar w/ 'unchuck' operator 
    foo =< bar; 
        // reconnect foo to new Filter to bar
    foo => Filter f => bar; 
    } 


Connecting and disconnecting two existing unit generator sub-patches
   from http://soundlab.cs.princeton.edu/publications/chuck_nime2005.pdf

 // connect/disconnect two unit generator graphs 
 if( toggle ) pa => pb;         // connect 
         else pa =< pb;         // disconnect

Tuesday, 1 November 2016

Funcky Somewhere - Illustrating functions and note-duration arrays

// "Notes" by Hugh R Frazer
//  ugen info at 
//   http://chuck.cs.princeton.edu/doc/program/ugen.html

//mtof values
//  C   C#  D   D#  E   F   F#  G   G#  A   A#  B
//     /Db     /Eb         /Gb     /Ab     /Bb  

//  0   1   2   3   4   5   6   7   8   9   10  11
//  12  13  14  15  16  17  18  19  20  21  22  23
//  24  25  26  27  28  29  30  31  32  33  34  35
//  36  37  38  39  40  41  42  43  44  45  46  47
//  48  49  50  51  52  53  54  55  56  57  58  59
//  60  61  62  63  64  65  66  67  68  69  70  71
//  72  73  74  75  76  77  78  79  80  81  82  83
//  84  85  86  87  88  89  90  91  92  93  94  95
//  96  97  98  99 100 101 102 103 104 105 106 107
// 
//  C   C#  D   D#  E   F   F#  G   G#  A   A#  B
//  C   Db  D   Eb  E   F   Gb  G   Ab  A   Bb  B



[100, 1, //Comment - Verse
69,4, 64,4, 64,4, 61,8,    61,4, 61,4, 61,4, 61,4,
62,4, 62,4, 62,4, 62,2,62,2, 62,4, 62,4, 62,4, 61,4, 71,2,62,2, 61,4,
69,2,64,2, 64,4, 61,8,   61,4,  61,4, 61,4, 61,4,
62,4, 62,4, 62,4, 62,2,62,2, 62,4, 62,4, 62,4, 61,4, 71,2,62,2, 61,4
] @=> int verse_notedur[]; //sequence data
[100, 2, //Comment - Bridge
60,4, 68,4, 68,4, 65,4,
60,4, 63,4, 63,4, 60,4,
61,4, 61,2,61,2, 61,4, 61,4, 61,4, 61,4, 61,2,60,2, 70,4, 60,2,61,2,60,2,
60,4, 68,4, 68,4, 65,4,
60,4, 60,2,60,2, 63,4, 63,4, 60,4,
61,4, 61,2,61,2, 61,4, 61,4, 61,4, 61,4, 61,2,60,2, 70,4, 60,2,61,2,60,2
] @=> int bridge_notedur[]; //sequence data
[100, 3, //Comment - Chorus
70,4, 70,4, 69,2,69,2,67,2, 62,2,60,2, 62,4, 65,2,62,2, 60,4,
70,4, 69,2,69,2,67,2, 62,2,60,2, 62,4, 65,2,62,2,60,2,
70,4, 69,2,69,2,67,2, 62,4, 60,4, 62,2,65,2,62,2,60,2,
62,4, 60,4, 65,2,62,2, 60,4,             
62,4, 60,4, 65,2,62,2, 60,4,             
62,2,60,2, 62,4, 65,2,60,2,70,2
] @=> int chorus_notedur[]; //sequence data
SqrOsc inst => JCRev r =>  dac;

.9 => inst.width;
.1 => r.gain;
.5 => r.mix;

now/ms => float mystart;
now/ms => float runtime;
while(true){//infinite loop
<<< "Begin" >>>;    
play ( verse_notedur );
play ( bridge_notedur );
play ( verse_notedur );
play ( bridge_notedur );
play ( chorus_notedur );
play ( bridge_notedur );
play ( chorus_notedur );
//Order of the song
//1. verse #1
//2. bridge
//3. verse #2
//4. bridge
//5. chorus
//6. bridge
//7. chorus   
}//While True infinate loop
fun void play(int part[])


      <<<"part=", part >>>;  
   for (1 => int i;i < part.cap(); i+2 => i) 
    { //for as long as we have notes in the array
    if (part[i-1] == 100) //if comment statement
        {
            if (part[i] == 1){ 
            <<< "--intro--" >>>; 
            }
            if (part[i] == 2){ 
            <<< "--bridge--" >>>; 
            }
            if (part[i] == 3){ 
            <<< "--chorus--" >>>; 
            }    
        } else 
        { 
        <<< "i=",i-1,"+",i, " runtime in s=", runtime/1000, " notedur[i-1]=", part[i-1], " notedur[i]=", part[i] >>>;
        Std.mtof(0 + part[i-1] ) => inst.freq; //set the note
        } //end if comment statement 
    now/ms - mystart => runtime;
   (part[i]*85)::ms => now; //getdur from array and play
  }// end for loop
}//end of function play

//  C   C#  D   D#  E   F   F#  G   G#  A   A#  B
//     /Db     /Eb         /Gb     /Ab     /Bb  
//  48  49  50  51  52  53  54  55  56  57  58  59
//  60  61  62  63  64  65  66  67  68  69  70  71
   
//Verse:
//A E E C#    C# C# C# C#
//1. I walked across    an empty land
//2. I came across        a  fallen tree
//
//D D D DD D D D C# B D C#
//1. I knew the pathway like the back of my hand
//2. I felt the branches of it looking at me
//
//A E E C#   C#  C# C# C#
//1. I felt the earth   beneath my feet
//2. Is this the place   we used to love
//
//D D D DD D D D C# B D C#
//1. sat by the river and it made me complete
//2. is this the place that i've been dreaming of
//
//Bridge:
//C Ab Ab F
//oh simple thing
//C Eb Eb C
//where have you gone
//C# C#C# C# C# C# C# C#C Bb CC#C
//I'm getting old and i neeed something to rely on
//C Ab Ab F
//so tell me when
//C CC Eb Eb C
//you're gonna let me in
//C# C#C# C# C# C# C# C#C Bb CC#C
//i'm getting tired and i need somewhere to begin
//
//Chorus:
//Bb Bb^ A A G DC D F D C
//and if you have a minute why don't we go
//Bb AA G DC D F DC
//talk about it somewhere only we know
//Bb A A G D C DFDC
//this could be the end of everything
//D C F D C             ]2x
//so why dont we go]
//DC D F CBb
//somewhere only we know
//
//
//Order of the song
//1. verse #1
//2. bridge
//3. verse #2
//4. bridge
//5. chorus
//6. bridge
//7. chorus

He then


[11,4, 12,4, 11,4,  7,4, 11,4, 12,4, 11,4,  7,4,  4,16,//18, 0-17
 11,4, 12,4, 11,4,  7,4, 11,4, 12,4, 11,4,  7,4,  4,16,//18-35
 16,6, 14,4, 12,6, 16,6, 14,4, 12,6, 16,6, 16,4, 11, 6,//36-53
 11,4, 12,4, 11,4,  7,4, 11,4, 12,4, 11,4,  7,4,  4,16//54-71
 ] @=> int notedur[]; //sequence data

SinOsc inst =>  JCRev r => dac;
.1 => r.gain;
.1 => r.mix;

now/ms => float mystart;
now/ms => float runtime;
while(true){for (1 => int i;i < notedur.cap(); i+2 => i) { //infinite loop
  Std.mtof(48 + notedur[i-1] ) => inst.freq; //set the note
    now/ms - mystart => runtime;
    <<< "i=",i, "  runtime in s=", runtime/1000, " notedur[i-1]=", notedur[i-1], " notedur[i]=", notedur[i] >>>;
  (notedur[i]*85)::ms => now; //getdur from array
}
    }

My ChucK notes (on Notes!)

My notes on document

//  ugen info at 
//   http://chuck.cs.princeton.edu/doc/program/ugen.html

//mtof values
//       C   C#  D   D#  E   F   F#  G   G#  A   A#  B
//          /Db     /Eb         /Gb     /Ab     /Bb  
//
// 1->   0   1   2   3   4   5   6   7   8   9   10  11   <-1
// 2->   12  13  14  15  16  17  18  19  20  21  22  23   <-2
// 3->   24  25  26  27  28  29  30  31  32  33  34  35   <-3
// 4->   36  37  38  39  40  41  42  43  44  45  46  47   <-4
// 5->   48  49  50  51  52  53  54  55  56  57  58  59   <-5
// 6->   60  61  62  63  64  65  66  67  68  69  70  71   <-6
// 7->   72  73  74  75  76  77  78  79  80  81  82  83   <-7
// 8->   84  85  86  87  88  89  90  91  92  93  94  95   <-8
// 9->   96  97  98  99 100 101 102 103 104 105 106 107   <-9

// For inline note translation: 
//      C           C#                    D           D#                    E           F           F#                    G           G#                    A           A#                    B
//                   =======>Db                       ========>Eb                                   ========>Gb                       ========>Ab                       ========>Bb  
//
 0=>int C1;  1=>int Cs1=>int Df1;  2=>int D1;  3=>int Ds1=>int Ef1;  4=>int E1;  5=>int F1;  6=>int Fs1=>int Gf1;  7=>int G1;  8=>int Gs1=>int Af1;  9=>int A1; 10=>int As1=>int Bf1; 11=>int B1;
12=>int C2; 13=>int Cs2=>int Df2; 14=>int D2; 15=>int Ds2=>int Ef2; 16=>int E2; 17=>int F2; 18=>int Fs2=>int Gf2; 19=>int G2; 20=>int Gs2=>int Af2; 21=>int A2; 22=>int As2=>int Bf2; 23=>int B2;
24=>int C3; 25=>int Cs3=>int Df3; 26=>int D3; 27=>int Ds3=>int Ef3; 28=>int E3; 29=>int F3; 30=>int Fs3=>int Gf3; 31=>int G3; 32=>int Gs3=>int Af3; 33=>int A3; 34=>int As3=>int Bf3; 35=>int B3;
36=>int C4; 37=>int Cs4=>int Df4; 38=>int D4; 39=>int Ds4=>int Ef4; 40=>int E4; 41=>int F4; 42=>int Fs4=>int Gf4; 43=>int G4; 44=>int Gs4=>int Af4; 45=>int A4; 46=>int As4=>int Bf4; 47=>int B4;
48=>int C5; 49=>int Cs5=>int Df5; 50=>int D5; 51=>int Ds5=>int Ef5; 52=>int E5; 53=>int F5; 54=>int Fs5=>int Gf5; 55=>int G5; 56=>int Gs5=>int Af5; 57=>int A5; 58=>int As5=>int Bf5; 59=>int B5;
60=>int C6; 61=>int Cs6=>int Df6; 62=>int D6; 63=>int Ds6=>int Ef6; 64=>int E6; 65=>int F6; 66=>int Fs6=>int Gf6; 67=>int G6; 68=>int Gs6=>int Af6; 69=>int A6; 70=>int As6=>int Bf6; 71=>int B6;
72=>int C7; 73=>int Cs7=>int Df7; 74=>int D7; 75=>int Ds7=>int Ef7; 76=>int E7; 77=>int F7; 78=>int Fs7=>int Gf7; 79=>int G7; 80=>int Gs7=>int Af7; 81=>int A7; 82=>int As7=>int Bf7; 83=>int B7;
84=>int C8; 85=>int Cs8=>int Df8; 86=>int D8; 87=>int Ds8=>int Ef8; 88=>int E8; 89=>int F8; 90=>int Fs8=>int Gf8; 91=>int G8; 92=>int Gs8=>int Af8; 93=>int A8; 94=>int As8=>int Bf8; 95=>int B8;
96=>int C9; 97=>int Cs9=>int Df9; 98=>int D9; 99=>int Ds9=>int Ef9;100=>int E9;101=>int F9;102=>int Fs9=>int Gf9;103=>int G9;104=>int Gs9=>int Af9;105=>int A9;106=>int As9=>int Bf9;107=>int B9;

now/ms => float mystart;
now/ms => float runtime;
    now/ms - mystart => runtime;
    <<< "i=",i, "  runtime in s=", runtime/1000 >>>;


//   
//       /\                                                                    
//       |/                                                                  
//       /|                                                        .              
//   ---/ |--------------------------------------------------------|\--------------(F)----
//     /  |_                                           .     |\    |         (E)     |
//   -/--/|-\------------------------------------------|\----|-----|---(D)-----|-----|----
//    | | | |                             .     |\    |     |   (C)     |     |     |/
//   -|---|--|-----------------------------|\----|-----|---(B)-----------|-----|/---------
//     \__|_/                  .     |\    |     |   (A)                 |/    `
//   -----|--------------------|\----|-----|---(G)----------------------------------------                       
//      \_/       .     |\    |     |   (F)
//   --------------|\----|-----|---(E)----------------------------------------------------
//           |\    |     |   (D)
//      -----|-----|---(C)-----
//           |   (B)
//   ---(A)-----------------
//        
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |  Db |    |  Eb |    |    |  Gb |   |  Ab |   |  Bb |    |    |  Db |    |  Eb |    |    |  Gb |   |  Ab |   |  Bb |    |    |  Db |
//   |     | C#  |    | D#  |    |    | F#  |   | G#  |   | A#  |    |    | C#  |    | D#  |    |    | F#  |   | G#  |   | A#  |    |    | C#  |
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |     |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|    |=====|    |    |=====|   |=====|   |=====|    |    |=====|
//   |       |        |        |        |        |        |        |        |        |        |        |        |        |        |        |  
//   |       |        |        |        |        |        |        |        |        |        |        |        |        |        |        |  
//   |       |        |        |        |        |        |        |        |        |        |        |        |        |        |        |  
//   |       |        |        |        |        |        |        |        |        |        |        |        |        |        |        |
//   |  C    |   D    |   E    |   F    |   G    |   A    |   B    |   C    |   D    |   E    |   F    |   G    |   A    |   B    |   C    |  D
//   |       |        |        |        |        |        |        |        |        |        |        |        |        |        |        |
//   |       |        |        |        |        |        |        |        |        |        |        |        |        |        |        |  
//   |         |        |        |        |        |        |        |        |        |        |        |        |        |        |        | 
//   |       |        |        |        |        |        |        |        |        |        |        |        |        |        |        |  
//   |_________|________|________|________|________|________|________|________|________|________|________|________|________|________|________|________
//   
//        Do       Ri       Mi       Fa       So       La       Ti       Do       Re       Me       Fa       So       La       Ti       Do      Ri 


/*
MIDI                   MIDI                   MIDI
 Note     Frequency      Note   Frequency       Note   Frequency
 C1  0    8.1757989156    12    16.3515978313    24    32.7031956626           0      8
 Db  1    8.6619572180    13    17.3239144361    25    34.6478288721           1      
 D   2    9.1770239974    14    18.3540479948    26    36.7080959897           2      9
 Eb  3    9.7227182413    15    19.4454364826    27    38.8908729653           3      
 E   4   10.3008611535    16    20.6017223071    28    41.2034446141           4      10
 F   5   10.9133822323    17    21.8267644646    29    43.6535289291           5
 Gb  6   11.5623257097    18    23.1246514195    30    46.2493028390           6      11
 G   7   12.2498573744    19    24.4997147489    31    48.9994294977           7
 Ab  8   12.9782717994    20    25.9565435987    32    51.9130871975           8      12
 A   9   13.7500000000    21    27.5000000000    33    55.0000000000           9
 Bb  10  14.5676175474    22    29.1352350949    34    58.2704701898           10     13
 B   11  15.4338531643    23    30.8677063285    35    61.7354126570           11
                                                                               12     14
 C4  36  65.4063913251    48   130.8127826503    60   261.6255653006           13
 Db  37  69.2956577442    49   138.5913154884    61   277.1826309769           14     15
 D   38  73.4161919794    50   146.8323839587    62   293.6647679174           15
 Eb  39  77.7817459305    51   155.5634918610    63   311.1269837221           16     16
 E   40  82.4068892282    52   164.8137784564    64   329.6275569129           
 F   41  87.3070578583    53   174.6141157165    65   349.2282314330           
 Gb  42  92.4986056779    54   184.9972113558    66   369.9944227116           
 G   43  97.9988589954    55   195.9977179909    67   391.9954359817           
 Ab  44  103.8261743950   56   207.6523487900    68   415.3046975799
 A   45  110.0000000000   57   220.0000000000    69   440.0000000000
 Bb  46  116.5409403795   58   233.0818807590    70   466.1637615181
 B   47  123.4708253140   59   246.9416506281    71   493.8833012561

 C7  72  523.2511306012   84  1046.5022612024    96  2093.0045224048
 Db  73  554.3652619537   85  1108.7305239075    97  2217.4610478150
 D   74  587.3295358348   86  1174.6590716696    98  2349.3181433393
 Eb  75  622.2539674442   87  1244.5079348883    99  2489.0158697766
 E   76  659.2551138257   88  1318.5102276515   100  2637.0204553030
 F   77  698.4564628660   89  1396.9129257320   101  2793.8258514640
 Gb  78  739.9888454233   90  1479.9776908465   102  2959.9553816931
 G   79  783.9908719635   91  1567.9817439270   103  3135.9634878540
 Ab  80  830.6093951599   92  1661.2187903198   104  3322.4375806396
 A   81  880.0000000000   93  1760.0000000000   105  3520.0000000000
 Bb  82  932.3275230362   94  1864.6550460724   106  3729.3100921447
 B   83  987.7666025122   95  1975.5332050245   107  3951.0664100490

 C10 108 4186.0090448096  120  8372.0180896192
 Db  109 4434.9220956300  121  8869.8441912599
 D   110 4698.6362866785  122  9397.2725733570
 Eb  111 4978.0317395533  123  9956.0634791066
 E   112 5274.0409106059  124 10548.0818212118
 F   113 5587.6517029281  125 11175.3034058561
 Gb  114 5919.9107633862  126 11839.8215267723
 G   115 6271.9269757080  127 12543.8539514160
 Ab  116 6644.8751612791
 A   117 7040.0000000000
 Bb  118 7458.6201842894
 B   119 7902.1328200980


 */

Happy Birthday to you -its my birthday and I'll ChucK if I want to

[100, 1, 
0,4,0,2, 43,1,0,2, 43,1,0,2, 45,2,0,2, 43,2,0,2, 48,2,0,2, 47,4,0,2, 
0,4,0,2, 43,1,0,2, 43,1,0,2, 45,2,0,2, 43,2,0,2, 50,2,0,2, 48,4,0,2,
0,4,0,2, 43,1,0,2, 43,1,0,2, 55,2,0,2, 52,2,0,2, 48,2,0,2, 47,2,0,2, 45,2,0,2, 
0,4,0,2, 53,1,0,2, 53,1,0,2, 52,2,0,2, 48,2,0,2, 50,2,0,2, 48,4,0,2,
0,64
] @=> int chorus_notedur[]; 
StifKarp inst  =>  dac;
now/ms => float mystart;
now/ms => float runtime;


while(true){
    <<< "Begin" >>>;    
    play ( chorus_notedur );    
}


fun void play(int part[])

      <<<"part=", part >>>;  
   for (1 => int i;i < part.cap(); i+2 => i) 
    { 
    if (part[i-1] == 100) 
        {
            if (part[i] == 1){ 
            <<< "--intro--" >>>; 
            }
            if (part[i] == 2){ 
            <<< "--bridge--" >>>; 
            }
            if (part[i] == 3){ 
            <<< "--chorus--" >>>; 
            }    
        } else 
        { 
        <<< "i=",i-1,"+",i, " runtime in s=", runtime/1000, " note[i-1]=", part[i-1], " dur[i]=", part[i] >>>;
        Std.mtof(24 + part[i-1] ) => inst.freq; 

    now/ms - mystart => runtime;
    if (part[i-1] != 0 ){
    .5 => inst.pluck;
        //.5 => inst.sustain;
        //.5 => inst.noteOn;
        .92 => inst.baseLoopGain;
        (part[i]*150)::ms => now; 

        } else {
         //1 => inst.noteOff;
        (0) => inst.sustain;
        (part[i]*60)::ms => now;
        }//end if gap
        }//end if comment
    }//end for in array loop
}//end while true loop

Wave Noise ChucK'ling

//sound chain: white noise to pan2 to dac
Noise n => LPF lpf => Pan2 p => dac;
45 => lpf.freq;
//noise can sound quite loud
1 => n.gain;

// infinite loop
while (true)
{
    //oscillate pan between 1.0 and -1.0
    (Math.sin(now/second) +2)  => n.gain;
    Math.cos(now/second)*-1  => p.pan;
    Math.cos(now/second)*5+20  => lpf.freq;
    //do it pretty often, to make it smooth
    ms => now;
}



Or
//sound chain: white noise to low pass filter (LPF) to pan2 to dac
Noise n => LPF lpf => Pan2 p => dac;
45 => lpf.freq;
//noise can sound quite loud
1 => n.gain;

// infinite loop
while (true)
{
    //oscillate pan between 1.0 and -1.0
    (Math.sin(now/second) +2)  => n.gain;
    Math.sin(now/second)*-1  => p.pan;
    Math.sin(now/second)*5+20  => lpf.freq;
    //do it pretty often, to make it smooth
  ms => now;

}


Installing miniAudicle on Ubuntu linux

Go get it at:
   http://audicle.cs.princeton.edu/mini/linux/

Then:
cd ~/Downloads/
tar -xvzf ./miniAudicle-1.3.3.tgz miniAudicle-1.3.3/
cd miniAudicle-1.3.3/
ls
more README.linux
cd src
sudo make linux-alsa
sudo apt-get install qt4
exit
chuck.alsa ~/h2.ck ./hanoi++.ck ~/HeathensWithFeelings.ck
cd miniAudicle-1.3.3/src
make linux-alsa
sudo make linux-alsa
sudo apt-get install qmake
sudo apt-get install qt4-dev-tools
sudo make linux-alsa
sudo apt-get install libqscintilla
sudo apt-get install libqscintilla-dev
sudo apt-get install libasound2-dev
sudo apt-get install libsndfile1-dev
sudo apt-get install flex
sudo apt-get install bison
sudo apt-get install g++
sudo make linux-alsa
ls
sudo reboot
cd miniAudicle-1.3.3/
./miniAudicle