Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions smoothing music sync

  • smoothing music sync

    Posted by 158slim on September 14, 2005 at 8:31 pm

    I’ve created a simple 3d animating layer that I’m trying to sync to a beat in some music as per one of Mr. Ebberts’ very useful tutorials. The syncing utilizes layer markers and a “hit” variable added to the Time Remap field to line up the markers from my animation timeline and my music timeline. My problem is the cycle exactness. I’ve placed the marker on my animation at the midpoint so that when the music timeline’s “nearest marker” changes at the halfway point between two markers, the animation cycle is also halfway. The music I’m using to sync with is not perfect (it’s a piano recording) so when the beat gets off a tiny bit and the half-way point is not the same number of frames as before some of the animation gets skipped. Is there any way to speed up/slow down the animation to match?

    I’m just catching onto actionscripting and can’t quite wrap my brain around this one.

    Any help would be appreciated.

    -slim

    158slim replied 20 years, 8 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    September 15, 2005 at 12:34 am

    Interesting problem. The expression in the tutorial was designed with the idea that the “hit” animation runs at normal comp speed, centered around each hit point marker in the audio layer. What you’re talking about here is something different.

    You need it to speed up/slow down the hit animation depending on the time between markers in the audio layer. That’s possible to do, but there are some loose ends, like what speed does it run at before the first audio marker or after the last one? How does it know how long the animation is?

    It would take a little work, but I think it’s doable.

    Dan

  • 158slim Create COW Profile Image

    158slim

    September 15, 2005 at 4:47 pm

    Dan, thanks for the hints…I’m working with some ideas for setting up different variables to define the duration of the animation and then the distance between the two markers I’m trying to match that animation up with. In theory, I could then just interpolate the two duration periods, right?

    Anyway, it helps to know that you think it is doable; and I think I’m on a better track than I was before. More hints – if you have any – would be very appreciated.

    -slim

  • Dan Ebberts

    September 15, 2005 at 7:19 pm

    Play around with this one – I think it’s pretty close to what you’re after. Set “dur” to the duration of your animation and “L” to your layer with the markers you want to sync to. You may need to change the behavior somewhat. Right now it will speed up if markers are too close together for it to run at normal speed, but if the markers are far apart the animation will run at normal speed (it doesn’t slow down to fit the space, but that’s a pretty easy mod).

    
    dur = 1; // duration of animation
    L = thisComp.layer("control");
    
    hit = marker.key(1).time;
    prev = 0;
    if (L.marker.numKeys > 0){
      prev = L.marker.nearestKey(time).index;
        if (L.marker.key(prev).time > time) prev--;
    }
    next = 0; // assume no markers in future
    if (L.marker.numKeys > 0){
      next = L.marker.nearestKey(time).index;
        if (L.marker.key(next).time <= time){
          next++;
          if (next > L.marker.numKeys) next = 0;
        }
    }
    if (prev == 0 && next == 0){
      0;
    }else if (prev == 0 || next == 0){
      time - L.marker.key(Math.max(prev,next)).time + hit;
    }else{
      t0 = L.marker.key(prev).time;
      t1 = L.marker.key(next).time;
      mid = t0 + (t1 - t0)*(dur - hit)/dur;
      if (time > mid){
        linear(time,mid,t1,0,hit);
      }else{
        linear(time,t0,mid,hit,dur);
      }
    }
    
    

    Dan

  • 158slim Create COW Profile Image

    158slim

    September 15, 2005 at 11:04 pm

    Wow! this works perfectly; and it does slow down when I spread out the markers. I was trying some other work-arounds but couldn’t get them to remap right. I was having a hard time following the exceptions through to the result I wanted. My brain was near exploding. I can’t thank you enough for the help.

    -slim

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