# Capturing Unity game’s FMOD output (5.1 / Busses)

**URL:** <https://qa.fmod.com/t/capturing-unity-game-s-fmod-output-5-1-busses/20485>\
**Category:** Unity\
**Tags:** unity\
**Created:** [July 31, 2023, 7:45am UTC](https://qa.fmod.com/t/capturing-unity-game-s-fmod-output-5-1-busses/20485 "2023-07-31T07:45:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [August 2, 2023, 5:10am UTC](https://qa.fmod.com/t/capturing-unity-game-s-fmod-output-5-1-busses/20485/2 "2023-08-02T05:10:27Z")

</div>

Hi,

FMOD has the [`FMOD_OUTPUTTYPE_WAVWRITER`](https://www.fmod.com/docs/2.02/api/core-api-system.html#fmod_outputtype_wavwriter) output mode that allows the system to write the final mixer output to a .wav file. Note that using `WAVWRITER` means that the system will solely output to file; it won’t output to a device. To accomplish this with the Unity Integration, you’ll have to modify `FMODUnity.RuntimeManager` as follows:

- Add the following as class members:

```auto
byte[] wavPath;
GCHandle wavHandle;
IntPtr wavPtr;

```

- Set the output type of the system to WAVWRITER, either from the platform-specific settings, or by modifying the `coreSystem` object on line 301:

```auto
result = coreSystem.setOutput(FMOD.OUTPUTTYPE.WAVWRITER);

```

- Replace the `studioSystem.initialize()` call on line 347 with the following:

```auto
using (FMOD.StringHelper.ThreadSafeEncoding encoder = FMOD.StringHelper.GetFreeHelper())
{
    wavPath = encoder.byteFromStringUTF8("C:\\Your\\Path\\Here\\wavFile.wav");
    wavHandle = GCHandle.Alloc(wavPath, GCHandleType.Pinned);
    wavPtr = wavHandle.AddrOfPinnedObject();
    result = studioSystem.initialize(virtualChannels, studioInitFlags, FMOD.INITFLAGS.NORMAL, wavPtr);
}

```

- Free the `GCHandle` object `wavHandle` in RuntimeManager.OnDestroy() after `ReleaseStudioSystem()` is called:

```auto
private void OnDestroy()
{
    coreSystem.setCallback(null, 0);
    ReleaseStudioSystem();

    wavHandle.Free();
    //...
}

```

You will also need to make the `static class StringHelper` in fmod.cs at line 3884 public.

However, this won’t allow you to separately capture audio for different Buses unless you do multiple recordings with the Buses muted/solo’d. To do this, you’ll need to go a little more in-depth - I would suggest modifying our [Unity DSP Capture script example](https://www.fmod.com/docs/2.02/unity/examples-dsp-capture.html) to collect the audio data, adding a wav header to the data, and writing it to a .wav file. The DSP Capture example specifically grabs the Master ChannelGroup’s output, but you can modify it to grab any Bus’ core ChannelGroup instead, which you can get with [`Studio::Bus::getChannelGroup`](https://www.fmod.com/docs/2.02/api/studio-api-bus.html#studio_bus_getchannelgroup). As for writing to a wav file with the appropriate header, [here’s a somewhat old post detailing how to record audio input and write it to a wav file](https://qa.fmod.com/t/record-and-output-to-wav-file/12151/2). The post uses in C++, and specifically pertains to writing audio input to file, but you should be able to adapt it to C# and your specific use-case.

If you have any additional questions, feel free to ask.

---

_[View the full topic](https://qa.fmod.com/t/capturing-unity-game-s-fmod-output-5-1-busses/20485)._
