EXPLANATION FOR EVERYBODY
I am a developer of a dj app and was searching for similar answers.
So i will explain all about the music waveform you may see in any software including audacity.
There are 3 types of waveforms used to display in any music software.
Namely Samples, Average and RMS.
1) Samples are the actual music points presented in a graph, could be an array of raw audio data (points you see when you zoom the waveform in audacity).
2) Average: most commonly used, suppose you are displaying 3 minute song on screen, so a single point on screen must display atleast 100ms(approx) of the song which has many raw audio points, so for displaying we calculate the average of all the points in that 100ms duration, and so on for the rest of the track (dark blue big waveform in audacity).
3) RMS: similar to average but here instead of average, root mean square of the particular duration is taken (the small light blue waveform inside the blue one is rms waveform in audacity).
Now how to calculate waveforms.
1) Samples is raw data when you decode a song using any technique you get raw samples/points. Now based on the format of points you convert them to range -1 to 1, example if format is 16-bit you divide all points by 32768(maximum range for 16 bit number) and then draw the points.
2) for average waveform - first add all points converting negative values to positive, then multiply by 2 and then take average.
//samples is the array and nb_samples is the length of array
float sum = 0;
for(int i = 0 ; i < nb_samples ; i++){
if(samples[i] < 0)
sum += -samples[i];
else
sum += samples[i];
}
float average_point = (sum * 2) / nb_samples; //average after multiplying by 2
//now draw this point
3) RMS: its simple take the root mean sqaure - so first square every sample, then take the sum and then calculate the mean and then sqaure root. I will show in programming
//samples is the array and nb_samples is the length of array
float squaredsum = 0;
for(int i = 0 ; i < nb_samples ; i++){
squaredsum += samples[i] * samples[i]; // square and sum
}
float mean = squaredsum / nb_samples; // calculated mean
float rms_point = Math.sqrt(mean); //now calculate square root in last
//now draw this point
Note here the samples is the array of points for calculating the point/pixel for a particular duration of song. example if you want to draw 1 minute of songs data in 60 pixels so the samples array will be the array of all points in 1 second, i.e the amount of audio points to be displayed in 1 pixel.
Hope this will help someone to clarify the concepts about audio waveform.