3 Replies Latest reply on Apr 21, 2010 9:41 AM by mr. ichybob

    expression to lower all values below threshold to 0

    mr. ichybob Level 1

      I'm looking for an expression to cut all values below a certain threshold to 0 (sort of a mathematical noise gate).


      The purpose is to drive some animation based on audio keyframes - but the music lacks sufficient dynamics. So I want to eliminate all but the loudest key frame values.




      AE CS3, OSX 10.4

        • 2. Re: expression to lower all values below threshold to 0
          Rick Gerard Adobe Community Professional & MVP

          Dan Ebbert's expression is great if what you want is a beat detector. It's an elegant but fairly complex solution for finding high audio levels.


          If you want to create a simple on/off switch a simple if else statement will do the job. Let's say that you want the Y position of a layer to be 2 pixels higher than it's current position until the audio level of both channels is greater than 20, then you want it to move up by the same number of pixels as the audio level. All you have do to is apply the following expression to the position property of your layer after you've converted the audio to keyframes using the Keyframe Assistant.


          lev = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
          thr = 20;
               if (lev < thr) {
               val = 2}
          else val = Math.round(lev);
          value - [0, val]




          • line 1 defines the variable "lev" as the level or value of the Both Channels slider in the Audio Amplitude layer created by the Keyframe Assistant
          • line 2 sets the threshold of the audio level to 20 as the variable "thr"
          • line 3 thru 5 is a simple if else statement that defines the variable "val" as a new value by comparing the threshold to the level. If the level "lev" is less than the threshold "thr" then the value for "val" is 2, if the level is higher then audio level "lev" will be rounded to the nearest whole number and used as the new value "val"
          • the last line takes the current value for the position array and subtracts zero from the X value so X does not change and then subtracts our variable "val" from the current Y value


          You could also change the else statement to read simply "else val = 100" to move the layer up 100 pixels on the Y axis. If applied to opacity you could switch a layer's visibility on and off.


          I hope these replies give you a starting point.

          • 3. Re: expression to lower all values below threshold to 0
            mr. ichybob Level 1

            Thank you very much, both of you. Dan Ebbert's solution will take a bit of time for me to digest, Rick's solution I understand. I'm on my way.