Laptop Instrument Meeting 4 January 29, 2018
ChucK Program 1 // Plays random frequencies // Connect unit generator SinOsc s => dac; // Start loop while (true) { // Generate random frequency // and assign to s Std.rand2f(30.0,1000.0) => s.freq; // Play for 100 milliseconds 100::ms => now; }
ChucK Program 2 // Plays octaves // Connect unit generator SinOsc s => dac; // Set starting frequency as a real number 30.0 => float playfreq; // Start loop while (playfreq <= 10000) { // Set frequency playfreq => s.freq; // Play for 2 seconds 2::second => now; // Double frequency 2 *=> playfreq; }
Low Notes Double bass: E or C Tuba: D Contrabassoon: B flat
Low Notes: Pipe Organ Massey Memorial Organ: 5640 pipes Chautauqua Institution, New York
What is a computer program? A sequence of statements. Either Statements end with a terminator (for example, ;) Statements are separated with a separator Statements are executed in order. But There may be branches There may be loops
What might go wrong? A syntax error: when the rules of the language are not followed A semantic error: perfect syntax, but the wrong result due to Logic Typos
Variables and values Variable names: identifiers Value types An identifier is a sequence of characters and digits, starting with a character. Capitalization counts. Variables are assigned values Value types int : integer (signed) float : real number (signed), a number with a decimal point time : internal to ChucK, sometimes called ChucKian dur : duration
Storing and Calculating Before using a variable, it must be declared. This action sets aside a space of the proper shape to hold the value. Declaring: int foo; dur short; float some;
Storing and Calculating (2) Once declared, a value of the correct type can be assigned (stored) in the space named by the variable. Assigning: value on left, location on right, => 2 => foo; 10::ms => short; Declaring and assigning together: 120.0 => float some;
Storing and Calculating (3) Example 120.0 => float some; //declare and initialize some 120.0
Storing and Calculating (4) Arithmetic 120.0 => float some; 100.0 + some => some; // increment some 220.0
Storing and Calculating (5) Arithmetic 120.0 => float some; 100.0 + some => some; 100.0 +=> some; //increment shorthand some 320.0
Storing and Calculating (6) 0 => int i; //declare and initialize
Storing and Calculating (7) 0 => int i; i++; // increment by 1 1
Peeking <<< i >>>; <<< “Answer:” , i >>>;
Exercise After each step, use the ChucK “print” statement to display the value of the answer. // Declare foo as an integer and store 3 // Increment foo by 5 // Increment foo by 1 // Multiply foo by 4 // Subtract 11 from foo // Divide foo by 7 Answer is 3. Integer divide.