Debian Codegraph @

examples/analysis/xsynth-stereo.ck

raw
1 // name: xsynth-stereo.ck
2 // desc: a FFT-based cross-synthesizer (stereo delay edition)
3 // => input X modulates a second input Y,
4 // carried out in the frequency domain
5 //
6 // authors: Ge Wang
7 // Celeste Betancur
8 // Andrew Zhu Aday
9 //
10 // date: 2007 initial (really bad) version
11 // 2025 made less bad (and added stereo version)
12
13 // input x (mic)
14 adc => FFT X => blackhole;
15 // source two (to be connected below)
16 FFT Y => blackhole;
17 // synthesis
18 IFFT ifft => Delay dL => dac.left;
19 dL => Gain dLg => dL;
20 300::ms => dL.max => dL.delay;
21 .5 => dLg.gain;
22
23 ifft => Delay dR => dac.right;
24 dR => Gain dRg => dR;
25 450::ms => dR.max => dR.delay;
26 .5 => dRg.gain;
27
28 // input y
29 BlitSquare blt[6];
30 [ 40, 46, 52, 60, 64, 87] @=> int pitches[];
31 for( int i; i < blt.size(); i++ )
32 {
33 blt[i] => Y;
34 20 => blt[i].harmonics;
35 pitches[i] => Std.mtof => blt[i].freq;
36 }
37
38 // set FFT size
39 1024 => X.size => Y.size => int FFT_SIZE;
40 // desired hop size
41 FFT_SIZE / 4 => int HOP_SIZE;
42 // set window and window size
43 Windowing.hann(FFT_SIZE) => X.window;
44 Windowing.hann(FFT_SIZE) => Y.window;
45 Windowing.hann(FFT_SIZE) => ifft.window;
46 // use this to hold contents
47 complex Z[FFT_SIZE/2];
48
49 // control loop
50 while( true )
51 {
52 // take ffts
53 X.upchuck();
54 Y.upchuck();
55
56 // multiply in frequency domain
57 // NOTE: using input X's magnitude to modulate input Y's signal
58 // X and Y are NOT commutative
59 for( int i; i < Z.size(); i++ )
60 (X.cval(i)$polar).mag * Y.cval(i) => Z[i];
61
62 // take ifft
63 ifft.transform( Z );
64
65 // advance time
66 HOP_SIZE::samp => now;
67 }