Audio Spectrum
Prepare an audio source for sampling
Last updated
Prepare an audio source for sampling
Last updated
Processes audio data to provide sampling data to behaviors. This works with audio files and live audio input devices supported on the target device.
When adding a new instance of Audio Spectrum, select the game object with the Audio Source you wish to sample, or if nothing is selected then it is applied to the main Audio Track object.
Select the object to view its settings in the Inspector.
Analyze live captured audio from an input device. Clicking on the button displays a list of all available devices, which may be a microphone, web camera, or any device supported for audio input by Unity.
If enabled, the 1st device found is used if the device by the specified name isn't found.
When deploying to mobile, the built-in microphone is the default input device.
If building for a device, additional configurations such as a manifest may be required to register audio listening permissions.
This only applies when using Device for audio input and isn't needed for Audio Source or Audio Listener input.
Use this field to optionally assign a Text Mesh Pro object to display the name of the input device onscreen. This may be helpful for end users to see the current device in use.
How long to wait (in seconds) for the device to initialize before timing out.
When an audio input device is working properly it should start up immediately, however there could be some latency causing it to take a moment. If it takes longer than the Timeout, then it is assumed the device is inactive or unavailable and audio listening is aborted. When this occurs, a different input device would need to be selected, or adjust the Timeout settings if needed.
Select between Left, Right, or Stereo audio analysis. When Stereo is selected, the left and right channels are averaged together.
Enter the sample rate to match the audio source. This can be found by selecting the audio file and viewing it in the Inspector preview panel.
If the sample rate does not match the source, it may not operate properly.
When using an audio device for input, the sample rate is automatically reduced to match the device specifications. Lower quality microphones may not support higher sample rates and will produce errors if the rate is unsupported.
Sets the quality level for analyzing audio frequencies, listed in order from simple to complex.
Each snapshot of audio represents the full range of frequencies, approximately from 20Hz to 20000Hz. The Resolution determines how many samples across the frequency range are made. The larger the value, the higher quality the sample result, though at the cost of performance.
Enable this to expose the Volume channel in the Timeflow view, outputting the current detected volume in the audio sampled.
If enabled, the RMS values are output directly without any processing.
Divides the RMS value to calculate decibels (dB). A value of 0.1 is 0dB
For volume levels in decibels (dB) disable Raw and enter a RMS reference value. Decibels are calculated using the following equation:
dB = RMS / Reference
Enable to detect the dominant pitch and output the value in a separate channel in the Timeflow view.
Sets the minimum level of RMS change to detect pitch. This essentially adjusts the sensitivity of pitch detection.
Enable to display a preview of the frequency spectrum in the game view.
Multiplies the spectrum values to increase the scale vertically.
Set this above 0 to only show data spikes above the threshold volume level (RMS).
For efficiency, only 1 Audio Spectrum is needed for each audio source. Sampling is based on the built-in Unity methods for frequency analysis, and
Audio Spectrum does not display channels in the Timeflow view unless or are enabled.
For common settings, see .
This behavior does not support since it doesn't relate to audio.
Analyzes the output from an component. This is the most common setup using an audio clip asset as the source.
Analyze audio of the entire scene using the .
To prevent audio feedback (ie. the microphone picking up the output audio in a perpetual loop causing high pitched sounds) it is recommended to use an to route the Audio Source to a muted channel. If the Audio Source is muted directly, it stops audio processing and will not produce the reactive effects. So by routing it instead to a muted mixer channel, the audio processing can still occur but is prevented from being output. This set up is not an issue if the user is using headphones, so may be an optional configuration in your game or app.
Audio Spectrum automatically requests permission through the built-in API:
For more information, see the Unity documentation for .
A power of 2 value is enforced on this field with the default value of 128. This also affects the display resolution of the , if enabled.
When using the Volume channel with , be aware the Time Offset isn't used and volume levels are always at the current time based on audio detection.
One technique for smoothing out results is to use .
Use the range slider to limit the frequency range displayed. This can be helpful when setting up an to find the right range for audio-reactive effects.