«analyze a sample with SCMIR and sort sample segments by similarity» by grirgz

on 15 Oct'21 13:01 in examplesampleanalysisscmirsimilarityclusteringfeatureextraction
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
~file = "~/Musique/sc/samplekit/loop/lovin.flac".standardizePath;

e = SCMIRAudioFile(~file, [[MFCC, 13], [Chromagram, 12]]); // open file for SCMIR
b = Buffer.read(Server.default, ~file); // buffer for the Pbind
{e.extractFeatures()}.fork; // extract features before creating similarityMatrix
m = e.similarityMatrix(unit:10, metric:2); // create similarityMatrix    

(
// simple buffer player
SynthDef(\playersec, { arg out=0, amp=0.1, gate=1, pan=0, freq=200, bufnum, speed=1, pos=0, doneAction=2, loop=0, trigger=1, velamp=1;
	// pos in seconds
	var sig;
	var sig1;
	sig = PlayBuf.ar(2, bufnum, BufRateScale.kr(bufnum) * speed, trigger, startPos: (pos*BufSampleRate.kr(bufnum)), doneAction:doneAction, loop: loop);
	sig = sig * EnvGen.ar(\adsr.kr(Env.adsr(0.001,0,1,0.01)),gate,doneAction:doneAction);
	//sig = Pan2.ar(sig, pan, 1).sum;
	Out.ar(out, sig * \gain.kr(1) * velamp);
}).add;
);

(
Pdef(\sortsample,
	Pbind(
		\instrument, \playersec,
		\bufnum, b,
		// take sample at column 105 and play other columns by order of similarity
		// pos is position in the sample in seconds
		// column 105 start at 105*m.reducedrows+0 and ends at 105*m.reducedrows+m.reducedcolumns
		// we take this slice of array, sort it and return the indexes (.order)
		// then scale column number to position in second
		\pos, Pseq(m.matrix[105*m.reducedrows+(0..m.reducedcolumns-1)].order) * b.duration/m.reducedrows, 
		\sustain, b.duration/m.reducedrows,
		\dur, 1,
		\gain, 1,
	)
).play;
);
raw 1516 chars (focus & ctrl+a+c to copy)
reception
comments