Audio Analyzer template allows you to drive different effects based on the power of the audio signal in certain frequency ranges.
Choosing the Audio Source to Analyze
When you first open the template - the project is set up to analyze audio data from an audio track. You can select the
Input Audio Track field to change the imported audio to use, or to use the
Audio from Microphone instead.
Audio from Microphone, you will need to provide access to your microphone. In the bottom of the Preview panel, click the microphone button. Then try making some sound to see the reaction of the scene objects!
Driving Effects based on Audio Analysis
Affecting Screen Transforms
By default the template analyzes audio data and outputs power of signal in 8 frequency bands in the range from
bins) are defined by splitting the interval from the minimal frequency to the maximum frequency into a certain amount of bins on the mel (logarithmic) scale. This scale is used as it better represents the way the human ear perceives the sound. You can find these advanced settings under the
Screen Images Example [TRY ME] scene object in the
Objects panel to see their simple visual representation.
You can expand the object to see that each bar is just an image with a script attached.
Select one of the images, and in the
Inspector panel you will find the
ScreenTransformExample script. Here you can customize how the selected image changes based on the audio.
- Band Index: The frequency band index we should get the power value from
- SmoothCoef: How much smoothing should be applied on the value
- Min Size: The minimum size the anchor rect of the ScreenTransform
- Max Size: The maximum size the anchor rect of the ScreenTransform
Affecting 3D Objects
In the same way you will see the other objects in the scene have similar patterns.
Headphones [EDIT SCRIPTS ON CHILDREN] scene object’s hierarchy. Each child object has a Script Graph Attached that controls one of this object's properties :
blendshape weight etc.
ScaleExample script attached to the
diamond1 sceneObject, like before, allows you to set the frequency band index (from 0 to 7), and a scale multiplier along each axis.
Each script is made in the Visual Script editor. You can use these scripts as helpers anywhere in your scene or customize what each script does by opening them. In the
Inspector panel, open the
Script Graphs folder, and double click any of the scripts.
Customizing Response to Audio Analysis
Next, let's take a look at how these scripts work so we can create our custom response.
Modifying the existing example scripts
We can first take a look at the
ScaleExample script to see an example. Each graph is annotated to help you see how it works.
You can see that we have a section that takes the current band Value and applies it to find current local scale of the transform by interpolating between min and max scale values :
You can swap the
setLocalScale to a different node to fit your needs. For example, to set the position of an object instead:
You’ll notice that this section relies on getting a band value. You will find a section that gets the band value from a custom script and lerps (interpolate) between the current value and the next value.
Creating custom scripts to respond to frequency change
You’ll notice in the example scripts we have the
GetBandByIndex node to get the value of a band. The result values from audio analyzer can be referenced in a Script Graph with the help of the
Custom Script nodes:
Simply drag them into a
Script Graph editor and connect execution input to the
As before, you can use these values to drive the properties of your object like you would in any other visual script. For example, you can use it to set the scale of your object:
Take a look at the different script graphs provided in the template to see different examples of this in action.
var bands = global.AudioAnalyzer.bands;
Still Looking for help?Visit Support