ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression to change color of a text layer based on amplitude of audio layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Alfred Hammer
Expression to change color of a text layer based on amplitude of audio layer
on Aug 6, 2017 at 5:48:26 pm

Hello,

I'm trying to create a text layer that changes color with every snare drum hit using a while loop that increments a flag variable when the amplitude crosses a certain threshold and then use an if else if ladder to assign different rgb values for each of the flag values. It doesnt work at all as intended, it just switches between the colors. I'm a beginner with expressions and cant for the life of me figure out what is wrong as the logic seems to be okay. I would be extremely grateful for a correction or an alternate approach.

Thank you

//x<10000 to prevent ae from thinking this is an infinite loop and getting a time out
//c to account for the fact that a drum hit lasts for more than 1 frame


op=thisComp.layer("Amp").effect("Sound Keys")("Output 1");
flag=0
x=0
c=0

R=1
G=1
B=1
A=1

while(x<10000)
{

if((op>60)&&(c==0))
{
flag++;
c=1;}
else if((op<60)&&(c==1))
{
c=0;
}

if(flag==0)
{
R=0
G=0.8
B=linear(op,0,80,.4,.8);
A=1
}
else if(flag==1)
{
R=1
G=0
B=0
A=1
}
else
{
R=0
G=0
B=0
A=0
}
x++
[R,G,B,A]
}



Return to posts index

Dan Ebberts
Re: Expression to change color of a text layer based on amplitude of audio layer
on Aug 6, 2017 at 6:31:01 pm

I can't tell exactly how you want this to work, but it appears (forgive me if I'm wrong) that you may not be aware that expressions have no memory. That is, nothing persists from frame to frame. At any given frame, you can look at past (or future) pre-expression values of the property using valueAtTime(), but you can't save any calculations for later use.

Dan



Return to posts index

Alfred Hammer
Re: Expression to change color of a text layer based on amplitude of audio layer
on Aug 6, 2017 at 6:50:58 pm

Yipes, no memory perfectly explains the issue I've been having. If you had to assign a unique defined fill color to a text layer whenever a particular condition is met(in this case amplitude of audio layer increasing 60), how would you do this? Is it even possible without memory?

Thank you so much for your time


Return to posts index


Dan Ebberts
Re: Expression to change color of a text layer based on amplitude of audio layer
on Aug 6, 2017 at 7:04:55 pm

The trick is, at each frame, you have to figure out if an event you're looking for has happened in the past, and if so, how long ago did it happen? The only tool you have to do this is valueAtTime(). You can set up a loop that starts at the current time and goes back in time, frame by frame, looking for the start of the event. It's essentially what I do here:

http://motionscript.com/design-guide/audio-trigger.html

Your application may be less complicated, depending on what you need it to do.

Dan



Return to posts index

Alfred Hammer
Re: Expression to change color of a text layer based on amplitude of audio layer
on Aug 11, 2017 at 11:25:13 am

Managed to get it to work after going through your tutorial. Thanks you Dan


Return to posts index

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