Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using changes in audio value to shift position up and down incrementally

  • Using changes in audio value to shift position up and down incrementally

    Posted by Benjamin Arthur on January 13, 2020 at 7:45 pm

    Hello all,

    I consider myself to have an intermediate level of experience with writing expressions, but this has been a difficult challenge I haven’t quite been able to make work.

    I have incoming audio data that I’ve linearly mapped to a number between 0-5. This is attached to the y axis of a single pixel, making it move up to 5 pixels down in time with the audio. I’m using the positional data to drive something else, but for my purposes the movement is too dramatic.

    The expression I’m trying to write is basically:
    pos1 = current position of a pixel moving using the audio input
    pos2 = previous position from -.09 seconds ago

    if pos1>pos2 then move up by one,
    if pos1 == pos2 no change,
    and if pos1https://www.motionscript.com/design-guide/audio-count.html

    But I’m not really getting the outcome I was hoping for, it’s not currently moving up or down. I’m still learning how an expression like this one works, so I’m probably facing a simple error of how to correctly compare values from different times.

    Thanks for any help you can give, I appreciate your time and assistance.

    audioLev = thisComp.layer("Yellow Solid 4").transform.yPosition
    above = false;
    frame = Math.round(time / thisComp.frameDuration);
    n = 0;
    while (frame >= 0){
    t = frame * thisComp.frameDuration;
    if (above){
    if (audioLev.valueAtTime(t) < audioLev.valueAtTime(t - .09) && n > 5){
    above = true;
    n++;
    }

    }else if (audioLev.valueAtTime(t) >= audioLev.valueAtTime(t - .09) && n > 0){
    above = false;
    n--;
    }
    frame--
    }

    n

    Benjamin Arthur replied 6 years, 3 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    January 13, 2020 at 8:45 pm

    Based on your description, I think it would be roughly like this:


    aud = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
    period = .09;
    curF = timeToFrames(time);
    f = 0;
    accum = 0;
    curT = 0;
    while (f <= curF){
    curT = framesToTime(f);
    p1 = aud.valueAtTime(curT);
    p2 = aud.valueAtTime(curT - period);
    if (p1 > p2)
    accum++
    else if (p1 < p2)
    accum--;
    accum = Math.max(accum,0);
    f++;
    }
    accum

    Dan

  • Benjamin Arthur

    January 16, 2020 at 12:44 am

    Thanks so much! I’m still foggy on how to use timeToFrames and framesToTime correctly – I better hit the books!

    Very much appreciated –

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