Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFT IFFT and xsynth.ck example #422

Open
celestebetancur opened this issue Dec 12, 2023 · 0 comments
Open

FFT IFFT and xsynth.ck example #422

celestebetancur opened this issue Dec 12, 2023 · 0 comments

Comments

@celestebetancur
Copy link
Contributor

I am adding a working example of the "// really really bad cross synthesizer..." . Some little adjustments but I don't know why the signal that is being re-synthesized needs to be boosted by such a big factor. I tried the same example using SndBufs and an impulse response and the gain needs to be boosted by a factor of 1000.

//Using headphones is recommended
// source one (mic)
adc => FFT X => blackhole;
FFT Y => blackhole;
IFFT ifft => Gain amp => dac;

//to add some dry signal to the chain
adc => Delay d => Gain dry => dac;

// source two (to be connected below)
BlitSquare blt[6];
[ 40, 46, 52, 60, 64, 87] @=> int pitches[];
for( int i; i < blt.size(); i++ )
{
blt[i] => Y;
20 => blt[i].harmonics;
pitches[i] => Std.mtof => blt[i].freq;
}

// This number will make a huge difference on the sound quality
// Powers of 2 usually recommended (try 2, 4, 8, 16, 32 ...)
64 => int fftSizeScaler;

(128fftSizeScaler)::samp => d.max;
(128
fftSizeScaler)::samp => d.delay;

// The amount of the original signal you want to hear in the final mix
0.04 => dry.gain;
// The gain of the convoluted (wet) signal
10 => amp.gain;

// set FFT size really big to get a better sound quality but it introduces a lot of delay (trade off)
128*fftSizeScaler => int FFT_SIZE;
FFT_SIZE => X.size => Y.size;

// set window and window size
Windowing.triangle(FFT_SIZE) => X.window => Y.window => ifft.window;

// use this to hold contents
complex Z[FFT_SIZE/2];

// desired hop size
FFT_SIZE / 4 => int HOP_SIZE;

// control loop
while( true )
{
// take ffts
X.upchuck();
Y.upchuck();

// multiply in frequency domain
for(int i; i < FFT_SIZE/2; i++){
    //Math.sqrt((Y.cval(i)$polar).mag) * X.cval(i) => Z[i];
    // Simple element wise multiplication should work in freq domain:
    (X.cval(i) * (Y.cval(i))) * 4 => Z[i];
}

// take ifft
ifft.transform( Z );

// advance time
HOP_SIZE::samp => now;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant