Friday, December 12, 2014

Last Week's Notes

Note: This is here temporarily for the benefit of some students. It will move to Moodle and disappear form here


/*
SuperCollider is an Object Oriented Language that is designed for music and audio. It is a Music V type language. that means, like MAX MSP, the sound generation runs on a different thread than the control stuff. In MAX / MSP, you see this represented by differented coloured patch connections. In SuperCollider, audio runs on a server.

Because we don't have much time, I'm going to ask you take notes and then try stuff out later, not in class.  I also will ask Pieman to put a tutorial up for you on Moodle.

Hopefully you all have SuperCollider installed. When you tried opening it, you saw the screen divided in two parts. One part was the post window, filled with strange text and the other part was just blank and called untitled. The untitled window is where you write your code.  When you want to run your code, you select it with your mouse and hit ctrl-enter if you are in windows or linux, or apple-enter if you are on a mac. On some computers, you may need to use the apple or control key on the right wide of your keyboard. Try this out later with a simple program:
*/

4 + 4

/*
When you highlight 4 + 4 and run it, 8 will print out in your post window.

We're going to start out with working with sound design. Sound runs on the server. Therefore, we need to fist boot the server.  There are a few ways to do this. If you look in the Language menu, one of the items is 'boot server'. Select that.

The text in the little status bar at the bottom should change and turn green. you will also see output in the post window.


Now that the server is booted, let's make some sound:

*/

(
SynthDef(\sine, {
 Out.ar(0,
  SinOsc.ar(440, 0, 0.2)
 )
}).play
)

/*
When you want it to stop, hit ctrl-period or apple-period.

We are defining a SynthDef, sending it to the server and telling it to play. a synthDef is a description of how the server makes a sound.

First it has the name, which starts with a \, then comman curly bracket, then all of the UGens.

Out.ar is where the sound should come out. The channels start with 0, so this is on the left. Next is what should come out.
SinOsc is a sinwav oscillator. It's running at 440 Hz, it's phase is 0, and it's amplitude is 0.2.
Notice that these items have commas between them.

Then we close all of our open parens and curly brackets

Then a .play tells the whole thing to play.


We can organise this better using variables.
A variable is a container with a name. Like a box named sine. It can hold an object.
*/

(
SynthDef(\sine, {
 var sine;
 sine = SinOsc.ar(440, 0, 0.2);
 Out.ar(0, sine);
}).play
)


/*

First we let SuperCollider know that we've got a variable named sine.
We end that with a semicolon, so it knows that statement is done.

Then we do an assignment. Don't read = as 'equals, read it as 'gets'.
sine gets SinOac.ar.  We've got a box named sine. We've put a sine oscillator in the box, to keep track of it.
Then a semi colon, so it knows we're done with the assignment.
Then Our.ar, saying what channel to go out on.  And we tell it, put out whatever's in sine. Take the contents of the box and send it to the left speaker.


Every line needs to be separated by semicolons. Later on, when you can't figure out why something isn't working, check the semi colons first. It's the most common mistake. I still forget them all the time.


These sines all last forever, so let's try an envelope:

*/


(
SynthDef(\sinenv, {
 var sine, env;
 sine = SinOsc.ar(440, 0, 0.2);
 env = EnvGen.kr(Env.perc, doneAction:2);
 Out.ar(0, sine * env);
}).play
)


/*
we have added an extra variable called env
We've put an EnvGen into it. env gets EnvGen.kr.  An EnvGen is an envelope generator. First we tell it what envelope shape, then we do this doneAction:2 thing.

When we're telling out what to play, we tell it to multiple the sine box by the env box.


Let's do some ring modulation:

*/

(
SynthDef(\sinerm, {
 var sine, ringmod, env;
 sine = SinOsc.ar(440, 0, 0.2);
 ringmod = SinOsc.ar(30) * sine;
 env = EnvGen.kr(Env.perc, doneAction:2);
 Out.ar(0, ringmod * env);
}).play
)


/*

We've added a new variable called ringmod.

Ring mod gets a new sinosc times the contents of the sine variable.
When SuperCollider is looking at your code and it sees an assignment - the equals sign - it does everything on the right hand side of the assingment and puts the result of everything into the variable on the left.

We've picked 30 Hz, because that's the frequency daleks use, but what if we want different frequencies?

We could keep changing the synthdef:
*/

(
SynthDef(\sinerm, {
 var sine, ringmod, env;
 sine = SinOsc.ar(470, 0, 0.2);
 ringmod = SinOsc.ar(30) * sine;
 env = EnvGen.kr(Env.perc, doneAction:2);
 Out.ar(0, ringmod * env);
}).play
)

(
SynthDef(\sinerm, {
 var sine, ringmod, env;
 sine = SinOsc.ar(810, 0, 0.2);
 ringmod = SinOsc.ar(30) * sine;
 env = EnvGen.kr(Env.perc, doneAction:2);
 Out.ar(0, ringmod * env);
}).play
)

