Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Sound Keys Expression

  • Sound Keys Expression

    Posted by Mark Woloschuk on March 26, 2008 at 10:40 pm

    So I’m trying to connect a Sound Keys audio output to the opacity of 15 color solids.

    In this case Sound Keys is generating values from 0-100 based on the overall average output of a piece of audio.

    Thanks to Dan Ebbert’s old site (thanks Dan!) I was able to create an “and” conditional statement that lets me turn on and off the various solids based on ranges within that 0-100 output. I apply this expression to opacity:

    sk= thisComp.layer(“SK_Avg”).effect(“Sound Keys”)(“Output 1”);
    if (sk>=7 && sk<=13) t=100 else t=0; t Great! As the values move up and down the spectrum, the 15 solids light up as if someone were playing them like a keyboard. But they're only on for a short time and I think it would look better if they slowly faded out over a few frames instead of just turning off, so I added this: d= 1; tD = opacity.valueAtTime(time - d); F= .5; sk= thisComp.layer("SK_Avg").effect("Sound Keys")("Output 1"); if (sk>=7 && sk<=13) t=100 else t=0 tF= t+ (F*tD); tF I thought this would add (.5 * the previous frame's opacity) to whatever the conditional generated. Doesn't work though. Can anyone help me out with this one? Seems like it should be mighty easy. Best, Mark Woloschuk

    Mark Woloschuk replied 18 years, 1 month ago 3 Members · 4 Replies
  • 4 Replies
  • Darby Edelen

    March 27, 2008 at 1:17 am

    [Mark Woloschuk] “d= 1;
    tD = opacity.valueAtTime(time – d);
    F= .5;
    sk= thisComp.layer(“SK_Avg”).effect(“Sound Keys”)(“Output 1”);
    if (sk>=7 && sk<=13) t=100 else t=0 tF= t+ (F*tD); tF "

    I think your problem is the d variable in this case. valueAtTime() takes a time value in seconds, so you’re subtracting 1 second from the current time in seconds when you want to be subtracting 1 frame’s duration in seconds (1 / fps).

    You need to use the comp property frameDuration to get the duration of a frame in seconds:

    d = thisComp.frameDuration;

    However, I feel it is my duty to tell you that you’ll get better results by playing with the Range > Falloff property in the SoundKeys effect itself, as you can specify instant, linear or exponential decay without writing a bit of code.

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Mark Woloschuk

    March 27, 2008 at 2:00 am

    Thanks Darby but that still doesn’t fix it. When I access the tD value it still doesn’t return a value that makes sense.

    I’m aware of the falloff settings in Sound Keys (and indeed am using an exponential falloff) but in this case I need the fade to happen in the layer not in the sound key data since this piece of audio moves so fast.

    Imagine someone playing the piano very fast and every key they hit lit up as soon as they touched it but faded out more slowly.

    Unless I’m missing something fundamental about Sound Keys, I think the way to do it is within each layer’s opacity values.

    But thanks for the effort!

    – Mark

  • Dan Ebberts

    March 27, 2008 at 1:35 pm

    I think you’re going to need something like this:

    sk= thisComp.layer(“SK_Avg”).effect(“Sound Keys”)(“Output 1”);
    decay = 7.5;
    gotOne = false;
    for (t = time; t > 0; t -= thisComp.frameDuration){
    if (sk.valueAtTime(t) >=7 && sk.valueAtTime(t)<=13){ gotOne = true; break; } } if (gotOne) 100/Math.exp((time-t)*decay) else 0; Dan

  • Mark Woloschuk

    March 27, 2008 at 8:27 pm

    Oh my… that’s way fancier than I would have imagined. But the important part is that it works quite nicely.

    Thanks Dan.

    P.S. I’m still first in line for that book/video expression training I just know you’re going to spring on us some day.

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