3

I'm currently developing an android app and need to be able to render a Waveform of an audio file. I already read about the Visualizer class, but I think that class is designed to do realtime calculation. What I want to do is go trough an audio file and generate for example an .PNG that contains a waveform of the whole audio file.

Basically something like soundcloud does: http://www.djban.com.br/wp-content/uploads/soundcloud-waveform.png

Are there any libraries that can do this? Or can you tell me how I can get an array of amplitudes of an audio file?

Community
  • 1
  • 1
Heisenbug
  • 154
  • 2
  • 14

1 Answers1

3

I don't know of any library but it should be easy to get it working.

First, in order to get the Amplitude of the wave form, you will need the audio in PCM format. Assuming that you need the waveform for arbitrary audio files (mp3 in particular), you will need to find a way to convert between formats. A quick google search gives this result. NOTE: if you just need to do it for audio coming from the microphone, you can avoid the conversion since it delivers audio data in the PCM format.

After getting the samples, you will need to draw their amplitudes somehow. You have several options, but I would give the Canvas a try. You can draw lines (or general shapes) there and then export it to a file or draw it on the screen.

Another option to draw is OpenGL. This is more complicated if you haven't use it before, but it will be probably faster.

Community
  • 1
  • 1
Esparver
  • 1,515
  • 1
  • 15
  • 28
  • Thanks for the fast answer, but can you explain why I need to convert the file to the PCM format? What are the benefits? Can't I just get the samples within any other format that android can open? The drawing process is not the problem, I'm familiar with Android. It's how I can read the samples of an audio file and how I can get the amplitude of these samples. Thanks for taking the time to respond! – Heisenbug Apr 08 '13 at 13:57
  • There is no amplitude information in the mp3 file (at least directly). That's why you need to convert it to PCM or a similar format (such as uncompressed WAV). Android's MediaPlayer can play mp3 files, but it doesn't give you the amplitude information. I didn't try it, but in the post about the mp3plugin seems quite easy. You don't need to save the converted file, just play a bit with buffers. – Esparver Apr 08 '13 at 14:14