Difference between revisions of "SuperCollider Tweets"

From CCRMA Wiki
Jump to: navigation, search
Line 10: Line 10:
  
  
=='micromoog' tweet==
+
==micromoog==
 
<pre>
 
<pre>
// Bruno Ruviaro, 2011-06-12
 
 
// SuperCollider code analysis
 
// SuperCollider code analysis
 +
// by Bruno Ruviaro, 2011-06-12
  
 
Server.default = s = Server.local.boot
 
Server.default = s = Server.local.boot
 
g = SwingOSC.default
 
g = SwingOSC.default
  
// SuperCollider tweet by 'micromoog'
+
// Original SuperCollider tweet by 'micromoog'
 
// http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899
 
// http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899
  
Line 107: Line 107:
 
// Outstanding unanswered question: how come the inner LFPulse of WhiteNoise.ar produces THREE short notes
 
// Outstanding unanswered question: how come the inner LFPulse of WhiteNoise.ar produces THREE short notes
 
// and ONE longer note? Why is it not two short and two long? (even with the phase change...)
 
// and ONE longer note? Why is it not two short and two long? (even with the phase change...)
 +
 +
 +
==headcube (Nathaniel Virgo)==
 +
<pre>
 +
// Original tweet by Nathaniel Virgo (headcube)
 +
// http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899
 +
 +
{LocalOut.ar(a=CombN.ar(BPF.ar(LocalIn.ar(2)*7.5+Saw.ar([32,33],0.2),2**LFNoise0.kr(4/3,4)*300,0.1).distort,2,2,40));a}.play//#supercollider
 +
</pre>
 +
 +
 +
==mathk==
 +
<pre>
 +
// Original tweet by mathk
 +
// http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899
 +
 +
{k=LFNoise1.kr(8.0.rand+2,0.5,0.5);SinOsc.ar([[333,444],[222,555]]*(k+(rrand(1.0,5.0))),0,k).sum.cubed * 0.1}.play // #supercollider #babies
 +
</pre>

Revision as of 02:14, 13 June 2011

This pages analyses and explains some "tweet-size" SuperCollider examples.

"A popular way to share SuperCollider code is to post it to the social networking site Twitter. This site imposes a restriction on the length of posts, limiting them to 140 characters or less. Creating an interesting sound or piece of music within this constraint has proved a popular challenge."

[quoted from http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899]

For more 140-character SuperCollider code, visit the link above. Feel free to contribute to this page with more analyses! [if you don't have edit access to this wiki, send it to ruviaro at stanford edu and I'll post it]


micromoog

// SuperCollider code analysis
// by Bruno Ruviaro, 2011-06-12

Server.default = s = Server.local.boot
g = SwingOSC.default

// Original SuperCollider tweet by 'micromoog'
// http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899

play{LFCub.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50))+(WhiteNoise.ar(LFPulse.kr(4,0,LFPulse.kr(1,3/4)/4+0.05))/8)!2}

// I'll start with the second part of the code, after the 'plus' sign.

//
// SECOND HALF OF THE PATCH: right side of + sign
//

// Listen to a LFPulse turning on and off some white noise.
// Frequency is 1 Hz, so one noise burst per second ("quarter notes").
// Notice that we actually have half a second of noise, and half second of silence.
// This is because the default "width" of LFPulse is 1/2.
{WhiteNoise.ar(LFPulse.kr(1))}.play

// By controlling the width parameter we can then control the note duration.
// The examples below are still 1 Hz ("quarter notes"), but the actual durations are different:
{WhiteNoise.ar(LFPulse.kr(freq: 1, width: 1/10))}.play // note dur is 1/10 of the beat (very "staccato")
{WhiteNoise.ar(LFPulse.kr(freq: 1, width: 0.9))}.play // note dur is 9/10 of the beat ("non legato") 

// Now let's make this white noise pulsate 4 times per beat ("sixteenth notes")
{WhiteNoise.ar(LFPulse.kr(4))}.play              // standard staccato (width default = 0.5)
{WhiteNoise.ar(LFPulse.kr(4, width: 0.05))}.play // much more staccato for the hi-hats

// What if I wanted to have one of the white noise bursts to simulate a snare drum?
// One out of ever four would have to be longer. The width parameter has to change accordingly.
// We can use another LFPulse to do just that.

