# \[c#\] best way to pass data to dsp.setParameterData?

**URL:** <https://qa.fmod.com/t/c-best-way-to-pass-data-to-dsp-setparameterdata/14917>\
**Category:** FMOD Engine\
**Created:** [August 5, 2019, 6:11pm UTC](https://qa.fmod.com/t/c-best-way-to-pass-data-to-dsp-setparameterdata/14917 "2019-08-05T18:11:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanslash332](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@sanslash332](https://qa.fmod.com/u/sanslash332)\
**Post date:** [August 5, 2019, 6:11pm UTC](https://qa.fmod.com/t/c-best-way-to-pass-data-to-dsp-setparameterdata/14917/1 "2019-08-05T18:11:00Z")

</div>

Hello guys,

The question is that the title says: How use correctly the dsp.setParameterData function?

For example, what is the correct way to get the byteArray that you have to pass to the function, if your data is a DSP\_PARAMETER\_3DATTRIBUTES object?

In my project I do that with this code:

I’m using resonanse plugin, and sourceDSP is an instanse of the sourcePlugin of resonanceAudio.

```auto
DSP_PARAMETER_3DATTRIBUTES atr3d = new DSP_PARAMETER_3DATTRIBUTES();
            atr3d.absolute = new _3D_ATTRIBUTES{position= pos, velocity= vel, forward= listenerForward, up=listenerUp};
            atr3d.relative = new _3D_ATTRIBUTES{ position = relativePos, velocity = vel, forward = listenerForward, up = listenerUp };
            errcheck(sourceDSP.setParameterFloat(2, 1.0f)); //Min distance
            errcheck(sourceDSP.setParameterFloat(3, 100.0f)); //Max distance

            byte[] dspdatabytes = new byte[Marshal.SizeOf(typeof(DSP_PARAMETER_3DATTRIBUTES))];
            GCHandle pinStructure = GCHandle.Alloc(atr3d, GCHandleType.Pinned);
            try
            {
                Marshal.Copy(pinStructure.AddrOfPinnedObject(), dspdatabytes, 0, dspdatabytes.Length);
                
                errcheck(sourceDSP.setParameterData(8,dspdatabytes));

            }
            catch (Exception e)
            {
                Console.WriteLine($"Prolemas al copiar convertir los bytes {e.Message}");
                
            }
            finally
            {
                pinStructure.Free();

            }
```

This code works, but is ugly… Exist other way (and better) to achieve this?

The documentation of setParameterData has this note:

> [@documentation](#):
>
> Certain data types are predefined by the system and can be specified via the  
> FMOD\_DSP\_PARAMETER\_DESC\_DATA,  
> see  
> FMOD\_DSP\_PARAMETER\_DATA\_TYPE

But, how you can use that class (FMOD\_DSP\_PARAMETER\_DESC\_DATA) to easy get the byteArray of the data to pass to the option?

That is!

¡thanks for your possible answers!

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [August 12, 2019, 3:44am UTC](https://qa.fmod.com/t/c-best-way-to-pass-data-to-dsp-setparameterdata/14917/2 "2019-08-12T03:44:11Z")

</div>

Unfortunately going from managed to native (C# to C++) things like this are necessary and can look a bit messy. It looks like you are doing the same sort of thing that the [FMODResonanceAudio.cs](https://github.com/resonance-audio/resonance-audio-fmod-sdk/blob/master/UnityIntegration/Assets/ResonanceAudio/Scripts/FmodResonanceAudio.cs) does, although they do an extra struct to pointer step.

The `FMOD_DSP_PARAMETER_DATA_TYPE` can be used as the index in `setParameterData` if it is for a built in type, rather than having to get the actual index of it.

Eg.

```auto
sourceDSP.setParameterData(FMOD_DSP_PARAMETER_DATA_TYPE_3DATTRIBUTES, dspdatabytes);

```

---

<div class="post-metadata">

**Author:** ![sanslash332](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@sanslash332](https://qa.fmod.com/u/sanslash332)\
**Post date:** [August 12, 2019, 3:50pm UTC](https://qa.fmod.com/t/c-best-way-to-pass-data-to-dsp-setparameterdata/14917/3 "2019-08-12T15:50:11Z")

</div>

Thanks for the answer! Is a bit more clear now!

So, for future versions of the wrapper, could be a good idea add a small function that turns defined built-in datatypes in to byteArrays something like  
fmod.utils.marshallDspData(any\_object\_of\_dsp\_data\_type) or something isimilar 🙂

But thanks! Probably this is the better way 🙂  
Thanks.
