Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Audio Expression

  • Posted by Malcolm Ricci on October 16, 2022 at 6:04 pm

    Hey all,

    I’ve got two audio layers, one is a background track and the other is a voice over track. The voice over track is not always used, so I’m trying to figure out an expression where if the voice over is used, the audio track would fade down to say -18db from 0db and then fade back up to 0db once the voice over track is over.

    I’m trying to work out a variation of this expression that Dan wrote on an Adobe forum:

    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];

    }

    Changing the above to this:

    fadeTime = 20;

    audio.audioLevelsMin = -18;

    audio.audioLevelsMax = 0;

    if(comp(“Slide 1 Image or Video”).layer(“Slide 1 Video Left”).audio.audioLevels) [-12]

    [audio.audioLevelsMin,audio.audioLevelsMin];

    }else{

    [audio.audioLevelsMax,audio.audioLevelsMax];

    }

    The voice over track (comp(“Slide 1 Image or Video”).layer(“Slide 1 Video Left”) is set at -12 if there is a voice over track and -50 if there isn’t one, so I’m trying to write the expression to explain that if the voice over track is at -12 (meaning there is one), then the background music fades down from 0db to -18db.

    I hope I’ve explained myself well.. if not please let me know.

    Thanks!

    Malcolm Ricci replied 3 years, 6 months ago 2 Members · 15 Replies
  • 15 Replies
  • Dan Ebberts

    October 16, 2022 at 7:01 pm

    Are you saying that the voice over layer always exists and the level will be -12 while voice over is happening and -50 when it’s not, with no fading? Or something else?

  • Malcolm Ricci

    October 16, 2022 at 7:54 pm

    Hey Dan,

    So I’ve set up a template where there is a pre-comped audio track, which is a placeholder for a voice over, which the client could upload externally.

    This is in turn rigged to an on/off checkbox, which if turned on then the audio level of this pre-comped audio layer is set to -12, but if not then it is set to -50.

    There is also a background audio track throughout the template that is set to -12 itself.

    I’d like to find an expression that basically tells the background audio track, if the client turns on the checkbox (which turns the audio level of the voice over track to -12), then the background audio track has to fade down from -12 to -18, so that the pre-comped voice over track could be heard.

    Once the pre-comped voice over track ends then the background music fades back up.

    Hope that this explains it a little better..

  • Dan Ebberts

    October 16, 2022 at 8:09 pm

    >Once the pre-comped voice over track ends…

    How will the expression know this has happened?

  • Dan Ebberts

    October 16, 2022 at 8:11 pm

    Also, couldn’t the background expression just monitor the checkbox instead of the voice over audio level? It’s much easier to detect changes in keyframes than value levels.

  • Malcolm Ricci

    October 16, 2022 at 8:42 pm

    >Once the pre-comped voice over track ends…

    How will the expression know this has happened?


    Maybe something related to this?

    layerDuration = outPoint – inPoint; but pointing to the voice over track if possible?…

    Also, couldn’t the background expression just monitor the checkbox instead of the voice over audio level? It’s much easier to detect changes in keyframes than value levels.


    Yes definitely, if it is easier for it to do..

    So I’m thinking the best answer would be some kind of amalgamation of the following two expressions?

    fadeTime = 30;

    audio.audioLevelsMin = -40;

    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];

    }

    AND

    if(comp(“Slide 1 Image or Video”).layer(“Scene 1: Video Audio – On/Off [Type: Dropdown, Options:{On| Off}, Linkto: Video, Required: No]”).effect(“On”)(“Checkbox”)==1){

    [-90,-90];

    } else {

    [-12,-12];

    }

    Not sure if this would make sense..

  • Dan Ebberts

    October 17, 2022 at 12:22 am

    In the simplest form, it could look something like this (you’ll have to edit it to point to the actual location of the checkbox). Hopefully it will work for you, or at least give you some ideas:

    cb = effect("Checkbox Control")("Checkbox");
    fadeFrames = 20;
    cbOn = -50;
    cbOff = -12;
    fadeTime = framesToTime(fadeFrames);
    v = cb.value ? cbOff : cbOn;;
    if (cb.numKeys > 0){
    n = cb.nearestKey(time).index;
    if (time < cb.key(n).time) n--;
    if (n > 0){
    t = time - cb.key(n).time;
    if (cb.key(n).value){
    v = linear(t,0,fadeTime,cbOff, cbOn);
    }else{
    v = linear(t,0,fadeTime,cbOn, cbOff);
    }
    }
    }
    [v,v]
  • Malcolm Ricci

    October 17, 2022 at 7:26 am

    Hey Dan,

    Thanks for this!

    I haven’t gotten it to work yet, but not sure if I’m doing something wrong or setting it up wrongly from my end..

    I’ll continue experimenting with it and I’ll keep you posted.

    Much appreciated 🙂

  • Malcolm Ricci

    October 18, 2022 at 11:39 pm

    Finally got it working.

    Showed your expression to a colleague of mine and he came up with the following:

    isAudioOn = (checkbox);
    soundOn = -20;
    soundOff = 0;
    fadeFrames = 10;

    fadeTime = framesToTime(fadeFrames);

    if (!isAudioOn) {

    value

    } else {

    v = soundOff

    buffer = 0.5

    startFade = layer.inPoint – buffer

    endFade = layer.outPoint – buffer

    if (time >= endFade) {

    v = linear(time – endFade, 0, fadeTime, soundOn, soundOff);

    } else if (time >= startFade) {

    v = linear(time – startFade, 0, fadeTime, soundOff, soundOn);

    }

    [v, v]

    }

    Thanks once again for the help and guidance Dan

  • Dan Ebberts

    October 19, 2022 at 12:11 am

    Ah, OK. I assumed you needed to be able to animate the checkbox to indicate when to duck the background level, but apparently you just need a static value. Glad you got it sorted!

  • Malcolm Ricci

    October 19, 2022 at 12:20 am

    I might have not explained myself well enough as I was too frazzled to understand what needed to be linked to what..

    Not sure if I’ve overcomplicated things, but it seems to be working 🙂

Page 1 of 2

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