Algorithm for drawing a signal from audio

I am trying to draw a signal from an unprocessed audio file. I debuted / decoded an audio file using FFmpeg and I have this information: sample buffer, sample buffer size, audio file length (in seconds), sample rate (44100, 48000, etc.), Sample size, sample format ( uint8, int16, int32, float, double) and the original audio data itself.

Digging on the Internet, I found this algorithm (more details here ):

White noise:

White noise

Algorithm

All you have to do is randomize each sample from -difference to amplitude. In most cases, we don’t care about the number of channels, so we just fill each sample with a new random number.

Random rnd = new Random(); short randomValue = 0; for (int i = 0; i < numSamples; i++) { randomValue = Convert.ToInt16(rnd.Next(-amplitude, amplitude)); data.shortArray[i] = randomValue; } 

This is really good, but I do not want to draw this way, but like this:

audacity

Is there any algorithm or idea of ​​how I can draw using the information I have?

+5
source share
6 answers

First you need to determine where each sample will be displayed on the screen.

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

Now, for all samples with the same x , define min and max separately for positive and negative values. Draw a vertical line dark from negative maximum to positive max, then light from minus minus to positive minimum over it.

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

+5
source

There is a good audiowaveform program from the BBC R&D that does what you want, you can consult your sources.

+3
source

I think you mean the waveform described here.

http://manual.audacityteam.org/o/man/audacity_waveform.html

I did not read the whole page. But each vertical bar represents a window of waveform samples. Blue are the maximum positive and minimum negative values ​​in this window (I think). And blue is the rms value of the rms value. http://www.mathwords.com/r/root_mean_square.htm . (basically you square the values ​​in each window, take the average value, and then the square root.

Hope this helps.

+3
source

The lower graphs simply include a longer period of time, so if you increase the number, you will get a denser graph. But with white noise, you will not see peaks and troughs that you will find in ordinary sounds / music.

So, if you can increase the sample size, or at least increase the sampling period (x axis), you will start emulating the bottom diagrams. Use two of them to get a stereo effect.

+1
source

showwavespic

ffmpeg can draw a waveform with a showwavespic filter.

enter image description here

 ffmpeg -i input -filter_complex "showwavespic=split_channels=1" output.png 

See the showwavespic documentation for parameters.

showwaves

You can also make live video using the showwaves filter.

 ffmpeg -i input -filter_complex \ "showwaves=s=600x240:mode=line:split_channels=1,format=yuv420p[v]" \ -map "[v]" -map 0:a -movflags +faststart output.mp4 

See the showwaves documentation for options.

+1
source

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

Each column is a row from the previous sample amplitude to the current sample amplitude.

So, read all the patterns in the canvas or texture as a preliminary test in the form of dots, then, as soon as you do this, you can do two cases, make columns instead of dots, draw up to the last pattern or up to this pattern, depending on which was higher as long as you draw a line between the two. This ensures that the waveform is small at low energies between the following samples and high with high energies.

You can pseudonize it and measure several samples, it just depends on what equipment you are working on, if you want to read 1000ds of samples and create a gigantic representation of a 2d wave array, and then hide it down to a smaller displayed image or if you just want to run Only 512 samples and update them quickly. with a 2-dimensional canvas in programs, it must be fast to create detailed waveforms with more than 512 samples.

... another option is the same as the gray wave in another answer, output the absolute value in the form of lines from + the current sample to the sample-camera.

it helps to average several samples, i.e. Ever 4 samples, or get the maximum out of every 4 samples to have a less erratic graph, this is a quick smoothing guy.

+1
source

Source: https://habr.com/ru/post/1205901/


All Articles