Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    SoundInstance Class

    Namespace: Stride.Audio
    Assembly: Stride.Audio.dll

    Base class for sound that creates voices

    System.Object → DisposeBase → ComponentBase → SoundInstance
    Derived from SoundInstance: SoundInstanceStreamedBuffer

    public class SoundInstance : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IPositionableSound, IPlayableSound
    Name Description
    Constructors
    SoundInstance(AudioEngine, AudioListener, DynamicSoundSource, Int32, Boolean, Boolean, Boolean, Single, HrtfEnvironment)

    Initializes a new instance of the SoundInstance class using a dynamic sound source.

    Fields
    engine
    isLooping
    pan
    pitch
    playState
    sound
    soundSource
    spatialized
    volume
    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.

    IsLooping

    Gets or sets whether the sound is automatically looping from beginning when it reaches the end.

    Pan

    Set the sound balance between left and right speaker.

    Pitch

    Gets or sets the pitch of the sound, might conflict with spatialized sound spatialization.

    PlayState

    Gets the state of the SoundInstance.

    Position

    Gets the position in time of this playing instance.

    Volume

    The global volume at which the sound is played.

    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/>.

    Destroy()

    Destroys the instance.

    Pause()

    Pause the sounds.

    Play()

    Play or resume the sound effect instance.

    Play(Boolean)

    Play the sound instance.

    PlayExclusive()

    Play or resume the sound effect instance, stopping sibling instances.

    ReadyToPlay()

    A task that completes when the sound is ready to play

    SetRange(PlayRange)

    Sets the range of the sound to play.

    Stop()

    Stop playing the sound immediately and reset the sound to the beginning of the track.

    | Improve this Doc View Source

    Constructors


    SoundInstance(AudioEngine, AudioListener, DynamicSoundSource, Int32, Boolean, Boolean, Boolean, Single, 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 = 0F, HrtfEnvironment environment = HrtfEnvironment.Small)
    Parameters
    Type Name Description
    AudioEngine engine

    The audio engine that will be used to play this instance

    AudioListener listener

    The listener of this instance

    DynamicSoundSource dynamicSoundSource

    The source from where the PCM data will be fetched

    System.Int32 sampleRate

    The sample rate of this audio stream

    System.Boolean mono

    Set to true if the souce is mono, false if stereo

    System.Boolean spatialized

    If the SoundInstance will be used for spatialized audio set to true, if not false, if true mono must also be true

    System.Boolean useHrtf

    If the engine should use Hrtf for spatialization

    System.Single directionalFactor
    HrtfEnvironment environment
    | Improve this Doc View Source

    Fields


    engine

    protected AudioEngine engine
    Field Value
    Type Description
    AudioEngine

    isLooping

    protected bool isLooping
    Field Value
    Type Description
    System.Boolean

    pan

    protected float pan
    Field Value
    Type Description
    System.Single

    pitch

    protected float pitch
    Field Value
    Type Description
    System.Single

    playState

    protected PlayState playState
    Field Value
    Type Description
    PlayState

    sound

    protected SoundBase sound
    Field Value
    Type Description
    SoundBase

    soundSource

    protected DynamicSoundSource soundSource
    Field Value
    Type Description
    DynamicSoundSource

    spatialized

    protected bool spatialized
    Field Value
    Type Description
    System.Boolean

    volume

    protected float volume
    Field Value
    Type Description
    System.Single
    | Improve this Doc View Source

    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
    Type Description
    DynamicSoundSource

    IsLooping

    Gets or sets whether the sound is automatically looping from beginning when it reaches the end.

    public bool IsLooping { get; set; }
    Property Value
    Type Description
    System.Boolean

    Pan

    Set the sound balance between left and right speaker.

    public float Pan { get; set; }
    Property Value
    Type Description
    System.Single
    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
    Type Description
    System.Single

    PlayState

    Gets the state of the SoundInstance.

    public PlayState PlayState { get; }
    Property Value
    Type Description
    PlayState

    Position

    Gets the position in time of this playing instance.

    public TimeSpan Position { get; }
    Property Value
    Type Description
    System.TimeSpan

    Volume

    The global volume at which the sound is played.

    public float Volume { get; set; }
    Property Value
    Type Description
    System.Single
    Remarks

    Volume is ranging from 0.0f (silence) to 1.0f (full volume). Values beyond those limits are clamped.

    | Improve this Doc View Source

    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
    Type Name Description
    AudioEmitter emitter

    The 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()
    Overrides
    ComponentBase.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(Boolean)

    Play the sound instance.

    protected void Play(bool stopSiblingInstances)
    Parameters
    Type Name Description
    System.Boolean stopSiblingInstances

    if 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 async Task<bool> ReadyToPlay()
    Returns
    Type Description
    System.Threading.Tasks.Task<System.Boolean>

    Returns a task that will complete when the sound has been buffered and ready to play


    SetRange(PlayRange)

    Sets the range of the sound to play.

    public void SetRange(PlayRange range)
    Parameters
    Type Name Description
    PlayRange range

    a 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.


    Inherited Members

    ComponentBase.Tags
    ComponentBase.Name
    ComponentBase.ICollectorHolder.Collector
    ComponentBase.OnNameChanged()
    ComponentBase.ToString()
    DisposeBase.Dispose()
    DisposeBase.IsDisposed
    DisposeBase.IReferencable.ReferenceCount
    DisposeBase.IReferencable.AddReference()
    DisposeBase.IReferencable.Release()
    DisposeBase.OnAddReference()
    DisposeBase.OnReleaseReference()

    Extension Methods

    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation