Activity › Forums › Adobe After Effects Expressions › variable minimum value
-
variable minimum value
Posted by Paul Evans on March 11, 2008 at 2:55 pmHi every body,
I have a good knowledge of AF but none of expressions. 🙁
My problem is needed to know how to assign a minimum value to a variable (I think). I am using “Jerzy Drozda Jr : Using Expressions to Create a Volume Meter” (witch is amazing btw) I have modified slightly to get a speaker cone to scale up and down with the music. It works fine but I don’t what the level to drop below 15% (I want it to move between 15% and 100%) if you know what I mean. so the speaker is still visible.
Any ideas??? I would love it if you guy could help me,
Thanks Paul
Vailancio Rodrigues replied 16 years, 7 months ago 4 Members · 6 Replies -
6 Replies
-
Darby Edelen
March 11, 2008 at 3:17 pmI’m not familiar with the specifics of your expression. If you post what you have, then others can give you the right answer for your specific expression. However, I can tell you that you’ll probably want to use the
linear()function somewhere.linear()works this way:
linear(x, inputMin, inputMax, outputMin, outputMax);
As ‘x’ ranges from ‘inputMin’ to ‘inputMax’ the value returned by
linear()will range from ‘outputMin’ to ‘outputMax.’So, for example:
linear(x, -48, 0, 15, 100)When ‘x’ is equal to -48 the above linear function would return 15, when ‘x’ is equal to 0 the above linear function would return 100. The steps in between are interpolated linearly, so when ‘x’ is equal to -24 (half way between -48 and 0) the returned value would be 57.5 (half way between 15 and 100).
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Paul Evans
March 11, 2008 at 3:52 pmThanks for that its put me on the right lines now,
This expression is connected to my key frames from the audio i am using.
thisFrame = timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false);
compDuration = timeToFrames(thisComp.duration, fps = 1.0 / thisComp.frameDuration, isDuration = false);max = 0;
for(i = 1; i < compDuration; i++){ ftt = framesToTime(i, fps = 1.0 / thisComp.frameDuration); sld = effect("Both Channels")("Slider"); val = sld.valueAtTime(ftt); if(val > max) max = val;
}linear(sld, 0, max, 0, 100);
then this is my layer that scales
vol = comp(“music 2”).layer(“Audio Amplitude”).effect(“Final”)(“Slider”);
mlp = thisComp.layer(“Multiply”).effect(“Slider Control”)(“Slider”) / 1000;
[vol, vol, vol * (mlp + 1)]I know I have one a linear function already but that dose something ells, I want variable ‘vol’ to have the full range but not do anything one it goes be low 15 so I am guessing something like this
linear(vol, 0, 100, 15, 100);
Maybe? Would this have the full range input and limit the output from 15 to 100?
cheers
Paul
-
Darby Edelen
March 11, 2008 at 6:07 pm[Paul Evans] “Maybe? Would this have the full range input and limit the output from 15 to 100? “
Yes, but it would scale the range 0-100 into the range 15-100. If you just want any value below 15 to be chopped off at 15 then you could use:
Math.max(vol, 15);
Which would return either ‘vol’ or 15, whichever has a higher value.
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Alex English
April 23, 2008 at 10:39 pmI know you have this solved already, but I thought I’d post this for others who happen by.
Since the data you’re working with is from 0 to 100, if you use Math.max(value, 15), you’re losing 15% of your range.
Another way to handle it would be to multiply your value by 0.85, then add 15:
scalefactor = (value * 0.85) + 15;This would scale your range of data to your range of motion, and guarantee that your minimum would be at 15 (since at a value of zero, it comes out to 0 + 15)
I hope someone finds that useful.
Reply to this Discussion! Login or Sign Up