@@ -1059,16 +1059,20 @@ void NetworkManager::Treat(sf::Packet &packet, bool udp) {
10591059 // decompress.
10601060 EVoiceResult res = steam->SteamUser ()->DecompressVoice (pVoiceData, pMsgVoiceData->GetDataLength (), pbUncompressedVoice, sizeof (pbUncompressedVoice), &numUncompressedBytes, sampleRate);
10611061
1062- // continuous stream for voice.
1063- static VoiceStream stream (sampleRate);
1062+ // continuous stream per id for voice.
1063+ static std::unordered_map<uint32_t , std::unique_ptr<VoiceStream>> voiceStreams;
1064+ if (!voiceStreams.count (ghost->ID ))
1065+ voiceStreams.insert (std::make_pair (ghost->ID , new VoiceStream (sampleRate)));
10641066
10651067 if (res == k_EVoiceResultOK && numUncompressedBytes > 0 ) {
1068+ auto stream = voiceStreams[ghost->ID ].get ();
1069+
10661070 // load from raw pcm data.
1067- stream. pushSamples ((const int16_t *)pbUncompressedVoice, numUncompressedBytes / sizeof (int16_t ));
1071+ stream-> pushSamples ((const int16_t *)pbUncompressedVoice, numUncompressedBytes / sizeof (int16_t ));
10681072
10691073 // account for ingame vol.
10701074 static auto vol = Variable (" volume" );
1071- stream. setVolume (vol.GetFloat () * 10000 .f );
1075+ stream-> setVolume (vol.GetFloat () * 10000 .f );
10721076
10731077 // proximity.
10741078 auto player = client->GetPlayer (GET_SLOT () + 1 );
@@ -1083,11 +1087,11 @@ void NetworkManager::Treat(sf::Packet &packet, bool udp) {
10831087 sf::Listener::setPosition ({origin.x , origin.z , origin.y });
10841088 sf::Listener::setDirection ({-forward.x , -forward.z , -forward.y });
10851089
1086- stream. setPosition ({ghost_pos.x , ghost_pos.z , ghost_pos.y });
1090+ stream-> setPosition ({ghost_pos.x , ghost_pos.z , ghost_pos.y });
10871091 }
10881092
1089- if (stream. getStatus () != sf::SoundSource::Status::Playing)
1090- stream. play ();
1093+ if (stream-> getStatus () != sf::SoundSource::Status::Playing)
1094+ stream-> play ();
10911095 }
10921096
10931097 break ;
0 commit comments