FFT tutorial: frequencies visualization

Hi guys! Hope all is well!
I’m making a multiband compressor plugin. Some weeks ago i wrote another topic about the FFT, in particular about the data exchange between Processor & Editor and you helped me a lot <3
But i still have some questions over this FFT tutorial

My goal is to display the frequencies logarithmically, but what i got from the tutorial is weird, not linear, but not logarithmic as i need…

This is what i get in my plugin:

VS what i would like to get:

I think the section i have to change is the part in which i access the FFT result to take the bins.
Cause in the tutorial we access the FFT result like this:

for (int i = 0; i < scopeSize; ++i)                         // [3]
            auto skewedProportionX = 1.0f - std::exp (std::log (1.0f - (float) i / (float) scopeSize) * 0.2f);
            auto fftDataIndex = juce::jlimit (0, fftSize / 2, (int) (skewedProportionX * (float) fftSize * 0.5f));
            auto level = juce::jmap (juce::jlimit (mindB, maxdB, juce::Decibels::gainToDecibels (fftData[fftDataIndex])
                                                               - juce::Decibels::gainToDecibels ((float) fftSize)),
                                     mindB, maxdB, 0.0f, 1.0f);
            scopeData[i] = level;                                   // [4]

so i prolly need to change skewedProportionX and fftDataIndex formula.
But i don’t know how to change it… i mean what formula do i have to use to get a logarithmic view like the one in Blue Cat’s one?

Also, i’m thinking about creating a shared Google Doc or smth where i/we explain the Juce FFT tutorial in a more clear way.
Don’t get me wrong, that tutorial was gold for me, but for example i struggled a lil bit with the AudioProcessor & Editor management, like how to exchange data between them. And other things like the frequency visualization.
And i saw some topics talking about that fft tutorial, so let me know if it’s a good idea and if you would like to contribute so i can start making it! :slight_smile:

Thank you for the attention!

instead of skewing the linear frequencies directly with a weird approximation function like in the tutorial i find it better to loop through all available midi pitches from 0hz to nyquist in 12edo, then get the bins of those pitches from the fft data. a lot of freq analyzers, like the one in pro-q, work like that, which is also highlighted by its on-screen keyboard component that lets you set cutoffs as pitches

Midi notes get you as high as 12,544 Hz which is the last midi pitch. Are you just carrying on after that note by note beyond midi?

The way I’ve always done this is to scan across the component width where you want the spectrum analyser displayed and have an algorithm that converts from component x pixel to bin and frequency. Then just use hermite/cubic to smooth things out. Doing it this way makes filling with solid or gradient easy too.

yeah, i’d just pretend like it goes beyond that

Interesting answers here, I’ll try that too
Im just a beginner so I found a way to work with the code in the tutorial, if that helps anyone.
You need to adjust the value of skewedProportionX
I think you can adjust the 0.2f at the end of that line to change the skewing

Hey, sorry for the late reply, i had eye surgery and i couldn’t answer :slight_smile: Btw thank you! At the end what i did is: i keep another array where i put the bins (taken with the skewedProportion thing) converted to frequencies and then i scale logarithmically. The result is a value between 0 and 1 and i multiply it with the component width so i have the X positions.
The level is the one kept in scopeData from the FFT.
Thank you for the suggestions!

1 Like