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 :)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).
If you think you are kind a newbie to C++ then I would recommend you to use Qt Phonon library. I have created a simple demo, see comments in the code:
#include <QtCore/QCoreApplication>
#include <phonon>
#include <iostream>
using namespace Phonon;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Phonon::AudioOutput m_AudioOutput(Phonon::MusicCategory);
// Create Phonon music player
MediaObject *music = createPlayer(MusicCategory,MediaSource("path_to_audio_file.mp3"));
// Get list of included Fxs and print it to the stdout
QList<EffectDescription> fxs = Phonon::BackendCapabilities::availableAudioEffects();
for(QList<EffectDescription>::iterator i = fxs.begin(); i != fxs.end(); i++)
{
std::cout<<std::string(i->name().toUtf8())<<std::endl;
}
// Creates a new Path connecting the two MediaNodes - source and sink
Phonon::Path path = Phonon::createPath(music, &m_AudioOutput);
if(path.isValid ())
{
// Create parametric EQ
Phonon::Effect *effect = new Phonon::Effect(fxs.at(0));
path.insertEffect(effect);
// Get list of fx parameters
QList<Phonon::EffectParameter> pars = effect->parameters();
// Do some changes with parameters - set frq. bands as you need
effect->setParameterValue(pars.at(0), 600); // Center frequency in Hz
effect->setParameterValue(pars.at(1), 12); // Bandwidth in Hz at -3dB
effect->setParameterValue(pars.at(2), -12); // Gain in dB
// Play audio file effected by the inserted Audio Fx
music->play();
}
return a.exec();
}
In case you are not familiar with the parametric EQ parameters take a look at this link:
http://www.astralsound.com/parametric_eq.htm
精彩评论