Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random color on audio beat, then hold color til next beat

  • Random color on audio beat, then hold color til next beat

    Posted by Lionel Vicidomini on February 25, 2013 at 4:02 pm

    Hello everyone,
    I hope the title is self explanatory.
    What I aimed to do is very simple but I’m having a really hard time to do it.
    I have an audio file. I converted it to keyframe. I want to use each beat on the sound to trigger a color change on a layer. This random color stays put until the next beat happens, then it changes and holds this color til the next beat, and so on…

    I know this has to do with the seedRandom as :

    seedRandom(seed, true)
    where seed changes every time x (for example) reaches let’s say 20

    I’m stuck there. I guess it has also to do with if/else statement or a while/do.
    I know this must be extremely simple, but I just don’t get it.

    Thanks for any hint !

    Lionel Vicidomini replied 13 years, 6 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    February 25, 2013 at 6:22 pm

    Don’t feel bad–it’s not extremely simple.

    Try this:


    threshold = 15.0;

    audioLev = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");

    above = false;
    frame = timeToFrames(time);
    while (true){
    t = framesToTime(frame);
    if (above){
    if (audioLev.valueAtTime(t) < threshold){
    frame++;
    break;
    }
    }else if (audioLev.valueAtTime(t) >= threshold){
    above = true;
    }
    if (frame == 0){
    break;
    }
    frame--
    }

    seedRandom(frame,true);
    random([0,0,0,1],[1,1,1,1])

    Set threshold to the audio amplitude that signifies a beat.

    Dan

  • Lionel Vicidomini

    February 25, 2013 at 6:30 pm

    Perfect ! It works like a charm.
    Ok, now I have to understand it !
    At least I was on the right track 🙂

  • Lionel Vicidomini

    February 26, 2013 at 3:09 pm

    I was going to ask a lot of questions about this expression, then I found on your website the template used to do it… with all the explanations I could dreamed of !
    I still struggle a bit with all the “while” statement but I’m starting to get the hang of it.
    So thanks again !

    https://www.motionscript.com/design-guide/audio-trigger.html

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy