First off I use these forums regularly to help me out with day to day problems and I've finally signed up today and this will be my first post. As much as expressions intrigue me it's all still a bunch of jumbled code to my brain which I find myself copy and pasting without understanding so if when you're answering my question could you please do your best to add an explanation in so that I can begin to understand.
I'm trying to create an overlay for my radio comms in my videos. When the comms are active I want it to turn on a layer so to indicate that's where the audio is coming from. I've converted the waveform to keyframes and made an if/else expression to turn it on and off however if there is a slight pause between words the layer will flicker on and off because of the drop in the audio levels. Is there a way to create a time buffer so that the audio has to be below or above the level for a certain period of time.
Expressions must be self-contained and cant use buffers.
At each frame, the expression code must look forward and backwards to see if there are enugh frames above threshold or not.
I didnt try but the following should work:
threshold = 0.5; // minimum amplitude
fMin = 15; // minimum number of frames above threshold
L = thisComp.layer("Audio Amplitude");
ampSlider = L.effect("Both Channels")("Slider");
f = 1;
dt = thisComp.frameDuration;
// search backwards
t = time;
while( f<fMin && L.inPoint<=(t-=dt) && ampSlider.valueAtTime(t)>threshold && ++f);
// search forwards
t = time;
while( f<fMin && ((t+=dt)<=L.outPoint) && ampSlider.valueAtTime(t)>threshold && ++f);