How save to wav in unity with non real time?

Hi! I try to save wav file with fmod from unity.

My code:

FMOD.Studio.EventInstance myInstance;

public void Save()
{

FMODUnity.RuntimeManager.CoreSystem.setOutput(FMOD.OUTPUTTYPE.WAVWRITER_NRT);
FMODUnity.RuntimeManager.CoreSystem.init(128, FMOD.INITFLAGS.STREAM_FROM_UPDATE, IntPtr.Zero);

myInstance = FMODUnity.RuntimeManager.CreateInstance(“event:/myevent 4”);
myInstance.start();

var state = FMOD.Studio.PLAYBACK_STATE.STARTING;

while(state != FMOD.Studio.PLAYBACK_STATE.STOPPED)
{
FMODUnity.RuntimeManager.CoreSystem.update();
myInstance.getPlaybackState(out state);
}

myInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
FMODUnity.RuntimeManager.CoreSystem.setOutput(FMOD.OUTPUTTYPE.AUTODETECT);
FMODUnity.RuntimeManager.CoreSystem.init(128, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);
}

This code get stuck in while-loop. And saves in wav many many nulls. Wav file contains only silence.

What am I doing wrong?

My code 2:

FMOD.Studio.EventInstance myInstance;

public void Save()
{

FMODUnity.RuntimeManager.CoreSystem.setOutput(FMOD.OUTPUTTYPE.WAVWRITER); // REAL TIME
FMODUnity.RuntimeManager.CoreSystem.init(128, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); // normal flag

myInstance = FMODUnity.RuntimeManager.CreateInstance(“event:/myevent 4”);
myInstance.start();

}

This code work. And saves event data to wav at real time.

But I need NRT code.

Please, help. :slight_smile:

First thing would be to check if all the FMOD functions are returning any errors, they should all return an FMOD.RESULT.

You are probably better off creating and using your own FMOD System references, the ones in the RuntimeManager are being created and initialized with all the settings from the editor.