Skip to content
Browse files

add whole contents of <ck> folder

  • Loading branch information...
1 parent ae3c5ad commit 2fcc09723698de377ac1de165883dcb2bee000a9 @hoch hoch committed Oct 9, 2012
Showing with 1,984 additions and 0 deletions.
  1. +125 −0 binaural/Binaural4.ck
  2. BIN binaural/ir/ballroom-4ch/ch1l.wav
  3. BIN binaural/ir/ballroom-4ch/ch1r.wav
  4. BIN binaural/ir/ballroom-4ch/ch2l.wav
  5. BIN binaural/ir/ballroom-4ch/ch2r.wav
  6. BIN binaural/ir/ballroom-4ch/ch3l.wav
  7. BIN binaural/ir/ballroom-4ch/ch3r.wav
  8. BIN binaural/ir/ballroom-4ch/ch4l.wav
  9. BIN binaural/ir/ballroom-4ch/ch4r.wav
  10. +28 −0 effects/chorusFile.ck
  11. +38 −0 effects/cubFile.ck
  12. +123 −0 effects/pan8chFileDAC.ck
  13. +82 −0 effects/panFileDAC.ck
  14. +9 −0 effects/pitADAC.ck
  15. +31 −0 effects/pitFile.ck
  16. +26 −0 effects/resoFile.ck
  17. +26 −0 effects/revFile.ck
  18. +27 −0 effects/stretchFile.ck
  19. +21 −0 jukebox/binauralTurenas.ck
  20. +21 −0 jukebox/quadHydroponicHydraulis.ck
  21. +21 −0 jukebox/quadTurenas.ck
  22. +29 −0 panning/ampPan.ck
  23. +30 −0 panning/delPan.ck
  24. +15 −0 panning/monoPan.ck
  25. +30 −0 panning/pwrAndDelPan.ck
  26. +63 −0 panning/pwrAndDelPanOSC.ck
  27. +30 −0 panning/pwrPan.ck
  28. +20 −0 reverbration/allpass.ck
  29. +35 −0 reverbration/allpassSeries3.ck
  30. +68 −0 reverbration/allpassSeries3LpfApAplApr.ck
  31. +14 −0 reverbration/comb.ck
  32. +45 −0 reverbration/combBank.ck
  33. +59 −0 reverbration/combOSC.ck
  34. +14 −0 reverbration/notch.ck
  35. +105 −0 reverbration/nrev.ck
  36. +76 −0 reverbration/nrevArray.ck
  37. +82 −0 reverbration/nrevArrayIR.ck
  38. +38 −0 synthesis/1-bellBeeps.ck
  39. +31 −0 synthesis/2-bellRestrike.ck
  40. +31 −0 synthesis/3-bellLonger.ck
  41. +35 −0 synthesis/4-bellOverlap.ck
  42. +48 −0 synthesis/5-bowl.ck
  43. +75 −0 synthesis/6-additiveADSR.ck
  44. +77 −0 synthesis/fmEnvOSC.ck
  45. +54 −0 synthesis/fmOSC.ck
  46. +70 −0 synthesis/sinEnvOSC.ck
  47. +55 −0 testtones/10-shepardTone.ck
  48. +37 −0 testtones/beepListeningRoom22ch.ck
  49. +31 −0 testtones/binBeeps.ck
  50. +34 −0 testtones/dacBeepsListeningRoom16.ck
  51. +32 −0 testtones/dacBeepsListeningRoom8.ck
  52. +43 −0 utilities/StereoRecorder.ck
