C++ & MP3 equalizer question

audiocmp3

I want a library or some sort of a command that takes an MP3 file location as an input (only MP3 I don't need WAV, OGG, or any other type) and plays the file to the end of it and make some sort of an equalizer output but only in frequencies as numbers like (31HZ, 62HZ, …, 16 KHZ), all the 10 bands available but show them to me as ever changing 10 variables .. meaning like 31 HZ band is like (1, 30, 24, 5, 31, .. and so on) and that goes for every band … but it doesn't need to be 1 – 31 I mean it can be anything but the idea I am trying to say is to have the value of each band in numbers & separate it from the other bands …

Same idea as an equalizer but not exactly ..
So can it be done? Is there anything that can do it or help in doing it?

P.S.
– I am not making an equalizer.
– I am still a kind of a NOOB to C++ so take it easy and don't go "YOU FOOL THERE IS A COMMAND LINE THAT DOES THAT IN C++ PROPER" .. Thanks a lot 🙂

Best Answer

SoX (sound exchange) can give you a frequency analysis of an audio file as it plays it. The command

sox myfile.mp3 temp.wav stat --freq

will decode the MP3 file to a WAV file; while it does this, it performs a 4096-point Fourier transform on each block of audio, and prints frequency-power pairs like this to stderr:

0.000000  3.079278
10.766602  5.994057
<snip>
22028.466797  14.589799
22039.233398  14.289429
0.000000  0.232025
<snip>

So you would take these pairs as input, map the frequency value to your choice of bands, and add up the total for each band.

Alternatively, you could start with an open-source MP3 decoder (such as MAD), and modify it to do the analysis you want. MP3 decoding can be divided into two stages:

  • reconstruct the frequency spectrum from the coded bitstream
  • transform the frequency spectrum into the audio output

For your analysis, you only need to do the first stage, and then add up the spectral power in each of your equaliser bands. So this method would need a lot less processing than using SoX (which would complete the decode, then transform back to the frequency domain), but would tie you to MP3 only (which you say isn't a problem).

Related Topic