«example sequencing soundfiles» by Fredrik Olofsson

on 14 May'13 22:17 in

simple example showing how to play one soundfile after the other in a sequence. use as a template.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//playing soundfiles in sequence - one after the other
s.boot;

(
s.latency= 0.05;
b.do{|x| x.free};	//free all previous buffers
b= [	//edit paths - any number of files - make sure mono
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-01.wav"),
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-02.wav"),
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-03.wav"),
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-04.wav"),
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-05.wav"),
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-06.wav"),
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-07.wav"),
	Buffer.read(s, "/Applications/SuperCollider344/sounds/samples/Screech-08.wav")
];
SynthDef(\sample, {|out= 0, buf, rate= 1|
	Out.ar(out, PlayBuf.ar(1, buf, rate, doneAction:2)!2);
}).add;
)


//test1 - single
Synth(\sample, [\buf, b[0]]).register.onFree{"hello".postln};//should post when first soundfile done playing


//test2 - looping through samples one after the other
(
Routine({
	var index= 0;
	var c= Condition.new;
	inf.do{
		var a= Synth(\sample, [\buf, b[index], \rate, 1]).register;
		a.onFree{
			("playing index:"+index).postln;
			c.unhang;
		};
		c.hang;
		index= index+1%b.size;	//play in sequence
		//index= b.size.rand;	//or play random
	};
}).play;
)
raw 1466 chars (focus & ctrl+a+c to copy)
reception
comments
foxparse user 26 May'13 10:42

an alternative buffer loading suggestion

b = "/Applications/SuperCollider344/sounds/samples/*".pathMatch.collect {|file| Buffer.read(s, file)};