Can I get raw PCM data from MediaPlayer or SoundPool?

I am using eclipse with android sdk 4.0.3 api lvl 15 to build a basic music player app.

I read and found that there are two main classes for playing sounds. MediaPlayer and SoundPool. SoundPool has more flexibility in sound priority and sound playback speed.

I would also like to draw an audio visualization graph.

Is there a way to get the raw PCM data from the loaded audio object so that I can draw the graph?

Is there a way to manipulate the raw data before it is played back in real time? for example if I want to add realtime effects. is this possible with these classes? or any other?

The main reason I want to use one of these classes is because they can read audio formats without having to read the file and parse the formats for raw PCM data on their own.

all information regarding this issue would be greatly appreciated.

thank!

Kfir

+3


source to share


3 answers


I have gone through one open source project.

because they downloaded the PCM audio file.



here is the link

hope it helps you to draw PCM from audio file.

+3


source


Hey, see AudioTrack for reading in bytes. You can manipulate the byte array before you start playing it back. http://developer.android.com/reference/android/media/AudioTrack.html

Audiotrack is definitely easier to control since you access the raw data, but you have to do the work yourself and not just load the class (MediaPlayer) into the asset file.

Also have a look at this example for reading assets into a byte array http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/content/ReadAsset.html



I'm not sure if you can use byte arrays to draw the graph?

Hope this helps you ;-) The Android audience is really not that well documented, I'm afraid I haven't been from day one; \

+3


source


I have a strong feeling that you are out of luck to get PCM from these Android classes. They are definitely too tied to their own layer (due to performance) and the implementation differs from different api versions or devices. If you haven't found any API related to PCM yet, then they may not be there.

The solution would be to make the audio mixer yourself, either in Java or C / C ++, then you will have PCM data. I expect it to be quite slow to receive PCM data in Java, process it there, send it back to play audio. You may have to move on to NDK programming.

+1


source







All Articles