Trying to go a bit further with oF, I would like to create spectrograms from music files (typically mp3/aac).
I have been able to generate spectrograms from mp3 files by playing it using ofSoundPlayer and ofSoundGetSpectrum, and from live audio (MIC) data using ofxFft (see ofxFftTest example).
But I did not find any way to get the audio data in order to analyze it using ofxFft.
Do you mean the raw audio data? You can retreive it directly within your testApp class. Take a look at the examples/audioInputExample, especially at the audioIn function. That’s what ofxFFT is using as well. Or if you just need the fft values and are using the github version of openFrameworks, you can also use the built in ofSoundGetSpectrum function. There’s an example called soundPlayerFFTExample.
The audio data I wan to access is the one inside my MP3 files (the audio buffers).
And I can’t use ofSoundGetSpectrum as that function only works in real-time audio output, and I want to process my files in the background and display their info as images.
hoh, if I understand you correctly you just want to work with the actual data of your mp3 file? i.e. the unencrypted binary bits? This is a bit tricky w/MP3 b/c it’s encoding using the mp3 codec, so if you, for instance, wanted the waveform data from a particular section of bytes you’d need to unencode it in the background. This isn’t too hard to do if you’re comfortable with threads, but it’s a bit tricky if you’re not. The easiest way to get raw waveform data is to use raw PCM files instead of MP3 (you can use Audacity to generate these). If you need something else out of the mp3 file there are plenty of examples around of that (for instance, album art here: http://digitalpbk.blogspot.com/2007/01/extracting-embedded-album-art-in-mp3.html)
Indeed, I want to decode the files on the fly. I am confident with threads, but not very with learning heavy libraries. MAD looks good, but only does MP3 and my music is also in AAC and FLAC.
There should be a way to access the audio buffer used by ofSoundPlayer (which is itself using FMOD), and the problem would be solved for all formats supported by oF, but I don’t know how to access these buffers.
An other solution would be to use FFmpeg, but I don’t really want to install it with all it’s dependencies on my Mac and all machines that would use my demo.
the new ofOpenALSoundPlayer in github, does exactly this: uses sndfile to decode most of the formats except mp3, mpg123 to decode mp3 and then kiss and indeed the same algorithms than ofxFFT to do the fft
the code is not the cleanest but if you want to take a look: