I'm working on Android project in which I must analyze audio signals in frequency domain. Actually I have ready module which is reading signal from device microphone and process it (FFT, visualizations, etc.) and I don't have any problems with this kind of signals.
Now I'm trying to analyze audio signal which is stored on device as mp3 file. Generally I don't have any issues with playing it from MediaPlayer object. Unfortunately I have some problem with getting access to data buffer played by my player, which I could you use to spectrum calculations.
Do you have any advices how can I get access to audio buffer? Is it at all possible with MediaPlayer or should I use other approach to this problem?
As far as I know, there is no way to directly access the buffer using a
MediaPlayer
.However, if you are using API >= 16 (Android 4.1), you can use the built-in
MediaCodec
class to decode your MP3 file to a raw PCM stream. You can perform your analysis on the data, then pass it along to anAudioTrack
to output it. This blog post shows an example of how to decode and send to an audio track.If you must support lower API levels, you can use a 3rd party library the same way. I've used JLayer in the past, but its performance is highly dependent on hardware. On some lower-end devices you won't be able to decode in real time.