Skip to content

Question: Does Korge have a built in solution for generating audio waveforms for an mp3? #1492

Answered by soywiz
Kietyo asked this question in Q&A
Discussion options

You must be logged in to vote

Yes. You can convert a Sound into an AudioData with toAudioData or directly load an AudioData. Then that class has the rate (hz). Typically 44100 and the samples: https://github.com/korlibs/korge/blob/main/korau/src/commonMain/kotlin/com/soywiz/korau/sound/AudioData.kt#L20

The samples is a list of amplitudes of the wave at the rate frequency. 44100 means that in 1 second you have 44100 amplitude samples. The samples are typically Shorts (between -32.768 and +32.767) or Floats between (-1f and +1f).

For plotting, you can reduce the number of samples by averaging them for example, then rendering the amplitudes. And that should be your waveform.

Replies: 2 comments

Comment options

Kietyo
Sep 7, 2022
Maintainer Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by soywiz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #976 on March 30, 2023 02:55.