Activity › Forums › Adobe After Effects Expressions › Random Motion Linked to an Audio Control
-
Random Motion Linked to an Audio Control
Posted by Twelvizm on March 22, 2007 at 9:22 pmI have some objects moving around being controlled by this expression:
————–START—————–
segMin = .3; //minimum segment duration
segMax = .7; //maximum segment duration
minVal = [0.1*thisComp.width, 380,-200];
maxVal = [0.99*thisComp.width, 450,1400];end = 0;
j = 0;
while ( time >= end){
j += 1;
seedRandom(j,true);
start = end;
end += random(segMin,segMax);
}
endVal = random(minVal,maxVal);
seedRandom(j-1,true);
dummy=random(); //this is a throw-away value
startVal = random(minVal,maxVal);
ease(time,start,end,startVal,endVal)
————–FINISH—————–It makes my objects move randomly around X,Z. (looks like bugs on the floor)
Now I want the objects to be linked to a sound that is louder as the move toward the camera and quieter as they move away.
Any suggestions?
Twelvizm replied 19 years, 1 month ago 3 Members · 12 Replies -
12 Replies
-
Darby Edelen
March 22, 2007 at 10:41 pmIf you’re trying to link the Audio Level to the Z values of the layers that should be fairly straightforward. I think the only thing you need to think about is how you want it to be carried out, do you want only one instance of the sound that takes an average Z value of all the layers? Do you want multiple instances of the sound that react to specific layers? The end result you’re looking for will determine how to carry it out.
-
Twelvizm
March 22, 2007 at 10:49 pmI wanted to have multiple instances controlling multiple audio files.
That was each object has it’s own sound it makes while it moves.
-
Darby Edelen
March 23, 2007 at 12:18 amIn that case you’d have something like this applied to the Audio Levels of the sound file (assuming that your audio file is directly above the associated moving layer in the timeline):
loudMax = -5; //The loudest that the audio file will ever be in dB
loudMin = -40; // The quietest that the audio file will ever be in dB
close = -200; // The smallest Z value expected
far = 1400; // The largest Z value expected
distance = thisComp.layer(index+1).transform.position[2]; //The Z value of the layer beneath this onelinear(distance, close, far, loudMax, loudMin); //As the Z-position of the layer below this one varies from ‘close’ to ‘far’ vary the return value from ‘loudMax’ to ‘loudMin’
Unless there’s something more complicated you’re looking for this should do it.
-
Twelvizm
March 23, 2007 at 1:05 amIt’s throwing a error at “transform”
Thanks for waling me through this. I’m starting to understand the logic, but I still have no vocabulary. This next semester I’m takng a actionscripting class. Then I’ll be able to ween myself from asking simple rooted questions.
-
Twelvizm
March 23, 2007 at 1:17 amI used the picWhip to select the exact variable distance =
thisComp.layer(“file_name”).position[2];
And now I get an error for
“Expression must be for dimension 2 not 1” -
Dan Ebberts
March 23, 2007 at 1:38 amTry changing the last line to this:
lev = linear(distance, close, far, loudMax, loudMin);
[lev, lev]Dan
-
Darby Edelen
March 23, 2007 at 2:05 amAh yes, I forgot that Audio Levels are stored in a 2 dimensional array (like 2D position data) the first entry in the array is the left channel’s level and the second is the right channels so the expression should actually be:
loudMax = -5; //The loudest that the audio file will ever be in dB
loudMin = -80; // The quietest that the audio file will ever be in dB
close = -200; // The smallest Z value expected
far = 1400; // The largest Z value expected
distance = thisComp.layer(index+1).transform.position[2]; //The Z value of the layer beneath this onemyLevel = linear(distance, close, far, loudMax, loudMin); //As the Z-position of the layer below this one varies from ‘close’ to ‘far’ vary the return value from ‘loudMax’ to ‘loudMin’
[myLevel, myLevel]
Thanks for catching my error, this is what I get for not testing my expression in AE (; This will give the audio the same level in the left and right stereo channels. You could improve upon this by lowering the amount coming out of the left channel if the ‘bug’ is on the right side of the screen:
myWidth = thisComp.width; //The largest X value visible in the Comp window
balance = thisComp.layer(index+1).transform.position[0]; //The X value of the layer below this one
leftMult = linear(balance, 0, myWidth, 1, 2);//As the bug moves to the right we increase the left multiplier to 10 (dB are measured in negative values… 2 * -5 = -10 = quieter)rightMult = linear(balance, 0, myWidth, 2, 1);//As the bug moves to the right we decrease the right multiplier to 1 (1 * -5 = -5 = louder)
myLeftLevel = myLevel * leftMult;
myRightLevel = myLevel * rightMult;[myLeftLevel, myRightLevel];
This would go just above the final statement [myLevel, myLevel] in the previous expression (which would now be deleted). Here is the final expression, and I promise I tested this one! I even tweaked some of the numbers to my liking, you can mess with them more:
loudMax = -5; //The loudest that the audio file will ever be in dB
loudMin = -80; // The quietest that the audio file will ever be in dB
close = -200; // The smallest Z value expected
far = 1400; // The largest Z value expected
distance = thisComp.layer(index+1).transform.position[2]; //The Z value of the layer beneath this onemyLevel = linear(distance, close, far, loudMax, loudMin);
myWidth = thisComp.width;
balance = thisComp.layer(index+1).transform.position[0];
leftMult = linear(balance, 0, myWidth, 1, 2);
rightMult = linear(balance, 0, myWidth, 2, 1);
myLeftLevel = myLevel * leftMult;
myRightLevel = myLevel * rightMult;[myLeftLevel, myRightLevel];
-
Twelvizm
March 23, 2007 at 5:11 amThanks for the follow up and adding a little more functionality. The panning will be even better. I’m locked out rendering right now, but I’ll check it out tomorrow.
-
Twelvizm
March 23, 2007 at 2:15 pm(SORRY, RENDERING RIGHT NOW ##CAPS##)
IT WORKS GREAT.
BUT
I FORGOT TO METION THAT I WANTED IT TO BE IN RELATION TO A ANIMATED CAMERA. IS THERE ANY WAY TO PULL THAT OFF?
-
Darby Edelen
March 23, 2007 at 3:26 pmI was having so much fun playing around with this expression that I decided to render out a sample of the (newly altered) expression in action. =) Thanks for inspiring me:
https://video.google.com/videoplay?docid=-1751789126326910391
The effect is most dramatic in the middle portion.
Here’s the [final?] code used:
loudMax = -12; //The loudest that the audio file will ever be in dB
loudMin = -20; // The quietest that the audio file will ever be in dB
close = -200; // The smallest Z value expected
far = 1400; // The largest Z value expected
distance = thisComp.layer(index+1).transform.position[2]; //The Z value of the layer beneath this onemyLevel = linear(distance, close, far, loudMax, loudMin);
myWidth = thisComp.width;
//The following section is new and required for the change to the ‘balance’ equation:
motionLayer = thisComp.layer(index+1);
halfWidth = motionLayer.width / 2;
halfHeight = motionLayer.height / 2;balance = motionLayer.toComp([halfWidth,halfHeight])[0]; //This is a new form of this equation that converts the XYZ coords of the layer to screen X coordinates for more realistic panning
leftMult = linear(balance, 0, myWidth, 1, 2);
rightMult = linear(balance, 0, myWidth, 2, 1);
myLeftLevel = myLevel * leftMult;
myRightLevel = myLevel * rightMult;[myLeftLevel, myRightLevel];
Reply to this Discussion! Login or Sign Up