Copy recorded sound to another (Multiplayer system)

Hey!

First at all sorry about my english, i will do my best.

I have created two sounds, one records the microphone and other plays the buffer generated by the first one.

private void Start()
        {
            FMODUnity.RuntimeManager.CoreSystem.getRecordDriverInfo(captureDeviceIndex, out string recordingDeviceName, 50,
            out Guid MicGUID, out captureSrate, out FMOD.SPEAKERMODE FMODSpeakerMode, out int numberOfChannels,
            out FMOD.DRIVER_STATE driverState);

            exInfo.cbsize = Marshal.SizeOf(typeof(FMOD.CREATESOUNDEXINFO));
            exInfo.numchannels = numberOfChannels;
            exInfo.format = FMOD.SOUND_FORMAT.PCM16;
            exInfo.defaultfrequency = captureSrate;
            exInfo.length = (uint)captureSrate * sizeof(short) * (uint)numberOfChannels;

            //Recorded Sound

            FMODUnity.RuntimeManager.CoreSystem.createSound(exInfo.userdata,
                FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER,
                ref exInfo, out recSound);

            recSound.getLength(out recSoundLength, FMOD.TIMEUNIT.PCM);
            buffer = new byte[recSoundLength];

            FMODUnity.RuntimeManager.CoreSystem.recordStart(captureDeviceIndex, recSound, true);

            // Emitted Sound

            FMODUnity.RuntimeManager.CoreSystem.createSound(exInfo.userdata,
                FMOD.MODE.LOOP_NORMAL | FMOD.MODE.OPENUSER,
                ref exInfo, out emittedSound);

            audioCallback = AudioEventCallback;

            programmerSound = FMODUnity.RuntimeManager.CreateInstance(voiceChatSoundEvent);
            FMODUnity.RuntimeManager.AttachInstanceToGameObject(programmerSound, transform);

            programmerSound.setVolume(1);

            GCHandle soundHandle = GCHandle.Alloc(emittedSound, GCHandleType.Pinned);
            programmerSound.setUserData(GCHandle.ToIntPtr(soundHandle));

            programmerSound.setCallback(AudioEventCallback);
            programmerSound.start();
            programmerSound.release();
        }

In Update() I’m trying to use @lock, Marshal.Copy and unlock methods trying to copy paste the buffer. I can listen my microphone, but every second there is a microsecond that nothing is heard and the sound is cut off.

FMODUnity.RuntimeManager.CoreSystem.getRecordPosition(captureDeviceIndex, out uint recordPosition);

            recSound.@lock(0, recordPosition, out IntPtr ptr1, out IntPtr ptr2, out uint len1, out uint len2);
            Marshal.Copy(ptr1, buffer, 0, (int)len1);
            recSound.unlock(ptr1, ptr2, len1, len2);

            emittedSound.@lock(0, recSoundLength, out IntPtr ptr3, out IntPtr ptr4, out uint len3, out uint len4);
            Marshal.Copy(buffer, 0, ptr3, (int)len3);
            recSound.unlock(ptr3, ptr4, len3, len4);

What should I do or change? Honestly I’m lost using the API and I don’t understand why the sound is cut every second.

Thank you very much!

Postdata: I’m taking this path for two reasons:

  1. If you use the microphone, I don’t want you listen yourself.
  2. My idea is use the buffer and send it to the other players.