Author Topic: Get spectrum data  (Read 4999 times)

3coy

  • Posts: 5
Get spectrum data
« on: 5 Apr '09 - 06:08 »
Hi,
 I'm used to Fmod but would like to switch over to Bass. I'd like to retrieve the frequency spectrum of an mp3 (preferably without playing the song, so I can process it faster). I looked in the docs for the equivalent of Fmod's GetSpectrum command, but I could only find visualization methods, which returned bitmaps instead of floats. Could someone please help me?
Thank you  :)

radio42

  • Posts: 4576
Re: Get spectrum data
« Reply #1 on: 5 Apr '09 - 06:35 »
The way to get the FFT data 'offline' is to create a DECODING channel (e.g. via BASS_StreamCreateFile and using the DECODE flag). You thena can call BASS_ChannelGetData in a loop using one of the FFT data flags with it.

3coy

  • Posts: 5
Re: Get spectrum data
« Reply #2 on: 5 Apr '09 - 07:15 »
Hi radio42. Thanks for the quick reply. I tried doing this:
Code: [Select]
int length = (int)Bass.BASS_ChannelSeconds2Bytes(stream, 0.03);
            float[] data = new float[length];

            length = Bass.BASS_ChannelGetData(stream, data,(int) BASSData.BASS_DATA_FFT512);
            for (int i = 0; i < 512 ; i++)
            {

                tbFreq.Text += data[i].ToString() + "\n";
            }

but all my mp3's seem to get 0's. My Wav file comes back with numbers such as 2.92842E-06 and 2.693452E-06 (which I guess are normal numbers to get). Any ideas why this isn't working with MP3 files?
Thanks again for the help

3coy

  • Posts: 5
Re: Get spectrum data
« Reply #3 on: 5 Apr '09 - 09:12 »
I think I've fixed the zero problem. I added the BASSFlag.BASS_SAMPLE_FLOAT  parameter and now I get the (very small) numbers. I've used FFT512, so I get an array with 256 floats returned. Therefore, in order to read over a file,  I set the position X seconds, read, set X + 10 (assuming every 10 seconds), read and repeat that till the end of the file. However, this is a lot of data. Would it make sense to average out each array and so I end up with 10 arrays (if I make 10 frequency calls, with one element in each)? I plan to find the MFCC of the MP3 files. I'm no music expert, so I may be messing things up with the frequency averaging?  ???
Thanks