View
125 binaural/Binaural4.ck
@@ -0,0 +1,125 @@
+// @title Binaural4.ck
+// @author Chris Chafe (cc@ccrma)
+// @desc Simulates the head being surrounded by 4 speakers and
+// delivers tailored signals to each ear, as if coming from
+// the speakers.
+// @note Plug headphones into dac.chan(1-2) and start it after
+// it's started, other shreds can send their signals to
+// Binaural.pssp[1-4] which are the "psuedo speakers" in quad
+// formation. Impulse responses were made from each speaker
+// to each ear using the nearfield quad setup in the CCRMA
+// ballroom with help from Jonathan Abel.
+// @version chuck-1.3.1.3
+// @revision 1
+
+// name:: Binaural4
+// desc:: 4-channel binaural simulator
+public class Binaural4
+{
+ // number of synthesized point sources
+ // which will be the number of speakers that produced impulse responses
+ ["a45", "a135", "a225", "a315"] @=> string azims[];
+ ["e0"] @=> string elevs[];
+ azims.cap() * elevs.cap() => int nChans;
+
+ // psuedo speakers
+ static Gain @ pssp[nChans];
+ for (0 => int i; i < nChans; ++i) new Gain @=> pssp[i];
+
+ // function to convolve 1 input with 1 ear
+ fun void mixEar(int chan, int e) {
+ string ear;
+ if (!e) "l" => ear; else "r" => ear;
+ azims[chan%azims.cap()] + elevs[chan/azims.cap()] + ear => string name;
+
+ // impulse response location
+ "[path_to_your_IR_file_location]"+name+".wav" => string Yname;
+ SndBuf Ybuf;
+ Yname => Ybuf.read;
+ Ybuf.gain(50.0);
+ FFT X;
+ Delay del;
+
+ // patch input to fft
+ if ((chan == 0) || (chan == 3)) {
+ pssp[chan] => X => blackhole;
+ } else {
+ // compensate rear angles a bit with ITD and IID
+ pssp[chan] => del => X => blackhole;
+ 0.5::ms => dur ITD;
+ 2.5 => float IID;
+ if (chan == 1) {
+ if (e == 0) del.delay(0::ms);
+ else del.delay(ITD);
+ if (e == 0) del.gain(IID);
+ else del.gain(1.0/IID);
+ } else {
+ if (e == 0) del.delay(ITD);
+ else del.delay(0::ms);
+ if (e == 0) del.gain(1.0/IID);
+ else del.gain(IID);
+ }
+ }
+
+ // patch impulse response to fft
+ Ybuf => FFT Y => blackhole;
+ // patch output to dac
+ IFFT ifft => dac.chan(e);
+
+ // set FFT size
+ 1024 => int FFT_SIZE;
+ if (FFT_SIZE < (Ybuf.samples())) <<<"need longer fft ", FFT_SIZE, Ybuf.samples()>>>;
+ FFT_SIZE => X.size => Y.size;
+ // desired hop size
+ FFT_SIZE / 4 => int HOP_SIZE;
+ // set window and window size
+ Windowing.hann(FFT_SIZE) => X.window;
+ Windowing.rectangle(FFT_SIZE) => Y.window;
+ Windowing.hann(FFT_SIZE) => ifft.window;
+ // use this to hold contents
+ complex Z[FFT_SIZE/2];
+
+ // feed impulse response into fft buffer
+ Ybuf.samples()::samp + now => time ir; // zero pad
+ while(now < ir) FFT_SIZE::samp => now;
+ Ybuf =< Y =< blackhole;
+ // take ir's fft
+ Y.upchuck();
+
+ while(true) {
+ // take incoming signal's fft
+ X.upchuck();
+
+ // multiply
+ for(0 => int i; i < X.size()/2; ++i) {
+ //Math.sqrt((Y.cval(i)$polar).mag) * X.cval(i) => Z[i]; // ask about this?
+ 2 * Y.cval(i) * X.cval(i) => Z[i];
+ }
+
+ // take ifft
+ ifft.transform( Z );
+
+ // advance time
+ HOP_SIZE::samp => now;
+ }
+ }
+
+ // mixing matrix 24x2
+ for (0 => int i; i < nChans; ++i) {
+ spork ~ mixEar(i,0);
+ spork ~ mixEar(i,1);
+ }
+}
+
+
+// ------------------------------------------------------------------
+// instantiate and tweak gains
+Binaural4 b4;
+for (0 => int i; i < b4.nChans; ++i) {
+ b4.pssp[i].gain(3.0);
+}
+
+// infinite stall
+while(true){
+ 1::day=>now;
+}
View
BIN binaural/ir/ballroom-4ch/ch1l.wav
Binary file not shown.
View
BIN binaural/ir/ballroom-4ch/ch1r.wav
Binary file not shown.
View
BIN binaural/ir/ballroom-4ch/ch2l.wav
Binary file not shown.
View
BIN binaural/ir/ballroom-4ch/ch2r.wav
Binary file not shown.
View
BIN binaural/ir/ballroom-4ch/ch3l.wav
Binary file not shown.
View
BIN binaural/ir/ballroom-4ch/ch3r.wav
Binary file not shown.
View
BIN binaural/ir/ballroom-4ch/ch4l.wav
Binary file not shown.
View
BIN binaural/ir/ballroom-4ch/ch4r.wav
Binary file not shown.
View
28 effects/chorusFile.ck
@@ -0,0 +1,28 @@
+// reads mono file and processes with Chorus while writing mono file
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a/jukebox/simulationNot.wav" => filename0;
+string filename1;
+"/zap/test.wav" => filename1;
+<<< "processing mono sound file ",filename0," into ",filename1>>>;
+
+SndBuf w0 => Chorus c => WvOut w1 => blackhole;
+filename0 => w0.read;
+filename1 => w1.wavFilename;
+
+0.9 => c.mix;
+10.0 => c.modFreq;
+0.1 => c.modDepth;
+
+w0.length() => dur l;
+now + l + 1::second => time then; // 1 second tail
+while( now < then )
+{
+100::samp => now;
+}
+
+w1.closeFile();
+
+
+
+
View
38 effects/cubFile.ck
@@ -0,0 +1,38 @@
+// reads mono file and processes with cubic non-linearity while writing mono file
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a/jukebox/simulationNot.wav" => filename0;
+string filename1;
+"/zap/test.wav" => filename1;
+<<< "processing mono sound file ",filename0," into ",filename1>>>;
+
+SndBuf w0 => Gain g => WvOut w1 => blackhole;
+3=>w1.op; // multiply inputs -- see below
+g => w1; // times itself
+g => w1; // again
+g.gain(1.5); // depends on input, might need boost
+filename0 => w0.read;
+filename1 => w1.wavFilename;
+
+w0.length() => dur l;
+now + l + 1::second => time then; // 1 second tail
+while( now < then )
+{
+100::samp => now;
+}
+
+w1.closeFile();
+
+/*
+# op(int) (of type int): set/get operation at the UGen. Values:
+
+ * 0 : stop - always output 0
+ * 1 : normal operation, add all inputs (default)
+ * 2 : normal operation, subtract inputs starting from the earliest connected
+ * 3 : normal operation, multiply all inputs
+ * 4 : normal operation, divide inputs starting from the earlist connected
+ * -1 : passthru - all inputs to the ugen are summed and passed directly to output
+
+*/
+
+
View
123 effects/pan8chFileDAC.ck
@@ -0,0 +1,123 @@
+// tell how many DAC channels in your Chuck preferences
+// choose a speaker pattern and whether to useITD (headphones)
+// and / or useREV (for distance)
+8 => int chansChuck;
+false => int useITD; // only if using headphones
+false => int useREV; // for distance effect, false = azimuth only
+
+// panning and distance envelopes (no doppler envelope)
+// demonstrates intensity panning via interaural intensity difference (IID) and
+// square-law distance effect (direct / reverb) and
+// some effect of interaural time delay (ITD)
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a-fall-2010/jukebox/simulationNot.wav" => filename0;
+//"/home/cc/220a/jukebox/simulationNot.wav" => filename0;
+
+// speaker patterns, these examples for CCRMA rooms have speakers numbered in a Z pattern
+[0, 1] @=> int stereo[]; // 2 chans
+[0, 1, 3, 2] @=> int four4[]; // 4 chans in a 4 channel room -- Classroom, workstations
+[0, 1, 3, 5, 7, 6, 4, 2] @=> int eight8[]; // 8 chans in any of the 8 channel rooms
+
+[0, 1, 2, 3] @=> int four4circle[]; // Banff
+[0, 1, 2, 3, 4, 5, 6, 7] @=> int eight8circle[]; // Banff
+//[0, 1, 7, 6] @=> int four8Long[]; // 4 chans in 8 channel rectangular setup using front / back -- Stage
+//[2, 3, 5, 4] @=> int four8Mid[]; // 4 chans in 8 channel rectangular setup using middle group -- Stage
+//[0, 3, 7, 4] @=> int four8[]; // 4 chans in 8 channel -- Listening Room, Studios D & E
+
+// choose a pattern from above
+eight8 @=> int mapChan[];
+
+mapChan.cap() => int nChans;
+1.0::ms => dur width; // time travel across your head
+0.03 => float revAmt;
+
+for (nChans => int i; i < chansChuck; i++) dac.chan(i).gain(0.0);
+for (0 => int i; i < nChans; i++) dac.chan(i).gain(1.0);
+SndBuf src;
+//SinOsc src;
+
+class Move
+{
+ Gain direct;
+ NRev rev;
+ DelayL itd[nChans];
+ Gain g[nChans];
+
+SawOsc recede => blackhole;
+recede.width(1.0);
+recede.freq(0.125);
+recede.phase(pi/4);
+
+SawOsc rotate => blackhole;
+rotate.width(1.0);
+rotate.freq(0.125);
+rotate.phase(pi/4);
+
+ if (useREV)
+ {
+ src => direct;
+ src => rev => dac;
+ rev.gain(revAmt);
+ }
+ if (useITD)
+ {
+ if (useREV)
+ for (0 => int i; i < nChans; i++) direct => itd[i] => dac.chan(mapChan[i]);
+ else
+ for (0 => int i; i < nChans; i++) src => itd[i] => dac.chan(mapChan[i]);
+ for (0 => int i; i < nChans; i++) itd[i].delay(width); // set here in case not set later
+ } else {
+ if (useREV)
+ for (0 => int i; i < nChans; i++) direct => g[i] => dac.chan(mapChan[i]);
+ else
+ for (0 => int i; i < nChans; i++) src => g[i] => dac.chan(mapChan[i]);
+ }
+
+ fun void run()
+ {
+ while (true)
+ {
+ (recede.last()+1.0) * 2.0 => float dist; // 0.0 - 1.0 - 2.0 inside head, speaker circle, distant
+ //1.0 => dist; // for constant distance
+ if (dist > 1.0)
+ {
+ direct.gain( 1.0 / (dist*dist) );
+ if (useREV) rev.gain(revAmt);
+ } else {
+ direct.gain(1.0);
+ if (useREV) rev.gain(revAmt * Math.pow(dist,2.0));
+ }
+ (rotate.last()+1.0)*0.5 => float theta; // 0.0 - 1.0 for full rotation
+ //0.3 => theta; // for constant angle
+ //<<<theta>>>;
+ Math.min(1.0, dist) => float distInside;
+ for (0 => int i; i < nChans; i++)
+ {
+ Math.sin(
+ Math.max(0.0, 1.0 -
+ Math.fabs(
+ Math.fmod(theta+0.5+(((nChans-i) $ float) /nChans), 1.0)
+ - 0.5)
+ * (nChans*distInside))) * (distInside/2.0+0.5) => float chanAmp;
+ if (useITD)
+ {
+ itd[i].gain( chanAmp ); // interaural intensity difference
+ itd[i].delay( distInside * width * Math.asin(1.0 - chanAmp) ); // interaural time delay
+ } else {
+ g[i].gain( chanAmp );
+ }
+ }
+ 10::ms => now;
+ }
+ }
+ spork ~ run(); // run run
+}
+Move loc;
+
+while (true) // loop input file
+{
+ filename0 => src.read; // read file again
+ src.length() => dur l; // how long file lasts
+ l => now;
+}
View
82 effects/panFileDAC.ck
@@ -0,0 +1,82 @@
+// panning and distance envelopes (with pitch shifter, but no doppler envelope)
+// demonstrates intensity panning via interaural intensity difference (IID) and
+// square-law distance effect (direct / reverb) and
+// some effect of interaural time delay (IID)
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a/jukebox/simulationNot.wav" => filename0;
+4 => int nChans;
+SndBuf w0 => PitShift p => Gain direct;
+w0 => NRev r => Gain rev => dac;
+0.001 => rev.gain;
+1.0::ms => dur width; // time delay across ears for motion
+DelayL itd[nChans];
+for (0 => int i; i < nChans; i++) direct => itd[i] => dac.chan(i);
+for (0 => int i; i < nChans; i++) itd[i].delay(width); // set here in case not set later
+float chLoc[nChans];
+for (0 => int i; i < nChans; i++) (4-i)*pi/2 => chLoc[i];
+
+1.0 => p.mix;
+1.0 => p.shift; // change for moving voice differing from reverb voice
+// 4.5 => p.shift; // very odd...
+
+// new class to manage envelopes
+class Env
+{
+ Step s => Envelope e => blackhole; // feed constant into env
+ fun void current (float val) { e.value(val); }
+ fun void target (float val) { e.target(val); }
+ fun void duration (dur val) { e.duration(val); }
+}
+
+class Distance extends Env // for gain
+{
+ fun void run() // sample loop to smoothly update gain
+ {
+ while (true)
+ {
+ direct.gain( Math.pow(e.last(), 2.0) );
+ 1::samp => now;
+ }
+ }
+ spork ~ run(); // run run
+};
+Distance distanceMotion;
+
+class Pan extends Env // for gain
+{
+ fun void run() // sample loop to smoothly update gain
+ {
+ while (true)
+ {
+ e.last() * 0.5 * pi => float angle;
+ for (0 => int i; i < nChans; i++)
+ {
+ Math.max(0.0, Math.cos(angle + chLoc[i])) => float tmp;
+ itd[i].gain( tmp ); // interaural intensity difference
+ itd[i].delay( width * Math.asin(1.0 - tmp) ); // interaural time delay
+ }
+ 1::samp => now;
+ }
+ }
+ spork ~ run(); // run run
+};
+Pan panMotion;
+
+1 => int close; // like in, I'm close
+distanceMotion.current(close);
+0 => int spkr; // like in, I'm on the left
+panMotion.current(spkr);
+while (true) // loop input file
+{
+ filename0 => w0.read; // read file again
+ w0.length() => dur l; // how long file lasts
+// comment out these two distance lines if you just want rotation
+ distanceMotion.duration(l); // is how long to ramp distance
+ distanceMotion.target(!close); // move me close or far
+ !close => close; // alternating-ly -- is that a word?
+ panMotion.duration(l); // ditto angle panning
+ panMotion.target((spkr+1)%nChans);// move me clockwise one speaker
+ (spkr+1)%nChans => spkr; // in a loop
+ l => now;
+}
View
9 effects/pitADAC.ck
@@ -0,0 +1,9 @@
+// real-time efx demo
+
+adc => PitShift p => dac;
+1.0 => p.mix;
+0.75 => p.shift;
+day => now;
+
+
+
View
31 effects/pitFile.ck
@@ -0,0 +1,31 @@
+// reads mono file and processes with PitShift while writing mono file
+// can be run much faster than real time with
+// chuck --silent pitFile.ck
+
+// set your own file names before running this
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a/jukebox/simulationNot.wav" => filename0;
+string filename1;
+"/zap/test.wav" => filename1; // your other name here
+<<< "processing mono sound file ",filename0," into ",filename1>>>;
+
+SndBuf w0 => PitShift p => WvOut w1 => blackhole;
+filename0 => w0.read;
+filename1 => w1.wavFilename;
+
+1.0 => p.mix;
+2.5 => p.shift;
+
+w0.length() => dur l;
+now + l => time then;
+while( now < then )
+{
+100::samp => now;
+}
+
+w1.closeFile();
+
+
+
+
View
26 effects/resoFile.ck
@@ -0,0 +1,26 @@
+// reads mono file and processes with ResonZ while writing mono file
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a/jukebox/simulationNot.wav" => filename0;
+string filename1;
+"/zap/test.wav" => filename1;
+<<< "processing mono sound file ",filename0," into ",filename1>>>;
+
+SndBuf w0 => ResonZ r => WvOut w1 => blackhole;
+
+r.freq(3000.0); // resonance freq
+r.Q(300.0); // sharpness
+r.gain(30.0); // might need boost
+
+filename0 => w0.read;
+filename1 => w1.wavFilename;
+
+w0.length() => dur l;
+now + l + 1::second => time then; // 1 second tail
+while( now < then )
+{
+100::samp => now;
+}
+
+w1.closeFile();
+
View
26 effects/revFile.ck
@@ -0,0 +1,26 @@
+// reads mono file and processes with NRev while writing mono file
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a/jukebox/simulationNot.wav" => filename0;
+string filename1;
+"/zap/test.wav" => filename1;
+<<< "processing mono sound file ",filename0," into ",filename1>>>;
+
+SndBuf w0 => NRev r => WvOut w1 => blackhole;
+filename0 => w0.read;
+filename1 => w1.wavFilename;
+
+0.1 => r.mix;
+
+w0.length() => dur l;
+now + l + 1::second => time then; // 1 second tail
+while( now < then )
+{
+100::samp => now;
+}
+
+w1.closeFile();
+
+
+
+
View
27 effects/stretchFile.ck
@@ -0,0 +1,27 @@
+// reads mono file and extends with PitShift up and rate down while writing mono file
+
+string filename0;
+"/usr/ccrma/web/html/courses/220a-fall-2010/jukebox/simulationNot.wav" => filename0;
+string filename1;
+"/zap/test.wav" => filename1;
+<<< "processing mono sound file ",filename0," into ",filename1>>>;
+
+SndBuf w0 => PitShift p => WvOut w1 => blackhole;
+filename0 => w0.read;
+filename1 => w1.wavFilename;
+
+1.0 => p.mix;
+2.0 => p.shift; // double
+0.5 => w0.rate; // half
+w0.length() / w0.rate() => dur l; // extend
+now + l => time then;
+while( now < then )
+{
+100::samp => now;
+}
+
+w1.closeFile();
+
+
+
+
View
21 jukebox/binauralTurenas.ck
@@ -0,0 +1,21 @@
+4 => int nChans;
+
+SndBuf ch[nChans];
+
+for (0=>int i; i<nChans; i++)
+{
+ string tname;
+ if(i==0) "RF" => tname;
+ else if(i==1) "LF" => tname;
+ else if(i==2) "LR" => tname;
+ else "RR" => tname;
+ "/usr/ccrma/web/html/courses/220a/jukebox/turenas4ch/turenas"+tname+".wav" => string Xname;
+<<<Xname>>>;
+ new SndBuf @=> ch[i];
+ Xname => ch[i].read;
+ ch[i] => Binaural.pssp[i];
+ ch[i].pos(48000*40);
+}
+
+while(true){1::day=>now;};
+
View
21 jukebox/quadHydroponicHydraulis.ck
@@ -0,0 +1,21 @@
+4 => int nChans;
+
+SndBuf ch[nChans];
+
+for (0=>int i; i<nChans; i++)
+{
+ string tname;
+ if(i==0) "RF" => tname;
+ else if(i==1) "LF" => tname;
+ else if(i==2) "LR" => tname;
+ else "RR" => tname;
+ "/usr/ccrma/web/html/courses/220a/jukebox/hydroponicHydraulis4ch/hh"+tname+".wav" => string Xname;
+<<<Xname>>>;
+ new SndBuf @=> ch[i];
+ Xname => ch[i].read;
+ ch[i] => dac.chan(i);
+ ch[i].pos(48000*0);
+}
+
+while(true){1::day=>now;};
+
View
21 jukebox/quadTurenas.ck
@@ -0,0 +1,21 @@
+4 => int nChans;
+
+SndBuf ch[nChans];
+
+for (0=>int i; i<nChans; i++)
+{
+ string tname;
+ if(i==0) "RF" => tname;
+ else if(i==1) "LF" => tname;
+ else if(i==2) "LR" => tname;
+ else "RR" => tname;
+ "/usr/ccrma/web/html/courses/220a-fall-2011/jukebox/turenas4ch/turenas"+tname+".wav" => string Xname;
+<<<Xname>>>;
+ new SndBuf @=> ch[i];
+ Xname => ch[i].read;
+ ch[i] => dac.chan(i);
+ ch[i].pos(48000*40); // to advance the position further into the file -- 40 secs
+}
+
+while(true){1::day=>now;};
+
View
29 panning/ampPan.ck
@@ -0,0 +1,29 @@
+// amplitude panning
+
+adc => DelayL left => dac.left;
+adc => DelayL right => dac.right;
+
+class Dizzy { // up/down sweeping in range 0.0 to 1.0
+ TriOsc t => Gain sum => blackhole; // triangle wave -1.0 to 1.0
+ Step u => sum; // add offset from Step UG
+ 1.0 => u.next; // offset is 1.0, range now 0.0 to 2.0
+ 0.5 => sum.gain; // scale gain output, now 0.0 to 1.0
+ public float freq( float f ) { f => t.freq; }
+ public float last() { return sum.last(); }
+}
+
+Dizzy lfo;
+0.5 => lfo.freq; // set lfo to 2 second cycle
+
+// ITD
+0::ms => left.delay; // no delay effect
+0::ms => right.delay;
+
+while (true)
+{
+ lfo.last() => float pan; // get pan from most recent lfo value
+ // IID
+ 1.0 - pan => left.gain;
+ pan => right.gain;
+ 0.001::second => now;
+}
View
30 panning/delPan.ck
@@ -0,0 +1,30 @@
+// delay panning
+
+adc => DelayL left => dac.left;
+adc => DelayL right => dac.right;
+
+class Dizzy { // up/down sweeping in range 0.0 to 1.0
+ TriOsc t => Gain sum => blackhole; // triangle wave -1.0 to 1.0
+ Step u => sum; // add offset from Step UG
+ 1.0 => u.next; // offset is 1.0, range now 0.0 to 2.0
+ 0.5 => sum.gain; // scale gain output, now 0.0 to 1.0
+ public float freq( float f ) { f => t.freq; }
+ public float last() { return sum.last(); }
+}
+
+Dizzy lfo;
+0.5 => lfo.freq; // set lfo to 2 second cycle
+
+// IID
+0.5 => left.gain;
+0.5 => right.gain;
+
+while (true)
+{
+ lfo.last() => float pan; // get pan from most recent lfo value
+ // ITD
+ 1.0 => float width; // 1ms for headphones, less for speakers
+ pan * width * 1::ms => left.delay;
+ (1.0 - pan) * width * 1::ms => right.delay;
+ 0.001::second => now;
+}
View
15 panning/monoPan.ck
@@ -0,0 +1,15 @@
+// centered image
+
+adc => Delay left => dac.left;
+adc => Delay right => dac.right;
+
+// ITD
+0::ms => left.delay;
+0::ms => right.delay;
+
+// IID
+0.5 => left.gain;
+0.5 => right.gain;
+
+30::second => now;
+<<<"done">>>;
View
30 panning/pwrAndDelPan.ck
@@ -0,0 +1,30 @@
+// combined power and delay panning
+
+adc => DelayL left => dac.left;
+adc => DelayL right => dac.right;
+
+class Dizzy { // up/down sweeping in range 0.0 to 1.0
+ TriOsc t => Gain sum => blackhole; // triangle wave -1.0 to 1.0
+ Step u => sum; // add offset from Step UG
+ 1.0 => u.next; // offset is 1.0, range now 0.0 to 2.0
+ 0.5 => sum.gain; // scale gain output, now 0.0 to 1.0
+ public float freq( float f ) { f => t.freq; }
+ public float last() { return sum.last(); }
+}
+
+Dizzy lfo;
+0.5 => lfo.freq; // set lfo to 2 second cycle
+
+while (true)
+{
+ lfo.last() => float pan; // get pan from most recent lfo value
+ // ITD
+ 1.0 => float width; // 1ms for headphones, less for speakers
+ pan * width * 1::ms => left.delay;
+ (1.0 - pan) * width * 1::ms => right.delay;
+ ( pi / 2.0 ) *=> pan; // range 0.0 to pi/2
+ // IID
+ Math.cos( pan )=> left.gain;
+ Math.sin( pan ) => right.gain;
+ 0.001::second => now;
+}
View
63 panning/pwrAndDelPanOSC.ck
@@ -0,0 +1,63 @@
+// power and delay panning from a slider
+
+// copy/paste into terminal:
+// java -jar /usr/ccrma/web/html/courses/220a-fall-2011/java/javaosc/lib/javaoscfull.jar
+
+// then hit button in GUI: Set Address
+// and hit: All On
+
+adc => DelayL left => dac.left;
+adc => DelayL right => dac.right;
+
+class slider { // access java slider example by receiving OSC events
+ fun float javaRange( float f) { return ((f - 20.0) / 10000.0); } // its range
+ javaRange( 440.0) => float topVal; // top-most horizontal slider initial val
+ OscRecv recv; // chuck object for OSC
+ 57110 => recv.port; // listen on localhost port 57110
+ recv.listen(); // start listening (launch thread)
+ // java example transmits to OSC address /n_set, formatted "i s f"
+ // create an address in the receiver, store in new variable
+ recv.event( "/n_set, i s f" ) @=> OscEvent @ oe;
+
+ fun void loop() { // infinite event loop
+ while( true )
+ {
+ oe => now; // wait for event to arrive
+ while( oe.nextMsg() ) // grab the next message from the queue.
+ {
+ // getInt fetches the expected int (as indicated by "i")
+ oe.getInt() => int i;
+ // getString fetches the expected int (as indicated by "s")
+ oe.getString() => string s;
+ // getFloat fetches the expected int (as indicated by "f")
+ oe.getFloat() => float f;
+ // <<< "got (from javaosc):", i, s, f >>>;
+ if (i == 1000) { // this is the top slider ID in java example
+ // <<< "(top):", f >>>;
+ javaRange(f) => topVal; // scale to 0.0 - 1.0 range
+ }
+ // not using the mid or bottom sliders so just print
+ else if (i == 1001) <<< "(mid):", f >>>;
+ else if (i == 1002) <<< "(bot):", f >>>;
+ }
+ }
+ }
+ spork ~ loop(); // start the infinite event loop listening
+ public float last() { return topVal; } // method to get current slider value
+}
+
+slider sl; // instantiate a slider instance
+
+while (true)
+{
+ sl.last() => float pan; // get current slider
+ // ITD
+ 1.0 => float width; // 1ms for headphones, less for speakers
+ pan * width * 1::ms => left.delay;
+ (1.0 - pan) * width * 1::ms => right.delay;
+ ( pi / 2.0 ) *=> pan; // range 0.0 to pi/2
+ // IID
+ Math.cos( pan )=> left.gain;
+ Math.sin( pan ) => right.gain;
+ 0.001::second => now;
+}
View
30 panning/pwrPan.ck
@@ -0,0 +1,30 @@
+// intensity (power) panning
+
+adc => DelayL left => dac.left;
+adc => DelayL right => dac.right;
+
+class Dizzy { // up/down sweeping in range 0.0 to 1.0
+ TriOsc t => Gain sum => blackhole; // triangle wave -1.0 to 1.0
+ Step u => sum; // add offset from Step UG
+ 1.0 => u.next; // offset is 1.0, range now 0.0 to 2.0
+ 0.5 => sum.gain; // scale gain output, now 0.0 to 1.0
+ public float freq( float f ) { f => t.freq; }
+ public float last() { return sum.last(); }
+}
+
+Dizzy lfo;
+0.5 => lfo.freq; // set lfo to 2 second cycle
+
+// ITD
+0::ms => left.delay; // no delay effect
+0::ms => right.delay;
+
+while (true)
+{
+ lfo.last() => float pan; // get pan from most recent lfo value
+ ( pi / 2.0 ) *=> pan; // range 0.0 to pi/2
+ // IID
+ Math.cos( pan )=> left.gain;
+ Math.sin( pan ) => right.gain;
+ 0.001::second => now;
+}
View
20 reverbration/allpass.ck
@@ -0,0 +1,20 @@
+// demo of a simple allpass delay (creates a colorless recirculating delay)
+
+adc => DelayL d => dac;
+// add a feedforward path
+adc => Gain ff => dac;
+// add a feedback path
+Gain fb => d => fb;
+
+// try different values of delay
+3000::samp => d.delay;
+
+// try different values of allpass coefficient
+0.8 => float apc;
+-apc => fb.gain;
+apc => ff.gain;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
35 reverbration/allpassSeries3.ck
@@ -0,0 +1,35 @@
+// demo of 3 allpass sections in series
+
+// ap1
+adc => DelayL d1 => Gain ap1Sum;
+adc => Gain ff1 => ap1Sum;
+Gain fb1 => d1 => fb1;
+
+// ap2
+ap1Sum => DelayL d2 => Gain ap2Sum;
+ap1Sum => Gain ff2 => ap2Sum;
+Gain fb2 => d2 => fb2;
+
+// ap3
+ap2Sum => DelayL d3 => dac;
+ap2Sum => Gain ff3 => dac;
+Gain fb3 => d3 => fb3;
+
+// try different values of delay
+347.0::samp => d1.delay;
+113.0::samp => d2.delay;
+37.0::samp => d3.delay;
+
+// try different values of allpass coefficient
+0.5 => float apc;
+-apc => fb1.gain;
+apc => ff1.gain;
+-apc => fb2.gain;
+apc => ff2.gain;
+-apc => fb3.gain;
+apc => ff3.gain;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
68 reverbration/allpassSeries3LpfApAplApr.ck
@@ -0,0 +1,68 @@
+// Nrev without the comb bank
+
+// allpass, lowpass coefficients
+0.6 => float apc;
+0.7 => float lpc;
+
+// series ap1, ap2, ap3, lpf, ap4
+// ap1
+adc => DelayL d1 => Gain ap1Sum;
+adc => Gain ff1 => ap1Sum;
+Gain fb1 => d1 => fb1;
+
+// ap2
+ap1Sum => DelayL d2 => Gain ap2Sum;
+ap1Sum => Gain ff2 => ap2Sum;
+Gain fb2 => d2 => fb2;
+
+// ap3
+ap2Sum => DelayL d3 => Gain ap3Sum;
+ap2Sum => Gain ff3 => ap3Sum;
+Gain fb3 => d3 => fb3;
+
+// lpf
+ap3Sum => OnePole lpf;
+
+// ap4
+lpf => DelayL d4 => Gain ap4Sum;
+lpf => Gain ff4 => ap4Sum;
+Gain fb4 => d4 => fb4;
+
+// stereo split to uncorrelated signals for left and right
+// ap5 -- left side
+ap4Sum => DelayL d5 => dac.left;
+ap4Sum => Gain ff5 => dac.left;
+Gain fb5 => d5 => fb5;
+
+// ap6 -- right side
+ap4Sum => DelayL d6 => dac.right;
+ap4Sum => Gain ff6 => dac.right;
+Gain fb6 => d6 => fb6;
+
+// NREV delays
+347.0::samp => d1.delay;
+113.0::samp => d2.delay;
+37.0::samp => d3.delay;
+59.0::samp => d4.delay;
+53.0::samp => d5.delay;
+43.0::samp => d6.delay;
+
+-apc => fb1.gain;
+apc => ff1.gain;
+-apc => fb2.gain;
+apc => ff2.gain;
+-apc => fb3.gain;
+apc => ff3.gain;
+lpc => lpf.a1;
+1.0 - lpc => lpf.b0;
+-apc => fb4.gain;
+apc => ff4.gain;
+-apc => fb5.gain;
+apc => ff5.gain;
+-apc => fb6.gain;
+apc => ff6.gain;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
14 reverbration/comb.ck
@@ -0,0 +1,14 @@
+// demo of a comb filter (IIR)
+
+// add a feedback path through a delay
+adc => DelayL d => dac;
+Gain fb => d => fb;
+
+// try different values of delay and gain
+300::samp => d.delay;
+0.8 => fb.gain;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
45 reverbration/combBank.ck
@@ -0,0 +1,45 @@
+// bank of 6 combs in parallel
+
+adc => Gain direct => dac;
+adc => Gain reverb;
+0.5 => direct.gain; // direct amount
+0.1 => reverb.gain; // reverb amount
+0.9995 => float R; // radius, affects reverb time
+
+reverb => DelayL d1 => dac;
+Gain fb1 => d1 => fb1;
+reverb => DelayL d2 => dac;
+Gain fb2 => d2 => fb2;
+reverb => DelayL d3 => dac;
+Gain fb3 => d3 => fb3;
+reverb => DelayL d4 => dac;
+Gain fb4 => d4 => fb4;
+reverb => DelayL d5 => dac;
+Gain fb5 => d5 => fb5;
+reverb => DelayL d6 => dac;
+Gain fb6 => d6 => fb6;
+
+// NREV combs
+1433.0 => float L1;
+1601.0 => float L2;
+1867.0 => float L3;
+2053.0 => float L4;
+2251.0 => float L5;
+2399.0 => float L6;
+L1::samp => d1.delay;
+L2::samp => d2.delay;
+L3::samp => d3.delay;
+L4::samp => d4.delay;
+L5::samp => d5.delay;
+L6::samp => d6.delay;
+Math.pow( R, L1 ) => fb1.gain;
+Math.pow( R, L2 ) => fb2.gain;
+Math.pow( R, L3 ) => fb3.gain;
+Math.pow( R, L4 ) => fb4.gain;
+Math.pow( R, L5 ) => fb5.gain;
+Math.pow( R, L6 ) => fb6.gain;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
59 reverbration/combOSC.ck
@@ -0,0 +1,59 @@
+// demo of a comb filter (IIR) with slider
+
+// copy/paste into terminal:
+// java -jar /usr/ccrma/web/html/courses/220a-fall-2010/java/javaosc/lib/javaoscfull.jar
+
+// then hit button in GUI: Set Address
+// and hit: All On
+
+adc => DelayL d => dac;
+Gain fb => d => fb;
+
+class slider { // access java slider example by receiving OSC events
+ fun float javaRange( float f) { return ((f - 20.0) / 10000.0); } // its range
+ javaRange( 440.0) => float topVal; // top-most horizontal slider initial val
+ OscRecv recv; // chuck object for OSC
+ 57110 => recv.port; // listen on localhost port 57110
+ recv.listen(); // start listening (launch thread)
+ // java example transmits to OSC address /n_set, formatted "i s f"
+ // create an address in the receiver, store in new variable
+ recv.event( "/n_set, i s f" ) @=> OscEvent @ oe;
+
+ fun void loop() { // infinite event loop
+ while( true )
+ {
+ oe => now; // wait for event to arrive
+ while( oe.nextMsg() ) // grab the next message from the queue.
+ {
+ // getInt fetches the expected int (as indicated by "i")
+ oe.getInt() => int i;
+ // getString fetches the expected int (as indicated by "s")
+ oe.getString() => string s;
+ // getFloat fetches the expected int (as indicated by "f")
+ oe.getFloat() => float f;
+ // <<< "got (from javaosc):", i, s, f >>>;
+ if (i == 1000) { // this is the top slider ID in java example
+ // <<< "(top):", f >>>;
+ javaRange(f) => topVal; // scale to 0.0 - 1.0 range
+ }
+ // not using the mid or bottom sliders so just print
+ else if (i == 1001) <<< "(mid):", f >>>;
+ else if (i == 1002) <<< "(bot):", f >>>;
+ }
+ }
+ }
+ spork ~ loop(); // start the infinite event loop listening
+ public float last() { return topVal; } // method to get current slider value
+}
+
+slider sl; // instantiate a slider instance
+
+// try different values of delay and gain
+0.8=> fb.gain;
+
+while (true)
+{
+ sl.last() => float delay; // get current slider, 0.0 t0 1.0 range
+ delay * 1000::samp => d.delay;
+ 0.001::second => now;
+}
View
14 reverbration/notch.ck
@@ -0,0 +1,14 @@
+// demo of a notch filter (FIR)
+
+// add a feedforward path around a delay
+adc => DelayL d => dac;
+adc => Gain ff => dac;
+
+// try different values of delay and gain
+300::samp => d.delay;
+0.999 => ff.gain;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
105 reverbration/nrev.ck
@@ -0,0 +1,105 @@
+// Nrev the hard way
+
+// allpass, lowpass coefficients
+0.6 => float apc;
+0.7 => float lpc;
+adc => Gain direct => dac;
+adc => Gain reverb;
+0.5 => direct.gain; // direct amount
+0.1 => reverb.gain; // reverb amount
+0.9995 => float R; // radius, affects reverb time
+
+reverb => DelayL dc1 => Gain combSum;
+Gain fbc1 => dc1 => fbc1;
+reverb => DelayL dc2 => combSum;
+Gain fbc2 => dc2 => fbc2;
+reverb => DelayL dc3 => combSum;
+Gain fbc3 => dc3 => fbc3;
+reverb => DelayL dc4 => combSum;
+Gain fbc4 => dc4 => fbc4;
+reverb => DelayL dc5 => combSum;
+Gain fbc5 => dc5 => fbc5;
+reverb => DelayL dc6 => combSum;
+Gain fbc6 => dc6 => fbc6;
+// NREV combs
+1433.0 => float L1;
+1601.0 => float L2;
+1433.0 => float L3;
+1867.0 => float L4;
+2053.0 => float L5;
+2399.0 => float L6;
+L1::samp => dc1.delay;
+L2::samp => dc2.delay;
+L3::samp => dc3.delay;
+L4::samp => dc4.delay;
+L5::samp => dc5.delay;
+L6::samp => dc6.delay;
+Math.pow( R, L1 ) => fbc1.gain;
+Math.pow( R, L2 ) => fbc2.gain;
+Math.pow( R, L3 ) => fbc3.gain;
+Math.pow( R, L4 ) => fbc4.gain;
+Math.pow( R, L5 ) => fbc5.gain;
+Math.pow( R, L6 ) => fbc6.gain;
+
+// series ap1, ap2, ap3, lpf, ap4
+// ap1
+combSum => DelayL da1 => Gain ap1Sum;
+combSum => Gain ffa1 => ap1Sum;
+Gain fba1 => da1 => fba1;
+
+// ap2
+ap1Sum => DelayL da2 => Gain ap2Sum;
+ap1Sum => Gain ffa2 => ap2Sum;
+Gain fba2 => da2 => fba2;
+
+// ap3
+ap2Sum => DelayL da3 => Gain ap3Sum;
+ap2Sum => Gain ffa3 => ap3Sum;
+Gain fba3 => da3 => fba3;
+
+// lpf
+ap3Sum => OnePole lpf;
+
+// ap4
+lpf => DelayL da4 => Gain ap4Sum;
+lpf => Gain ffa4 => ap4Sum;
+Gain fba4 => da4 => fba4;
+
+// stereo split to uncorrelated signals for left and right
+// ap5 -- left side
+ap4Sum => DelayL da5 => dac.left;
+ap4Sum => Gain ffa5 => dac.left;
+Gain fba5 => da5 => fba5;
+
+// ap6 -- right side
+ap4Sum => DelayL da6 => dac.right;
+ap4Sum => Gain ffa6 => dac.right;
+Gain fba6 => da6 => fba6;
+
+// NREV all-pass delays
+347.0::samp => da1.delay;
+113.0::samp => da2.delay;
+37.0::samp => da3.delay;
+59.0::samp => da4.delay;
+53.0::samp => da5.delay;
+43.0::samp => da6.delay;
+
+-apc => fba1.gain;
+apc => ffa1.gain;
+-apc => fba2.gain;
+apc => ffa2.gain;
+-apc => fba3.gain;
+apc => ffa3.gain;
+lpc => lpf.a1;
+1.0 - lpc => lpf.b0;
+-apc => fba4.gain;
+apc => ffa4.gain;
+-apc => fba5.gain;
+apc => ffa5.gain;
+-apc => fba6.gain;
+apc => ffa6.gain;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
76 reverbration/nrevArray.ck
@@ -0,0 +1,76 @@
+// Nrev, looking prettier
+
+6 => int NCOMB; // number of combs
+6 => int NAP; // all-passes
+
+0.6 => float apc;
+0.7 => float lpc;
+adc => Gain direct => dac;
+adc => Gain reverb;
+0.5 => direct.gain; // direct amount
+0.1 => reverb.gain; // reverb amount
+0.9999 => float R; // radius, affects reverb time
+
+float L[NCOMB];
+1433.0 => L[0];
+1601.0 => L[1];
+1867.0 => L[2];
+2053.0 => L[3];
+2251.0 => L[4];
+2399.0 => L[5];
+float A[NAP];
+347.0 => A[0];
+113.0 => A[1];
+37.0 => A[2];
+59.0 => A[3];
+53.0 => A[4];
+43.0 => A[5];
+Gain combOut;
+
+fun void combs (int nComb)
+{
+ DelayL d[nComb];
+ Gain fb[nComb];
+ int i;
+ for (0=>i; i<nComb; i++) {
+ reverb => d[i] => combOut;
+ fb[i] => d[i] => fb[i];
+ L[i]::samp => d[i].delay;
+ Math.pow( R, L[i] ) => fb[i].gain;
+ }
+}
+DelayL dap[NAP];
+Gain apIn[NAP];
+Gain ff[NAP];
+Gain fbap[NAP];
+Gain apOut[NAP];
+fun void allpasses (int nAP)
+{
+ int i;
+ for (0=>i; i<nAP; i++) {
+apIn[i] => dap[i] => apOut[i];
+apIn[i] => ff[i] => apOut[i];
+fbap[i] => dap[i] => fbap[i];
+ A[i]::samp => dap[i].delay;
+ -apc => fbap[i].gain;
+ apc => ff[i].gain;
+ }
+}
+
+combs(NCOMB);
+allpasses(NCOMB);
+combOut => apIn[0];
+apOut[0] => apIn[1];
+apOut[1] => apIn[2];
+apOut[2] => OnePole lpf => apIn[3];
+apOut[3] => apIn[4];
+apOut[3] => apIn[5];
+apOut[4] => dac.left;
+apOut[5] => dac.right;
+lpc => lpf.a1;
+1.0 - lpc => lpf.b0;
+
+while (true)
+{
+ 0.1::second => now;
+}
View
82 reverbration/nrevArrayIR.ck
@@ -0,0 +1,82 @@
+// Nrev, IR to file
+
+dac => WvOut o => blackhole;
+"/zap/test.wav" => o.wavFilename;
+
+// make an impulse
+Impulse I;
+1.0 => I.gain;
+
+6 => int NCOMB; // number of combs
+6 => int NAP; // all-passes
+
+0.6 => float apc;
+0.7 => float lpc;
+I => Gain direct => dac;
+I => Gain reverb;
+0.5 => direct.gain; // direct amount
+0.1 => reverb.gain; // reverb amount
+0.9999 => float R; // radius, affects reverb time
+
+float L[NCOMB];
+1433.0 => L[0];
+1601.0 => L[1];
+1867.0 => L[2];
+2053.0 => L[3];
+2251.0 => L[4];
+2399.0 => L[5];
+float A[NAP];
+347.0 => A[0];
+113.0 => A[1];
+37.0 => A[2];
+59.0 => A[3];
+53.0 => A[4];
+43.0 => A[5];
+Gain combOut;
+
+fun void combs (int nComb)
+{
+ DelayL d[nComb];
+ Gain fb[nComb];
+ int i;
+ for (0=>i; i<nComb; i++) {
+ reverb => d[i] => combOut;
+ fb[i] => d[i] => fb[i];
+ L[i]::samp => d[i].delay;
+ Math.pow( R, L[i] ) => fb[i].gain;
+ }
+}
+DelayL dap[NAP];
+Gain apIn[NAP];
+Gain ff[NAP];
+Gain fbap[NAP];
+Gain apOut[NAP];
+fun void allpasses (int nAP)
+{
+ int i;
+ for (0=>i; i<nAP; i++) {
+apIn[i] => dap[i] => apOut[i];
+apIn[i] => ff[i] => apOut[i];
+fbap[i] => dap[i] => fbap[i];
+ A[i]::samp => dap[i].delay;
+ -apc => fbap[i].gain;
+ apc => ff[i].gain;
+ }
+}
+
+combs(NCOMB);
+allpasses(NCOMB);
+combOut => apIn[0];
+apOut[0] => apIn[1];
+apOut[1] => apIn[2];
+apOut[2] => OnePole lpf => apIn[3];
+apOut[3] => apIn[4];
+apOut[3] => apIn[5];
+apOut[4] => dac.left;
+apOut[5] => dac.right;
+lpc => lpf.a1;
+1.0 - lpc => lpf.b0;
+
+1::ms => now;
+1.0 => I.next; // set the current sample/impulse
+3::second => now;
View
38 synthesis/1-bellBeeps.ck
@@ -0,0 +1,38 @@
+// derived from testTones/dacBeeps.ck
+// FM bell
+// Stk instrument
+// has stretched partials and envelope to give bell sound
+// noteOn at beginning, beeps fade out
+
+2 => int nChans;
+
+TubeBell ch[nChans];
+
+for (0=>int c; c<nChans; c++)
+{
+ new TubeBell @=> ch[c];
+ ch[c].gain(0.0);
+ ch[c].noteOn(1.0); // strike, full velocity
+ ch[c] => dac.chan(c);
+}
+
+0.2 => float amp;
+
+// function to beep the channel number
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].gain(amp);
+ 100::ms => now;
+ ch[c].gain(0.0);
+ 100::ms => now;
+ }
+ 500::ms => now;
+}
+
+// go around channels, beeping the channel number
+// infinite loop
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
View
31 synthesis/2-bellRestrike.ck
@@ -0,0 +1,31 @@
+// new note each beep, using noteOn
+
+2 => int nChans;
+
+TubeBell ch[nChans];
+
+for (0=>int c; c<nChans; c++)
+{
+ new TubeBell @=> ch[c];
+ ch[c].gain(0.0);
+ ch[c] => dac.chan(c);
+}
+
+0.2 => float amp;
+
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].noteOn(1.0); // strike every beep
+ ch[c].gain(amp);
+ 100::ms => now;
+ ch[c].gain(0.0);
+ 100::ms => now;
+ }
+ 500::ms => now;
+}
+
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
View
31 synthesis/3-bellLonger.ck
@@ -0,0 +1,31 @@
+// longer tones to hear "bell-ness" from envelopes
+
+2 => int nChans;
+
+TubeBell ch[nChans];
+
+for (0=>int c; c<nChans; c++)
+{
+ new TubeBell @=> ch[c];
+ ch[c].gain(0.0);
+ ch[c] => dac.chan(c);
+}
+
+0.2 => float amp;
+
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].noteOn(1.0);
+ ch[c].gain(amp);
+ 1000::ms => now; // longer tone
+ ch[c].gain(0.0);
+ 100::ms => now;
+ }
+ 500::ms => now;
+}
+
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
View
35 synthesis/4-bellOverlap.ck
@@ -0,0 +1,35 @@
+// use noteOff
+// overlap requires multiple voices per channel
+// assign output channel in the beep function
+
+2 => int nChans;
+
+// same number of UGens but they'll switch channels
+TubeBell ch[nChans];
+
+for (0=>int c; c<nChans; c++)
+{
+ new TubeBell @=> ch[c];
+ ch[c].gain(1.0/nChans); // automatically scale output
+}
+
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[i] => dac.chan(c); // connect bells to this channel
+ ch[i].noteOn(1.0);
+ 1000::ms => now;
+ }
+ 500::ms => now;
+ for (0=>int i; i<n; i++)
+ {
+ ch[i].noteOff(0.0); // leave gain up, damp with noteOff
+ 1000::ms => now;
+ }
+ for (0=>int i; i<n; i++) ch[i] =< dac.chan(c); // disconnect bells from this channel
+}
+
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
View
48 synthesis/5-bowl.ck
@@ -0,0 +1,48 @@
+// physical model from coupled waveguides, Stk instrument
+// allow channels to persist, so 1 bell for ch 1, 2 for ch 2, etc.
+// no noteOff, persistent state gives restrike detail
+
+2 => int nChans;
+
+// new class which contains it's own bells, defined below
+ChanBells ch[nChans];
+
+for (0=>int c; c<nChans; c++)
+{
+ new ChanBells @=> ch[c];
+ ch[c].initOnChan(c); // set up this instance of ChanBells
+}
+
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].bell[i].noteOn(1.0);
+ 1000::ms => now;
+ }
+ 500::ms => now;
+}
+
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
+class ChanBells
+{
+ nChans => int myBells; // max number of bells is number of channels
+ BandedWG bell[myBells]; // so make an array big enough for highest channel
+ int myChan;
+ fun void initOnChan(int chan) // function to initialize this instance
+ {
+ chan => myChan; // e.g., chan 0
+ myChan + 1 => myBells; // has 1 bell
+ for (0=>int b; b<myBells; b++)
+ {
+ new BandedWG @=> bell[b];
+ bell[b].preset(3); // tibetan bowl
+ bell[b] => dac.chan(myChan);
+ bell[b].freq() + (b*3.0) => bell[b].freq; // detune slightly, e.g. 220.0 + 3.0
+ bell[b].gain(1.0/nChans); // scale according to most populous channel
+ }
+ }
+}
+
View
75 synthesis/6-additiveADSR.ck
@@ -0,0 +1,75 @@
+// derived from bowls.ck
+// using sines, custom additive synthesis instrument AdditiveSynthBell
+// new class to fake a UGen that doesn't already exist in chuck
+
+2 => int nChans;
+
+ChanBells ch[nChans];
+
+for (0=>int c; c<nChans; c++)
+{
+ new ChanBells @=> ch[c];
+ ch[c].initOnChan(c);
+}
+
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].bell[i].noteOn();
+ 1000::ms => now;
+ }
+ 500::ms => now;
+}
+
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
+class ChanBells
+{
+ nChans => int myBells; // max number of bells is number of channels
+ AdditiveSynthBell bell[myBells]; // so make an array big enough for highest channel
+ int myChan;
+ fun void initOnChan(int chan) // function to initialize this instance
+ {
+ chan => myChan; // e.g., chan 0
+ myChan + 1 => myBells; // has 1 bell
+ for (0=>int b; b<myBells; b++)
+ {
+ new AdditiveSynthBell @=> bell[b];
+ ( 220.0 + (b*3.0) ) => bell[b].baseFreq; // detune slightly, e.g. 220.0 + 3.0
+ bell[b].stretchPartials( 2.15 ); // exp
+ bell[b].out => dac.chan(myChan);
+ bell[b].out.gain(1.0/nChans); // scale according to most populous channel
+ }
+ }
+}
+
+
+class AdditiveSynthBell
+{
+ 5 => int nSins;
+ SinOsc s[nSins];
+ ADSR e[nSins];
+ Gain out;
+ 220.0 => float baseFreq;
+ for (0=>int i; i<nSins; i++)
+ {
+ new SinOsc @=> s[i];
+ new ADSR @=> e[i];
+ s[i] => e[i] => out;
+ 1.0/(i + 2) => float rollOff;
+ e[i].keyOff();
+ e[i].set( 1::ms, rollOff*7::second, 0.001, 10::ms );
+ s[i].gain(Math.pow(rollOff, 0.7));
+ stretchPartials(1.0);
+ }
+ fun void noteOn()
+ {
+ for (0=>int i; i<nSins; i++) e[i].keyOn();
+ }
+ fun void stretchPartials(float exp)
+ {
+ for (0=>int i; i<nSins; i++) s[i].freq(baseFreq + baseFreq * Math.pow(i+1,exp));
+ }
+}
View
77 synthesis/fmEnvOSC.ck
@@ -0,0 +1,77 @@
+// copy/paste into terminal:
+// java -jar /usr/ccrma/web/html/courses/220a-fall-2009/java/javaosc/lib/javaoscfull.jar
+
+// then hit button in GUI: Set Address
+// and hit: All On
+
+SinOsc mod => blackhole;
+SinOsc car => dac;
+car.gain(0.2);
+
+slider sl; // instantiate a slider instance, defined below
+
+while (true)
+{
+ sl.last(0) * 4000.0 => float freq;
+ sl.last(1) * 10.0 => float index;
+ sl.last(2) => float ratio;
+
+ mod.gain( freq * index );
+ mod.freq( freq * ratio );
+ car.freq( freq + mod.last() );
+ 1::samp => now;
+}
+
+class slider { // access java slider example by receiving OSC events
+ fun float javaRange( float f) { return ((f - 20.0) / 10000.0); } // its range
+ 3 => int numSliders;
+ float val[numSliders];
+ Env env[numSliders];
+ for ( 0 => int i; i < numSliders; i++ ) javaRange( 440.0) => val[i];
+ OscRecv recv; // chuck object for OSC
+ 57110 => recv.port; // listen on localhost port 57110
+ recv.listen(); // start listening (launch thread)
+ // java example transmits to OSC address /n_set, formatted "i s f"
+ // create an address in the receiver, store in new variable
+ recv.event( "/n_set, i s f" ) @=> OscEvent @ oe;
+ fun void loop()
+ {
+ while( true )
+ {
+ oe => now; // wait for event to arrive
+ while( oe.nextMsg() ) // grab the next message from the queue.
+ {
+ // fully parse message, must be done in this order
+ oe.getInt() - 1000 => int i;
+ oe.getString() => string s;
+ oe.getFloat() => float f;
+ env[i].setTarget(javaRange(f));
+ }
+ }
+ }
+ spork ~ loop(); // start the infinite event loop listening
+ fun float last(int i) { return env[i].last(); } // method to get current slider value
+}
+
+class Env
+{ // does asymptotic enveloping
+ 0.001 => float exp; // depends on incoming "smoothness" -- update rate and resolution
+ 0.0 => float target;
+ 0.0 => float current;
+ fun void loop () // towards target
+ {
+ while( true )
+ {
+ target - current => float dif;
+ (dif * exp) +=> current;
+ 1::samp => now;
+ }
+ }
+ fun void setTarget (float v)
+ {
+ target => current; // slam to last target
+ v => target;
+ }
+ fun float last () { return current; }
+ spork ~ loop(); // start the infinite event loop listening
+}
View
54 synthesis/fmOSC.ck
@@ -0,0 +1,54 @@
+// copy/paste into terminal:
+// java -jar /usr/ccrma/web/html/courses/220a-fall-2009/java/javaosc/lib/javaoscfull.jar
+
+// then hit button in GUI: Set Address
+// and hit: All On
+
+SinOsc mod => blackhole;
+SinOsc car => dac;
+car.gain(0.2);
+
+slider sl; // instantiate a slider instance, defined below
+
+while (true)
+{
+ sl.last(0) * 4000.0 => float freq;
+ sl.last(1) * 10.0 => float index;
+ sl.last(2) => float ratio;
+
+ mod.gain( freq * index );
+ mod.freq( freq * ratio );
+ car.freq( freq + mod.last() );
+ 1::samp => now;
+}
+
+class slider { // access java slider example by receiving OSC events
+ fun float javaRange( float f) { return ((f - 20.0) / 10000.0); } // its range
+ 3 => int numSliders;
+ float val[numSliders];
+ for ( 0 => int i; i < numSliders; i++ ) javaRange( 440.0) => val[i];
+ OscRecv recv; // chuck object for OSC
+ 57110 => recv.port; // listen on localhost port 57110
+ recv.listen(); // start listening (launch thread)
+ // java example transmits to OSC address /n_set, formatted "i s f"
+ // create an address in the receiver, store in new variable
+ recv.event( "/n_set, i s f" ) @=> OscEvent @ oe;
+
+ fun void loop()
+ {
+ while( true )
+ {
+ oe => now; // wait for event to arrive
+ while( oe.nextMsg() ) // grab the next message from the queue.
+ {
+ // fully parse message, must be done in this order
+ oe.getInt() => int i;
+ oe.getString() => string s;
+ oe.getFloat() => float f;
+ javaRange(f) => val[i-1000];
+ }
+ }
+ }
+ spork ~ loop(); // start the infinite event loop listening
+ fun float last(int i) { return val[i]; } // method to get current slider value
+}
View
70 synthesis/sinEnvOSC.ck
@@ -0,0 +1,70 @@
+// copy/paste into terminal:
+// java -jar ~/220a/java/javaosc/lib/javaoscfull.jar
+
+// then hit button in GUI: Set Address
+// and hit: All On
+
+SinOsc s => dac;
+s.gain(0.05);
+
+slider sl; // instantiate a slider instance, defined below
+
+class slider { // access java slider example by receiving OSC events
+ 1 => int numSliders;
+ float val[numSliders];
+ Env env[numSliders];
+ for (0 => int i; i<numSliders; i++) 440.0 => val[i];
+ OscRecv recv; // chuck object for OSC
+ 57110 => recv.port; // listen on localhost port 57110
+ recv.listen(); // start listening (launch thread)
+ // java example transmits to OSC address /n_set, formatted "i s f"
+ // create an address in the receiver, store in new variable
+ recv.event( "/n_set, i s f" ) @=> OscEvent @ oe;
+ fun void loop()
+ {
+ while( true )
+ {
+ oe => now; // wait for event to arrive
+ while( oe.nextMsg() ) // grab the next message from the queue.
+ {
+ // fully parse message, must be done in this order
+ oe.getInt() - 1000 => int i;
+ oe.getString() => string s;
+ oe.getFloat() => float f;
+ env[i].setTarget(f);
+ }
+ }
+ }
+ spork ~ loop(); // start the infinite event loop listening
+ fun float last(int i) { return env[i].last(); } // method to get current slider value
+}
+
+class Env
+{ // does asymptotic enveloping
+ 0.001 => float exp; // depends on incoming "smoothness" -- update rate and resolution
+ 0.0 => float target;
+ 0.0 => float current;
+ fun void loop () // towards target
+ {
+ while( true )
+ {
+ target - current => float dif;
+ (dif * exp) +=> current;
+ 1::samp => now;
+ }
+ }
+ fun void setTarget (float v)
+ {
+ target => current; // slam to last target
+ v => target;
+ }
+ fun float last () { return current; }
+ spork ~ loop(); // start the infinite event loop listening
+}
+
+while (true)
+{
+ sl.last(0) * 5.0 => float freq;
+ s.freq( freq );
+ 1::samp => now;
+}
View
55 testtones/10-shepardTone.ck
@@ -0,0 +1,55 @@
+7 => int NUMOSC;
+fun void shep (float initfreq, float freqmultiplier, float pan, dur speed)
+{
+ SinOsc oct[NUMOSC];
+ int i;
+ float currentfreq;
+ 0 => int lowestosc;
+ std.ftom(initfreq) => float omcf; // Original Midi Center Frequency
+ float newvolume;
+ for (0=>i; i<oct.cap(); i++)
+ {
+ oct[i] => Pan2 p1 => dac;
+ pan => p1.pan;
+ std.mtof( omcf+(12*(i-(NUMOSC-1)/2)) )=> oct[i].freq;
+ }
+ while (true)
+ {
+ for (0=>i; i<oct.cap(); i++)
+ {
+ oct[i].freq()*freqmultiplier=>currentfreq;
+ currentfreq => oct[i].freq;
+ std.fabs(omcf-std.ftom(currentfreq)) => newvolume;
+ 1.0-(newvolume/40.0) => newvolume;
+ if (newvolume<0)
+ {
+ if (i==lowestosc)
+ {
+ if (lowestosc==0)
+ oct[(oct.cap()-1)].freq()*2*freqmultiplier=>currentfreq;
+ else
+ oct[(i-1)].freq()*2=>currentfreq;
+ currentfreq => oct[i].freq;
+ std.fabs(omcf-std.ftom(currentfreq))/2.0 => newvolume;
+ newvolume/20.0 => newvolume;
+ 1-newvolume => newvolume;
+ if (newvolume<0) 0=>newvolume;
+ newvolume/4 => oct[i].gain;
+ lowestosc+1 => lowestosc;
+ if (lowestosc==oct.cap()) 0=>lowestosc;
+ }
+ else
+ 0=>newvolume;
+ }
+ else
+ newvolume/4 => oct[i].gain;
+ }
+ speed=>now;
+ }
+}
+
+spork ~ shep(440,0.995,0,20::ms);
+
+while (true){
+ 4::second=>now;
+}
View
37 testtones/beepListeningRoom22ch.ck
@@ -0,0 +1,37 @@
+// test all 22 channels in Listening Room
+
+[0,1,2,3,4,5,6,7, 8,9,10,11,12,13,14, 16,17,18,19,20,21,22] @=> int chanMap[];
+//[0,1,2,3,4,5,6,7, 8,9,10] @=> int chanMap[]; // mid ring of 8
+//[8,9,10,11,12,13,14] @=> int chanMap[]; // hi ring of 6 then zenith
+// skip [15] @=> int chanMap[];
+//[16,17,18,19,20,21,22] @=> int chanMap[]; // lo ring of 6 then anti-zenith
+chanMap.cap() => int nChans;
+fun void beep(int n)
+{
+ SinOsc s => dac.chan( chanMap[((n-1)%nChans)] );
+ for (0=> int i; i<n; i++)
+ {
+ s.gain(.2); // gain up
+ 50::ms => now; // stall
+ s.gain(0.0); // gain down
+ 50::ms => now; // stall
+ }
+}
+
+fun void test()
+{
+ while (true)
+ {
+ for (1=> int i; i<=nChans; i++)
+ {
+ spork ~ beep(i);
+ 2.5::second - (nChans-i)*.1::second => now;
+ }
+// 1::second => now;
+ }
+}
+
+spork ~ test();
+
+1::day => now;
+<<<"bye">>>;
View
31 testtones/binBeeps.ck
@@ -0,0 +1,31 @@
+// send to 4 psuedo-speaker channels
+// must shred binaural.ck first
+
+4 => int nChans;
+
+SinOsc ch[nChans];
+
+for (0=>int i; i<nChans; i++)
+{
+ new SinOsc @=> ch[i];
+ ch[i].gain(0.0);
+ ch[i] => Binaural.pssp[i];
+}
+
+0.2 => float amp;
+
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].gain(amp);
+ 100::ms => now;
+ ch[c].gain(0.0);
+ 100::ms => now;
+ }
+ 500::ms => now;
+}
+
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
View
34 testtones/dacBeepsListeningRoom16.ck
@@ -0,0 +1,34 @@
+16 => int nChans;
+
+// declare an array of oscillators
+SinOsc ch[nChans];
+// mid circle, hi circle, lo circle
+[0, 1, 3, 5, 7, 6, 4, 2, 12, 13, 15, 14, 8, 9, 11, 10] @=> int mapChan[];
+
+// for each
+for (0=>int i; i<nChans; i++)
+{
+ new SinOsc @=> ch[i]; // instantiate an oscillator
+ ch[i].gain(0.0); // mute it
+ ch[i] => dac.chan(mapChan[i]); // connect it to a dac channel
+}
+
+0.2 => float amp; // overall level
+
+// function to beep once for channel 0, twice for channel 1, etc.
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].gain(amp); // unmute
+ 100::ms => now; // stall
+ ch[c].gain(0.0); // mute
+ 100::ms => now; // stall
+ }
+ 500::ms => now; // stall some more
+}
+
+// create an infinite pattern that rotates around the speakers
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
View
32 testtones/dacBeepsListeningRoom8.ck
@@ -0,0 +1,32 @@
+8 => int nChans;
+
+// declare an array of oscillators
+SinOsc ch[nChans];
+[0, 1, 3, 5, 7, 6, 4, 2] @=> int mapChan[];
+// for each
+for (0=>int i; i<nChans; i++)
+{
+ new SinOsc @=> ch[i]; // instantiate an oscillator
+ ch[i].gain(0.0); // mute it
+ ch[i] => dac.chan(mapChan[i]); // connect it to a dac channel
+}
+
+0.2 => float amp; // overall level
+
+// function to beep once for channel 0, twice for channel 1, etc.
+fun void beep( int n )
+{
+ n-1 => int c;
+ for (0=>int i; i<n; i++)
+ {
+ ch[c].gain(amp); // unmute
+ 100::ms => now; // stall
+ ch[c].gain(0.0); // mute
+ 100::ms => now; // stall
+ }
+ 500::ms => now; // stall some more
+}
+
+// create an infinite pattern that rotates around the speakers
+while (true) for (1=>int n; n<=nChans; n++) beep(n);
+
View
43 utilities/StereoRecorder.ck
@@ -0,0 +1,43 @@
+// @title StereoRecorder.ck
+// @arguments [seconds]
+// @author Chris Chafe (cc@ccrma), Hongchan Choi(hongchan@ccrma)
+// @desc Record the stereo output from dac.chan(0, 1)
+// @note Add this code into VM to capture the audio output of dac.
+// @version chuck-1.3.1.3
+// @revision 1
+
+
+// default duration of audio file you'll create:
+10.0 => float seconds;
+if (me.args()) {
+ me.arg(0) => Std.atof => seconds;
+}
+
+// files will be written into current directory
+"earL.wav" => string filename0;
+"earR.wav" => string filename1;
+<<< "[StereoRecorder] Recording mono sound files... ", filename0, "|", filename1 >>>;
+
+// pull samples from the dac
+dac.chan(0) => WvOut w0 => blackhole;
+dac.chan(1) => WvOut w1 => blackhole;
+
+// assign file name to Ugens
+filename0 => w0.wavFilename;
+filename1 => w1.wavFilename;
+
+// advance time
+now + seconds::second => time later;
+while( now < later ) {
+ 100::ms => now;
+}
+
+// close files
+w0.closeFile();
+w1.closeFile();
+
+// end messages
+<<<"[StereoRecorder] Done recording! ">>>;
+<<<"OSX: To mix them into stereo, use Audacity and merge them into stereo:" >>>;
+<<<"CCRMA Linux: To mix them into stereo, run the following command in a terminal:" >>>;
+<<<"sox -M earL.wav earR.wav Stereo.wav">>>;

0 comments on commit 2fcc097

Please sign in to comment.
Something went wrong with that request. Please try again.