ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Using changes in audio value to shift position up and down incrementally

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Benjamin Arthur
Using changes in audio value to shift position up and down incrementally
on Jan 13, 2020 at 7:45:23 pm

Hello all,

I consider myself to have an intermediate level of experience with writing expressions, but this has been a difficult challenge I haven't quite been able to make work.

I have incoming audio data that I've linearly mapped to a number between 0-5. This is attached to the y axis of a single pixel, making it move up to 5 pixels down in time with the audio. I'm using the positional data to drive something else, but for my purposes the movement is too dramatic.

The expression I'm trying to write is basically:
pos1 = current position of a pixel moving using the audio input
pos2 = previous position from -.09 seconds ago

if pos1>pos2 then move up by one,
if pos1 == pos2 no change,
and if pos1
My goal is to force the pixel to move incrementally toward the current value, never skipping a move.

My current approach is a version of Dan's audio counter:
http://www.motionscript.com/design-guide/audio-count.html

But I'm not really getting the outcome I was hoping for, it's not currently moving up or down. I'm still learning how an expression like this one works, so I'm probably facing a simple error of how to correctly compare values from different times.

Thanks for any help you can give, I appreciate your time and assistance.

audioLev = thisComp.layer("Yellow Solid 4").transform.yPosition
above = false;
frame = Math.round(time / thisComp.frameDuration);
n = 0;
while (frame >= 0){
t = frame * thisComp.frameDuration;
if (above){
if (audioLev.valueAtTime(t) &lt; audioLev.valueAtTime(t - .09) && n > 5){
above = true;
n++;
}

}else if (audioLev.valueAtTime(t) >= audioLev.valueAtTime(t - .09) && n > 0){
above = false;
n--;
}
frame--
}

n


Return to posts index

Dan Ebberts
Re: Using changes in audio value to shift position up and down incrementally
on Jan 13, 2020 at 8:45:12 pm

Based on your description, I think it would be roughly like this:


aud = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
period = .09;
curF = timeToFrames(time);
f = 0;
accum = 0;
curT = 0;
while (f <= curF){
curT = framesToTime(f);
p1 = aud.valueAtTime(curT);
p2 = aud.valueAtTime(curT - period);
if (p1 > p2)
accum++
else if (p1 < p2)
accum--;
accum = Math.max(accum,0);
f++;
}
accum



Dan



Return to posts index

Benjamin Arthur
Re: Using changes in audio value to shift position up and down incrementally
on Jan 16, 2020 at 12:44:58 am

Thanks so much! I'm still foggy on how to use timeToFrames and framesToTime correctly - I better hit the books!

Very much appreciated -


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]