added scriptable FFT
-
Saw this commit and got very excited...
Now how on earth do we use it
-
I'll write the docs once the API for this has stabilised, but a rough howto is this:
// Create a dummy signal with two sine waves const var signal = Buffer.create(4096); reg uptime = 0.0; for(s in signal) { s = 0.3 * Math.sin(uptime); s += 0.7 * Math.sin(uptime * 2.0); uptime += 0.1; } // Create a FFT object. If you right click on it in the // script watch table and view the popup you'll see a spectrogram // for the data passed in const var fft = Engine.createFFT(); // creates a spectrogram image (required for // the debug popup but might be used later to draw // on a panel. */ fft.setEnableSpectrum2D(true); // Setup the processing specs (fft size and channel count) fft.prepare(1024, 1); // Set the window type for the processing fft.setWindowType(fft.BlackmanHarris); // Convert the FFT output to magnitudes fft.setDomain(fft.Magnitude); // Give the fft a function that will be called for // each signal chunk. `data` will contain either a // buffer or an array of buffers containing the transformed // FFT signal and offset will contain the index of the first // sample in the chunk (here it will be 0, 1024, 2048 and 3072 // because the processing size is 1024 fft.setProcessFunction(function(data, offset) { var max = 0.0; for(s in data) { max = Math.max(max, s); } Console.print("The max value at " + offset + " is " + Engine.getDecibelsForGainFactor(max)); }); // Process the buffer with the function above. fft.process(signal);
-
@christoph-hart Sweet, thanks for that. :)
-
If you have any ideas how to extend this class let me know. At the moment it's just possible to analyse the data (so there is no inverse FFT) also it's not optimised for real time usage (but rather to analyse samples).
-
@christoph-hart holy cow! I was looking for a decimation yesterday! That should do it, right?
-
@christoph-hart said in added scriptable FFT:
If you have any ideas how to extend this class let me know.
also it's not optimised for real time usage
I think this is probably the biggest one, albeit easier said than done
The main purpose I (and I believe others) needed it for was realtime frequency detection for things like Dynamic EQ. Unless there's something in the new scriptnode that can accomplish it... I'm a bit out of touch on the latest branches tbh
I think FFTs can also be used for time-stretching stuff right? Probably above my paygrade
-
@iamlamprey said in added scriptable FFT:
I think FFTs can also be used for time-stretching stuff right?
The FFT is maybe the most important algorithm in DSP but let's keep it realistic guys. This implementation works within the scripting layer and any attempt for realtime usage will at some point run against performance issues: As soon as you need to operate on the actual sample data, it will burn the CPU as @dustbro has shown with its infamous CPU Screamer example.
At some point in the future I will add the FFT to the SNEX API, with an emphasis on realtime usage, but until then just relax and enjoy the possibility of sorting a sample set based on its harmonic spectrum :)
-
@christoph-hart Of course! :) keep up the great work
-
Could this be used to compare dynamic layers and create an aet type thing?
-
@christoph-hart said in added scriptable FFT:
it will burn the CPU
Wait till you see my analog tape dsp :grinning_squinting_face:
-
@d-healey Yes that's more in the ballpark. However it would require an inverse FFT so that you can do (in pseudo code):
for(chunk in signal) { forwardTransform(chunk); doSomeStuffInFrequencyDomain(); inverseTransform(chunk); }
However I gotta admit I have never used the inverse transform (all FFT application I did until now only needed to analyse the frequency domain) so maybe I need a bit input of someone who is a bit more proficient in this area. A quick googling revealed this website which contains some basic information, but let me know if you know better resources:
https://www.dsprelated.com/freebooks/sasp/Overlap_Add_Decomposition.html
-
@christoph-hart as for a non-real time decimation of a buffer, it should work right? Just in order to get something better than than one sample every X samples…
This is not related to displaying the buffer, which works great btw thanks to you :) -
@ustk said in added scriptable FFT:
Just in order to get something better than than one sample every X samples…
Ah, you're still in the waveform drawing stuff? Not sure if the FFT is seriously overkill for this task. Have you tried other interpolation algorithms? The next best thing is linear interpolation which should be good enough (it's good enough for the sample playback lol).
-
@christoph-hart no no as I said this is not for drawing, this one is for computational stuff.
Actually I am taking a sample every X samples to decimate before a correlation function, and it works. But I'd like a more precise decimation model…What I found online always uses an fft, but the formulas are too complex for me to translate into code. Although I'm sure it's a trivial operation, I'm just not used to fft…
I imagine this requires an inverse fft too though
-
This post is deleted! -
What about a resynthesis module? :D
-
@d-healey with the results I got from DDSP I'm surprised more developers aren't looking into resynthesis more... we'd never have to sample a round robin again
-
@iamlamprey It would be nice if we never had to sample anything again.
-
@iamlamprey
What's DDSP?Nevermind it's more googleable than I thought. -
@christoph-hart Yep :) The style-transfer is particularly appealing, I wouldn't be surprised if you can legally train it with other people's sample libraries since it's 100% synthesis.
Not a lawyer but ;)