Unity play streaming PCM16 sound

Hello everyone,
I am stumped a bit with a feature and hoping you can help me.
I am creating a multiplayer game where you can talk to other players via in game voice chat.
I have networking solved and can send PCM16 data though it. My problem is how to play it on other clients? I have some code, but no luck with getting it working.
I saw the user_created_sound example, but I have hard time modifying it to play external data in Unity.

I am creating a Sound when a player joins the game

var system = FMODUnity.RuntimeManager.CoreSystem;
exinfo.cbsize = MarshalHelper.SizeOf(typeof(CREATESOUNDEXINFO));
exinfo.format = SOUND_FORMAT.PCM16;
exinfo.defaultfrequency = (int)11025;
exinfo.decodebuffersize = (int)11025;
exinfo.length = (uint)exinfo.defaultfrequency * sizeof(ushort);
exinfo.numchannels = 1;
exinfo.pcmreadcallback = pcmreadcallback;
exinfo.pcmsetposcallback = (IntPtr sound, int subsound, uint position, TIMEUNIT postype) => {return FMOD.RESULT.OK;};
var bus = FMODUnity.RuntimeManager.GetBus("bus:/Voice");
bus.getChannelGroup(out var channelGroup);
var createSoundResult = system.createSound((string)null, FMOD.MODE.CREATESTREAM | FMOD.MODE.OPENUSER | FMOD.MODE.LOOP_NORMAL, ref exinfo, out var fmodSound);
var result = system.playSound(fmodSound, channelGroup, false, out var channel);

and for pcmreadcallback, I managed to get sine wave demo working, but how do I play the audio that I receive?

Also, just fyi, I managed to get it working by playing one sound when I get the audio data, but then the audio is choppy and unusable.

Sorry if this is written somewhere, or code is wrong, I am still getting a hang of Fmod. :slight_smile:
Thanks for helping!

Looks like you have set it up properly, you just need to provide the audio in the PCM read callback. The callback will fire when more data is needed and will pass in how much data it wants (in bytes). You need to copy it from the data source using Marshal.Copy.