This document is about: FUSION 2
SWITCH TO

Dynamic Audio group


Available in the Industries Circle
Circle
Fusion Industries prototyping Addons

Dynamic Audio group

fusion industries addon dynamic audio group

The dynamic audio group feature allows to discuss with all the remote users around the local one, without using bandwidth or adding noise from user afar. Users beyond a defined distance are not heard. Coupled with a adapted sound spatialization and attenuation, this provides a natural listening sensation.

The current implementation is based on Photon Voice interest groups.

Each user will speak in one unique interest group and it will never be changed. However, the list of groups he listens to is dynamically modified according to the proximity of the other players limiting the needed bandwidth. Moreover, isolated people don't send their voice over the network to even further avoid consuming bandwidth.

This feature rely on the DynamicAudioGroupMember class.

DynamicAudioGroupMember

DynamicAudioGroupMember is located on each network player prefab In the Spawned(), a unique audio GroupId is computed for the player (in other words, each player has it own GroupId). Then, the local player Recorder audio interest group is configured with this GroupId and the voice client is configured to listen it.

C#

async void SpeakAndListenOnlyToGroup(byte groupId)
{
...
    recorder.InterestGroup = groupId;
    fusionVoiceClient.Client.OpChangeGroups(groupsToRemove: new byte[] { }, groupsToAdd: new byte[] { groupId });
...
}

To update the groups the player listens to, we check if other players are within the defined distance during the Update().

C#

private void Update()
{
    CheckProximity();
}

For each player found at proximity, the local player starts to listen the GroupId of the remote player (GroupId is a networked variable).

C#

private void CheckProximity()
{
...
    if(DistanceSqr(member) < proximityDistanceSqr)
    {
    ...
        ListentoGroupId(member.GroupId);
    }
...
}

C#

async void ListentoGroupId(byte groupId)
{
    if (!Object.HasStateAuthority) return;
    while (!IsPhotonVoiceready || !isSpeakInitialized) await Task.Delay(10);
    fusionVoiceClient.Client.OpChangeGroups(groupsToRemove: null, groupsToAdd: new byte[] { groupId });
}

Conversely, if a remote player is no longer in the proximity perimeter, then he is no longer listened to thanks to the StopListeningToGroupId() method.

Because these operations are performed by all the players, a two-way conversation is possible although each player sends his voice only in his own GroupId.

Additional Filter

Also, because the player may be close to another player but in a different closed room, CheckProximity() checks whether the member should stop listening to another member if the room is isolated. So, the DynamicAudioGroupMember class provides an additionalFilter parameter : to be abble to listen to each other, two audio group members must have the same additionalFilter value.

For instance, in the audio room addon, the additionalFilter parameter is set in AudioRoomMember when a user is in an isolated room.

The special additionnal filter value NEVER_MATCHING_GROUP_FILTER prevent joining any member group (listening to no one), as this special filter will be consider never matching between two members.

C#

if (additionalFilter == NEVER_MATCHING_GROUP_FILTER || additionalFilter != member.additionalFilter)
    {
    // No matching filter
    StopListeningToMember(member);
    }

Demo

To illustrate the usage, a demo scene can be found in Assets\Photon\FusionAddons\DynamicAudioGroup\Demo\Scenes\DynamicAudioGroup.unity.

Connect multiple clients and observe the information panel associated with each player. Each player is surrounded by two spheres. The green sphere is the area that will start listening to another player as soon as his head enters it. Listening will stop as soon as the head leaves the red sphere.

Dependencies

  • Photon Voice SDK

Download

This addon latest version is included into the addon project

Supported topologies

  • shared mode

Changelog

  • Version 2.0.1: Add NEVER_MATCHING_GROUP_FILTER to DynamicAudioGroup additional filters to prevent joining any member group (listening to no one)
  • Version 2.0.0: Fusion 2.0 support
  • Version 1.0.2: Fix error in DisplayDynamicAudioGroupInfos when listened member disconnected
  • Version 1.0.1: Add demo scene + add namespace
  • Version 1.0.0: First release
Back to top