Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Audio reactive shape layer query

  • Audio reactive shape layer query

    Posted by Ben Beasley on December 6, 2023 at 3:09 pm

    Hi AFX expression experts

    I’m going to try and get away with asking for help with two problems, however they are related:

    1) I want to use the audio amplitude from a track to change the number of points in a shape layer, so that the points change with the main beat of a piece of music. I know that I can use the following expression to achieve this, which will also use a selected range of keyrames from the audio amplitude that’s mapped to a range of points on the shape layer:

    maxAudio = 45;
    temp = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
    linear(temp,35,maxAudio,3,20)

    So with this, the shape has 3 points at 35 audio units or less. This results in the shape having 3 points (a triangle!) most of the time, as there is a keyframe on every frame, and most of these are under 35, apart from the main beat which is approximately every 12 frames.

    However, is there a way for the keyframes that fall beneath the range (under 35) to be disregarded entirely? So that the shape only reacts to the keyrames within the range (35-45), and keeps the number of points from last keyframe that falls in that range?

    2) Can the number of points in the above shape layer that are reacting to the audio be randomised, but, still fall within a range (e.g. a random number of points between 3 and 20 that are reacting to the beat of the song)?

    I hope that makes sense!

    Many thanks for any help

    Ben

    Ben Beasley replied 2 years, 8 months ago 3 Members · 5 Replies
  • 5 Replies
  • Tom Morton

    December 6, 2023 at 3:35 pm

    On your first question, you can analyse the variables with standard if statements:

    if (temp < 35) { temp=35 ; };

    Not sure I entirely get point 2, but just to sum up, when the amplitude ranges from 35 to 45, you map that to the equivalent number in 3-20, and then the polygon has the corresponding amount of points? Are you asking how to animate a random selection of those points?

    If you can explain a bit more what you’re trying to do that would be useful – it’s some kind of live audio visualisation right?

    Just another note, for the cleanness of your code you may want to round the “temp” variable as the output from the linear() expression may give you a float. If you add “temp = Math.floor(temp)” after the linear expression, that will remove any numbers after the decimal point and ensure you’re working with whole numbers. (although AE can handle this, it’s good practise to keep it clean)

  • Ben Beasley

    December 6, 2023 at 4:43 pm

    Hi thanks so much for your reply.


    On your first question, you can analyse the variables with standard if statements:

    if (temp < 35) { temp=35 ; };

    Ok great – I’ll give that a try.

    Are you asking how to animate a random selection of those points? If you can explain a bit more what you’re trying to do that would be useful – it’s some kind of live audio visualisation right?

    Yes, that’s right. I’m trying to create an audio visualiser. It would be great if the points of the shape (3 – 20) that have been mapped from the amplitude range (35 – 45), could ultimately be randomised, so that the same number of points don’t always correspond to the same unit of amplitude.

    Thanks!


    </div>

  • Dan Ebberts

    December 6, 2023 at 9:05 pm

    Try this:

    minAudio = 35;
    seed = 1013;
    a = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
    f = timeToFrames(time) - 1;
    if (a.value < minAudio){
    while (a.valueAtTime(framesToTime(f)) < minAudio && f >= 0){
    f--;
    }
    while (a.valueAtTime(framesToTime(f)) >= minAudio && f >= 0){
    f--;
    }
    }else{
    while (a.valueAtTime(framesToTime(f)) >= minAudio && f >= 0){
    f--;
    }
    }
    seedRandom(seed+f,true);
    Math.floor(random(3,21));


  • Tom Morton

    December 7, 2023 at 7:39 am

    Haha should have known you’d reply Dan – you’re THE man! I like the idea of this project though, I now want to give this a go too 🙂

  • Ben Beasley

    December 7, 2023 at 10:18 am

    Wow – amazing. Brilliant, thanks so much to the legend that is Dan Ebberts!

    Not had time to try yet but will very soon! Will keep you posted.

    Don’t understand it all but very keen to learn.

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