Skip to main content
Version: 0.4.1

ST Audio Analyser

An ST Audio Analyser listens to one Audio Source in your world, such as music or a video's sound, and turns it into numbers your world can react to: bass, mid and treble levels, overall loudness, a beat pulse and a 64-bar spectrum. Add it with Add Component → StageTime → ST Audio Analyser and drag the Audio Source into Source.

Field
sourceThe Audio Source to listen to. For a video, set its Video Player's Audio Output Mode to Audio Source and use that source. For an ST Live Stream, use its Audio Source
gainDbBoosts quiet sound, in decibels, before it is turned into 0 to 1 levels
smoothingHow slowly levels fall after a peak: 0 = instantly, 0.95 = very slowly. Rises are always instant
beatSensitivityHow far the bass must jump above its recent average to count as a beat. Lower = more beats
visualEffectsVFX Graphs it drives directly (see below)
setShaderGlobalsAlso sets the global shader values below, for your own shaders
Member
bass, mid, trebleLevels, 0 to 1 (about 30–160 Hz, 160 Hz–2.5 kHz, 2.5–16 kHz)
loudnessOverall level, 0 to 1
beat1 on a beat, then fades to 0 over about a quarter of a second
beatCountBeats heard since the world loaded on this device
GetBand(i)One of 8 bands, 0 (deep bass) to 7 (air), 0 to 1
GetSpectrum(i)One of 64 spectrum bars, 0 (lowest) to 63, 0 to 1
spectrumTextureThe spectrum as a 64 × 1 texture (red channel), updated every frame. Use it in a material or with Graphics.Blit

The analyser hears the source before the player's Music volume is applied, so the levels stay the same when a player turns their music down. A source with an ST Spatial Audio Source is muted at Music volume 0, and its levels then drop to 0 too.

OnAudioBeat​

Scripts on the same GameObject as the analyser get OnAudioBeat on every beat:

public class BeatFlash : StageTimeBehaviour
{
public STAudioAnalyser analyser;
public Light[] lights;

public override void OnAudioBeat()
{
foreach (Light light in lights) light.color = Random.ColorHSV(0f, 1f, 0.6f, 0.8f, 1f, 1f);
}

private void Update()
{
foreach (Light light in lights) light.intensity = 2f + analyser.bass * 20f;
}
}

Driving VFX Graphs and shaders​

List VFX Graphs in Visual Effects and the analyser sets these exposed properties on each of them every frame, when the graph has them:

Exposed propertyType
AudioBass, AudioMid, AudioTreble, AudioLoudness, AudioBeatFloat, 0 to 1
AudioSpectrumTexture2D, the 64 × 1 spectrum

With Set Shader Globals on, your own shaders (including Shader Graphs) can read _STAudioLevels (a Vector4: bass, mid, treble, loudness), _STAudioBeat (Float) and _STAudioSpectrum (Texture2D). Declare them as global properties, for example a Shader Graph property with Exposed unticked and the same reference name.

Not synced, but in time​

Each player's device listens to its own copy of the sound, so nothing here is networked. Play the sound in sync, for example with a synced ST Video Player or a clip started from the room clock, and everyone sees the same reactions within a frame or two. beatCount counts what this device has heard, so it differs between players who joined at different times: use the video's time when something must match exactly.