Getting audio volume during playback

I have some audio data (raw AAC) inside a byte array for playback. During playback, I need to get its volume/amplitude to draw (something like an audio wave when playing).

What I'm thinking now is to get the volume/amplitude of the current audio every 200 milliseconds and use that for drawing (using a canvas), but I'm not sure how to do that.

. . . .

** 2011/07/13 add following **

Sorry just been delayed on other project until now.

What I tried is run the following codes in a thread, and playing my AAC audio.

a loop
{
  // int v=audio.getStreamVolume(AudioManager.MODE_NORMAL);
  // int v=audio.getStreamVolume(AudioManager.STREAM_MUSIC);
  int v=audio.getStreamVolume(AudioManager.STREAM_DTMF);
  // Tried 3 settings above
  Log.i(HiCardConstants.TAG, "Volume - "+v);
  try{Thread.sleep(200);}
  catch(InterruptedException ie){}
}

But only get a fixed value, not dynamic volume...

And I also found a class named Visualizer, but unfortunately, my target platform is Android 2.2 ... :-(


Any suggestions are welcome :-)

Answers


After days and nights, I found that an Android app project called ringdroid can solve my problem. It helps me to get an audio gain value array, so that I can use to to draw my sound wave.

BTW, as my experience, some .AMR or .MP3 can't be parsed correctly, due to too low bitrate...


Need Your Help

auto generate Rest service in node.js

rest node.js express mongoose

Is there a way to auto generate a Rest service in node.js like in rails?

Get static date from calendar

c# .net datetime calendar

I want to run some processes(C# class) on 20th day in every month. How can i do this.