Simple Voice Chat

Simple Voice Chat

31M Downloads

Immersive voice directions

Asphahyre opened this issue · 1 comments

commented

I’m an old mumble link player for immersive games, and it always have been a concern when hearing people talking from the surface while being 40m underground.

Now that voice chat is brought by a game mod rather than by external software, I wonder if there is a way to get directions and/or distances with some sort of pathfinding.

Ex: you’re on a cave, 10m below your comrade. The entrance is 30m behind you: when speaking, your comrade will hear you a bit low, and from the cave entrance, rather than behind him.

I believe the actual magic happens here:

client.getTalkCache().updateTalking(player.getUniqueID());
float distance = player.getDistance(minecraft.player);
float percentage = 1F;
float fadeDistance = Main.SERVER_CONFIG.voiceChatFadeDistance.get().floatValue();
float maxDistance = Main.SERVER_CONFIG.voiceChatDistance.get().floatValue();
if (distance > fadeDistance) {
percentage = 1F - Math.min((distance - fadeDistance) / (maxDistance - fadeDistance), 1F);
}
gainControl.setValue(Math.min(Math.max(Utils.percentageToDB(percentage * Main.CLIENT_CONFIG.voiceChatVolume.get().floatValue() * (float) Main.VOLUME_CONFIG.getVolume(player)), gainControl.getMinimum()), gainControl.getMaximum()));
Pair<Float, Float> stereoVolume = Utils.getStereoVolume(minecraft.player.getPositionVec(), minecraft.player.rotationYaw, player.getPositionVec());
byte[] stereo = Utils.convertToStereo(packet.getData(), stereoVolume.getLeft(), stereoVolume.getRight());

Replacing distance fetching and direction vector computing by an separate class/component could also allow more sophisticated stuff:

  • echoes you could have when in a cave, or mountains
  • muffled sound depending on the blocks you’re behind (doors, glass, 1m of stone/dirt, water)
  • a more realistic sound attenuation
  • could add some items such as phone blocks or cellulars to bypass proximity chat

This is a suggestion, on which I can propose my help, but it may not be appropriated to include everything in this mod.
Here are some cons:

  • it brings completely different mechanics to Minecraft sound system
  • it may be more suitable inside one or multiple distinct mod(s) which entirely rework Minecraft sound system

But there’s some pros too:

  • it seems fairly easy to implement it here
  • it’s not really bad if immersive sound only works for voice chat
  • I can easily bring some PR on an already existing mod, but I still fear starting/maintaining a mod reworking all Minecraft sound system
commented

I'm sorry, but I believe such calculations are way too intensive for every voice packet (Multiple times per second).
As you can see in #70 the voice chat struggles as is with many connected clients.