Zack Lovatt

Behance Bitbucket Dribbble LinkedIn Skype Vimeo
February 18, 2014

Preset: linear() – Syncing Precomp Audio to Main

Posted In: downloads, expressions, presets

The Idea

OK, so, you’re working on an amazing infographic piece slated to become the best thing out there since that Stuxnet video. You’ve got your master comp with the audio bed in place, and have a series of precomps w/ audio & graphics sequenced and arranged together in your main composition.

You’re working away on your project, have everything in each precomp chapter timed out and synced properly with the audio, and then… your client wants to re-record the VO. Or add in some copy. Or needs an alternate language version.

Alright, that’s cool, we’ll just drop in the new audio, slide our precomp over in time to where it should now be, open it up and do a preview to ensure everything’s aligned properly. Except– the audio clip in the precomp is now out of sync with the master, as we’ve time-shifted the entire thing!

Here’s a quick little expression that uses the linear() function to make sure your precomp’s audio is always synced up with your master audio.

The Code

This will be applied to the Time Remap property, requires that your audio layer (be it a layer or precomp) has the same name in this child composition as the parent, and will need user input for the name of the source comp.

// Set the part in quotation marks to be the name of your parent comp.
parentComp = comp("Main Comp");

compStartTimeInParent = parentComp.layer(thisComp.name).startTime;
audioStartTimeInParent = parentComp.layer(thisLayer.name).startTime;
fullStartTime = this.startTime;
fullEndTime = this.source.duration+startTime;

linear(time, fullStartTime, fullEndTime, fullStartTime+compStartTimeInParent-audioStartTimeInParent, fullEndTime+compStartTimeInParent-audioStartTimeInParent)

The Explanation

This expression looks at what time both the whole precomp and the audio layer specifically starts in the master comp, then looks at the start and end points of the audio layer inside of the precomp, and remaps the inner start & end points to match that of the master audio layer.

The first set bunch of lines are teaching the expression what each value is, with the vital piece of logic coming in last– the linear() function. This, along with the other functions under the Interpolation menu option of the Expression language menu, are all about automating values and mapping properties across each other.

Now, back to our specific case. Here, we’re giving it five variables:

time
the current project time
fullStartTime
the time the precomp’s audio layer starts, in relation to the precomp
fullEndTime
the time the precomp’s audio layer ends, in relation to the precomp
fullStartTime+compStartTimeInParentaudioStartTimeInParent
the start time from above,
plus the start time of the composition in the master comp (to account for the comp shifting around)
minus the start time of the audio in the master comp (in case it was offset)
fullEndTime+compStartTimeInParentaudioStartTimeInParent
same as above, but starting with the end time from above
By default, the variables for linear() are listed as linear(t, tMin, tMax, value1, value2). Translating this into English, it would read “As the value of variable t changes from tMin to tMax, output a value between value1 to value2.” While this can sound a little confusing and vague, let’s look at it in a practical sense.Slotting in some values, let’s look at linear(time, 0, 5, 40, 60). This would mean “as the current time in the comp goes from 0 seconds to 5 seconds, output a value between 40 and 60” (if the current time is below 0 or above 5, the output will be capped at 40 or 60, respectively. The word linear at the start means that the values will be mapped in a linear fashion, meaning that 10% of the way between 0 and 5, the output value will be 10% of the way between 40 and 60, and so on. Available alternatives are ease(), easeIn(), and easeOut().) Thus, this can be used as a handy way to automate some animation without any keyframes whatsoever!

Read more about interpolation expression methods here.

So what this says is “as the current time in the comp goes from the start of the precomp’s audio to the end, output a value between the start and end of the audio clip in the master comp.” This will give a value in seconds– and as we’re slotting it into the Time Remap function, we’re now retiming the child layer to match the current time of the parent.

The Application

Now, you can slide around your precomp to your heart’s content, and the audio will always match up with your master. See here the before/after, and keep in mind that the expression is being placed on the audio layer inside the precomp, not on the precomp itself.

Two caveats:

  1. If you shift the main audio in the main timeline, you’ll need to ‘refresh’ the child comp’s position to update; either slide it around and put it back, or move the play head to the start of the precomp and hit [ on your keyboard to shift the precomp to this start time.
  2. If you have multiple audio tracks with the same name in the parent, the expression will pull from the topmost one. A better workflow is to have a dedicated audio precomp with your edit/mix in there, and use that everywhere in lieu of raw files.
7 Comments

  1. Mathias Brocks • September 10, 2014

    I have been looking all over for something like this - excellent script.
    - But what if there is more than one level of comps between the sound files that have to be synced? Reply


  2. zack • September 10, 2014

    Hey Mathias!

    Could you send a sample aep to zack@zacklovatt.com? May be a bit messy to come up with a solution, but should be doable.

    Z Reply


    • Robert Ignasiak • August 30, 2016

      Really enjoying this script. I have the same question. Is there a way to have it reference the master audio comp from anywhere even if its nested a few comps deep? Would really help me out to know.

      Thanks!
      Rob Reply


  3. Ashish • September 22, 2014

    Amazing idea and expression. This is gonna be extremely helpful in future projects. Reply


  4. Rafferty Pendery • January 9, 2016

    Just wanted to make sure you knew that there is a link on this page: http://lesterbanks.com/2014/02/keeping-audio-sync-aftereffects/ pointing to an old link to this page. You might just want to redirect it on your end the new url so people don't get the 404 error. Thanks for your contributions to the community! Reply


    • zack • May 3, 2016

      Thanks for the heads up! Reply


  5. Jason Jantzen • July 5, 2016

    I don't if this is my error, or what, but when I applied the preset, nothing happened. So I opened the sample project file, copied the Time Remap effect and saved over the preset. Works beautifully. Thanks for making this magic available, Zack! Reply


Would you like to share your thoughts?

Leave a Reply