Algorithm to draw waveform from audio

后端 未结 7 1227
不思量自难忘°
不思量自难忘° 2021-01-31 12:06

I\'m trying to draw a waveform from a raw audio file. I demuxed/decoded an audio file using FFmpeg and I have those informations: samples buffer, the size of the samples buffer,

7条回答
  •  忘了有多久
    2021-01-31 12:30

    The second waveform is probably a column approximation of a simple zig zag graph.

    Every column is a line from the previous sample amplitude to the current sample amplitude.

    So read all the samples into a canvas or texture as a pre-test as dots, then, once you have done that you can do two cases, make bars instead of dots, draw upwards to last sample or upwards to this sample depending on whichever was higher, as long as you draw a line between to two. That makes sure that the waveform is small with low energies between next samples and high with high energies.

    You can alias it and measure multiple samples, it just depends what hardware you are running on, if you want to read 1000ds of samples and make a giant 2d array representation of the wave and then alias it downwards into a smaller displayable image or if you want to just run 512 samples only and update fast. with 2d canvas in programs it should be fast to make detailed waveforms with more than 512 samples.

    ... a different option is same as the grey waveform in the other answer, draw absolute value as lines from +current sample to -current sample.

    it helps to average multiple samples i.e. ever 4 samples or get max of every 4 samples to have a less erratic graph, it's a kid of fast aliasing.

提交回复
热议问题