Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////// Dynamic Amplitude, Part 5 //////////////////////////
- s.boot;
- s.meter;
- s.scope;
- s.plotTree;
- s.reboot;
- s.quit;
- // Bypassing Sound Files With Two Oscillators
- // Review Oscillators
- {SinOsc.ar(10)}.plot(1);
- {LFSaw.ar(10)}.plot(1); // for bypassing
- {LFTri.ar(10)}.plot(1);
- {LFPar.ar(10)}.plot(1);
- {LFCub.ar(10)}.plot(1);
- {LFPulse.ar(10)}.plot(1); // for bypassing
- {Saw.ar(10)}.plot(1); // there's no phase argument.
- {Pulse.ar(10)}.plot(1); // don't forget the width argument!
- {VarSaw.ar(10)}.plot(1); // there's a phase AND width argument!
- {[SinOsc.ar(10), LFSaw.ar(10)]}.plot(1);
- {[SinOsc.ar(10), LFPulse.ar(10)]}.plot(1);
- {[SinOsc.ar(10), LFPulse.ar(10, add: -0.5) * 2]}.plot(1); // or write like below
- {[SinOsc.ar(10), LFPulse.ar(10, mul: 2, add: -1)]}.plot(1);
- // CAUTION: Be very careful using an amplitude modulator using things other than SinOsc. Pulse.ar, for example, stacks amplitude instances one after the other when you use a width modulation.
- // Same with Saw.
- // Add Sound File
- ~patterns = Buffer.read(s, "insertaudiofilehere");
- // Name it whatever you like! I chose "~patterns" for this demo's purposes.
- ~patterns.play;
- ~patterns.free;
- ~patterns.duration;
- ~patterns.numChannels;
- ~patterns.sampleRate;
- (
- ~patternSynth = SynthDef.new(\play, {
- arg amp=0.5, atk=0.001, rel=8, c1=1, c2(-1),
- buf=0, rate=1, spos=0, pan=0, out=0;
- var sig, env;
- env = Env([0, 1, 0], [atk, rel], [c1, c2]).kr(2);
- sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos);
- sig = Pan2.ar(sig, pan, amp);
- sig = sig * env;
- Out.ar(out, sig);
- }).add;
- )
- ~patternSynth.play;
- // Replace the Envelope variable with a modulator.
- // LFSaw
- (
- ~patternLFSaw = SynthDef.new(\play, {
- arg lowSaw=1, minAmp=0.001, maxAmp=1,
- buf=0, rate=1, spos=0, amp=0.5, pan=0, out=0;
- var sig, modAmp;
- modAmp = LFSaw.kr(lowSaw).exprange(minAmp, maxAmp);
- sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos);
- sig = Pan2.ar(sig, pan, amp);
- sig = sig * modAmp;
- Out.ar(out, sig);
- }).add;
- )
- ~patternLFSaw = Synth(\play, [\buf, ~patterns]);
- ~patternLFSaw.set(\lowSaw, 1/2); // Try random \pulse values.
- ~patternLFSaw.free; // Free the synth if you don't have an Env or doneAction value.
- // LFPulse
- (
- ~patternPulse = SynthDef.new(\play, {
- arg pulse=1, minAmp=0.001, maxAmp=0.5,
- buf=0, rate=1, spos=0, pan=0, amp=1, out=0;
- var sig, modAmp;
- modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
- sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos);
- sig = Pan2.ar(sig, pan, amp);
- sig = sig * modAmp;
- Out.ar(out, sig);
- }).add;
- )
- ~patternPulse = Synth(\play, [\buf, ~patterns]);
- ~patternPulse.set(\pulse, 1/8); // Try random \pulse values.
- ~patternPulse.free; // Free the synth if you don't have an Env or doneAction value.
- // Include doneAction value of 2 (which frees the synth).
- // Remember, doneAction is only evaluated if the loop in the PlayBuf is a value of 0.
- (
- ~patternPulse = SynthDef.new(\play, {
- arg pulse=1, minAmp=0.001, maxAmp=0.5,
- buf=0, rate=1, spos=0, da=2, pan=0, amp=1, out=0;
- var sig, modAmp;
- modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
- sig = PlayBuf.ar(2, buf, BufRateScale.kr(buf) * rate, spos, doneAction: da);
- sig = Pan2.ar(sig, pan, amp);
- sig = sig * modAmp;
- Out.ar(out, sig);
- }).add;
- )
- ~patternPulse = Synth(\play, [\buf, ~patterns]);
- ~patternPulse.set(\pulse, 1/4);
- // If you like arguments spelled out...
- (
- ~patternPulse = SynthDef.new(\play, {
- arg pulse=1, minAmp=0.001, maxAmp=0.5,
- buf=0, rate=1, spos=0, da= 2, pan=0, amp=1, out=0;
- var sig, modAmp;
- modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
- sig = PlayBuf.ar(
- numChannels: 2,
- bufnum: buf,
- rate: BufRateScale.kr(buf) * rate,
- startPos: spos,
- doneAction: da);
- sig = Pan2.ar(sig, pan, amp);
- sig = sig * modAmp;
- Out.ar(out, sig);
- }).add;
- )
- ~patternPulse = Synth(\play, [\buf, ~patterns]);
- ~patternPulse.set(\pulse, 1/4);
- // Loop it!
- (
- ~patternPulse = SynthDef.new(\play, {
- arg pulse=1, minAmp=0.001, maxAmp=0.5,
- buf=0, rate=1, spos=0, loop=1, pan=0, amp=1, out=0;
- var sig, modAmp;
- modAmp = LFPulse.kr(pulse).exprange(minAmp, maxAmp);
- sig = PlayBuf.ar(
- numChannels: 2,
- bufnum: buf,
- rate: BufRateScale.kr(buf) * rate,
- startPos: spos,
- loop: loop); // A value of 1 means true, and a value of 0 means false.
- sig = Pan2.ar(sig, pan, amp);
- sig = sig * modAmp;
- Out.ar(out, sig);
- }).add;
- )
- ~patternPulse = Synth(\play, [\buf, ~patterns]);
- ~patternPulse.set(\pulse, 1/8); // 4 seconds of sound; 4 seconds of silence.
- ~patternPulse.set(\loop, 0); // The loop will stop after running through the sound file.
- ~patternPulse.free; // Free the synth if you don't have an Env or doneAction value.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement