Having fun with sclang buffers

This commit is contained in:
Dan Buch 2015-12-27 02:08:38 -05:00
parent 2fece459f8
commit 472d6a606f

View File

@ -541,3 +541,198 @@
Group.findRespondingMethodFor('postln').postln;
// Group.findHelpForMethod('postln');
)
(
b = Buffer.alloc(s, 100, 2);
b.free;
)
(
b = Buffer.alloc(s, s.sampleRate * 8.0, 2);
b.free;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
x = SynthDef(
"tutorial-PlayBuf",
{
|out = 0, bufnum|
Out.ar(out,
PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum))
)
}
).play(s, [\bufnum, b]);
// x.free;
// b.free;
)
(
SynthDef(
"tutorial-Buffer-cue",
{
|out = 0, bufnum|
Out.ar(out, DiskIn.ar(1, bufnum))
}
).add;
)
(
b = Buffer.cueSoundFile(
s,
Platform.resourceDir +/+ "sounds/a11wlk01-44_1.aiff",
0,
1
);
y = Synth.new("tutorial-Buffer-cue", [\bufnum, b], s);
b.free;
y.free;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
b.bufnum.postln;
b.numFrames.postln;
b.numChannels.postln;
b.sampleRate.postln;
b.free.postln;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav", action: { |buffer|
("numFrames after update:" + buffer.numFrames).postln;
x = {
PlayBuf.ar(1, buffer, BufRateScale.kr(buffer))
}.play;
});
("numFrames before update:" + b.numFrames).postln;
// x.free; b.free;
)
(
b = Buffer.alloc(s, s.sampleRate * 5, 1);
x = SynthDef(
"tutorial-RecordBuf",
{
|out = 0, bufnum = 0|
var noise;
noise = PinkNoise.ar(0.3);
RecordBuf.ar(noise, bufnum);
}
).play(s, [\out, 0, \bufnum, b]);
)
(
x.free;
)
(
SynthDef(
"tutorial-Playback",
{
|out = 0, bufnum = 0|
var playbuf;
playbuf = PlayBuf.ar(1, bufnum);
FreeSelfWhenDone.kr(playbuf);
Out.ar(out, playbuf);
}
).play(s, [\out, 0, \bufnum, b]);
)
(
b.free;
)
(
Date.getDate.postln;
b = Buffer.alloc(s, 8, 1);
b.updateInfo({
|buf|
buf.set(7, 0.5);
buf.get(7, { |msg| msg.postln });
});
)
(
b.free;
)
(
var nFrames = 16;
Buffer.alloc(s, nFrames).updateInfo({
|b|
Task.new({
0.01.wait;
b.setn(0, [1, 2, 3]);
b.getn(0, 3, { |msg| ("1: "+ msg).postln });
0.01.wait;
b.setn(0, Array.fill(nFrames, { 1.0.rand }));
b.getn(0, nFrames, {
|msg|
("2: " + msg).postln;
"3: buh bye".postln;
b.free
});
}).play;
});
)
(
v = FloatArray.fill(44100, { 1.0.rand2 });
b = Buffer.alloc(s, 44100);
)
(
b.loadCollection(v, action: {
|buf|
x = {
PlayBuf.ar(buf.numChannels, buf, BufRateScale.kr(buf), loop: 1) * 0.2;
}.play;
});
)
(
x.free;
)
(
b.loadToFloatArray(0, -1, { |floatArray| (floatArray == v).postln; });
b.free;
)
(
b.free;
)
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
b.updateInfo({
|b|
x = b.play(true);
SystemClock.sched(5, { x.free; b.free; });
});
// b.play;
)
(
b = Buffer.alloc(s, 512, 1);
b.cheby([1, 0, 1, 1, 0, 1]);
x = play({
Shaper.ar(
b,
SinOsc.ar(300, 0, Line.kr(0, 1, 6)),
0.5
)
});
SystemClock.sched(10, { x.free; b.free; });
)