开发者

Getting audio volume during playback

开发者 https://www.devze.com 2023-03-19 05:28 出处:网络
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).

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 :-)


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消