HISE Logo Forum
    • Categories
    • Register
    • Login

    [Free dsp] C++ FFT

    Scheduled Pinned Locked Moved C++ Development
    28 Posts 6 Posters 1.1k 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.
    • griffinboyG
      griffinboy
      last edited by griffinboy

      For @ustk

      Simple FFT implementation using Juce
      (C++ scriptnode)

      https://1drv.ms/u/c/6c19b197e5968b36/EcVjEd7aayFHhItxr2gISeMBUD15DXs-oPHNg9Os9pYXWA?e=EW0gfm

      By default it's a spectral lowpass filter (silences fft bins above the cutoff).
      It has been implemented into a sampler, and into a real-time effect.

      If you want to fully understand how the scripts work, ask chat gpt to walk through the code.

      Christoph's own Hise FFT implementation is likely better: but this'll be a good starting point if you need a custom implementation. If you want to extend it, I recommend investigating a multi resolution approach (Constant Q). This simple fft uses a han window at one resolution, resulting in the general smearing of content and transients. I'd like to improve this aspect in the future.

      Oli UllmannO DabDabD clevername27C 3 Replies Last reply Reply Quote 11
      • Oli UllmannO
        Oli Ullmann @griffinboy
        last edited by

        @griffinboy
        Thank you very much! 😊

        griffinboyG 1 Reply Last reply Reply Quote 1
        • griffinboyG
          griffinboy @Oli Ullmann
          last edited by

          @Oli-Ullmann

          This is my first time doing spectral. So it's likely poorly informed, and has issues somewhere xD

          mmprodM 1 Reply Last reply Reply Quote 0
          • mmprodM
            mmprod @griffinboy
            last edited by

            @griffinboy Would something like a spectral denoiser be the job for C++? https://forum.hise.audio/topic/11754/fft-spectral-denoiser-faust-dsp?_=1738883351225

            The conversation here https://forum.hise.audio/topic/8874/spectral-morphing-in-hise, was that RNBO and Faust are unusable for this type of thing. Loris could be a possibility, but doesn't do live processing? Just wondering if C++ is the best option for live spectral processing

            For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.
            John 3:16

            griffinboyG 1 Reply Last reply Reply Quote 1
            • griffinboyG
              griffinboy @mmprod
              last edited by griffinboy

              @mmprod

              So, like I said, this is my first adventure with FFT.
              However, I would say pretty confidently that c++ is the way to go.
              Because FFT is expensive, cpu wise. Everyone uses SIMD / parallel processing for it. You'd want to do FFT in an environment where you can vectorize the math and have the freedom to optimize as much as possible. In this example I am using Juce vectorized math, which attempts to use SIMD for all the multiplications and adds that are used in FFT.

              For quality it's probably best to use a C++ FFT library. There are a few online but I decided to do this Juce one manually because someone was asking about it on the forum.

              Spectral smearing and quality issues are a problem in my script. But the complexity skyrockets for dealing with these issues. Maybe ill deal with them but probably in the far future. I am mostly interested in using FFT for mangling sounds or for additive resynthesis, so preserving the original signal isn't my main concern. Libraries online do complex things to keep the signal fresh though, and will have special configurations that optimize quality for different use cases: filtering, analysis, reverbs ect.

              mmprodM ustkU clevername27C 3 Replies Last reply Reply Quote 0
              • mmprodM
                mmprod @griffinboy
                last edited by

                @griffinboy thanks for the information, and great to hear what's possible with C++. What C++ libraries do you recommend?

                For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.
                John 3:16

                griffinboyG clevername27C 2 Replies Last reply Reply Quote 0
                • griffinboyG
                  griffinboy @mmprod
                  last edited by

                  @mmprod

                  No clue, I've never used one of them.

                  mmprodM 1 Reply Last reply Reply Quote 0
                  • mmprodM
                    mmprod @griffinboy
                    last edited by

                    @griffinboy Ah ok - I'll look into that myself. Thanks for your help

                    For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.
                    John 3:16

                    1 Reply Last reply Reply Quote 1
                    • ustkU
                      ustk @griffinboy
                      last edited by

                      @griffinboy Oh my boy that's amazing! I'll study that example closely and try to derive it for my own spectral things, should I succeed... For sure optimisation and vectorisation is very important with FFT. It is also often not the right tool despite it seems to be for the novice. For instance I've recently read about pitch shifting, where frequency domain seems to be the way but the issues it brings are raising as you go further. All that to say the path to DSP is a long, long path, and I am happy to have this as a starting point! Thanks @griffinboy !

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

                      griffinboyG 1 Reply Last reply Reply Quote 1
                      • griffinboyG
                        griffinboy @ustk
                        last edited by griffinboy

                        @ustk

                        I'm looking into implementing prism, which would be much more powerful for signal analysis. Looking at the data, this would be much more powerful than Loris (which uses kaiser window fft and the reassignment method).

                        Link Preview Image
                        Control group news: Prism

                        This Control Group news article is a spotlight on work from the Advanced Instrumentation Research Group on prism, an Ultra-Precise FFT calculation.

                        favicon

                        (eng.ox.ac.uk)

                        For audio effects, if you want to preserve the signal, the constant Q method seems ideal:

                        Link Preview Image
                        Constant-Q transform - Wikipedia

                        favicon

                        (en.wikipedia.org)

                        I'll likely have a shot at this too at somepoint.

                        1 Reply Last reply Reply Quote 0
                        • DabDabD
                          DabDab @griffinboy
                          last edited by

                          @griffinboy Awesome. your 2nd Tutorial Video.
                          giphy.gif

                          Bollywood Music Producer and Trance Producer.

                          griffinboyG 1 Reply Last reply Reply Quote 2
                          • griffinboyG
                            griffinboy @DabDab
                            last edited by

                            @DabDab

                            hahaha.
                            Not quite as riveting as you would've hoped.

                            I have scripted the next few videos though, I simply need to sit down and record and they'll be out. I've taken way too long on these

                            DabDabD 1 Reply Last reply Reply Quote 1
                            • DabDabD
                              DabDab @griffinboy
                              last edited by

                              @griffinboy I am always very excited for your videos. I know FAUST and RNBO (may be a little bit in respect of other HISE mates) but core C++ with HISE always pushes me from my DSP comfort zone and Lethargy.

                              Bollywood Music Producer and Trance Producer.

                              1 Reply Last reply Reply Quote 0
                              • clevername27C
                                clevername27 @griffinboy
                                last edited by

                                @griffinboy Excellent, and good thought on multi-resolution!

                                RX does multi-resolution offline, but SpectraLayers does it in real-time.

                                Refinement is another strategy, though you'll encounter regions of (quantum) uncertainty. The data isn't directly applicable, but can be extrapolated from. It can also provide additional information to the user in terms of visual feedback. Refinement is likewise offline in RX, but real-time in SL.

                                bd42e554-047d-4ceb-8a83-c3ed87402e94-Screenshot 2025-02-07 at 2.16.29 pm.png


                                23570d59-0d78-424c-b9a6-6611ba47cb31-Screenshot 2025-02-07 at 2.16.38 pm.png


                                a4eb58d2-616f-47b6-a575-8a6e2556529b-Screenshot 2025-02-07 at 2.16.51 pm.png

                                griffinboyG 2 Replies Last reply Reply Quote 1
                                • griffinboyG
                                  griffinboy @clevername27
                                  last edited by

                                  @clevername27

                                  Ah I forgot that we had an fft expert here!
                                  I may need to talk to you for advice. This little tangent has led me deep into FFT algorithms and I've discovered some really cool but complex modern research on the matter.

                                  DabDabD 1 Reply Last reply Reply Quote 0
                                  • griffinboyG
                                    griffinboy @clevername27
                                    last edited by griffinboy

                                    @clevername27

                                    Something I'm thinking of is combining Prism, with reassignment method.
                                    Using reassignment to increase accuracy in the time domain as a post process.

                                    Have you looked at this, it's ridiculous:

                                    Link Preview Image
                                    Control group news: Prism

                                    This Control Group news article is a spotlight on work from the Advanced Instrumentation Research Group on prism, an Ultra-Precise FFT calculation.

                                    favicon

                                    (eng.ox.ac.uk)

                                    I think they've patented it now, but I do have an old matlab project from two years ago where they created an early unoptimized version.

                                    This wouldn't be for real time, but would surely be an amazing for frequency accuracy.

                                    Overkill maybe? And way beyond my ability, but pretty interesting. Most resynthesis misses a ton of partials due to the fft method used to analyse the signal. But they always claim that these frequencies aren't important to perception. So maybe I'd be wasting a ton of effort xD
                                    Stuff like Loris already sounds good perceptually. And perhaps insane resolution isn't a good thing: how are you going to group and track all those partials?

                                    I should probably give in and just use Loris... But for some reason I love going through the pain of doing dsp from scratch.

                                    1 Reply Last reply Reply Quote 0
                                    • DabDabD
                                      DabDab @griffinboy
                                      last edited by

                                      @griffinboy said in [Free dsp] C++ FFT:

                                      Ah I forgot that we had an fft expert here!

                                      @clevername27 Any getting started FFT video like your above image?
                                      Every day I open up computer and think today I will learn new things. Will watch more videos on HISE. But sadly we have very few Video authors.

                                      Bollywood Music Producer and Trance Producer.

                                      griffinboyG clevername27C 3 Replies Last reply Reply Quote 0
                                      • griffinboyG
                                        griffinboy @DabDab
                                        last edited by

                                        @DabDab

                                        Most dsp is shared via papers.

                                        clevername27C 2 Replies Last reply Reply Quote 1
                                        • clevername27C
                                          clevername27 @griffinboy
                                          last edited by

                                          This post is deleted!
                                          1 Reply Last reply Reply Quote 0
                                          • clevername27C
                                            clevername27 @DabDab
                                            last edited by clevername27

                                            @DabDab @griffinboy I appreciate the questions. To my knowledge, SpectraLayers is only software that does real-time FFTs like this, based mostly on brilliant work by creator Robin Lobel. The good news is if you want to simply do a 3D waterfall FFT (or Wavelet) display, the internet (including YouTube) is overflowing with how-tos, tutorials and walktlhoughts. Everything you need is readily available in HISEscript, and I can imagine it being more 100 lines of code at the most (50 if you're @Christoph-Hart).

                                            I will divulge one secret from my own research: Remember that when drawing FFT or Wavelet-derived visualisations, few users (if any) know precisely what the graph should look like. In other words, you can lie to them. It's faster. "But what about processing that data?" Same answer. The user rarely knows precisely what it should sound like. (That being said, everything Robin is doing in SL is exactly correct.)

                                            One other: Run your FFTs on the graphics card.

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

                                            50

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            102.2k

                                            Posts