ILocalSpatialAudioEngine
This class implements spatial audio by calculating user coordinates through the SDK.
This class inherits from IBaseSpatialAudioEngine. Before calling other APIs in this class, you need to call the initialize method to initialize it.
clearRemotePositions
Deletes the spatial position information of all remote users.
abstract clearRemotePositions(): number;
After successfully calling this method, the local user will not hear any remote users. After leaving the channel, you can also call this method to delete all remote users' spatial position information to avoid wasting computing resources.
Return Values
- 0: Success.
- < 0: Failure. See Error Codes for details and resolution suggestions.
initialize
Initializes ILocalSpatialAudioEngine.
abstract initialize(): number;
- You need to call this method to initialize ILocalSpatialAudioEngine before calling any other methods in the ILocalSpatialAudioEngine class.
- The SDK supports only one ILocalSpatialAudioEngine instance per app.
Return Values
- 0: Success.
- < 0: Failure. See Error Codes for details and resolution suggestions.
removeRemotePosition
Deletes the spatial position information of the specified remote user.
abstract removeRemotePosition(uid: number): number;
After this method is successfully called, the local user will no longer hear the specified remote user. To avoid wasting computing resources after leaving the channel, you need to call this method to delete the spatial position information of the specified remote user. Otherwise, the spatial position information of that user will be retained. When the number of remote users exceeds the maximum number of audio streams set in setMaxAudioRecvCount, the SDK will automatically unsubscribe from the audio streams of the farthest users based on relative distance.
Parameters
- uid
- User ID. Must be the same as the user ID used when joining the channel.
Return Values
- 0: Success.
- < 0: Failure. See Error Codes for details and resolution suggestions.
setRemoteAudioAttenuation
Sets the audio attenuation effect for the specified user.
abstract setRemoteAudioAttenuation(
uid: number,
attenuation: number,
forceSet: boolean
): number;
Parameters
- uid
- User ID. Must be the same as the user ID used when joining the channel.
- attenuation
- The audio attenuation coefficient for the user, ranging from [0,1].
- forceSet
- Whether to force the audio attenuation effect for the user:
- true: Forces the use of
attenuationto set the user's audio attenuation effect. In this case, theaudioAttenuationset in SpatialAudioZone does not apply to the user. - false: Does not force the use of
attenuationto set the user's audio attenuation effect. There are two cases:- If the sound source and listener are inside and outside the sound insulation zone respectively, the attenuation effect is determined by
audioAttenuationin SpatialAudioZone. - If the sound source and listener are both inside the same sound insulation zone or both outside, the attenuation effect is determined by
attenuationin this method.
- If the sound source and listener are inside and outside the sound insulation zone respectively, the attenuation effect is determined by
- true: Forces the use of
Return Values
- 0: Success.
- < 0: Failure. See Error Codes for details and resolution suggestions.
updateRemotePosition
Updates the spatial position information of a remote user.
abstract updateRemotePosition(
uid: number,
posInfo: RemoteVoicePositionInfo
): number;
After successfully calling this method, the SDK calculates the spatial audio parameters based on the relative position between the local and remote users.
Parameters
- uid
- User ID. Must be the same as the user ID used when joining the channel.
- posInfo
- The spatial position information of the remote user. See RemoteVoicePositionInfo.
Return Values
- 0: Success.
- < 0: Failure. See Error Codes for details and resolution suggestions.