Author Topic: FFT returns all 0  (Read 112 times)


  • Posts: 58
FFT returns all 0
« on: 25 Jun '22 - 08:01 »
I'm getting the FFT the very basic way.

Code: [Select]
var filePath = "SourceLong.mp3";

var chan = Bass.CreateStream(filePath, Flags: BassFlags.Float | BassFlags.Decode).Valid();
var fft = new float[512];
var read = Bass.ChannelGetData(chan, fft, (int)DataFlags.FFT1024);

foreach (var f in fft)

It works for some music, and for others, like the one below, it returns all 0. Why?

Bass.LastError is 0 (OK).

Also "read" is always 8192 (bytes read from source to calculate FFT), even if I set flags as (int)DataFlags.FFT1024 | 100000

How can I calculate the FFT for the 100 first seconds?


  • Posts: 120
Re: FFT returns all 0
« Reply #1 on: 25 Jun '22 - 18:40 »
I think FFT1024 will always use 8192 bytes to calculate the FFT off a float stereo channel, so in your call 100000 bytes will be pulled from the channel's buffer but only 8192 of them will be used to calculate the FFT.

If you want to get FFT from a 100 sec window you'll have to request many FFT1024 and average the values for each of the 512 bands.

8192 bytes will account for just a few milliseconds of audio on a 44100 Hz samplerate audio.

In my mind I figure that you'd need to request
desired_window_sec * samplerate * 8 / 8912
FFTs. And don't ask for 100000 bytes to be pulled from the buffer.

Besides, I think you'll get more and better answers on Monday, since the forum isn't usually very active on weekends.



  • Posts: 58
Re: FFT returns all 0
« Reply #2 on: 25 Jun '22 - 19:05 »
Ya I figured that I need to loop through the audio and sum up the FFTs. That seems to work.

It was those first few milliseconds that were all 0 for some audios.

Ian @ un4seen

  • Administrator
  • Posts: 24494
Re: FFT returns all 0
« Reply #3 on: 27 Jun '22 - 12:33 »
MP3 encoding introduces a short delay at the start, so you will get all 0s within that unless the file includes a header (eg. from LAME) to tell the decoder (eg. BASS) about the delay so that it can be removed. In your example file's case, it does include a LAME header, so the delay can be removed, but the file has a little silence after that too, ie. the original file didn't begin with sound. If you would like to check that, you can convert the file to WAV and load that in a sample editor - you may also be able to load the MP3 file directly but that might not give the same results, eg. if the editor doesn't support LAME headers.