Stereo

enableSoundPositionIndication

Enables or disables stereo panning for remote users.

virtual int enableSoundPositionIndication(bool enabled) = 0;

Make sure to call this method before joining a channel. The local user can then call setRemoteVoicePosition to track the position of remote users.

Parameters

enabled
Whether to enable stereo panning for remote users:
  • true: Enable stereo panning.
  • false: Disable stereo panning.

Return Values

  • 0: Success.
  • < 0: Failure.

setRemoteVoicePosition

Sets the position and volume of a remote user's voice on the horizontal plane.

virtual int setRemoteVoicePosition(uid_t uid, double pan, double gain) = 0;

This method sets the 2D position and volume of a remote user to help you hear and identify the user's location more clearly. By differentiating between left and right audio channels, you can perceive the direction of the remote user in real time, creating a sense of spatial presence. This method is suitable for large-scale multiplayer online games, such as battle royale games.

Note:
  • To make this method take effect, call enableSoundPositionIndication before joining the channel to enable stereo panning for remote users.
  • For optimal voice positioning, Agora recommends using wired headphones.
  • Call this method after joining the channel.

Parameters

uid
Remote user ID.
pan
The voice position of the remote user. The range is [-1.0, 1.0]:
  • 0.0: (Default) The remote voice comes from the front.
  • -1.0: The remote voice comes from the left.
  • 1.0: The remote voice comes from the right.
gain
The volume of the remote user. The range is [0.0, 100.0]. The default value is 100.0, which means the original volume of the remote user. The smaller the value, the lower the volume.

Return Values

  • 0: Success.
  • < 0: Failure.

setRemoteVoicePositionEx

Sets the 2D position and volume of the remote user's voice.

virtual int setRemoteVoicePositionEx(uid_t uid, double pan, double gain, const RtcConnection& connection) = 0;

Agora uses the difference between the left and right audio channels to allow you to perceive the location of remote users in real time, creating a sense of spatial presence. This method is suitable for large-scale multiplayer online games, such as battle royale games.

Note:
  • For optimal voice positioning, Agora recommends using wired headphones.
  • Call this method after joining the channel.

Scenario

This method applies to multi-channel scenarios.

Parameters

uid
The remote user ID.
pan
The voice position of the remote user. The range is [-1.0, 1.0]:
  • -1.0: The voice comes from the left.
  • 0.0: (Default) The voice comes from the front.
  • 1.0: The voice comes from the right.
gain
The volume of the remote user. The range is [0.0, 100.0]. The default is 100.0 (original volume). The smaller the value, the lower the volume.
connection
Connection information. See RtcConnection.

Return Values

  • 0: Success.
  • < 0: Failure.