Class SoundEvent
Namespace: ValveResourceFormat.Renderer.Audio
Assembly: Renderer.dll
A playing (or pending) instance of a sound event definition.
public abstract class SoundEventInheritance
object ← SoundEvent
Constructors
SoundEvent(SoundEventDefinition)
Creates a sound event instance for the given definition.
protected SoundEvent(SoundEventDefinition definition)Parameters
definition SoundEventDefinition
Properties
ChildSoundEvents
Gets the child sound events spawned by this event.
protected List<SoundEvent> ChildSoundEvents { get; }Property Value
Definition
Gets the sound event definition this instance was built from.
public SoundEventDefinition Definition { get; }Property Value
DelayOverride
Gets or sets a playback start delay in seconds, passed by a container, replacing the definition's "delay" property. Used to stagger otherwise-identical children (e.g. quad-channel ambient beds) so they do not all loop in phase lock; a negative value seeks ahead into the track instead of adding silence (see CachedSoundSampleProvider.DelaySamples).
public float? DelayOverride { get; set; }Property Value
float?
FadingOut
Gets whether the event is fading out towards a stop (see SoundEvent.FadeOutAndStop(float)). Retriggers are suppressed while fading.
public bool FadingOut { get; }Property Value
bool
LiveVolume
Gets or sets a live 0..1 gain on top of the volume the play started with, unlike SoundEvent.VolumeOverride which is folded in at start.
public float LiveVolume { get; set; }Property Value
float
Mixer
Gets the mixer this event plays through.
protected AudioMixer Mixer { get; }Property Value
PlaybackId
Gets the id of the play this pooled instance currently represents, so a SoundHandle can tell its own play from a later reuse.
public long PlaybackId { get; }Property Value
long
Playing
Gets whether the event is currently producing audible samples.
public bool Playing { get; protected set; }Property Value
bool
PlayingSoundFile
Gets the vsnd file currently playing for this event.
public string? PlayingSoundFile { get; protected set; }Property Value
string?
Position
Gets or sets the world position of the sound. Null plays the sound without spatialization (e.g. UI or first person sounds). Can be updated while the sound is playing to move it.
public Vector3? Position { get; set; }Property Value
PositionOffset
Gets or sets the offset added to SoundEvent.Position ("position_offset" in the event data, e.g. footsteps play 20 units above the ground).
public Vector3 PositionOffset { get; protected set; }Property Value
SampleProvider
Gets the combined sample provider for this event.
public SampleProviderMulti SampleProvider { get; }Property Value
SampleProviders
Gets the sample providers built by SoundEvent.DoStart().
protected List<AudioSampleProvider> SampleProviders { get; }Property Value
SampleRate
Gets the mixer output sample rate.
protected int SampleRate { get; }Property Value
int
SoundEventData
Gets the key-values the definition was parsed from.
public KVObject SoundEventData { get; }Property Value
KVObject
Started
Gets whether the event is active in the mixer (it may be momentarily silent, e.g. between retriggers).
public bool Started { get; }Property Value
bool
VolumeOverride
Gets or sets a volume passed by game code, replacing the definition's volume property.
public float? VolumeOverride { get; set; }Property Value
float?
VolumeScale
Gets or sets an extra multiplier applied on top of the final volume, including a SoundEvent.VolumeOverride. Carries a scripted soundscape's "playsoundscape" volume, cascading to every child event it pulls in.
public float VolumeScale { get; set; }Property Value
float
Methods
AnyChildStarted()
Gets whether any child event is still active (e.g. waiting on its own retrigger).
protected bool AnyChildStarted()Returns
bool
Build(SoundEventDefinition)
Creates a sound event instance for the given definition, or null when the event type is not supported.
public static SoundEvent? Build(SoundEventDefinition definition)Parameters
definition SoundEventDefinition
Returns
BuildTrackProvider(CachedSound, Vector3?, float, int)
Builds (or reuses, on a later retrigger) a leaf provider streaming cachedSound, wrapped for 3D playback at position when given, otherwise unspatialized. The returned provider's AudioSampleProvider.Volume (and, for a SampleProvider3D, its Range/DistanceVolumeCurve/StereoMixCurve) are left at their defaults - callers set those afterwards. For definitions that play one track at a time; call once per SoundEvent.DoStart().
protected AudioSampleProvider BuildTrackProvider(CachedSound cachedSound, Vector3? position, float pitch, int delaySamples)Parameters
cachedSound CachedSound
position Vector3?
pitch float
delaySamples int
Returns
CollectDebugSounds(List<(Vector3 Position, string Text)>, List<string>)
Collects the position and vsnd name of every audible positioned sound in this event tree into positioned, and the vsnd name of every audible non-positioned (2D) sound into flat.
public void CollectDebugSounds(List<(Vector3 Position, string Text)> positioned, List<string> flat)Parameters
positioned List<(Vector3 Position, string Text)>
flat List<string>
DoStart()
Builds the sample providers (and child events) for this event based on its definition.
protected abstract void DoStart()FadeIn(float)
Fades the whole event tree in from silence over seconds, so it doesn't jump straight to full volume the moment it starts. Call right after SoundEvent.Start(); harmless to call on an event that isn't started yet or already mid-fade-in.
public void FadeIn(float seconds)Parameters
seconds float
FadeOutAndStop(float)
Fades the whole event tree out along SoundEvent.FadeOutCurve (or linearly over fallbackSeconds when the event has none) and stops it when the fade completes.
public void FadeOutAndStop(float fallbackSeconds = 1)Parameters
fallbackSeconds float
OnFinished()
Marks the event as no longer audible, raises SoundEvent.OnSoundOver and stops the event unless something in it is scheduled to sound again.
protected virtual void OnFinished()OnStarted()
Marks the event as audible and raises SoundEvent.OnSoundStart.
protected virtual void OnStarted()Start()
Starts (or restarts, in the case of retriggered events) the sound event.
public bool Start()Returns
bool
Whether the event became active. False means it was inert - nothing in it could ever produce samples this play (no tracks and no children, or dropped by its limiter) - and it was stopped again immediately. Callers must detect that from this return value, not from SoundEvent.Started, which a fast mixer may already have cleared again for an ultra-short sound.
StartAsChild(SoundEvent)
Starts a child sound event mixed into this event's output. A retrigger may pass the same instance again (e.g. cached by child index), which is restarted rather than rebuilt.
protected void StartAsChild(SoundEvent childSoundEvent)Parameters
childSoundEvent SoundEvent
StartChildren(SoundEventDefinition?[], Action<SoundEvent, int>?)
Starts (or restarts, on a retrigger) one child per entry in definitions, building each once and reusing it afterwards instead of rebuilding its provider subtree. Null entries (unresolved definitions) are skipped. Call once per SoundEvent.DoStart() for a definition with a fixed set of children.
protected void StartChildren(SoundEventDefinition?[] definitions, Action<SoundEvent, int>? beforeStart = null)Parameters
definitions SoundEventDefinition?[]
The child definitions to start, by index.
beforeStart Action<SoundEvent, int>?
Optional per-child customization (e.g. SoundEvent.DelayOverride), invoked right after a child is built/resolved but before it starts. Not invoked again for a child already started on an earlier call - set values that must survive every retrigger directly on the child's definition instead.
Stop()
Stops the sound event and any child events it has spawned.
public void Stop()Update(in ListenerState)
Updates spatialization and time-based behavior. Returns whether any sample provider is currently audible.
public virtual bool Update(in ListenerState listener)Parameters
listener ListenerState
Returns
bool
OnSoundOver
Raised when the event has run out of samples.
public event Action<SoundEvent>? OnSoundOverEvent Type
OnSoundStart
Raised when the event begins producing audible samples.
public event Action<SoundEvent>? OnSoundStartEvent Type
OnStart
Raised when the event becomes active in the mixer.
public event Action<SoundEvent>? OnStartEvent Type
OnStop
Raised when the event is removed from the mixer.
public event Action<SoundEvent>? OnStop
