Quantcast
Channel: Adobe Community : Popular Discussions - After Effects Expressions
Viewing all articles
Browse latest Browse all 47983

Triggering a random color change with audio amplitude?

$
0
0

Hey guys, I have a project I'm working on where I want the audio (specifically the bass hit in the song) to trigger a color change of the background's color. I am almost getting the desired effect, but it is not an instant change, and seems to change multiple times for each bass hit rather than just once per beat. The other unintended effect is that when the bass beat stops completely, the color changes back to the original hue the layer has before the timeline starts. Instead, I'd like each hit to make the color change and it keep it there until the next beat. I would appreciate any and all help to try to get this to work!

 

First, I isolated the beat of the song and converted the audio to keyframes. I have named this keyframed slider layer "bass". Next, I am starting with a solid the size of my composition and using the Hue/Saturation effect. From there I am making it colorize the layer, writing the expression on the stopwatch of the Hue property. This is the expression I currently have:

 

threshold = 20.0; //audio amplitude to trigger color change
b = thisComp.layer("bass").effect("Both Channels")("Slider"); //bass layer
c = (b+(2*time)); //Hue change increment as to grow over time
accum = 0;

above = false;
frame = Math.round(time / thisComp.frameDuration);
while (true){
  t = frame * thisComp.frameDuration;
  if (above){
    if (b.valueAtTime(t) < threshold){
      accum += 0;
      frame++;
      break;
    }
  }else if (b.valueAtTime(t) >= threshold){
      accum += c;
      above = true;
  }
  if (frame == 0){
    break;
  }
  frame--
}
if (! above){
  t = 0;
}else{
  t = time - frame * thisComp.frameDuration;
}


effect("Hue/Saturation")("Colorize Hue") + accum

 

Any thoughts?


Viewing all articles
Browse latest Browse all 47983

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>