«Canvas3D used to plot realtime sound» by Fredrik Olofsson

on 17 Jun'13 04:48 in graphicanimation3d
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
44
45
46
//--redFrik 2013
//req. Canvas3D quark
//use mouse to rotate canvas
//add your own sounds to x, y, z (maybe with InFeedback.ar)
(
//--settings
var width= 640, height= 480;
var fps= 60;
var buffersize= 1024;
var scale= 250;
var perspective= 0.3;
var distance= 2;

//--
var win= Window("3d soundwave canvas", Rect(128, 64, width, height), false).front;
var can= Canvas3D(win, Rect(0, 0, width, height)).scale_(scale).perspective_(perspective).distance_(distance);
var itemCube= Canvas3DItem.cube;
var itemWave= Canvas3DItem.new;
var path= [];
var buffer;
can.add(itemCube);
can.add(itemWave);
s.waitForBoot{
	buffer= Buffer.alloc(s, buffersize, 3);
	s.sync;
	{
		var x= SinOsc.ar(42);//sound x
		var y= SinOsc.ar(83);//sound y
		var z= SinOsc.ar(164);//sound z
		RecordBuf.ar([x, y, z], buffer);
		Silent.ar;
	}.play;
	s.sync;
	can.animate(fps, {|frame|
		buffer.getn(0, buffersize-1*3, {|data| path= data.clump(3)});
		itemWave.paths= [path];
	});
	can.mouseMoveAction= {|v, x, y|
		can.transforms= [
			Canvas3D.mRotateY(x/scale.neg%2pi),
			Canvas3D.mRotateX(y/scale%2pi)
		];
	};
	CmdPeriod.doOnce({win.close; buffer.free});
};
)
raw 1176 chars (focus & ctrl+a+c to copy)
reception
comments