-
I'm creating a keyboard based rhythm game and I'd like to create an editor which shows the audio wave form of the song to make it easier for users to create their own songs to play on. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Note to self: Useful reading: https://www.izotope.com/en/learn/digital-audio-basics-sample-rate-and-bit-depth.html |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
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.