Click to See Complete Forum and Search --> : Simple Spectrum Analyzer with textfile output?


AlionSolutions
August 26th, 2008, 06:06 AM
Hi,
I want to code something weird again and maybe some of you can help me to save a lot of time again. First: I am a musician, but I have no idea about audio programming. I messed more with the graphics side of coding as some of you may know.

What do I want to do? I want an application that:

- takes a mp3 or wav file for input
- analizes the soundspectrum of the file on a regular basis
- writes the volume values of selected frequency bands to a textfile

I have really not the slightest idea where to start. Ok, I started: The GUI is ready ;)

I found a sample program with sample code somewhere on the web. But that thing monitors what is playing on the computers soundcard instead of giving the possibility to analize a soundfile.

For the curious ones: I need that frequency data for a animation project in 3D where objects will be controlled by the frequency spectrum of the soundtrack.

So I hope I could describe in an understandable manner what I want to accomplish. And I also hope some of you can push me in a direction where to read.

Thanks

Sonny

egawtry
August 26th, 2008, 09:04 AM
1. Find a mp3 decoder. Believe me, you don't want to write one yourself. I believe there are several subjects on this here on codeguru.

2. Once you have the wave data, since you are using multiple frequencies, do a FFT on the wave file. Oohura's FFT is the easiest to use for your purposes. Again easy to find on a search.

3. Once filtered, you will have dB levels (standard output from the FFT). If you want scaled levels, just take the antilog.

-Erik

AlionSolutions
August 26th, 2008, 09:27 AM
Thanks alot egawtry! Yepp, that's what I meant with "a push in the right direction" ;)
What I read does not make sense yet, except for the fact, that indeed have no plans to write a own mp3 decoder *LOL*

The mp3 is not so important as I have all audio as wave. So if I understand you right, I have to:

- load the wavefile data into memory
- get that Ohura FFT thing (I assume it is a library doing that magical fourier stuff)
- pass the wavebuffer in some way to the Ohura thing.
- get the output from the Ohura thing and save it

Am I right so far? I better ask before I run in circles because I didn't get an important fact.

Thanks again

Sonny

egawtry
August 26th, 2008, 09:40 AM
Exactly.:thumb:

:)

P.S. You can chunk the wave file unless you want the results of the entire wave.

AlionSolutions
August 26th, 2008, 10:48 AM
Thanks for confirming egawtry! Do you know a site wih a good and understandable description on how to load the wavefiles data? I found some rather small information about the wav/riff format, but they allways ommit how the data chunk is stored and how to read it.

Thanks again

Sonny

egawtry
August 26th, 2008, 02:14 PM
Hmmm... MS used to have a whole description with their MM API, but it looks like they ripped it out for the DirectX stuff.

Take a look at the CWaveFile class that comes with DirectX. You can look at the source and get the file header if you want (or even use the class).

The basic layout is:

RIFF
{
WAVE
{
hdr
{
// Header data
}
data
{
// PCM File Data: Big Endian, left 16 bits, right 16 bits
}
}
}
-Erik

AlionSolutions
September 5th, 2008, 02:58 PM
Hi Egawtry,
hope you are still reading ;) because I don't know how to start with that Ooura package. I have a bunch of cpp files that do "transformations". I have no iea how to get, for example, the value of all sound between -30Hz and 60Hz out of wave audio material. I am not really a wizzard in things of math. So can you help me to understand that stuff or must I study mathematics before I can do anything?

Thanks

Juergen

egawtry
September 5th, 2008, 03:30 PM
1. Run the init function - SetFFTParams(). You can set the params to zero.
2. Normalize your incoming data (if 16 bit, divide it by 0x7FFF and store in a double).
3. Pass the last "FFT_SIZE" normalized samples to CalcFFT(). You only need to call it every FFT_SIZE samples.
4. Call GetFFTData anytime to get the FFT. start and stop will be 3*4=12 and 6*4=24 if your FFT_SIZE is 2048 and your sample rate is 8KHz.

-Erik

AlionSolutions
September 6th, 2008, 07:52 AM
Wow, reads complicated. I'll try it as soon as I find the time. I'm afraid, I cannot find any of the function names you mentioned in the Ooura package I downloaded. But it as on that oldfashoined looking OOura site and it says it does Discrete Fast Fourier Transformation. There are other routines that do cosine transformations and stuff. Ok, maybe I overlooked the routines. I'll be back right after I tried to do what you say.

Thanks

Juergen