Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Variable speed oscillator

  • Variable speed oscillator

    Posted by Perry Kroll on May 10, 2012 at 7:56 pm

    Me again!

    I have this delightful oscillation script I picked up somewhere and modified:

    freq = thisComp.layer("H BPM #").effect("value")("Slider")/60; //oscillations per second
    intensity = 5; // intensity
    i = intensity*(1 + Math.sin(freq*time*Math.PI*2))/2;
    [95+i,95+i]

    I’m applying it to the scale on a heart icon, and controlling it based on another expression controller which is animated for beats per minute.

    it works perfectly when I don’t animate the BPM/frequency value. As soon as I animate that, some weird stuff starts happening. Speeds will go up and down in between keyframes. If the keyframes aren’t the first and last frames of the comp, the results will be reversed or just entirely wrong.

    I suspect it has something to do with sine and how it works with time, but I am stuck…

    Any ideas?

    Perry Kroll replied 14 years ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    May 10, 2012 at 11:19 pm

    Short answer: expect unpredictable results if you animate speed or frequency.

    You can probably fix it by integrating (as in area under the curve) your BPM slider and using that result to feed degrees or radians into Math.sin() (instead of an animated frequency value). What’s the nature of the slider animation? That will determine how hard/easy it will be to perform the integration.

    Dan

  • Perry Kroll

    May 11, 2012 at 2:50 pm

    Well, the slider animation will never be too complex. It just needs to be able to be adjusted gradually (over, at the shortest, like 5-10 seconds, or maybe over long periods of time like 20-30 seconds.) It would need to go from perhaps 70 bpm to around 120 or 150.

    Technically it doesn’t even need a nice sine wave to the scale. It could be a straight up linear scale up and down if that is easier.

    I am very curious to hear what the potential solution you were thinking of is…

    Thanks so much!

  • Dan Ebberts

    May 11, 2012 at 5:44 pm

    If you can live with linear keyframes on your BPM slider, I believe this will give you what you want:


    p = thisComp.layer("H BPM #").effect("value")("Slider");

    v1 = p.value;
    t1 = time;
    accum = 0;
    n = 0;
    if (p.numKeys > 0){
    n = p.nearestKey(time).index;
    if (p.key(n).time > time){
    n--;
    }
    }
    if (n > 0){
    t0 = p.key(n).time;
    v0 = p.key(n).value;
    accum += ((v0 + v1)/2)*(t1-t0);
    t1 = t0;
    v1 = v0;
    while (n > 1){
    t0 = p.key(n-1).time;
    v0 = p.key(n-1).value;
    accum += ((v0 + v1)/2)*(t1-t0);
    t1 = t0;
    v1 = v0;
    n--
    }
    }
    accum += ((p.valueAtTime(0) + v1)/2)*t1;
    intensity = 5; // intensity
    i = intensity*(1 + Math.sin((accum/60)*Math.PI*2))/2;
    [95+i,95+i]

    Dan

  • Perry Kroll

    May 11, 2012 at 10:51 pm

    Dan, thank you so much! You are like some kind of wizard. This works perfectly.

    Hey google – send people here when they want to oscillate something in After Effects and animate it to change or vary the speed of oscillation.

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