Class AudioSource
Represents the audio source class.
Namespace: Evergine.Common.Audio
Assembly: Evergine.Common.dll
Syntax
public abstract class AudioSource
Constructors
AudioSource(WaveFormat)
Initializes a new instance of the AudioSource class.
Declaration
public AudioSource(WaveFormat format)
Parameters
Type | Name | Description |
---|---|---|
WaveFormat | format | The format of the audio data. |
Properties
CurrentBuffer
Gets the buffer at the start of the pending queue.
Declaration
public AudioBuffer CurrentBuffer { get; }
Property Value
Type | Description |
---|---|
AudioBuffer |
Format
Gets the format of the audio data.
Declaration
public WaveFormat Format { get; }
Property Value
Type | Description |
---|---|
WaveFormat |
IsLooped
Gets or sets a value indicating whether the sound should loop from the beginning when it reaches the end.
The default value is false
.
Declaration
public bool IsLooped { get; set; }
Property Value
Type | Description |
---|---|
bool |
Pan
Gets or sets the sound balance between the left and right speakers. The default value is 0.0f
.
Declaration
public float Pan { get; set; }
Property Value
Type | Description |
---|---|
float |
Remarks
The panning ranges from -1.0f
(full left) to 1.0f
(full right). 0.0f
is centered.
Values beyond this range are clamped.
PendingBuffers
Gets an enumerable that contains the buffers that are pending to be processed by this audio source, including CurrentBuffer.
Declaration
public IEnumerable<AudioBuffer> PendingBuffers { get; }
Property Value
Type | Description |
---|---|
IEnumerable<AudioBuffer> |
PendingBuffersCount
Gets the number of buffers that are pending to be processed by this audio source, including CurrentBuffer.
Declaration
public int PendingBuffersCount { get; }
Property Value
Type | Description |
---|---|
int |
Pitch
Gets or sets the pitch of the sound, which might conflict with spatialized sound.
The default value is 1.0f
.
Declaration
public float Pitch { get; set; }
Property Value
Type | Description |
---|---|
float |
Remarks
Pitch ranges from Epsilon to MaxValue. Values beyond this range are clamped. Each reduction by 50 percent equals a pitch shift of -12 semitones (one octave reduction). Each doubling equals a pitch shift of 12 semitones (one octave increase).
PlayPosition
Gets the playback position. If IsLooped is active, the value will reset to zero at the start of each loop.
Declaration
public TimeSpan PlayPosition { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
QueueDuration
Gets the total duration of the buffers currently queued in this audio source.
Declaration
public TimeSpan QueueDuration { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
QueuePlayPosition
Gets or sets the playback position relative to the beginning of the PendingBuffers queue.
Declaration
public TimeSpan QueuePlayPosition { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
Remarks
QueuePosition ranges from Zero to QueueDuration. Values beyond this range are clamped. When the audio source is in the Stopped state, and the value is higher than Zero, the state will change to Paused. The position is relative to the beginning of all the queued buffers for the source, and any queued buffers traversed by a set value will raise the event BufferEnded.
State
Gets the state (playing, paused, or stopped) of the sound.
Declaration
public PlayState State { get; }
Property Value
Type | Description |
---|---|
PlayState |
Volume
Gets or sets the global volume at which the sound is played. The default value is 1.0f
.
Declaration
public float Volume { get; set; }
Property Value
Type | Description |
---|---|
float |
Remarks
Volume ranges from 0.0f (silence) to 1.0f (full volume). Values beyond these limits are clamped.
Methods
Apply3D(AudioEmitter)
Sets the 3D properties of the Audio Source according to an audio emitter.
Declaration
public abstract void Apply3D(AudioEmitter emitter)
Parameters
Type | Name | Description |
---|---|---|
AudioEmitter | emitter | The audio emitter. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public abstract void Dispose()
EnqueueBuffer(AudioBuffer)
Enqueues an audio buffer.
Declaration
public void EnqueueBuffer(AudioBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
AudioBuffer | buffer | The audio buffer. |
FlushBuffers()
Flushes all the audio buffers.
Declaration
public abstract void FlushBuffers()
GetPlayPosition()
Gets the playback TimeSpan position of the audio.
Declaration
protected abstract TimeSpan GetPlayPosition()
Returns
Type | Description |
---|---|
TimeSpan | A TimeSpan with the current playback position. |
GetQueuePlayPosition()
Gets the Queue Play TimeSpan position.
Declaration
protected abstract TimeSpan GetQueuePlayPosition()
Returns
Type | Description |
---|---|
TimeSpan | A TimeSpan with the Queue Play position. |
InternalEnqueueBuffer(AudioBuffer, out int?)
Enqueues an audio buffer into the source.
Declaration
protected abstract void InternalEnqueueBuffer(AudioBuffer buffer, out int? index)
Parameters
Type | Name | Description |
---|---|---|
AudioBuffer | buffer | The buffer to enqueue. |
int? | index | Output variable containing the buffer's index. |
InternalPause()
Pauses the audio source.
Declaration
protected abstract void InternalPause()
InternalPlay()
Plays the audio source.
Declaration
protected abstract void InternalPlay()
InternalStop()
Stops the audio source.
Declaration
protected abstract void InternalStop()
IsPaused()
Checks if this audio source is paused.
Declaration
protected abstract bool IsPaused()
Returns
Type | Description |
---|---|
bool | True if this audio source is paused; false otherwise. |
IsPlaying()
Checks if the source is playing.
Declaration
protected abstract bool IsPlaying()
Returns
Type | Description |
---|---|
bool | True if the audio source is playing; false otherwise. |
OnBufferProccessed(bool)
Method called when an audio buffer has been processed.
Declaration
protected void OnBufferProccessed(bool isReused)
Parameters
Type | Name | Description |
---|---|---|
bool | isReused | Indicates if the buffer must be reused. |
OnBufferStart()
Method that is called when an audio buffer starts playing.
Declaration
protected void OnBufferStart()
Pause()
Pauses the audio source.
Declaration
public void Pause()
Play()
Plays the audio source.
Declaration
public void Play()
SetLoop(bool)
Sets a new value to indicate if the source is looped.
Declaration
protected abstract void SetLoop(bool isLooped)
Parameters
Type | Name | Description |
---|---|---|
bool | isLooped | Indicates if the source should loop the sound. |
SetPan(float)
Sets the pan of this audio source.
Declaration
protected abstract void SetPan(float pan)
Parameters
Type | Name | Description |
---|---|---|
float | pan | The new pan value. |
SetPitch(float)
Sets the new pitch of this source.
Declaration
protected abstract void SetPitch(float pitch)
Parameters
Type | Name | Description |
---|---|---|
float | pitch | The new pitch. |
SetQueuePlayPosition(TimeSpan)
Sets the queue play TimeSpan position.
Declaration
protected abstract void SetQueuePlayPosition(TimeSpan position)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | position | The new TimeSpan position. |
SetVolume(float)
Sets the volume of this source.
Declaration
protected abstract void SetVolume(float volume)
Parameters
Type | Name | Description |
---|---|---|
float | volume | The new volume level. |
Stop()
Stops the audio source.
Declaration
public void Stop()
Events
BufferEnded
Occurs when this audio source finishes processing an enqueued AudioBuffer.
Declaration
public event EventHandler<AudioBufferEventArgs> BufferEnded
Event Type
Type | Description |
---|---|
EventHandler<AudioBufferEventArgs> |
BufferStarted
Occurs when this audio source is about to start processing an enqueued AudioBuffer.
Declaration
public event EventHandler<AudioBufferEventArgs> BufferStarted
Event Type
Type | Description |
---|---|
EventHandler<AudioBufferEventArgs> |