# Where can I find a DSP\_CONVOLUTION\_REVERB C#-Unity Example?

**URL:** <https://qa.fmod.com/t/where-can-i-find-a-dsp-convolution-reverb-c-unity-example/22736>\
**Category:** FMOD Engine\
**Tags:** unity\
**Created:** [March 27, 2025, 5:07am UTC](https://qa.fmod.com/t/where-can-i-find-a-dsp-convolution-reverb-c-unity-example/22736 "2025-03-27T05:07:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelmar](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@samuelmar](https://qa.fmod.com/u/samuelmar)\
**Post date:** [March 27, 2025, 5:07am UTC](https://qa.fmod.com/t/where-can-i-find-a-dsp-convolution-reverb-c-unity-example/22736/1 "2025-03-27T05:07:06Z")

</div>

Hi again,

I want to apply in Unity (on runtime) a FMOD.DSP\_CONVOLUTION\_REVERB effect to a specific track of a specific event, I’m doing the things this way.

```auto
FMODUnity.RuntimeManager.CoreSystem.createDSPByType(FMOD.DSP_TYPE.CONVOLUTIONREVERB, out reverb_FmodDSP);
reverb_FmodDSP.setParameterData((int)FMOD.DSP_CONVOLUTION_REVERB.IR, [index 0 = numchannels][index 1 + = raw 16 bit PCM data]); //I'm struggling here
reverb_FmodDSP.setParameterFloat((int)FMOD.DSP_CONVOLUTION_REVERB.WET, 0.0f);
reverb_FmodDSP.setParameterFloat((int)FMOD.DSP_CONVOLUTION_REVERB.DRY, -80.0f);
reverb_FmodDSP.setActive(true);
myEventInstance.getChannelGroup(out FMOD.ChannelGroup channelGroup_Master);
channelGroup_Master.getGroup(0, out FMOD.ChannelGroup channelGroup_Track);
channelGroup_Track.addDSP(_trackIndex, reverb_FmodDSP);

```

My idea is implement a wav file from an Asset or an Event direcly from FMOD Studio file,I looked on internet for an idea but I didn’t find it.

Of course, I have read the documentation [https://www.fmod.com/docs/2.00/api/core-api-common-dsp-effects.html#fmod\_dsp\_convolution\_reverb](https://www.fmod.com/docs/2.00/api/core-api-common-dsp-effects.html#fmod_dsp_convolution_reverb) but is not too clear for me, sorry.

Thanks in advance FMOD team!

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [March 28, 2025, 2:57am UTC](https://qa.fmod.com/t/where-can-i-find-a-dsp-convolution-reverb-c-unity-example/22736/2 "2025-03-28T02:57:39Z")

</div>

Hi,

I made a function that will read a `.wav` file from disk and convert it into FMOD friendly IR data:

> **Conversion Function**
>
> ```c
> public static bool ConvertWavToIR(string wavFilePath, out byte[] wavData)
> {
> wavData = null;
> 
> if (!File.Exists(wavFilePath))
> {
> Debug.LogError($"Error: Unable to open WAV file: {wavFilePath}");
> return false;
> }
> 
> try
> {
> using (FileStream fileStream = new FileStream(wavFilePath, FileMode.Open, FileAccess.Read))
> using (BinaryReader reader = new BinaryReader(fileStream))
> {
> byte[] chunkID = reader.ReadBytes(4);
> uint chunkSize = reader.ReadUInt32();
> byte[] format = reader.ReadBytes(4);
> byte[] subchunk1ID = reader.ReadBytes(4);
> uint subchunk1Size = reader.ReadUInt32();
> ushort audioFormat = reader.ReadUInt16();
> ushort numChannels = reader.ReadUInt16();
> uint sampleRate = reader.ReadUInt32();
> uint byteRate = reader.ReadUInt32();
> ushort blockAlign = reader.ReadUInt16();
> ushort bitsPerSample = reader.ReadUInt16();
> byte[] subchunk2ID = reader.ReadBytes(4);
> uint subchunk2Size = reader.ReadUInt32();
> 
> if (System.Text.Encoding.ASCII.GetString(chunkID) != "RIFF" ||
> System.Text.Encoding.ASCII.GetString(format) != "WAVE")
> {
> Debug.LogError("Error: Invalid WAV file format.");
> return false;
> }
> 
> if (audioFormat != 1 || bitsPerSample != 16)
> {
> Debug.LogError("Error: Only PCM 16-bit WAV files are supported.");
> return false;
> }
> 
> wavData = new byte[subchunk2Size + 4];
> 
> wavData[0] = (byte)(numChannels & 0xFF);
> wavData[1] = (byte)((numChannels >> 8) & 0xFF);
> wavData[2] = 0;
> wavData[3] = 0;
> 
> reader.Read(wavData, 4, (int)subchunk2Size);
> }
> 
> Debug.Log("WAV file successfully converted to IR data.");
> return true;
> }
> catch (Exception ex)
> {
> Debug.LogError($"Error: {ex.Message}");
> return false;
> }
> }
> 
> ```

I am retrieving the IR data and then passing it to my DSP through the `setParameterData` function:

```auto
if (ConvertWavToIR("ExampleFile.wav", out byte[] data))
{
    Debug.Log("Converted data"};
}
FMOD.RESULT result = reverb_FmodDSP.setParameterData((int)FMOD.DSP_CONVOLUTION_REVERB.IR, data);
if (result != FMOD.OK)
{
    Debug.Log($"Failed to set IR data with result {result}");
}

```

Please let me know if you have any issues!

---

<div class="post-metadata">

**Author:** ![samuelmar](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@samuelmar](https://qa.fmod.com/u/samuelmar)\
**Post date:** [March 31, 2025, 8:52pm UTC](https://qa.fmod.com/t/where-can-i-find-a-dsp-convolution-reverb-c-unity-example/22736/3 "2025-03-31T20:52:26Z")

</div>

Thank you very much for the example, I’m implementing and testing it right now.

Regards!
