Hello.
I recently implemented voice chat using FMOD. Each player has an FMOD.Sound that stores the player’s voice. Each player has an object with FMOD Studio Event Emitter that plays Programmer Sound, so if there are 10 players, then 10 objects with Event Emitter are used. This is quite logical here because each sound is spatial and should come from the player’s position.
Now I need to implement a radio system in which the player can change the “channel” and players can hear and talk only to those players who are on the same “channel”. and I would like to use these same FMOD.Sound’s. But creating 10 Event Emitters in each radio seems illogical (because one radio will have 10 Event Emitters with the same position) and too demanding in terms of performance, since if each player has a radio, then each radio should have 10 objects with the Event Emitter component, i.e. there will be 100 of these objects (and, accordingly, Event Emitters).
Also, I really need to use the Event Emitter because I also use Steam Audio Source, which only works with this component.
Is there a way to combine several Sound’s into one to play it through 1 Event Emitter?
Thanks.
I wrote some code that mix player voice samples and it works, but maybe there are some built-in or simpler solutions?
Hi,
You’ve correctly identified what is essentially one of the simplest solutions. Since you’re using a programmer sound, to the FMOD Studio API there isn’t really any distinction between each player’s voice channel because you’re the one providing the stream of audio to the programmer at runtime.
As a result, the “simplest” solutions are to either directly modify the stream to mix between each player’s voice samples (which you’ve done), or have the event instance stop playing the programmer instrument and then start playing it again, i.e. by restarting the event, or transitioning away and back to the programmer instrument. Both of these allow you to use a single event instance to accommodate all players’ channels.
If you wanted to elaborate on this behavior, for example by playing some kind of radio SFX when swapping channels, a basic implementation would be something like the following:
You can “change channel” by stopping and then restarting the above event - it will stop playing the current programmer sound when stopping, then on starting play a short burst of noise as a “change channel” sound effect, followed by playing the looping programmer sound again, in the callback for which you can create a new stream and specify the channel to use.