«A Convolution Reverb: Stereo with Reverse Option» by prko

on 09 Apr'18 02:20 in convolutionreverseir
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(
fork{ 
	var path, inSrc, irL, irR, convTime, fftsize, bufsizeL, bufsizeR, irSpctrmL, irSpctrmR, convolver;
	
	path= Platform.resourceDir; // path!
	
	"preparing buffers.. ".post;
	inSrc= Buffer.readChannel(s, path+/+"sounds/a11wlk01.wav", channels:0); // your file! 
	/*
	irL= Buffer.readChannel(s, path++"", channels:0); // IR left
	irR= Buffer.readChannel(s, path++"", channels:0); // IR right
	*/
	
	/* Test IRs */
	// test IRs begin. -->
	// synthesise the honourable 'Dan Stowell' impulse response */
	~ir= [1] ++ 0.dup(100) ++ (
		(1, 0.99998 .. 0)
		.collect {|f|
			f = f.squared.squared;
			f = if(f.coin) { 0 }{ f.squared };
			f = if(0.5.coin) { 0 - f } { f }
		} * 0.1
	);
	~irNorm = ~ir.normalizeSum;
	irR = Buffer.loadCollection(s, ~irNorm);
	irL = Buffer.loadCollection(s, ~irNorm);
	// <-- test IRs end.
	
	/* reverse IRs */
	"finished.. \nreverting IR buffers.. ".post;
	// irL.loadToFloatArray(action: { |array| irL.sendCollection(array.reverse) });
			// Only the right channel buffer is reversed for tests.
	irR.loadToFloatArray(action: { |array| irR.sendCollection(array.reverse) });
	
	s.sync;
	
	/* Increase the number 1 at the end of the following line if the sound is broken */
	convTime= inSrc.duration+([irL.duration, irR.duration].sort[1]) + 1;
	
	fftsize= 2048;
	bufsizeL= PartConv.calcBufSize(fftsize, irL);
	irSpctrmL= Buffer.alloc(s, bufsizeL, 1);
	irSpctrmL.preparePartConv(irL, fftsize);
	bufsizeR= PartConv.calcBufSize(fftsize, irR);
	irSpctrmR= Buffer.alloc(s, bufsizeR, 1);
	irSpctrmR.preparePartConv(irR, fftsize);
	
	s.sync;
	
	irL.free; irR.free;
	
	"finished..\nconvolution is started.".postln;
	s.record;
	
	convolver= { 
		var in, conv, mix;
		in = PlayBuf.ar(1, inSrc.bufnum, BufRateScale.kr(inSrc.bufnum));
		conv = PartConv.ar (
			in,
			fftsize,
			[irSpctrmL.bufnum, irSpctrmR.bufnum],
			0.2 // Adjust the number to get a proper amplitude. 
		);
		mix = (in * 0) + (conv * 1); // mix!
		Out.ar( 0, mix ) 
	}.play;
	
	convTime.wait;
	
	convolver.free;
	
	s.stopRecording;
	
	inSrc.free; irSpctrmL.free; irSpctrmR.free;
}
)
raw 2149 chars (focus & ctrl+a+c to copy)
reception
comments