how FFT output is encoded in the single variable 'value' ?

Audio software developers forum.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
jerome42
Posts: 60
Joined: Fri Jan 11, 2013 9:20 am
Operating System: Please select

how FFT output is encoded in the single variable 'value' ?

Post by jerome42 » Mon May 13, 2013 8:06 pm

The Audacity file TrackArtist.cpp contains a method TrackArtist::DrawClipSpectrum(...) which is responsible for the FFT conversion of a waveform and the drawing on screen of the Spectrum of that waveform. The amplitudes of the different frequencies in the spectrum are displayed on screen by different colors.

In that DrawClipSpectrum() method there is a single float called 'value' which contains the information with which a single frequency in the spectrum at one particular point in time can be displayed, thus:
  • the frequency which is detected by the FFT routine
and
  • the signal strength of that detected frequency.
The method
  • GetColorGradient(value, selflag, mIsGrayscale, &rv, &gv, &bv);
converts the encoded info of 'value' into the three basic color values rv, gv and bv which together make the color by which the amplitude of a particular frequency is indicated.

My problem is that I can't deduce from the source code how a single freqency and its amplitude are both encoded in this single float 'value'.
The source code is poorly commented on that issue.

Is there anybody who can explain me the encoding rules of this float 'value' ?
or do I have to contact the author Dominic Mazzoni himselve in the hope he still remembers?

Thanks for any help,
jerome42

Robert J. H.
Posts: 3633
Joined: Thu May 31, 2012 8:33 am
Operating System: Windows 10

Re: how FFT output is encoded in the single variable 'value'

Post by Robert J. H. » Tue May 14, 2013 12:52 am

I doubt that the frequency is encoded in this variable - only the Amplitude (or Magnitude).
The frequency is always known, it is just the bin index multiplied by the fixed bin distance.
It is possible that 2 Bytes make up the index but a float is rather short for that, isn't it?
I don't know much about C++ and I haven't studied the source code, sorry if that's all wrong.

jerome42
Posts: 60
Joined: Fri Jan 11, 2013 9:20 am
Operating System: Please select

Re: how FFT output is encoded in the single variable 'value'

Post by jerome42 » Tue Jun 04, 2013 8:04 pm

Robert J. H. wrote:I doubt that the frequency is encoded in this variable - only the Amplitude (or Magnitude).
The frequency is always known, it is just the bin index multiplied by the fixed bin distance.
It is possible that 2 Bytes make up the index but a float is rather short for that, isn't it?
I don't know much about C++ and I haven't studied the source code, sorry if that's all wrong.
I think you are very right. Indeed, the frequency isn't encoded in 'value', a possibility that never occurred to me, but after some experimenting, that must be the right conclusion. As you say, 'value' gives only the amplitude of the frequency and is normalized into a range between 0.0 and 1.0. A float can handle that very well. So keep away from C++ and from diving into the source code: apparently that gives the best insight!
Thank you Robert, for your very logic perspective.

Post Reply