# Need help building a multiplayer VOIP system

**URL:** <https://qa.fmod.com/t/need-help-building-a-multiplayer-voip-system/19267>\
**Category:** Unity\
**Created:** [September 12, 2022, 1:39pm UTC](https://qa.fmod.com/t/need-help-building-a-multiplayer-voip-system/19267 "2022-09-12T13:39:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerrardflynne](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/gerrardflynne/32/3424_2.png) [@gerrardflynne](https://qa.fmod.com/u/gerrardflynne)\
**Post date:** [September 12, 2022, 1:39pm UTC](https://qa.fmod.com/t/need-help-building-a-multiplayer-voip-system/19267/1 "2022-09-12T13:39:38Z")

</div>

Hello everyone!  
So the game I’m working on is finally adding multiplayer features and now I need to build a push-to-talk VOIP system.

I am an intermediate Studio user and have some coding experience, however I am not any good at Core API coding and need some help.

1. First and foremost, do I really need to run VOIP through FMOD? If there’s any way it can be run through native Unity Audio without performance issues, then I’ll just ask developers to find and install some third-party VOIP solution.

2. I’ve done my research through forums and FMOD scripting examples, so am currently trying to build a simplest VOIP prototype. And at this point I am stopped with my lack of experience with Core API coding.

So I know the best way to do this would be by using a dedicated VOIP event in a Studio with progammer sound instrument added, and then setting up a callback.

Firstly I get my hardware info and set up basic things

> FMODUnity.RuntimeManager.CoreSystem.getRecordDriverInfo(RecordingDeviceIndex, out RecordingDeviceName, 50, out MicGUID, out SampleRate, out FMODSpeakerMode, out NumOfChannels, out driverState);
> 
> ```
> FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
> exinfo.cbsize = Marshal.SizeOf(typeof(FMOD.CREATESOUNDEXINFO));
> exinfo.numchannels = NumOfChannels;
> exinfo.format = FMOD.SOUND_FORMAT.PCMFLOAT;
> exinfo.defaultfrequency = SampleRate;
> exinfo.length = (uint)(exinfo.defaultfrequency * sizeof(float) * exinfo.numchannels);
> FMOD.MODE recordMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER;
> 
> ```

Then under Input.GetKeyDown method I’m creating an instance of my VOIP event and set a callback for it:

> VOIPCallback = new FMOD.Studio.EVENT\_CALLBACK(VOIPEventCallback);  
> VOIPEvent = FMODUnity.RuntimeManager.CreateInstance(“event:/VOIP”);  
> VOIPEvent.setCallback(VOIPCallback);  
> VOIPEvent.start();  
> VOIPEvent.release();

And then I need to record a sound and play it trough a programmer instrument in VOIP event using a callback. I’ve created the event and now am trying to get at least my mic to sound through it and this is where I’m stuck at the moment.

> static FMOD.RESULT VOIPEventCallback(FMOD.Studio.EVENT\_CALLBACK\_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)  
> {
> 
> ```
> switch (type)
> {
> case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
> {
> 
> FMOD.Sound VOIPSound;
> FMOD.CREATESOUNDEXINFO exinfo = new FMOD.CREATESOUNDEXINFO();
> FMOD.MODE recordMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER;
> var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound("VOIP", recordMode, ref exinfo, out VOIPSound);
> 
> if (soundResult == FMOD.RESULT.OK)
> {
> //get properties
> FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES properties = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
> properties.sound = VOIPSound.handle;
> Marshal.StructureToPtr(properties, parameterPtr, false);
> FMODUnity.RuntimeManager.CoreSystem.recordStart(RecordingDeviceIndex, sound, true);
> }
> }
> break;
> }
> 
> return FMOD.RESULT.OK;
> }
> 
> ```

Sure it’s not working and, honestly, I have no idea what I’m doing here, and even somehow re-declare some variables since it gives me errors otherwise.

Could anyone please help me with the right way to do this ? For now I need a simple push-to-talk single-user voice system run through FMOD Stuido, but this callback thing is a bit out of my skill range at the moment.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [September 16, 2022, 5:53am UTC](https://qa.fmod.com/t/need-help-building-a-multiplayer-voip-system/19267/2 "2022-09-16T05:53:27Z")

</div>

> [@gerrardflynne](#):
>
> First and foremost, do I really need to run VOIP through FMOD?

VOIP does not necessarily need to be run through FMOD, you can use a 3rd party package such as Normcore or Vivox. Such packages would however rely on Unity’s internal audio system, so you would need to re-enable that in the Unity settings, which would also mean you couldn’t ship on PS5 or Xbox.

> [@gerrardflynne](#):
>
> Could anyone please help me with the right way to do this ? For now I need a simple push-to-talk single-user voice system run through FMOD Stuido, but this callback thing is a bit out of my skill range at the moment.

There have been some good discussions on this topic previously, I recommend you look through this thread: [Using FMOD with voice chat utilizing OnAudioFilterRead()](https://qa.fmod.com/t/using-fmod-with-voice-chat-utilizing-onaudiofilterread/17763), which has lots of code samples and various resolutions to issues encountered along the way.
