Can I get raw PCM data from MediaPlayer or SoundPool?

心不动则不痛 提交于 2019-12-01 06:25:56

问题


i use eclipse with android sdk 4.0.3 api lvl 15 to create a basic music player application.

I read and found that there are two main classes to play sounds. MediaPlayer and SoundPool. SoundPool has more flexibility regarding sound priority and rate of played sound.

I would also like to draw a visualization graph of the audio.

is there a way to get raw PCM data from the loaded audio asset in order for me to be able to draw the graph ?

is there a way to manipulate the raw data before it's being played on realtime? for example if i want to add real time effects. is that possible with these classes ? or any other ?

the main reason that I want to use one of these classes because they can read audio formats without me needing to read the file and parse the formats to raw PCM data myself.

any information regarding the issue would be greatly appreciated.

thanks!

Kfir


回答1:


I have been go through one open source project .

in that they have loaded PCM of audio file .

here is the link

hope its help you draw PCM from audio file .




回答2:


Hey have a look at AudioTrack for reading in bytes. You can manipulate the byte array of sound before you actually play it back. http://developer.android.com/reference/android/media/AudioTrack.html

Audiotrack is definately more easy to control, since you get access to do the raw data, but you gotta do the work yourself, instead of just loading the class (MediaPlayer) with an asset file.

Also 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 the byte arrays for drawing a graph?

Hope this helps you ;-) The audiopart of Android really isn't that well-documented I'm afraid and hasn't been since day one ;\




回答3:


I have strong feeling you're out of luck to get PCM from these Android classes. They're certainly too much tied to native layer (due to performance), and implementation differs on various api versions or devices. If you didn't find any PCM-related API yet, then there may not be any.

Solution would be to make audio mixer yourself, either in Java or C/C++, then you'd have PCM data. I expect it to be rather slow to get PCM data to Java, process it there, send back to audio playback. You'd probably have to go down to NDK programming.



来源:https://stackoverflow.com/questions/9762949/can-i-get-raw-pcm-data-from-mediaplayer-or-soundpool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!