Decode mp3 to an array of amplitude values

406 views
Skip to first unread message

Zander Labuschagne

unread,
Jun 2, 2021, 4:09:47 PM6/2/21
to gstreamer-java
Hello,

Can someone please point me into a direction that will allow me to decode mp3 files and provide me with an array of amplitudes or even just a byte array of the audio?

My aim is to draw an audio graph of the sound similar to Audacity but for one channel only. I am already doing this for wav where I get the byte array from the audio input stream and converting the values from the byte array into a float array of amplitudes using the provided sample size, number of channels and endianness.

PS: I am new to audio processing.

Thank you and kind regards,
Zander Labuschagne

Neil C Smith

unread,
Jun 3, 2021, 9:52:58 AM6/3/21
to gstream...@googlegroups.com
Hi,

On Wed, 2 Jun 2021 at 21:09, Zander Labuschagne <labusc...@gmail.com> wrote:
> Can someone please point me into a direction that will allow me to decode mp3 files and provide me with an array of amplitudes or even just a byte array of the audio?

Using GStreamer just for that purpose may be somewhat overkill if you
don't need it elsewhere. Maybe look into the Tritonus JavaSound
support for MP3 - seems to be available on Maven at
https://search.maven.org/search?q=g:com.googlecode.soundlibs

You can see an example of using the GStreamer level element on audio
with playbin in
https://github.com/gstreamer-java/gst1-java-examples/blob/master/SwingPlayer/src/main/java/org/freedesktop/gstreamer/examples/SwingPlayer.java

Best wishes,

Neil

--
Neil C Smith
Codelerity Ltd.
www.codelerity.com

Codelerity Ltd. is a company registered in England and Wales
Registered company number : 12063669
Registered office address : Office 4 219 Kensington High Street,
Kensington, London, England, W8 6BD

Zander Labuschagne

unread,
Jun 3, 2021, 10:48:16 AM6/3/21
to gstreamer-java
Thanks,

That worked for me. I am still using GStreamer to play the audio and to seek around and loop certain segments etc, I just thought there might be a quick and easy way to let GStreamer give me an array of the levels.

That level element is only the current level though? Or can it give me the levels for the entire file? From what I saw is that it subscribes to get messages with the level in that moment while playing.

Kind regards,
Zander Labuschagne

Neil C Smith

unread,
Jun 3, 2021, 11:01:49 AM6/3/21
to gstream...@googlegroups.com
On Thu, 3 Jun 2021 at 15:48, Zander Labuschagne <labusc...@gmail.com> wrote:
> That level element is only the current level though? Or can it give me the levels for the entire file? From what I saw is that it subscribes to get messages with the level in that moment while playing.

Yes, but you can make it play faster! eg. using a fakesink or other
sink not synced to the clock, you should be able to collect all the
level data as fast as you can. Or you could use an appsink and get
all the audio data as raw bytes / float values.

Zander Labuschagne

unread,
Jun 3, 2021, 11:15:59 AM6/3/21
to gstreamer-java
Ah ok thanks I understand now. I will stick to my current implementation (the one you mentioned at the top), when I need to get them from a new format not supported by Tritonus JavaSound I will use GStreamer as it will probably support more formats.

Thanks for your help!
Kind regards,
Zander Labuschagne
Reply all
Reply to author
Forward
0 new messages