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

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.

            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);
                Marshal.Copy(pinStructure.AddrOfPinnedObject(), dspdatabytes, 0, dspdatabytes.Length);

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


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

The documentation of setParameterData has this note:

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!

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 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.


sourceDSP.setParameterData(FMOD_DSP_PARAMETER_DATA_TYPE_3DATTRIBUTES, dspdatabytes);
1 Like

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 :slight_smile:

But thanks! Probably this is the better way :slight_smile: