HISE Logo Forum
    • Categories
    • Register
    • Login

    added scriptable FFT

    Scheduled Pinned Locked Moved Scripting
    28 Posts 6 Posters 2.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by A Former User

      Saw this commit and got very excited...

      Now how on earth do we use it 😂

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by

        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);
        
        ? 1 Reply Last reply Reply Quote 0
        • ?
          A Former User @Christoph Hart
          last edited by

          @christoph-hart Sweet, thanks for that. :)

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by

            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).

            ustkU ? 2 Replies Last reply Reply Quote 0
            • ustkU
              ustk @Christoph Hart
              last edited by

              @christoph-hart holy cow! I was looking for a decimation yesterday! That should do it, right?

              Can't help pressing F5 in the forum...

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User @Christoph Hart
                last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart
                  last edited by

                  @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 :)

                  ? Dan KorneffD ustkU 3 Replies Last reply Reply Quote 3
                  • ?
                    A Former User @Christoph Hart
                    last edited by

                    @christoph-hart Of course! :) keep up the great work

                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey
                      last edited by

                      Could this be used to compare dynamic layers and create an aet type thing?

                      1 Reply Last reply Reply Quote 0
                      • Dan KorneffD
                        Dan Korneff @Christoph Hart
                        last edited by

                        @christoph-hart said in added scriptable FFT:

                        it will burn the CPU

                        Wait till you see my analog tape dsp :grinning_squinting_face:

                        Dan Korneff - Producer / Mixer / Audio Nerd

                        1 Reply Last reply Reply Quote 1
                        • Christoph HartC
                          Christoph Hart
                          last edited by Christoph Hart

                          @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:

                          Link Preview Image
                          Overlap-Add Decomposition | Spectral Audio Signal Processing

                          favicon

                          (www.dsprelated.com)

                          d.healeyD 1 Reply Last reply Reply Quote 1
                          • ustkU
                            ustk @Christoph Hart
                            last edited by

                            @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 :)

                            Can't help pressing F5 in the forum...

                            1 Reply Last reply Reply Quote 0
                            • Christoph HartC
                              Christoph Hart
                              last edited by

                              @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).

                              ustkU 1 Reply Last reply Reply Quote 0
                              • ustkU
                                ustk @Christoph Hart
                                last edited by ustk

                                @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

                                Can't help pressing F5 in the forum...

                                1 Reply Last reply Reply Quote 0
                                • d.healeyD
                                  d.healey @Christoph Hart
                                  last edited by

                                  This post is deleted!
                                  1 Reply Last reply Reply Quote 0
                                  • d.healeyD
                                    d.healey
                                    last edited by

                                    What about a resynthesis module? :D

                                    ? 1 Reply Last reply Reply Quote 1
                                    • ?
                                      A Former User @d.healey
                                      last edited by

                                      @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 😂

                                      d.healeyD Christoph HartC 2 Replies Last reply Reply Quote 2
                                      • d.healeyD
                                        d.healey @A Former User
                                        last edited by

                                        @iamlamprey It would be nice if we never had to sample anything again.

                                        1 Reply Last reply Reply Quote 2
                                        • Christoph HartC
                                          Christoph Hart @A Former User
                                          last edited by Christoph Hart

                                          @iamlamprey What's DDSP? Nevermind it's more googleable than I thought.

                                          ? 1 Reply Last reply Reply Quote 1
                                          • ?
                                            A Former User @Christoph Hart
                                            last edited by

                                            @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 ;)

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            30

                                            Online

                                            1.8k

                                            Users

                                            12.0k

                                            Topics

                                            104.7k

                                            Posts