Channel¶
An object that represents a single channel of audio.
Detailed Description¶
The Channel class is a lightweight reference to a ChannelInternalState object which is managed internally by the Engine. Multiple channels may point to the same underlying data while maintaining different states.
Public Functions¶
| Type | Name |
|---|---|
| ChannelInstance | AddInstance (const AmVector3 & location) const Adds a new instance at the specified world position. |
| Channel () Construct an uninitialized channel. | |
| Channel (ChannelInternalState * state) Creates a wrapper instance over the provided state. | |
| void | Clear () Uninitializes this channel. |
| void | ClearInstances () const Removes all instances. |
| void | DisableInstancing () const Disables multi-position mode, reverting to single-position behavior. |
| void | EnableInstancing (eChannelInstanceMode mode) const Enables multi-position mode for this channel. |
| Entity | GetEntity () const Returns the Entity associated with this channel. |
| AmReal32 | GetGain () const Returns the gain on this channel. |
| AmChannelID | GetId () const Gets the ID of this channel. |
| ChannelInstance | GetInstance (AmChannelInstanceID instanceId) const Gets an instance by ID. |
| AmSize | GetInstanceCount () const Gets the number of active instances. |
| eChannelInstanceMode | GetInstancingMode () const Gets the instancing mode. |
| Listener | GetListener () const Returns the Listener associated with this channel. |
| const AmVector3 & | GetLocation () const Gets the location of this channel in the game environment. |
| AmTime | GetPlaybackPosition () const Gets this channel's current playback position. |
| eChannelPlaybackState | GetPlaybackState () const Returns the playback state of this channel. |
| Room | GetRoom () const Returns the Room associated with this channel. |
| ChannelInternalState * | GetState () const Returns the internal state of this channel. |
| bool | IsInstancingEnabled () const Checks if multi-position instancing is enabled. |
| void | On (eChannelEvent event, ChannelEventCallback callback, void * userData=nullptr) const Registers a callback for a channel event. |
| void | Pause (AmTime duration=kMinFadeDuration) const Pauses the channel. |
| void | Pause (AmTime duration, AmUInt64 clock) const Pauses the channel at an exact frame of the audio clock. |
| bool | Playing () const Checks if the sound associated with this channel is playing. |
| void | RemoveInstance (AmChannelInstanceID instanceId) const Removes an instance by ID. |
| void | Resume (AmTime duration=kMinFadeDuration) const Resumes the channel. |
| void | Resume (AmTime duration, AmUInt64 clock) const Resumes the channel at an exact frame of the audio clock. |
| bool | ScheduleStart (AmUInt64 clock) const Starts this channel at an exact frame of the audio clock. |
| void | SetGain (AmReal32 gain) const Sets the gain on this channel. |
| void | SetLocation (const AmVector3 & location) const Sets the location of this channel in the game environment. |
| bool | SetPlaybackPosition (AmTime position) const Sets this channel's playback position. |
| bool | SetPlaybackPosition (AmTime position, AmUInt64 clock) const Sets this channel's playback position at an exact frame of the audio clock. |
| void | Stop (AmTime duration=kMinFadeDuration) const Stops the channel. |
| void | Stop (AmTime duration, AmUInt64 clock) const Stops the channel at an exact frame of the audio clock. |
| bool | Valid () const Checks whether this channel has been initialized. |
Public Functions Documentation¶
AddInstance
Adds a new instance at the specified world position.
Creates a new position instance for this channel. In Blended mode, all instances share the same playback cursor. In Separate mode, each instance has an independent cursor starting from the current playback position.
Parameters:
-
locationThe world position for the new instance.
Returns:
The created ChannelInstance handle.
Note:
Instancing must be enabled before adding instances.
See also: EnableInstancing
See also: ChannelInstance
Channel[1/3]
Construct an uninitialized channel.
Note:
An uninitialized channel cannot have its data set or queried.
Channel[2/3]
Creates a wrapper instance over the provided state.
Parameters:
-
stateThe internal state to wrap.
Warning:
This constructor is for internal usage only.
Clear
Uninitializes this channel.
Note:
This does not stop the audio or destroy the internal state it references, it just removes this reference to it.
ClearInstances
Removes all instances.
After calling this, the channel will have no position instances. Instancing will still be enabled with the same mode.
DisableInstancing
Disables multi-position mode, reverting to single-position behavior.
All existing instances will be removed when instancing is disabled.
EnableInstancing
Enables multi-position mode for this channel.
When enabled, this channel can have multiple position instances, allowing the same sound to be perceived from multiple locations simultaneously.
Parameters:
-
modeThe instance mode.
Note:
Must be called before adding instances. The mode cannot be changed while instancing is already enabled.
See also: eChannelInstanceMode
See also: AddInstance
GetEntity
Returns the Entity associated with this channel.
Note:
If no Entity is associated with this channel, this method will return an uninitialized Entity object. You should check if the entity is valid before using it.
Returns:
The entity associated with this channel.
See also: Entity
GetGain
Returns the gain on this channel.
Returns:
The channel's gain.
GetId
Gets the ID of this channel.
Returns:
The ID of this channel.
GetInstance
Gets an instance by ID.
Parameters:
-
instanceIdThe ID of the instance to retrieve.
Returns:
The ChannelInstance handle, or an invalid instance if not found.
See also: ChannelInstance::Valid
GetInstanceCount
Gets the number of active instances.
Returns:
The number of position instances.
GetInstancingMode
Gets the instancing mode.
Returns:
The current instancing mode.
See also: eChannelInstanceMode
GetListener
Returns the Listener associated with this channel.
Note:
If no Listener is associated with this channel, this method will return an uninitialized Listener object. You should check if the listener is valid before using it.
Returns:
The listener associated with this channel.
See also: Listener
GetLocation
Gets the location of this channel in the game environment.
If the audio on this channel doesn't support positional data, this method will return an invalid location.
Returns:
The location of this channel.
GetPlaybackPosition
Gets this channel's current playback position.
Returns:
The current playback position in milliseconds.
GetPlaybackState
Returns the playback state of this channel.
Returns:
An eChannelPlaybackState enumeration value representing the current state of the channel.
GetRoom
Returns the Room associated with this channel.
Note:
If no Room is associated with this channel, this method will return an uninitialized Room object. You should check if the room is valid before using it.
Returns:
The room associated with this channel.
GetState
Returns the internal state of this channel.
Returns:
The internal state of this channel.
Warning:
This method is for internal usage only.
IsInstancingEnabled
Checks if multi-position instancing is enabled.
Returns:
true if instancing is enabled, false otherwise.
On
Registers a callback for a channel event.
void Amplitude::Channel::On (
eChannelEvent event,
ChannelEventCallback callback,
void * userData=nullptr
) const
Parameters:
-
eventThe channel event. -
callbackThe callback function. -
userDataThe user data to pass to the callback.
Note:
Events fire when the voice reports them, or on the next frame, not at the moment of the call. The userData must outlive the channel's Stop event, including the Stop that Engine::Deinitialize() raises for channels still playing. There is no way to unregister a callback.
See also: eChannelEvent
See also: ChannelEventCallback
Pause[1/2]
Pauses the channel.
Note:
A paused channel may be resumed where it left off.
Parameters:
-
durationThe fade out duration before to pause the channel.
See also: Resume
Pause[2/2]
Pauses the channel at an exact frame of the audio clock.
A duration of 0 still applies a short de-click fade.
Parameters:
-
durationThe fade out duration before to pause the channel. -
clockThe frame, onEngine::GetAudioClock(), at which the pause begins.
Playing
Checks if the sound associated with this channel is playing.
Returns:
true if the channel is currently playing, false otherwise.
RemoveInstance
Removes an instance by ID.
Parameters:
-
instanceIdThe ID of the instance to remove.
See also: ChannelInstance::GetId
Resume[1/2]
Resumes the channel.
If this channel is paused, it will continue where it left off.
Parameters:
-
durationThe fade-in duration after resuming the channel.
See also: Pause
Resume[2/2]
Resumes the channel at an exact frame of the audio clock.
A duration of 0 still applies a short de-click fade.
Parameters:
-
durationThe fade-in duration after resuming the channel. -
clockThe frame, onEngine::GetAudioClock(), at which the resume begins.
ScheduleStart
Starts this channel at an exact frame of the audio clock.
Only valid on the frame the channel was returned by Engine::Play(), before the engine processes it.
Parameters:
-
clockThe audio-clock frame of the first sample. A frame already in the past starts the sound as soon as possible.
Returns:
true when the start was scheduled, false when the channel already started.
SetGain
Sets the gain on this channel.
Parameters:
-
gainThe new gain value.
SetLocation
Sets the location of this channel in the game environment.
If the audio on this channel doesn't support positional data, this method does nothing.
Parameters:
-
locationThe new location of the channel.
SetPlaybackPosition[1/2]
Sets this channel's playback position.
Parameters:
-
positionThe playback position in milliseconds.
Returns:
true if the playback position was set, false otherwise.
SetPlaybackPosition[2/2]
Sets this channel's playback position at an exact frame of the audio clock.
Parameters:
-
positionThe playback position in milliseconds. -
clockThe frame, onEngine::GetAudioClock(), at which the seek lands.
Returns:
true if the seek was scheduled, false otherwise.
Stop[1/2]
Stops the channel.
Note:
A sound will stop on its own if it's not set to loop. Looped audio must be explicitly stopped.
Parameters:
-
durationThe fade out duration before to stop the channel.
Stop[2/2]
Stops the channel at an exact frame of the audio clock.
A duration of 0 still applies a short de-click fade. The channel keeps playing until clock, then settles when the fade ends.
Parameters:
-
durationThe fade out duration before to stop the channel. -
clockThe frame, onEngine::GetAudioClock(), at which the stop begins.
Valid
Checks whether this channel has been initialized.
Returns:
true if this channel has been initialized, false otherwise.
The documentation for this class was generated from the following file: include/SparkyStudios/Audio/Amplitude/Core/Playback/Channel.h