I am trying to implement ‘volume automation’ in a jQuery audio player I have built.
As you can see form the picture below I have a line graph overlayed which has draggable points.
While the audio is playing an event fires every second (currently, I may up the frequency if needed) which collects the data.
The data I am returning is the audio position and the volume (determined from the height of the ‘point’… not the line itself.
This means that currently despite a slope being rendered the volume only changes when each individual point is reached in the song. (a point being a single ‘dot’ on the line.

I have chosen to do it this way performance reasons.
However, using this method means that I need to perform a calculation to work out the volume inbetween the points.
Math really is not my strong point and I can remember very little from my school days.
I am storing the variables currently as:-
- x0 = Last point position
- x1 = next point position
- y0 = Last point
- y1 = next point
- position = current position in seconds
I hope the above makes sense!
If I remember correctly the equation needed is something to do with calculating the difference between the two points, so I assume this would just need a simple equation using the contents of the above variables.
The volume scale is 0-100. Therefore obiously a point at the top of the waveform should have a volume value of 100 and a point at the bottom should have a volume value of 0. With the individual points inbetween being calculated by the required equation.
If anyone can shed any light on this matter or help point me towards a solution It would be much appreciated!
So you want to find the volume(y) between two points? As in (position – x0) * (y1 – y0) + y0?
Note that that is simplified based on the given that x0 and x1 are 1 unit apart.
Full detail:
Find slope: slope = (y1-y0)/(x1-x0)
Find % we are between x0 and x1: distance = (position – x0) / (x1 – x0)
slope * distance will give us the change thus far: change = slope * distance
To find the new value, add the change to the last value: y position = change + y0;
Re-substituting all the variables gives us:
y0 + ( ((y1 – y0)/(x1 – x0)) * ((position – x0) / (x1 – x0)))
If you’re sample is at 1 unit, you can leave out the (x1 – x0) term.