flake-update-20260505
1desc: CentreCut
2
3gaindb:3<-15,15>Boost gain (dB)
4
5@init
6gaindb = -0.72;
7
8function db2mag(db)
9(
10 pow(10, db / 20);
11);
12function mag2db(mag)
13(
14 20 * log10(mag);
15);
16fftsize = 4096;
17bufpos = idx = 0;
18stftIndexLeft = 2;
19stftIndexRight = 50;
20memreq = stftCheckMemoryRequirement(stftIndexLeft, fftsize, 4, 2);
21memreq = stftCheckMemoryRequirement(stftIndexRight, fftsize, 4, 2);
22stftStructLeft = 120;
23stftStructRight = stftStructLeft + memreq;
24requiredSamples = stftInit(stftIndexLeft, stftStructLeft);
25requiredSamples = stftInit(stftIndexRight, stftStructRight);
26inBufLeft = stftStructRight + memreq + 10; // Pointer to memory
27outBufLeft = inBufLeft + fftsize + 10; // Pointer to memory plus safe zone
28inBufRight = outBufLeft + fftsize + 10; // ...
29outBufRight = inBufRight + fftsize + 10; // ...
30gain=db2mag(gaindb) - 1; // Boost 3 dB
31
32@sample
33inBufLeft[bufpos] = spl0;
34spl0 = outBufLeft[bufpos];
35inBufRight[bufpos] = spl1;
36spl1 = outBufRight[bufpos];
37bufpos += 1;
38bufpos >= requiredSamples ?
39(
40 error1 = stftForward(inBufLeft, stftIndexLeft, stftStructLeft, 1);
41 error2 = stftForward(inBufRight, stftIndexRight, stftStructRight, 1);
42 idx=0;
43
44 loop(error1 / 2,
45 sumR = inBufLeft[idx] + inBufRight[idx];
46 sumI = inBufLeft[idx + 1] + inBufRight[idx + 1];
47 diffR = inBufLeft[idx] - inBufRight[idx];
48 diffI = inBufLeft[idx + 1] - inBufRight[idx + 1];
49 sumSq = sumR*sumR + sumI*sumI;
50 diffSq = diffR*diffR + diffI*diffI;
51 alpha = 0.0;
52 sumSq > $EPS ? (alpha = 0.5 - sqrt(diffSq / sumSq) * 0.5;);
53 cR = sumR * alpha;
54 cI = sumI * alpha;
55 inBufLeft[idx] = inBufLeft[idx] + cR * gain;
56 inBufLeft[idx + 1] = inBufLeft[idx + 1] + cI * gain;
57 inBufRight[idx] = inBufRight[idx] + cR * gain;
58 inBufRight[idx + 1] = inBufRight[idx + 1] + cI * gain;
59 idx+=2);
60 error = stftBackward(inBufLeft, stftIndexLeft, stftStructLeft, 1);
61 error = stftBackward(inBufRight, stftIndexRight, stftStructRight, 1);
62 idx = 0;
63 loop(requiredSamples,
64 outBufLeft[idx] = inBufLeft[idx];
65 outBufRight[idx] = inBufRight[idx];
66 idx+=1);
67 bufpos = 0;
68);