@Mirlashttps://dl.dropboxusercontent.com/u/553 ... ation.capx
Before you read my long comment below, maybe you want to see this capx first, if this is roughly what you wanted, then the long comment below might interest you, but if it is not, then just ignore my rambling >.<
The velocity of movement, whether it is angular or positional, is always the 1st derivative of displacement. In this case, we can either take the formula of the used tween's function, then get the derivative of it, multiply it with some value (in here, the duration), then we get the velocity of it.
If you use linear tween, it is so easy to get velocity because the speed at any moment is the same everywhere. The derivative of a linear function is a constant, in this example it proportionally inverse with duration.
- So, in this case, you can set timescale of the audio to 1 for 1 sec. I just use set playback rate in the audio object to correctly change pitch also.
- When the duration is 0.5 then the speed at any given moment of time is always 2. So set timescale to 2 for duration of 0.5 sec.
- When the duration is 0.75, then the speed at any given moment is 1/0.75, 1.33333. So set timescale to 1.3333 for duration of 0.75.
- For other duration, just take 1/x as timescale.
Now the worse part.
For other tween's formula, like elastic ease, it would be hard or even impossible to take derivative, because its function is segmented. And I can't also set the audio timescale to alter the pitch. The speed at an any exact time is different. So, in these case, the previous example of how to calculate speed in every time moment would be useful. So, each tick i get the old position/angle and take the new position and angle, and then divide it by the delta time, it will make it a very roughly approximation of the current speed. If we divide this value with the linear speed of the tween, we can get the right timescale for it.
In this capx I stop and play the audio at every tick and adjust the timescale at every deltatime. In this capx example though, it has a clicking noise, because it is stopping abruptly during a waveform play, the way to eliminate this will be to use very quick crossfading between the microsample.