Skip to main content
Known Participant
August 7, 2021
Answered

Rotation Expression

  • August 7, 2021
  • 1 reply
  • 937 views

I saw a comment on the thread I have linked below, I will also attach a couple screenshots of the comment which describes the expression I need. I want to know how to make the rotation property increase every time the value of both channels goes up instead of returning to the original position when the audio levels drop.

 

 

https://community.adobe.com/t5/after-effects/how-can-i-associate-an-expression-to-move-a-rotating-wheel-x-times-depending-on-audio-amplitude/m-p/10577859

This topic has been closed for replies.
Correct answer Dan Ebberts

Hi Dan,

 

I have made a video detailing what I want hope this helps. rotation expression explaination 


You could try playing around with this, but it'll get pretty slow if your comp is long:

a = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
constSpeed = 10;
mult = 10;
n = a.numKeys;
if (n > 0 && a.key(1).time < time){
  accum = a.key(1).value*(a.key(1).time - inPoint);
  for (i = 2; i <= n; i++){
    if (a.key(i).time > time) break;
    k1 = a.key(i-1);
    k2 = a.key(i);
    accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
  }
  accum += (a.value + a.key(i-1).value)*(time - a.key(i-1).time)/2;
}else{
  accum = a.value*(time - inPoint);
}
value + accum*mult + constSpeed*(time-inPoint)

Adjust constSpeed to control how fast it rotates with low/no audio and adjust mult to control how much it responds to loud audio.

 

 

1 reply

Dan Ebberts
Community Expert
Community Expert
August 7, 2021

Your question could be interpreted more than one way, and it's not clear which one you're after, but I think this is one possible solution:

a = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
mult = 1.0;
f = timeToFrames(time);
accum = 0;
prev = 0;
for (i = 0; i <= f; i++){
  next = a.valueAtTime(framesToTime(i));
  if (next > prev){
    accum += (next - prev)*mult;
  }
  prev = next;
}
accum

 

Known Participant
August 15, 2021

Hi Dan thanks for your response. The effect I am aiming to achieve is to have the rotation of the subject increase smoothly as the volume of the audio amplitude/audio keyframes increases and as the volume decreases I'd like the rotation to slow down while still rotating in the same direction (clockwise). I tried to use the expression you gave me however thte motion is really jagged and not smooth. Hope that made sense, if possible it would be great if we could have a zoom call so I can share my screen with you but if not please provide the appropriate expression.

 

Many Thanks!

Dan Ebberts
Community Expert
Community Expert
August 15, 2021

The key is coming up with the algorithm that defines the relationship between the audio that has occured in the past and the current rotation value. Maybe you could provide a sketch of what that would look like?