BaseSpatialAudioEngine

This class contains some of the APIs in the LocalSpatialAudioEngine class.

The LocalSpatialAudioEngine class inherits from BaseSpatialAudioEngine.

muteAllRemoteAudioStreams

Stops or resumes subscribing to the audio streams of all remote users.

Future<void> muteAllRemoteAudioStreams(bool mute);

Details

After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all remote users, including all subsequent users.

Note:
  • Call this method after joinChannel.
  • When using the spatial audio effect, if you need to set whether to stop subscribing to the audio streams of all remote users, Agora recommends calling this method instead of the muteAllRemoteAudioStreams method in RtcEngine.
  • After calling this method, you need to call updateSelfPosition and updateRemotePosition to update the spatial location of the local user and the remote user; otherwise, the settings in this method do not take effect.

Parameters

mute
Whether to stop subscribing to the audio streams of all remote users:
  • true: Stop subscribing to the audio streams of all remote users.
  • false: Subscribe to the audio streams of all remote users.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteLocalAudioStream

Stops or resumes publishing the local audio stream.

Future<void> muteLocalAudioStream(bool mute);

Details

Note:
  • This method does not affect any ongoing audio recording, because it does not disable the audio capture device.
  • Call this method after joinChannel.
  • When using the spatial audio effect, if you need to set whether to stop subscribing to the audio stream of a specified user, Agora recommends calling this method instead of the muteLocalAudioStream method in RtcEngine.
  • A successful call of this method triggers the onUserMuteAudio and onRemoteAudioStateChanged callbacks on the remote client.

Parameters

mute
Whether to stop publishing the local audio stream:
  • true: Stop publishing the local audio stream.
  • false: Publish the local audio stream.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

muteRemoteAudioStream

Stops or resumes subscribing to the audio stream of a specified user.

Future<void> muteRemoteAudioStream({required int uid, required bool mute});

Details

Note:
  • Call this method after joinChannel.
  • When using the spatial audio effect, if you need to set whether to stop subscribing to the audio stream of a specified user, Agora recommends calling this method instead of the muteRemoteAudioStream method in RtcEngine.

Parameters

uid
The user ID. This parameter must be the same as the user ID passed in when the user joined the channel.
mute
Whether to subscribe to the specified remote user's audio stream.
  • true: Stop subscribing to the audio stream of the specified user.
  • false: (Default) Subscribe to the audio stream of the specified user. The SDK decides whether to subscribe according to the distance between the local user and the remote user.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

release

Destroys BaseSpatialAudioEngine.

abstract release(): void;

Details

This method releases all resources under BaseSpatialAudioEngine. When the user does not need to use the spatial audio effect, you can call this method to release resources for other operations.

After calling this method, you can no longer use any of the APIs under BaseSpatialAudioEngine.
Note: Call this method before the release method under RtcEngine.

setAudioRecvRange

Sets the audio reception range of the local user.

Future<void> setAudioRecvRange(double range);

Details

After the setting is successful, the local user can only hear the remote users within the setting range or belonging to the same team. You can call this method at any time to update the audio reception range.

Parameters

range
The maximum audio reception range. The unit is meters. The value of this parameter must be greater than 0, and the default value is 20.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setDistanceUnit

Sets the length (in meters) of the game engine distance per unit.

Future<void> setDistanceUnit(double unit);

Details

In a game engine, the unit of distance is customized, while in the Agora spatial audio algorithm, distance is measured in meters. By default, the SDK converts the game engine distance per unit to one meter. You can call this method to convert the game engine distance per unit to a specified number of meters.

Parameters

unit
The number of meters that the game engine distance per unit is equal to. The value of this parameter must be greater than 0.00, and the default value is 1.00. For example, setting unit as 2.00 means the game engine distance per unit equals 2 meters.

The larger the value is, the faster the sound heard by the local user attenuates when the remote user moves far away from the local user.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setMaxAudioRecvCount

Sets the maximum number of streams that a user can receive in a specified audio reception range.

Future<void> setMaxAudioRecvCount(int maxCount);

Details

If the number of receivable streams exceeds the set value, the local user receives the maxCount streams that are closest to the local user.

Parameters

maxCount
The maximum number of streams that a user can receive within a specified audio reception range. The value of this parameter should be ≤ 16, and the default value is 10.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setPlayerAttenuation

Sets the sound attenuation properties of the media player.

Future<void> setPlayerAttenuation(
      {required int playerId,
      required double attenuation,
      required bool forceSet});

Details

Parameters

playerId
The ID of the media player.
attenuation
The sound attenuation coefficient of the remote user or media player. The value range is [0,1]. The values are as follows:
  • 0: Broadcast mode, where the volume and timbre are not attenuated with distance, and the volume and timbre heard by local users do not change regardless of distance.
  • (0,0.5): Weak attenuation mode, that is, the volume and timbre are only weakly attenuated during the propagation process, and the sound can travel farther than the real environment.
  • 0.5: (Default) simulates the attenuation of the volume in the real environment; the effect is equivalent to not setting the speaker_attenuation parameter.
  • (0.5,1]: Strong attenuation mode, that is, the volume and timbre attenuate rapidly during the propagation process.
