How to access raw audio (ie. to draw waveform)?

All your problems with Audio, Video and Images.

How to access raw audio (ie. to draw waveform)?

Postby metachris » Mon Feb 23, 2009 4:25 pm

Hi all!

I would like to draw the waveform of an audio file, and was wondering how to access the raw data...

I have not too much experience with audio processing, but figured I need to decode a local audio file in order to access the raw data. With this data I would get the amplitudes I need for the waveform, right?

Thanks for any ideas / hints!

Chris
Last edited by metachris on Sat Feb 28, 2009 3:34 pm, edited 1 time in total.
metachris
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sat Feb 07, 2009 11:40 am

Top

Postby Haibane » Wed Feb 25, 2009 9:23 am

I think you should access the data as a bit array and do the processing on it (FFT?)
User avatar
Haibane
Junior Developer
Junior Developer
 
Posts: 17
Joined: Fri Feb 13, 2009 10:05 am
Location: Klagenfurt, Austria

Postby torpor » Wed Feb 25, 2009 10:35 am

I think the question is how can we access the raw data array through the MediaPlayer object - is there a Listener event we can track, or is there some other method to gain access to the current play-back buffer? The idea would be that we would still use the MediaPlayer object, but somehow track the amplitude in realtime .. so some sort of listener?
torpor
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Feb 24, 2009 12:23 pm

Postby metachris » Wed Feb 25, 2009 11:48 am

torpor wrote:I think the question is how can we access the raw data array through the MediaPlayer object - is there a Listener event we can track, or is there some other method to gain access to the current play-back buffer?

Exactly! Like this we could use the audio decoding of the MediaPlayer and access the raw buffer. That would be awesome!

torpor wrote:The idea would be that we would still use the MediaPlayer object, but somehow track the amplitude in realtime .. so some sort of listener?

Hm, I think realtime is far to slow (if we mean the same thing). Realtime as I understand it in that context would be that you play the track first and each second or so get the max Amplitude. That would take simply too long. The MediaRecorder has a feature called getMaxAmplitude() that does that...

The best way would be if we could:
(1) Use the MediaPlayer to decode the audio files and access the buffer (raw audio data)
(2) Use the Android Audio-Decoders manually and get the buffer that way

Either way, it has to be fast (the waveform of a 3 minute track should be recognized in like 5 seconds)!
Last edited by metachris on Sat Feb 28, 2009 3:34 pm, edited 1 time in total.
metachris
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sat Feb 07, 2009 11:40 am

Postby MrSnowflake » Wed Feb 25, 2009 1:17 pm

metachris wrote:
torpor wrote:I think the question is how can we access the raw data array through the MediaPlayer object - is there a Listener event we can track, or is there some other method to gain access to the current play-back buffer?

Exactly! Like this we could use the audio decoding of the MediaPlayer and access the raw buffer. That would be awesome!
Indeed, but this is not possible :(.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Haibane » Wed Feb 25, 2009 1:44 pm

I think it would highly depend on the cpu... which can be a problem on slower android devices
User avatar
Haibane
Junior Developer
Junior Developer
 
Posts: 17
Joined: Fri Feb 13, 2009 10:05 am
Location: Klagenfurt, Austria

Top

Postby tbennett » Tue Jun 16, 2009 7:22 pm

Analyze the file itself. If it's a .wav, you can just parse the WAV header, seek to the data offset, then measure/store a sample of amplitude values, similar for .mp3's. Google Code Search for "Ringdroid" and examine the method used there for .mp3's. Also code search "android WaveHeader" for some useful WAV header types. I've done exactly this a few different ways and it's surprisingly fast on an actual G1 for both short .wav sounds and full-length .mp3's, just have to set a reasonable interval to pull your amplitude samples.
tbennett
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Dec 07, 2008 7:58 am

Re: How to access raw audio (ie. to draw waveform)?

Postby misu_cosma@yahoo.com » Mon May 09, 2011 11:07 am

Hey can u post some code?

I'm new to android so I could use some help?

Thanks!
misu_cosma@yahoo.com
Freshman
Freshman
 
Posts: 7
Joined: Mon May 09, 2011 11:03 am

Re: How to access raw audio (ie. to draw waveform)?

Postby tbennett » Tue May 10, 2011 8:42 pm

tbennett
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Dec 07, 2008 7:58 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 12 guests