To use the WAVWRITER_NRT
output type you will need to make a minor change to the RuntimeManager
initialization code to allow it to mix from update:
//Assets\Plugins\FMOD\src\RuntimeManager.cs
private FMOD.RESULT Initialize()
{
... // Line ~376
+ result = studioSystem.initialize(virtualChannels, studioInitFlags, FMOD.INITFLAGS.MIX_FROM_UPDATE, IntPtr.Zero);
if (result != FMOD.RESULT.OK && initResult == FMOD.RESULT.OK)
...
}
With that you can set you can now switch between the WAVWRITER_NRT
and other output types, depending on whether you want to export or playback your scene in Unity. Here is a basic script demonstrating how to export the audio from a Unity scene using WAVWRITER_NRT
:
Bounce.cs
using UnityEngine;
public class Bounce : MonoBehaviour
{
[SerializeField]
bool bounce = false;
[SerializeField]
int durationSeconds = 25;
void Start()
{
if (bounce)
{
FMODUnity.RuntimeManager.CoreSystem.getOutput(out FMOD.OUTPUTTYPE output);
FMODUnity.RuntimeManager.CoreSystem.getMasterChannelGroup(out FMOD.ChannelGroup cg);
cg.getDSPClock(out ulong child, out _);
FMODUnity.RuntimeManager.CoreSystem.getSoftwareFormat(out int sampleRate, out _, out _);
ulong future = child + (ulong)sampleRate * (uint)durationSeconds;
FMODUnity.RuntimeManager.CoreSystem.setOutput(FMOD.OUTPUTTYPE.WAVWRITER_NRT);
while (child < future)
{
FMODUnity.RuntimeManager.StudioSystem.update();
cg.getDSPClock(out child, out _);
}
FMODUnity.RuntimeManager.CoreSystem.setOutput(output);
}
}
}
That will then produce a file called “fmodoutput.wav”, which I believe should be the application’s persistent data path in Unity. Otherwise you could potentially override the FMOD file system with System::setFileSystem
to save it to a different location without reinitializing your system object just to change the path.