forceSet
Whether to force the sound attenuation effect of the media player:
  • true: Force attenuation to set the attenuation of the media player. At this time, the attenuation coefficient of the sound insulation are set in the audioAttenuation in the SpatialAudioZone does not take effect for the media player.
  • false: Do not force attenuation to set the sound attenuation effect of the media player, as shown in the following two cases.
    • If the sound source and listener are inside and outside the sound isolation area, the sound attenuation effect is determined by the audioAttenuation in SpatialAudioZone.
    • If the sound source and the listener are in the same sound insulation area or outside the same sound insulation area, the sound attenuation effect is determined by attenuation in this method.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setRemoteAudioAttenuation

Sets the sound attenuation effect for the specified user.

Future<void> setRemoteAudioAttenuation(
      {required int uid, required double attenuation, required bool forceSet});

Details

Parameters

uid
The user ID. This parameter must be the same as the user ID passed in when the user joined the channel.
attenuation
For the user's sound attenuation coefficient, the value range is [0,1]. The values are as follows:
  • 0: Broadcast mode, where the volume and timbre are not attenuated with distance, and the volume and timbre heard by local users do not change regardless of distance.
  • (0,0.5): Weak attenuation mode, that is, the volume and timbre are only weakly attenuated during the propagation process, and the sound can travel farther than the real environment.
  • 0.5: (Default) simulates the attenuation of the volume in the real environment; the effect is equivalent to not setting the speaker_attenuation parameter.
  • (0.5,1]: Strong attenuation mode, that is, the volume and timbre attenuate rapidly during the propagation process.
forceSet
Whether to force the user's sound attenuation effect:
  • true: Force attenuation to set the sound attenuation of the user. At this time, the attenuation coefficient of the sound insulation area set in the audioAttenuation of the SpatialAudioZone does not take effect for the user.
  • false: Do not force attenuation to set the user's sound attenuation effect, as shown in the following two cases.
    • If the sound source and listener are inside and outside the sound isolation area, the sound attenuation effect is determined by the audioAttenuation in SpatialAudioZone.
    • If the sound source and the listener are in the same sound insulation area or outside the same sound insulation area, the sound attenuation effect is determined by attenuation in this method.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

setZones

Sets the sound insulation area.

Future<void> setZones(
      {required SpatialAudioZone zones, required int zoneCount});

Details

In virtual interactive scenarios, you can use this method to set the sound insulation area and sound attenuation coefficient. When the sound source (which can be the user or the media player) and the listener belong to the inside and outside of the sound insulation area, they can experience the attenuation effect of sound similar to the real environment when it encounters a building partition.

  • When the sound source and the listener belong to the inside and outside of the sound insulation area, the sound attenuation effect is determined by the sound attenuation coefficient in SpatialAudioZone.
  • If the user or media player is in the same sound insulation area, it is not affected by SpatialAudioZone, and the sound attenuation effect is determined by the attenuation parameter in setPlayerAttenuation or setRemoteAudioAttenuation. If you do not call setPlayerAttenuation or setRemoteAudioAttenuation, the default sound attenuation coefficient of the SDK is 0.5, which simulates the attenuation of the sound in the real environment.
  • If the sound source and the receiver belong to two sound insulation areas, the receiver cannot hear the sound source.
Note: If this method is called multiple times, the last sound insulation area set takes effect.

Parameters

zones
Sound insulation area settings. See SpatialAudioZone. When you set this parameter to NULL, it means clearing all sound insulation zones.
CAUTION: On the Windows platform, it is necessary to ensure that the number of members in the zones array is equal to the value of zoneCount; otherwise, it may cause a crash.
zoneCount
The number of sound insulation areas.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updatePlayerPositionInfo

Updates the spatial position of the media player.

Future<void> updatePlayerPositionInfo(
      {required int playerId, required RemoteVoicePositionInfo positionInfo});

Details

After a successful update, the local user can hear the change in the spatial position of the media player.

Parameters

playerId
The ID of the media player.
positionInfo
The spatial position of the media player. See RemoteVoicePositionInfo.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.

updateSelfPosition

Updates the spatial position of the local user.

Future<void> updateSelfPosition(
      {required List<double> position,
      required List<double> axisForward,
      required List<double> axisRight,
      required List<double> axisUp});

Details

  • Under the LocalSpatialAudioEngine class, this method needs to be used with updateRemotePosition. The SDK calculates the relative position between the local and remote users according to this method and the parameter settings in updateRemotePosition, and then calculates the user's spatial audio effect parameters.

Parameters

position
axisForward
axisRight
The unit vector of the y axis in the coordinate system. This parameter is an array of length 3, and the three values represent the front, right, and top coordinates in turn.
axisUp
The unit vector of the z axis in the coordinate system. This parameter is an array of length 3, and the three values represent the front, right, and top coordinates in turn.

Exceptions

When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown; and you need to catch the exception and handle it accordingly.