/*************************************************************************/ /* Examples we went through during X hour for Disk, buffer I/O and misc. */ /*************************************************************************/ /* Using the OrcScore */ /**********************/ ( /* Env.new([levels: a, d, s, r], [durations(1 less than adsr], type) */ /* Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4], -2).plot; */ /* Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4], -1).plot; */ /* Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4], 0).plot; */ /* Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4], 1).plot; */ /* Env.new([0.001,1,0.3,0.8,0.001],[2,3,1,4], 2).plot; */ /* Env.new([0,1,0.2,0],[0.004, 0.9, 0.5], -2).plot; */ e = Env.new([0,1,0.2,0],[0.004, 0.9, 0.5], -2); Synth.play({ // OrcScore.ar(orchestra, score, numChannels, nextTime, maxRepeats, mul, add) OrcScore.ar( [ // the orchestra { // arg spawn, i, synth, deltaTime, instrumentNum, ... // intrument 0 arg spawn, i, synth, deltaTime, instrumentNum, note, amp; EnvGen.ar(e, FSinOsc.ar(note, amp)); }, { // instrument 1 arg spawn, i, synth, deltaTime, instrumentNum, note, amp; EnvGen.ar(e, Saw.ar(note, amp)); }, { // instrument 2 // Synth.plot({ XLine.ar(0.1, 0.9, 0.005) }); arg spawn, i, synth, deltaTime, instrumentNum, note, amp, duration; var signal2; signal2 = EnvGen.ar(e, WhiteNoise.ar(amp)); BPF.ar(signal2, FSinOsc.kr(XLine.kr(0.7,300,duration),3600,4000), 0.3); } ], // the score // the score uses literal arrays, hence cannot change at run time //del. time instNum note amplitude misc parameters ... #[ [1.0, 0, 146, 0.5], [1.0, 1, 156, 0.3], [0, 2, 170, 0.7, 5], [0, 0, 171, 0.4], [0, 0, 172, 0.4], [0, 0, 173, 0.4], [1.0, 1, 217, 0.3], [1.0, 0, 231, 0.5], [1.0, 1, 294, 0.5], [1.0, 0, 318, 0.5], [0.5, 2, 340, 1, 2], [0.25, 0, 439, 0.5], [0.25, 0, 466, 0.5], [0.125, 0, 587, 0.4], [0.125, 0, 631, 0.4], [0.125, 0, 689, 0.4], [0, 0, 690, 0.2], [0, 0, 691, 0.1] ], 1, // number of channels nil, // time between events 40) // number of repeats }) ) /************************************************************************************/ /* this is an example used for file reading/opening and playing the read file */ /* filename = ":DIRECTORY:SOUDNFILE_NAME"; */ /* */ /************************************************************************************/ PlayBuf.at(signal, sigSampleRate, playbackRate, offset, loopstart, loopend, mul, add) signal - a Signal buffer sigSampleRate - the sample rate of the signal playbackRate - 1.0 is normal, 2.0 is one octave up, 0.5 is one octave down offset - sample offset. This can either be a static starting offset, or a modulateable offset. loopstart - sample number of beginning of loop loopend - sample number of end of loop ( var filename, sound, signal; filename = ":Sounds:floating_1"; // specify read filename sound = SoundFile.new; // Creates a new SoundFile instance. if (sound.read(filename), // Check if file exists { signal = sound.data.at(0); // signal, sigSampleRate, playbackRate, offset, loopstart, loopend, mul, add // no loop Synth.play( { PlayBuf.ar(signal, sound.sampleRate, 1, 0, signal.size-2) } ); // loop through end // Synth.play( { PlayBuf.ar(signal, sound.sampleRate, 1, 0, 0, signal.size) } ); // different loop points // Synth.scope( { PlayBuf.ar(signal, sound.sampleRate, 1, 0, (signal.size)/2, signal.size-2) } ); }, { (filename ++ " not found.\n").post }); ) ( // sine wave control of playback rate. negative rate plays backwards var filename, sound, signal, rate; filename = ":Sounds:floating_1"; sound = SoundFile.new; if (sound.read(filename), { signal = sound.data.at(0); Synth.play({ rate = FSinOsc.kr(XLine.kr(0.2,8,30), 2, 0.1); // rate: -2 ~ + 2 PlayBuf.ar(signal, sound.sampleRate, rate, 0, 0, signal.size-2) }); },{ (filename ++ " not found.\n").post }); ) /*************************************************************************************/ /* Orc score and buffer usage example */ /*************************************************************************************/ ( var filename, sound, signal; filename = ":Sounds:floating_1"; // specify read filename sound = SoundFile.new; // Creates a new SoundFile instance. if (sound.read(filename), // Check if file exists Synth.scope({ signal = sound.data.at(0); // points at header of wave OrcScore.ar( [{ arg spawn, i, synth, deltaTime, instrumentNum, amp, playbackRate; var signal1, signal2; signal1 = PlayBuf.ar(signal, sound.sampleRate, playbackRate + (playbackRate.rand2/5), // read from score signal.size-2, 0, signal.size-2, amp.rand + 0.1); // read from score signal2 = signal1*SinOsc.ar(400); // ring modulation Pan2.ar(Mix.ar([signal2,signal1]), FSinOsc.kr(3)); }], #[ // deltaTime, instrumentNum, amp, playbackRate; [3.0, 0, 0.3, 1.0], [3.0, 0, 0.3, -1] ], 2, nil, 40) }), { (filename ++ " not found.\n").post }); ) /************************************************************************************/ /* this is an example used for streaming soundfiles from disk */ /* Here you can control the loop through a boolean flag */ /* */ /************************************************************************************/ DiskIn.ar(soundFile, loopFlag, startFrame, numFrames) soundFile - the SoundFile to read. loopFlag - a Boolean value. If true, then the file is looped. startFrame - the sample frame at which to start playback if the sound file has not been preloaded.The default value is zero. numFrames - the number of frames in the double buffer if the sound file has not been preloaded.The default value is 32768. no loop ( var myFile, loopFlag; var filename; // must include directory loopFlag = false; filename = ":Sounds:floating_1"; // this is boilerplate stuff myFile = SoundFile.new; myFile.readHeader(filename); myFile.preloadData; Synth.scope({ DiskIn.ar(myFile, loopFlag) }, 0.5); ) looping ( var file; file = SoundFile.new; if ( file.readHeader(":Sounds:floating_1"), // read the file's header { file.sustainLoopStart = file.numFrames - 20000; file.sustainLoopEnd = file.numFrames; Synth.scope({ DiskIn.ar(file, true) * 0.4 }, 0.5); }); ) /************************************************************************************/ /* this is an example used for recording to a file */ /* This is easier to use than the DiskOut streaming function, so use it! */ /* */ /************************************************************************************/ ( var fileName = ":Sounds:testOne"; var duration = 10, freq, amp; Synth.record({ freq = 800; amp = 0.25; SinOsc.ar(freq, amp)}, duration, fileName, 'AIFF', '16 big endian signed'); ) /*************************************************************************************/ /* Simple audio in from mic/line */ /*************************************************************************************/ AudioIn: read audio input from ADC AudioIn.ar(channel, mul, add) Reads audio from the sound input hardware (microphone, line in etc. ) channel - input channel number to read. Channel numbers begin at 1. ( Synth.scope({ AudioIn.ar([1,2])}); // this does a multi channel expansion, hence ) /************************************************************************************/ /* Example for multi slider, numerical view, and range to control line in signal */ /* This uses input from line in or microphone */ /* */ /************************************************************************************/ { var w, a, b, c, a1, b1, c1; var panelName = "Mic in control"; // window setup and string placement w = GUIWindow.new(panelName, Rect.newBy( 616, 63, 241, 217 )); StringView.new( w, Rect.newBy( 11, 53, 66, 21 ), "Amplitude") .labelColor_(rgb(209,69,12)); StringView.new( w, Rect.newBy( 8, 20, 219, 26 ), "Input from external mic or line in") .labelColor_(rgb(36,42,115)); StringView.new( w, Rect.newBy( 10, 125, 66, 21 ), "Pan") .labelColor_(rgb(25,97,35)); // numerical view and slider setup for amplitude a = NumericalView.new( w, Rect.newBy( 12, 78, 65, 24 ), "Amplitude Numrical", 0, -1e+10, 1e+10, 0, 'exponential'); b = SliderView.new( w, Rect.newBy( 82, 52, 136, 24 ), "SliderView", 0, 0, 1, 0, 'linear') .knobColor_(rgb(250,7,0)); c = RangeView.new( w, Rect.newBy( 83, 81, 136, 24 ), "RangeView", 0, 0, 0, 1, 0, 'linear') .rangeColor_(rgb(215,10,7)); a.action = { b.value = a.value}; // numerical b.action = { a.value = b.value; c.range = b.value }; // slider c.action = { b.value = c.range }; // range // numerical view and slider setup for panning a1 = NumericalView.new( w, Rect.newBy( 11, 150, 65, 24 ), "Amplitude Numrical", 0, -1, 1, 0, 'exponential'); b1 = SliderView.new( w, Rect.newBy( 81, 124, 136, 24 ), "SliderView", 0, -1, 1, 0, 'linear') .knobColor_(rgb(35,143,28)); c1 = RangeView.new( w, Rect.newBy( 82, 153, 136, 24 ), "RangeView", 0, 0, -1, 1, 0, 'linear') // init, min, max, resolution .rangeColor_(rgb(25,133,33)); a1.action = { b1.value = a1.value}; // numerical b1.action = { a1.value = b1.value; c1.value = b1.value }; // slider c1.action = { b1.value = c1.value }; // range // make sound, scope and use control from GUI ({ Pan2.ar( AudioIn.ar(1, ControlIn.kr(a)), ControlIn.kr(c1) ) }).scope; w.close; } /*******************************************************************************************/ /* this is an example shows how to control pitch of incoming speech with a slider */ /* */ /*******************************************************************************************/ PitchShift.ar(in, windowSize, pitchRatio, pitchDispersion, timeDispersion, mul, add) A time domain granular pitch shifter. Grains have a triangular amplitude envelope and an overlap of 4:1. in - the input signal. windowSize - the size of the grain window in seconds. This value cannot be modulated. pitchRatio - the ratio of the pitch shift. Must be from 0.0 to 4.0. pitchDispersion - the maximum random deviation of the pitch from the pitchRatio. timeDispersion - a random offset of from zero to timeDispersion seconds is added to the delay of each grain. Use of some dispersion can alleviate a hard comb filter effect due to uniform grain placement. It can also be an effect in itself. timeDispersion can be no larger than windowSize. { var w, a, b, z; w = GUIWindow.new(" One Slider", Rect.newBy( 249, 106, 172, 135 )); StringView.new( w, Rect.newBy( 16, 12, 131, 29 ), "Line In Pitch Shifter"); b = SliderView.new( w, Rect.newBy( 18, 78, 128, 24 ), "SliderView", 0, 0, 4, 0.1, 'linear'); a = NumericalView.new( w, Rect.newBy( 18, 48, 128, 23 ), "NumericalView", 0, 0, 4, 0.1, 'linear'); a.action = { b.value = a.value }; b.action = { a.value = b.value }; { var pitch = 0.2; // 0.2 ... 4 var pan = -1; z = AudioIn.ar([1,2]); PitchShift.ar(z, 0.02, ControlIn.kr(a), 0, 0.0001) }.play; w.close; } /*******************************************/ /* using repeat, poll and macros/functions */ /* use this with version 2.1.3 only!!! */ /*******************************************/ { var w, fSlider, pSlider, raSlider, rpSlider, vSlider, nView1, nView2, cBox1, cBoxMute, cBoxPlay, cBoxLineOn, cBoxLineOff, cBoxW1On, cBoxW1Off, cBoxW2On, cBoxW2Off; var envelope1; var link1, link2, boxToggle; // debugginh var testView1, testView2, testBox0; w = GUIWindow.new("Stomp Box", Rect.newBy( 309, 81, 565, 325 )); fSlider = SliderView.new( w, Rect.newBy( 20, 40, 41, 248 ), "freq slider", 0.5, 0, 1, 0.01, 'linear').knobColor_(rgb(17,25,176)); pSlider = SliderView.new( w, Rect.newBy( 65, 40, 41, 248 ), "phase slider", 0, 0, 1, 0.01, 'linear').knobColor_(rgb(15,176,23)); raSlider = SliderView.new( w, Rect.newBy( 116, 168, 21, 119 ), "freq rate", 1, 0, 20, 0.01, 'linear').knobColor_(rgb(28,38,176)); rpSlider = SliderView.new( w, Rect.newBy( 141, 168, 21, 119 ), "phase rate", 0.5, 0, 10, 0.01, 'linear').knobColor_(rgb(47,176,35)); vSlider = SliderView.new( w, Rect.newBy( 166, 168, 21, 119 ), "phase rate", 0.1, 0, 6, 0.01, 'linear').knobColor_(rgb(156,14,40)); nView1 = NumericalView.new( w, Rect.newBy( 20, 14, 40, 18 ), "NumericalView", 0.5, 0, 2, 0.01, 'linear'); nView2 = NumericalView.new( w, Rect.newBy( 67, 14, 40, 18 ), "NumericalView", 0, 0, 2, 0.01, 'linear'); cBox1 = CheckBoxView.new( w, Rect.newBy( 115, 40, 80, 23 ), "No Hands ", 0, 0, 1, 0, 'linear'); cBoxPlay = CheckBoxView.new( w, Rect.newBy( 114, 67, 58, 22 ), "Play", 0, 0, 1, 0, 'linear'); cBoxMute = CheckBoxView.new( w, Rect.newBy( 114, 95, 58, 22 ), "Mute", 1, 0, 1, 0, 'linear'); /* ugen type */ cBoxLineOn = CheckBoxView.new( w, Rect.newBy( 321, 42, 60, 17 ), "On", 0, 0, 1, 0, 'linear'); cBoxLineOff = CheckBoxView.new( w, Rect.newBy( 385, 42, 60, 17 ), "Off", 1, 0, 1, 0, 'linear'); cBoxW1On = CheckBoxView.new( w, Rect.newBy( 321, 66, 58, 22 ), "On", 0, 0, 1, 0, 'linear'); cBoxW1Off = CheckBoxView.new( w, Rect.newBy( 385, 66, 58, 22 ), "Off", 1, 0, 1, 0, 'linear'); cBoxW2On = CheckBoxView.new( w, Rect.newBy( 321, 92, 58, 22 ), "On", 0, 0, 1, 0, 'linear'); cBoxW2Off = CheckBoxView.new( w, Rect.newBy( 385, 92, 58, 22 ), "Off", 1, 0, 1, 0, 'linear'); StringView.new( w, Rect.newBy( 248, 40, 60, 21 ), "Line In"); StringView.new( w, Rect.newBy( 248, 65, 60, 21 ), "Wave 1"); StringView.new( w, Rect.newBy( 248, 90, 60, 21 ), "Wave 2"); StringView.new( w, Rect.newBy( 22, 290, 86, 20 ), "Freq Phase"); StringView.new( w, Rect.newBy( 126, 295, 36, 12 ), "Rate"); StringView.new( w, Rect.newBy( 114, 148, 68, 16 ), "Fr Ph Am"); StringView.new( w, Rect.newBy( 164, 295, 27, 13 ), "Vol"); // debugging testBox0 = CheckBoxView.new( w, Rect.newBy( 255, 140, 272, 44 ), "NumericalView", 0, 0, 1, 0, 'linear'); testView1 = NumericalView.new( w, Rect.newBy( 255, 187, 272, 44 ), "ON Monitor", 0, -1000, 1000, 1, 'linear'); testView2 = NumericalView.new( w, Rect.newBy( 256, 244, 272, 44 ), "Off Monitor", 0, -1000, 1000, 1, 'linear'); /* one action = other ones value, from 0 to N */ link1 = { arg in, out; w.views.at(in).action = { w.views.at(out).value = w.views.at(in).value }}; link2 = { arg in, out; link1.value(out, in); link1.value(in,out)}; /* box toggle */ boxToggle = { arg boxOne, boxTwo; w.views.at(boxOne).action = { w.views.at(boxTwo).value = 0; w.views.at(boxOne).value = 1; } }; /* do actual links and toggle connections */ link2.value(0,5); link2.value(1,6); boxToggle.value(8,9); boxToggle.value(9,8); boxToggle.value(10,11); boxToggle.value(11,10); boxToggle.value(12,13); boxToggle.value(13,12); boxToggle.value(14,15); boxToggle.value(15,14); envelope1 = Env.adsr(0.08, 0.1, 0.1, 0.01, 1, -4); Synth.scope({ arg synth, amplitude, lineIn, sineWave, pulseTrain; var automaticf, automaticp, trigger, signal1, signal2, temp; var randomNum; automaticf = 1+SinOsc.ar(ControlIn.kr(raSlider)); automaticp = 1+SinOsc.ar(ControlIn.kr(rpSlider)); synth.trepeat ( 0, 0.001, {trigger = cBox1.poll; if(trigger == 1, { fSlider.value = automaticf.poll*0.5; pSlider.value = automaticp.poll*0.5; nView1.value = automaticf.poll; nView2.value = automaticp.poll; } ); // debugging testView1.value = cBoxW2On.value; testView2.value = cBoxW2Off.value; testView2.value = 10.rand; } ); amplitude = ControlIn.ar(cBoxPlay)*ControlIn.kr(vSlider); // ring modulation module lineIn = ControlIn.ar(cBoxLineOff) + (AudioIn.ar(2)*ControlIn.ar(cBoxLineOn)); sineWave = ControlIn.ar(cBoxW1Off) + (SinOsc.ar(400*ControlIn.kr(fSlider)+0, 360*ControlIn.kr(pSlider))*ControlIn.ar(cBoxW1On)); pulseTrain = EnvGen.ar(envelope1, ControlIn.ar(cBoxW2Off) + (Pulse.ar(ControlIn.kr(testView2), 0.5)*ControlIn.ar(cBoxW2On)), 0, 1, 0, 1, -50); temp = sineWave*lineIn*pulseTrain*amplitude*ControlIn.ar(cBoxPlay); signal1 = Resonz.ar(temp, 20+(1000*SinOsc.kr(0.1)), 4*SinOsc.kr(0.1)); signal2 = DelayL.ar(signal1, 0.8, 0.8); //signal2 = BPF.ar(temp, 20+1000*FSinOsc.kr(20), 0.3); Pan2.ar(Mix.ar([signal1,signal2]), FSinOsc.kr(2)); }); w.close; }