9 Replies Latest reply on Oct 5, 2017 2:00 PM by bryan.gough

    Fade audio with expressions

    trinitywebdesign

      Ok, I've taken an epxression for automactically fading opacity (which worked wonderfully) and tried to modify it to fade audio the same way.  Now, I get an error that says "After Effects warning: Expression Disabled. Error at line 0 in property....  expression result must be of dimension 2 not 1."

       

      Here is the tweaked expression:

       

      fadeTime = 30;

      audio.audioLevelsMin = -50;

      audio.audioLevelsMax = 0;

      layerDuration = outPoint - inPoint;

      singleFrame = thisComp.frameDuration;

       

      animateIn = linear(time, inPoint, (inPoint + framesToTime(fadeTime)), audio.audioLevelsMin, audio.audioLevelsMax);

      animateOut = linear(time, (outPoint - framesToTime(fadeTime+1)), (outPoint-singleFrame), audio.audioLevelsMax, audio.audioLevelsMin);

       

      if(time < (layerDuration/2+inPoint)){

      animateIn;

      }else{

      animateOut;

      }

       

      Now, opacity is a linear, 1 dimensional characteristic.  Why did that work and the updated expression for audio cause an error?

        • 1. Re: Fade audio with expressions
          Dan Ebberts Level 5

          Try it this way:

           

          fadeTime = 30;

          audio.audioLevelsMin = -50;

          audio.audioLevelsMax = 0;

          layerDuration = outPoint - inPoint;

          singleFrame = thisComp.frameDuration;

          animateIn = linear(time, inPoint, (inPoint + framesToTime(fadeTime)), audio.audioLevelsMin, audio.audioLevelsMax);

          animateOut = linear(time, (outPoint - framesToTime(fadeTime+1)), (outPoint-singleFrame), audio.audioLevelsMax, audio.audioLevelsMin);

          if(time < (layerDuration/2+inPoint)){

            [animateIn,animateIn];

          }else{

            [animateOut,animateOut];

          }

           

           

          Dan

          • 2. Re: Fade audio with expressions
            trinitywebdesign Level 1

            It worked!!  I see the small change that you made at the end with [animateIn,animateIn]; How did that effect the process? Was it like giving it an extra coordinate??

            • 3. Re: Fade audio with expressions
              Dan Ebberts Level 5

              Yes, stereo audio level is a two-dimensional property, so you need to provide two values, in array notation.

               

              Dan

              • 4. Re: Fade audio with expressions
                bryan.gough Level 1

                I have a similar question (I think)... where I have several pre comps that have different lengths, but use the same .wav file for the background music. The end of the .wav file has a chime timed to the motion at the end of the pre-comp. I'd like to be able to copy/paste the .wav file into my pre-comps, align the chime with the animation at the end, and let an expression handle the fade-up at the beginning of the pre-comp, so I don't have to go in and manually adjust keyframes.

                 

                UPDATE:

                It works, but only if I trim the layer to the beginning of the comp. If I just slide the layer and don't trim the inPoint of the layer... it doesn't work. Could the above expression be modified to use the comp's In and Out instead?

                • 5. Re: Fade audio with expressions
                  Dan Ebberts Level 5

                  Something like this maybe:

                   

                  fadeTime = 30;

                  audio.audioLevelsMin = -50;

                  audio.audioLevelsMax = 0;

                  animateIn = linear(time,0,framesToTime(fadeTime), audio.audioLevelsMin, audio.audioLevelsMax);

                  [animateIn,animateIn];

                   

                   

                  Dan

                  1 person found this helpful
                  • 6. Re: Fade audio with expressions
                    bryan.gough Level 1

                    Mr. Ebberts... I don't ask for help on here very often. And when I do, I'm always expecting someone to say, "Read the manual." or "Let me Google that for you." But, usually what happens is that—within 24 hours, usually—I get a response from a Dan Ebberts (and a few other regulars) that absolutely sets me on the right path, if not solve my problem directly.

                    This is another home run. Thank you sir!

                    Consider the next beer/tab/round that someone else picks up on your behalf as "inspired" by my gratitude! Thank you!

                    • 7. Re: Fade audio with expressions
                      bryan.gough Level 1

                      fadeTime = 30;

                      audio.audioLevelsMin = -50;

                      audio.audioLevelsMax = 0;

                      animateIn = linear(time,0,framesToTime(fadeTime), audio.audioLevelsMin, audio.audioLevelsMax);

                      [animateIn,animateIn];

                       

                      This expression solved my problem, but then I created another one:

                       

                      I want to move this expression onto a controller in my main comp so I only have to edit values for audioLevelsMin/Max in one place and have it propagate across all instances of the music track in a variety of pre-comps.

                       

                      1. I added Slider to my Null object
                      2. I attached the above expression to the slider by alt+clicking on the slider stopwatch.
                      3. Then I got an immediate expression error.
                        • The property name "audio" is missing...

                       

                      Am I thinking about this correctly?

                      • 8. Re: Fade audio with expressions
                        Dan Ebberts Level 5

                        You could try this on your slider:

                         

                        fadeTime = 30;

                        audioLevelsMin = -50;

                        audioLevelsMax = 0;

                        linear(time,0,framesToTime(fadeTime), audioLevelsMin, audioLevelsMax);

                         

                        and then link each audio level to it with something like this:

                         

                        animateIn = comp("Main Comp").layer("Null 1").effect("Slider Control")("Slider");

                        [animateIn,animateIn]

                         

                         

                        Dan

                        1 person found this helpful
                        • 9. Re: Fade audio with expressions
                          bryan.gough Level 1

                          thanks Dan (again)!

                           

                          I think what was breaking my previous attempt was that I was looking for audio.audioLevelsMin/Max where no audio property existed.

                          I appreciate the help!