(
SynthDef(\sinerm, {
 var sine, ringmod, env;
 sine = SinOsc.ar(752, 0, 0.2);
 ringmod = SinOsc.ar(30) * sine;
 env = EnvGen.kr(Env.perc, doneAction:2);
 Out.ar(0, ringmod * env);
}).play
)

/*

Or, we could use a special kind of variable called an argument

*/

(
SynthDef(\sinermarg, { arg freq;
 var sine, ringmod, env;
 sine = SinOsc.ar(freq, 0, 0.2);
 ringmod = SinOsc.ar(30) * sine;
 env = EnvGen.kr(Env.perc, doneAction:2);
 Out.ar(0, ringmod * env);
}).add
)

/*

We've declared the argument at the top. That uses the keyword arg. argument need to go before variables.
So first you have the SynthDef and the name of it and the culry bracked.
Then next is arguments, starting with the keyword arg.
then are the variables, starting with the keyword var.
Everything else is below that.


It does not make sound when we play this one, because we changed the .play at the end to .add.

Instead of playing this right away, we tell the server to remember it, so we can play it later.

*/

Synth(\sinermarg, [\freq, 440])


/*
there are a lot of ways we can play a SynthDef, and one of them is by via Synth.

The first argument to Synth is \sinermarg, which is the name of the synthdef.  The next is this square bracket thing.

The first thing in the square brackets is \freq, this is the name of our argument, but starting with a slash.
Then is the value we want to give it.

*/


Synth(\sinermarg, [\freq, 860])

/*

What if we want to have more arguments?

*/

(
SynthDef(\sinermargs, { arg freq, rm, dur, amp;
 var sine, ringmod, env;
 sine = SinOsc.ar(freq, 0, amp);
 ringmod = SinOsc.ar(rm) * sine;
 env = EnvGen.kr(Env.sine(dur), doneAction:2);
 Out.ar(0, ringmod * env);
}).add
)

Synth(\sinermargs, [\freq, 912, \rm, 123, \dur, 7, \amp, 0.3])



/*

For this morning, we're going to focus more on SynthDefs, so we'll get to do sequences of notes in the afternoon.


Let's try different waves, panned to centre
*/


(
SynthDef(\saw, { arg freq, dur, amp;
 var saw, env, panner;
 saw =  Saw.ar(freq, amp);
 env = EnvGen.kr(Env.sine(dur), doneAction:2);
 panner = Pan2.ar(saw, 0,env);
 Out.ar(0, panner);
}).add
)

Synth(\saw, [\freq, 550, \dur, 3, \amp, 0.2])


/*

Notice that saw and sign have different arguments in their list. the second thing in the list to sign is a 0 and the amplitude is third. But saw just goes directly from frequency to amplitude.

How would you know about how these are different (or even what the various oscillators are)?  the answer is in the help browser!

Under the Help menu, there is a 'show help browser' option. You can click on search there to start searching. Or just browse around. Get to know the help browser. It is your friend. There are lots of examples.

Let's try some filtered noise:

*/


(

SynthDef(\subtractive, { arg freq, dur, amp;
 var noise, filt, env, panner;
 noise = WhiteNoise.ar;
 filt = RLPF.ar(noise, freq);
 env = EnvGen.kr(Env.sine(dur), doneAction:2);
 panner = Pan2.ar(filt, 0,env * amp);
 Out.ar(0, panner);
}).add
)

Synth(\subtractive, [\freq, 1200, \dur, 3, \amp, 0.2])


/*
WhiteNoise is just noise, so there's no need to give it additional information
RLPF is a Resonant Low Pass Filter

You may have noticed some of these are .ar and some are .kr.
ar is audio rate
kr is control rate

The envelope doesn't need to change values as often as a 440 Hz sine oscillator in order to sound good. The oscillator needs to go through it's entire wave form 440 times a second, whereas, the envelope needs much less precision.

*/


/*

This file is a SuperCollider file.  The english text is in a comment.  Programmers sometimes want to put human-language notes in their files.  This makes the files more readable to humans, but the text is not meaningful to SuperCollider. They mark the text as not being code by putting comment markers around it. Every one of these block of text starts with a slash star and ends with a star slash.
*/


/* <-- this is the starts of a comment
this is the end of a comment ---> */

// <- this marks a comment that only lasts for one line (and thus does not need an end marker)




1 comment:

Unknown said...

"
At the point when all activities and slimming down stage gets fizzled, Keto Primal works splendidly to give the coveted results by giving a thin and sharp body appearance since it is a characteristic craving boosting fat buster. The supplement additionally limits the nourishment desires or enthusiastic eating of people where they would encounter less appetite feel and that would offer them to stay in controlled calorie admission.

The supplement attempts to influence a person to go fit as a fiddle and carry on with a sound and a la mode way of life. The weight reduction process that begins after the admission of the pills go normally, and you may encounter the results inside 2-3 weeks of time. The expansion of every common concentrate here attempts to support the stomach related framework and furthermore clean the colon framework to stay free from hurtful poison squander. It supports the digestion level and gives a lift to vitality and stamina level where you would have the capacity to exercise more without getting worn out and stay dormant way of life. Visit for more informations:
Keto Primal
Health Care 350"