Class SoundInstance
Base class for sound that creates voices
public class SoundInstance : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IPositionableSound, IPlayableSound
- Inheritance
-
SoundInstance
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
SoundInstance(AudioEngine, AudioListener, DynamicSoundSource, int, bool, bool, bool, float, HrtfEnvironment)
Initializes a new instance of the SoundInstance class using a dynamic sound source.
public SoundInstance(AudioEngine engine, AudioListener listener, DynamicSoundSource dynamicSoundSource, int sampleRate, bool mono, bool spatialized = false, bool useHrtf = false, float directionalFactor = 0, HrtfEnvironment environment = HrtfEnvironment.Small)
Parameters
engine
AudioEngineThe audio engine that will be used to play this instance
listener
AudioListenerThe listener of this instance
dynamicSoundSource
DynamicSoundSourceThe source from where the PCM data will be fetched
sampleRate
intThe sample rate of this audio stream
mono
boolSet to true if the souce is mono, false if stereo
spatialized
boolIf the SoundInstance will be used for spatialized audio set to true, if not false, if true mono must also be true
useHrtf
boolIf the engine should use Hrtf for spatialization
directionalFactor
floatenvironment
HrtfEnvironment
Fields
engine
protected AudioEngine engine
Field Value
isLooping
protected bool isLooping
Field Value
pan
protected float pan
Field Value
pitch
protected float pitch
Field Value
playState
protected PlayState playState
Field Value
sound
protected SoundBase sound
Field Value
soundSource
protected DynamicSoundSource soundSource
Field Value
spatialized
protected bool spatialized
Field Value
volume
protected float volume
Field Value
Properties
DynamicSoundSource
Gets the DynamicSoundSource, might be null if the sound is not using DynamicSoundSource, e.g. not streamed from disk or not using a DynamicSoundSource derived class as backing.
public DynamicSoundSource DynamicSoundSource { get; }
Property Value
IsLooping
Gets or sets whether the sound is automatically looping from beginning when it reaches the end.
public bool IsLooping { get; set; }
Property Value
Pan
Set the sound balance between left and right speaker.
public float Pan { get; set; }
Property Value
Remarks
Panning is ranging from -1.0f (full left) to 1.0f (full right). 0.0f is centered. Values beyond this range are clamped. Panning modifies the total energy of the signal (Pan == -1 => Energy = 1 + 0, Pan == 0 => Energy = 1 + 1, Pan == 0.5 => Energy = 1 + 0.5, ...)
Pitch
Gets or sets the pitch of the sound, might conflict with spatialized sound spatialization.
public float Pitch { get; set; }
Property Value
PlayState
Gets the state of the SoundInstance.
public PlayState PlayState { get; }
Property Value
Position
Gets the position in time of this playing instance.
public TimeSpan Position { get; }
Property Value
Volume
The global volume at which the sound is played.
public float Volume { get; set; }
Property Value
Remarks
Volume is ranging from 0.0f (silence) to 1.0f (full volume). Values beyond those limits are clamped.
Methods
Apply3D(AudioEmitter)
Applies 3D positioning to the sound.
More precisely adjust the channel volumes and pitch of the sound,
such that the sound source seems to come from the emitter
to the listener/>.
public void Apply3D(AudioEmitter emitter)
Parameters
emitter
AudioEmitterThe emitter that correspond to this sound
Remarks
Apply3D(AudioEmitter) can be used only on mono-sounds.
The final resulting pitch depends on the listener and emitter relative velocity. The final resulting channel volumes depend on the listener and emitter relative positions and the value of Volume.
Destroy()
Destroys the instance.
protected override void Destroy()
Pause()
Pause the sounds.
public void Pause()
Remarks
A call to Pause when the sound is already paused or stopped has no effects.
Play()
Play or resume the sound effect instance.
public void Play()
Play(bool)
Play the sound instance.
protected void Play(bool stopSiblingInstances)
Parameters
stopSiblingInstances
boolif true any other istance of the same Sound will be stopped.
PlayExclusive()
Play or resume the sound effect instance, stopping sibling instances.
public void PlayExclusive()
ReadyToPlay()
A task that completes when the sound is ready to play
public Task<bool> ReadyToPlay()
Returns
SetRange(PlayRange)
Sets the range of the sound to play.
public void SetRange(PlayRange range)
Parameters
range
PlayRangea PlayRange structure that describes the starting offset and ending point of the sound to play in seconds.
Stop()
Stop playing the sound immediately and reset the sound to the beginning of the track.
public void Stop()
Remarks
A call to Stop when the sound is already stopped has no effects.