Created
May 5, 2015 09:33
-
-
Save iani/f9b6a5065ff6b8c7ce43 to your computer and use it in GitHub Desktop.
loopiera1 150505: First steps in playing with live input playback in SuperCOllider
This file contains hidden or 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
//========== 0. SETUP ============ | |
// Must boot first to get sample rate! | |
Server.default.boot; | |
// After the server has booted, we can set up: | |
( | |
~recduration = 4; | |
~sampleRate = Server.default.sampleRate; | |
// allocate a Buffer | |
~buffer1 = Buffer.alloc( | |
Server.default, | |
~sampleRate * ~recduration, // allocate size | |
1); // single channel | |
) | |
// Check: Watch input and output levels | |
ServerMeter(Server.default); | |
//========== 1. BASIC TESTS ============ | |
( | |
// Record audio from the first input channel | |
{ | |
RecordBuf.ar( | |
SoundIn.ar(0), // first input channel | |
~buffer1, // store recording in buffer | |
loop: 0, // do not loop | |
doneAction: 2 // free synth when done. | |
); | |
0.0; // Output silence | |
}.play; | |
) | |
( | |
// Play back the recorded buffer | |
{ | |
PlayBuf.ar(1, ~buffer1.bufnum, doneAction: 2); | |
}.play; | |
) | |
//========== 2. Start playback after recording ============ | |
( | |
// Record audio from the first input channel | |
{ | |
RecordBuf.ar( | |
SoundIn.ar(0), // first input channel | |
~buffer1, // store recording in buffer | |
loop: 0, // do not loop | |
doneAction: 2 // free synth when done. | |
); | |
0.0; // Output silence | |
}.play.onEnd(\master, { | |
{ PlayBuf.ar(1, ~buffer1.bufnum, doneAction: 2); }.play; | |
}); | |
) | |
//========== 3. Start playback after recording, many times! ============ | |
( | |
// Record audio from the first input channel | |
~recordAndPlayback1 = { | |
var buffer; | |
buffer = Buffer.alloc(Server.default, ~sampleRate * ~recduration, 1); | |
{ | |
RecordBuf.ar( | |
SoundIn.ar(0), // first input channel | |
buffer, // store recording in buffer | |
loop: 0, // do not loop | |
doneAction: 2 // free synth when done. | |
); | |
0.0; // Output silence | |
}.play.onEnd(\master, { | |
{ PlayBuf.ar(1, buffer.bufnum, doneAction: 2); } | |
.play | |
.onEnd(\master, { buffer.free; }); | |
}) | |
}; | |
) | |
// Test the above: | |
~recordAndPlayback1.value; | |
//========== 4. Add GUI to multipe record and playback ============ | |
( | |
~window1 = Window().front; | |
~window1.layout = VLayout( | |
Button().states_([["RECORD!"]]).action_(~recordAndPlayback1); | |
); | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi - thanks for posting this example. Does there need to be another library for onEnd to work. I keep getting Message 'onEnd' not understood. I'm not very experienced with supercollider and it would be great to get this working but I can't find any reference to onEnd in the SC documentation.