-
Expression to change color of a text layer based on amplitude of audio layer
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=0R=1
G=1
B=1
A=1while(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]
}