Created
April 25, 2014 13:54
-
-
Save thormagnusson/11290382 to your computer and use it in GitHub Desktop.
Record and Play Buffers in SuperCollider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav"); // remember to free the buffer later. | |
b = Buffer.alloc(s, s.sampleRate * 2.0, 1); | |
b.bufnum | |
x = {arg rate=1; RecordBuf.ar(SoundIn.ar(0), b, 0, preLevel:0.5, loop:1)}.play; | |
a = {arg rate=1; PlayBuf.ar(1, b, rate, loop:1)}.play | |
b.free; | |
a.set(\rate, -0.5) | |
x.set(\preLevel, 0.8) | |
SynthDef(\recbuf, {arg buffer, preLevel=0.5; | |
RecordBuf.ar(SoundIn.ar(0), buffer, 0, preLevel:preLevel, loop:1); | |
}).add; | |
SynthDef(\playbuf, {arg buffer, out=0, rate=1, amp=1; | |
var signal; | |
signal = PlayBuf.ar(1, buffer, rate:rate, loop:1) * amp; | |
Out.ar(out, Pan2.ar(signal, 0)); | |
}).add; | |
Synth(\recbuf, [\buffer, b]) | |
Synth(\playbuf, [\buffer, b, \rate, 1]) | |
( | |
var bufferArray, recSynths, playSynths; | |
bufferArray = Array.fill(8, { Buffer.alloc(s, s.sampleRate * 2.0, 1)}); | |
recSynths = Array.fill(8, { nil }); | |
playSynths = Array.fill(8, { nil }); | |
w = Window.new("recbuffs", Rect(10, 10, 500, 300)).front; | |
8.do({arg i; | |
// rec buttons | |
Button.new(w, Rect(10+(i*60), 10, 50, 20)) | |
.states_([["Record"],["Stop"]]) | |
.action_({arg butt; | |
if(butt.value == 1, { | |
"recording".postln; | |
recSynths[i] = Synth(\recbuf, [\buffer, bufferArray[i]]); | |
},{ | |
"stop synth".postln; | |
recSynths[i].free; | |
}) | |
}); | |
// play buttons | |
Button.new(w, Rect(10+(i*60), 40, 50, 20)) | |
.states_([["Play"],["Stop"]]) | |
.action_({arg butt; | |
if(butt.value == 1, { | |
"playing".postln; | |
playSynths[i] = Synth(\playbuf, [\buffer, bufferArray[i], \rate, 1]); | |
},{ | |
"stop synth".postln; | |
playSynths[i].free; | |
}) | |
}); | |
}); | |
Button.new(w, Rect(10, 130, 70, 50)) | |
.states_([["DEBUG"],["Stop"]]) | |
.action_({arg butt; | |
"debug".postln; | |
[\bufferArray, bufferArray].postln; | |
[\recSynths, recSynths].postln; | |
[\playSynths, playSynths].postln; | |
}); | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment