2 Replies Latest reply: Oct 31, 2011 11:34 AM by Andy Bay RSS

    Expression question: keep adding to value

    Andy Bay Community Member

      Hi!

       

      I want to animate the cameras z-position based on an audio track. I have converted the audio to keyframes, but now I'm stuck trying to figure out how to feed the audio peak values to the cameras z-position so that they keep adding to each other.

       

      Simply linking the camera z-position to the keyframe data will make the camera fly back and forth, but I need it to keep going forward in a pulsating motion. So when there is a peak in the audio amplitude, the camera moves more rapidly forward and when there is a flat waveform the camera stays put or moves only slightly.

       

      Is this possible to do?

        • 1. Re: Expression question: keep adding to value
          Dan Ebberts Community Member

          This Position expression should work. Adjust mult to set the sensitivity (how much it moves in response to the audio) and minVal to set how much it moves when there is no audio.

           

          mult = 10;

          minVal = 5;

          L = thisComp.layer("Audio Amplitude");

          aud = L.effect("Both Channels")("Slider");

          accum = 0;

          for (f = timeToFrames(inPoint); f <= timeToFrames(); f++){

            accum += Math.max(aud.valueAtTime(framesToTime(f)),minVal);

          }

          value + [0,0,accum*mult]

           

           

          If you have separated the Camera's dimensions, change the last line to this to make it suitable for Z Position:

           

          value + accum*mult

           

           

          Dan

          • 2. Re: Expression question: keep adding to value
            Andy Bay Community Member

            OMG, Dan you are the man!

             

            I have no idea of what half of those things included do, but it works!