{LFPulse.kr(1, mul: 1/4, add: 0.05).poll(8, label: "out")}.play // outputs 0.05 and 0.3 for half a second each

// Simply plug the line above into the white noise:
{WhiteNoise.ar(LFPulse.kr(4, width: LFPulse.kr(1, mul: 1/4, add: 0.05)))}.play

// The beginning was a little off, so we adjust the iphase of inner LFPulse:
{WhiteNoise.ar(LFPulse.kr(4, width: LFPulse.kr(1, iphase: 3/4, mul: 1/4, add: 0.05)))}.play

// Abbreviate this to make it "twitter friendly". Note that we add '0' as the iphase of first
// LFPulse in order to avoid having to declare the keyword 'width' after, saving several characters...
// Also, the original code divides the whole thing by 8 to scale its global amplitude in the mix.
{WhiteNoise.ar(LFPulse.kr(4,0,LFPulse.kr(1,3/4)/4+0.05))/8}.play

//
// FIRST HALF OF THE PATCH: left side of + sign
//

// This inner LFPulse outputs number 2 for three 'beats', then 4 for one beat (bpm: 60)
// LFPulse(freq, iphase, width, mul, add)
{(LFPulse.kr(1/4,1/4,1/4)*2+2).poll(4)}.play

// The LFPulse above controls the frequency of this LFSaw (2 or 4 Hz).
// With the mul/add, the LFSaw outputs a downward ramp from 70 to 30.
{LFSaw.kr(freq: LFPulse.kr(1/4,1/4,1/4)*2+2, iphase: 1, mul: -20, add: 50).poll}.play

// The LFSaw above controls the frequency of this LFCub. LFCub is more or less like a sine wave, different timbre.
// Thus we have a bass line glissando downwards from 70 Hz to 30 Hz; That LFPulse is controlling rhythm, then.
{LFCub.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50))}.play

// Compare how the same thing sounds using a SinOsc instead:
{SinOsc.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50))}.play

//
// MIXING THE TWO PARTS TOGETHER
//

// Here's the first and second half of the code, still isolated:

{LFCub.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50))}.play

{WhiteNoise.ar(LFPulse.kr(4,0,LFPulse.kr(1,3/4)/4+0.05))/8}.play

// A simple '+' puts them together:
{LFCub.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50)) + (WhiteNoise.ar(LFPulse.kr(4,0,LFPulse.kr(1,3/4)/4+0.05))/8)}.play

// Note that the WhiteNoise has been enclosed in parentheses to force its division by 8 to happen *before* the sum.
// Listen to it without parentheses:
{LFCub.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50)) + WhiteNoise.ar(LFPulse.kr(4,0,LFPulse.kr(1,3/4)/4+0.05))/8}.play // without parentheses: white noise too loud!

// Now add a !2 at the end of the line to make it stereo...
{LFCub.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50)) + (WhiteNoise.ar(LFPulse.kr(4,0,LFPulse.kr(1,3/4)/4+0.05))/8)!2}.play

// Finally, to save ONE more character, put the 'play' in the beginning:
play{LFCub.ar(LFSaw.kr(LFPulse.kr(1/4,1/4,1/4)*2+2,1,-20,50))+(WhiteNoise.ar(LFPulse.kr(4,0,LFPulse.kr(1,3/4)/4+0.05))/8)}

// Done!

// Outstanding unanswered question: how come the inner LFPulse of WhiteNoise.ar produces THREE short notes
// and ONE longer note? Why is it not two short and two long? (even with the phase change...)


==headcube (Nathaniel Virgo)==
<pre>
// Original tweet by Nathaniel Virgo (headcube)
// http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899

{LocalOut.ar(a=CombN.ar(BPF.ar(LocalIn.ar(2)*7.5+Saw.ar([32,33],0.2),2**LFNoise0.kr(4/3,4)*300,0.1).distort,2,2,40));a}.play//#supercollider


mathk

// Original tweet by mathk
// http://swiki.hfbk-hamburg.de:8888/MusicTechnology/899

{k=LFNoise1.kr(8.0.rand+2,0.5,0.5);SinOsc.ar([[333,444],[222,555]]*(k+(rrand(1.0,5.0))),0,k).sum.cubed * 0.1}.play // #supercollider #babies