Debian Codegraph @

examples/analysis/xsynth.ck

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