Skip to content

Instantly share code, notes, and snippets.

@iani
Created June 29, 2013 13:06
Show Gist options
  • Save iani/5891034 to your computer and use it in GitHub Desktop.
Save iani/5891034 to your computer and use it in GitHub Desktop.
Like SC_buffer_player but with example of effects
/* Playing a sound file to an internal bus and then using that internal bus as input for effects.
This example assumes that we are playing a stereo sound file. For different number of channels,
edit the code.
*/
// Prep
Server.default.boot;
Server.default.scope(4);
~fxBus = Bus.audio(Server.default, 2); // an internal audio bus for playing the audio file
(
~play = { | path, out = 0 |
if (~buffer.notNil) { ~buffer.free };
Buffer.read(
Server.default, path, action: { | buffer |
~buffer = buffer;
~synth = { | out = 0, amp1 = 1, amp2 = 1 |
var left, right;
"===================== STARTED ===================== ".postln;
#left, right = PlayBuf.ar(2, buffer, BufRateScale.kr(buffer), doneAction: 2);
Out.ar(out, [left, right]
* [amp1, amp2]
)
}.play(args: [\out, out ? { ~fxBus.index }]);
})
}
)
// example of usage
// ~synth = ~play.("/path/to/my/audiofile.wav");
~synth = ~play.("/Users/iani2/Desktop/Black/Concert 2/Concert 2 Audio/Kilian's Antipodean Dream MASTER 44-1k.wav", ~fxBus.index);
// example effect
(
~fx = { | in = 0, impulsefreq = 10, dur = 0.1, pan = 0, maxGrains = 512, mul = 1, add = 0 |
var input, fx;
input = In.ar(in, 1); // just the left channel to start
fx = GrainIn.ar(2, Impulse.kr(impulsefreq), dur, input, pan, -1, maxGrains, mul, add);
// fx = input;
Out.ar(0, fx)
}.play(target: ~synth, addAction: \addAfter, args: [\in, ~fxBus.index])
)
~synth.set(\out, 0);
~synth.set(\out, 50);
~synth.set(\amp1, 0.1); // lower the amplitude of channel 1 output
~fx.set(\in, 50);
~fx.set(\impulsefreq, 0.5);
(
~routine = {
var stream;
stream = Pseq((10, 9.5 ..1) ++ (1, 1.5 ..10), inf).asStream;
loop {
~fx.set(\impulsefreq, stream.next);
5.wait;
}
}.fork
)
Bus.audio();
AudioIn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment