Class SoundEvent
Namespace: ValveResourceFormat.Renderer.Audio
Assembly: Renderer.dll
A playing (or pending) instance of a sound event definition.
public abstract class SoundEventInheritance
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 ).
public float? DelayOverride { get; set; }Property Value
FadingOut
Gets whether the event is fading out towards a stop (see ). Retriggers are suppressed while fading.
public bool FadingOut { get; }Property Value
Mixer
Gets the mixer this event plays through.
protected AudioMixer Mixer { get; }Property Value
Playing
Gets whether the event is currently producing audible samples.
public bool Playing { get; protected set; }Property Value
PlayingSoundFile
Gets the vsnd file currently playing for this event.
public string? PlayingSoundFile { get; protected set; }Property Value
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 ("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 .
protected List<AudioSampleProvider> SampleProviders { get; }Property Value
SampleRate
Gets the mixer output sample rate.
protected int SampleRate { get; }Property Value
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
VolumeOverride
Gets or sets a volume passed by game code, replacing the definition's volume property.
public float? VolumeOverride { get; set; }Property Value
Methods
AnyChildStarted()
Gets whether any child event is still active (e.g. waiting on its own retrigger).
protected bool AnyChildStarted()Returns
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 (and, for a , 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 .
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)>
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 ; 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 (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 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 .
protected virtual void OnStarted()Start()
Starts (or restarts, in the case of retriggered events) the sound event.
public bool Start()Returns
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
, which a fast mixer may already have cleared again for an ultra-short sound.StartAsChild(SoundEvent)
Starts another sound event as a child of this one, mixed into this event's output. Callers may pass the same instance again on a later retrigger (e.g. cached by child index) instead of building a new one - already-wired instances are recognized and only restarted, not rebuilt.
protected void StartAsChild(SoundEvent childSoundEvent)Parameters
childSoundEvent SoundEvent
StartChildren(SoundEventDefinition?[], Action<SoundEvent, int>?)
Starts (or restarts, on a later retrigger) one child per entry in definitions: builds each the first time and reuses the same instance afterwards instead of rebuilding its whole provider subtree from scratch every time. Null entries (unresolved definitions) are skipped. Call once per when a definition plays a fixed set of child events.
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. ), 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(Vector3, Vector3)
Updates spatialization and time-based behavior. Returns whether any sample provider is currently audible.
public virtual bool Update(Vector3 listenerPosition, Vector3 rightEarDirection)Parameters
listenerPosition Vector3
rightEarDirection Vector3
Returns
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
