simple file player

This commit is contained in:
FoAM 2018-05-09 22:44:44 +00:00
parent 19e60e5669
commit 6cc0dab3cb

136
ephemera.sc Normal file
View file

@ -0,0 +1,136 @@
///// // / / / / / / /
//
// supercollider tests
//
////// / /
"e p h e m e r a l g a r d e n".postln;
// sc server
s = Server.local;
//s.options.memSize = 1024 * 1024;
//s.options.maxNodes = 1024 * 1024;
//s.options.numBuffers = 1024 * 1024 * 1024;
//s.latency = 0.05;
s.options.sampleRate = 44100;
s.boot;
"...".postln;
~background = {
"background >> ".post;
// list of soundfiles
~sources = [
"/home/pi/snd/39-incomprehensible-restaurtant-chatter-02.wav",
"/home/pi/snd/39-incomprehensible-restaurtant-chatter-03.wav",
"/home/pi/snd/39-incomprehensible-restaurtant-chatter-04.wav",
"/home/pi/snd/46-afternoon-chorus-02.wav",
"/home/pi/snd/46-afternoon-chorus-03.wav",
"/home/pi/snd/46-afternoon-chorus-04.wav",
];
// select random element from the list
~file = ~sources.choose;
~file.postln;
// read file then play buffer
Buffer.read (server: s, path: ~file, action: ~play1);
};
~foreground = {
"foreground >> ".post;
// list of soundfiles
~sources = [
"/home/pi/snd/26-multilayered-conversations-01.wav",
"/home/pi/snd/26-multilayered-conversations-02.wav",
"/home/pi/snd/39-incomprehensible-restaurtant-chatter-02.wav",
"/home/pi/snd/39-incomprehensible-restaurtant-chatter-03.wav",
"/home/pi/snd/39-incomprehensible-restaurtant-chatter-04.wav",
"/home/pi/snd/26-party-chatter-02.wav",
"/home/pi/snd/26-party-chatter-03.wav",
"/home/pi/snd/26-party-chatter-04.wav",
"/home/pi/snd/06-uw-pebbles-urchins-waves.wav",
"/home/pi/snd/17-uw-waves-crashing-on-pebble-beach-slow.wav"
];
// select random element from the list
~file = ~sources.choose;
~file.postln;
// read file then play buffer
Buffer.read (server: s, path: ~file, action: ~play2);
};
~play1 = { arg b1;
Routine {
"~play [bg - ".post; b1.path.post; "]".postln;
{(PlayBuf.ar(1, b1, rate: 1, loop: 0, doneAction: 2) * 0.1).dup }.play.waitForFree;
// free buffer once done?
"freed [bg - ".post; b1.path.post; "]".postln;
b1.free
~background.value;
}.play;
};
~play2 = { arg b2;
Routine {
"~play [fg - ".post; b2.path.post; "]".postln;
{(PlayBuf.ar(1, b2, rate: 1, loop: 0, doneAction: 2) * 0.1).dup }.play.waitForFree;
// free buffer once done?
"freed [fg - ".post; b2.path.post; "]".postln;
b2.free;
~foreground.value;
}.play;
};
s.waitForBoot {
"booted...".postln;
i = 0;
j = 0;
p = 2; // how many background layers?
q = 3; // how many foreground layers?
while ( { i < p }, { i = i + 1; ~background.value;});
while ( { j < q }, { j = j + 1; ~foreground.value;});
};
// 167/31 -> 175/31 -> 168/31
// via http://danielnouri.org/docs/SuperColliderHelp/Tutorials/Getting-Started/Buffers.html
// Streaming a File in From Disk
// In some cases, for instance when working with very large files, you might not want to load a sound completely into memory. Instead, you can stream it in from disk a bit at a time, using the UGen DiskIn, and Buffer's 'cueSoundFile' method:
// (
// SynthDef("tutorial-Buffer-cue",{ arg out=0,bufnum;
// Out.ar(out,
// DiskIn.ar( 1, bufnum )
// )
// }).send(s);
// )
// b = Buffer.cueSoundFile(s,"sounds/a11wlk01-44_1.aiff", 0, 1);
// y = Synth.new("tutorial-Buffer-cue", [\bufnum,b.bufnum], s);
// b.free; y.free;
// This is not as flexible as PlayBuf (no rate control), but can save memory.