Algorithm to draw waveform from audio

后端 未结 7 1170
不思量自难忘°
不思量自难忘° 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:26

    First, you need to determine where on the screen each sample will end up.

    int x = x0 + sample_number * (xn - x0) / number_of_samples;
    

    Now, for all samples with the same x, determine the min and the max separately for positive and negative values. Draw a vertical line, a dark one from negative max to positive max, then a light one from negative min to positive min over the top of it.

    Edit: thinking about this a little more, you probably want to use an average instead of the min for the inner lines.

提交回复
热议问题