# Resonance Audio Source doesn't work

**URL:** <https://qa.fmod.com/t/resonance-audio-source-doesnt-work/15215>\
**Category:** FMOD Engine\
**Created:** [November 14, 2019, 1:59am UTC](https://qa.fmod.com/t/resonance-audio-source-doesnt-work/15215 "2019-11-14T01:59:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lightsome](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@lightsome](https://qa.fmod.com/u/lightsome)\
**Post date:** [November 14, 2019, 1:59am UTC](https://qa.fmod.com/t/resonance-audio-source-doesnt-work/15215/1 "2019-11-14T01:59:22Z")

</div>

Dear experienced developers,

```
I've spent many months with trying Resonance Audio and it almost drove me crazy. Please help me, 

```

I need to finally solve this problem and use Resonance Audio in a school project.

# Problem description

When I try to change 3d attributes of Resonance Audio Source DSP, the sound doesn’t seem to be afected at all. It seems that just

## Used technologies

- CSharp
- Official FMOD wrapper
- FMOD version 1.10.16
- Resonance Audio plugin

# Code

using System;  
using System.Runtime.InteropServices;

using FMOD;

namespace FmodResonanceTest  
{  
internal class Program  
{  
private static FMOD.System \_fmod;  
private static Channel \_channel;  
private static DSP \_listenerDSP;  
private static uint \_listenerHandle;  
private static ChannelGroup \_masterGroup;  
private static uint \_raHandle;  
private static Sound \_sound;  
private static DSP \_soundFieldDSP;  
private static uint \_soundFieldHandle;  
private static DSP \_sourceDSP;  
private static uint \_sourceHandle;  
private static ChannelGroup \_worldGroup;

```
    private static byte[] GetBytes(IntPtr ptr, int length)
    {
        if (ptr != IntPtr.Zero)
        {
            byte[] byteArray = new byte[length];
            Marshal.Copy(ptr, byteArray, 0, length);
            return byteArray;
        }

        // Return an empty array if the pointer is null.
        return new byte[1];
    }

    private static void Check(RESULT r, string activity)
    {
        if (r != RESULT.OK)
            throw new InvalidOperationException(activity);
    }

    private static void Say(string s, bool wait = true)
    {
        Console.WriteLine(s);
        if (wait)
            Wait();
    }

    private static void Set3dParameters(DSP sourceDSP, DSP_PARAMETER_3DATTRIBUTES param3d)
    {
        int propertiesSize = Marshal.SizeOf(typeof(DSP_PARAMETER_3DATTRIBUTES));
        IntPtr propertiesPtr = Marshal.AllocHGlobal(propertiesSize);
        Marshal.StructureToPtr(param3d, propertiesPtr, false);
      Check(sourceDSP.setParameterData(8, GetBytes(propertiesPtr,
                                                                       propertiesSize)), "Sending 3d properties to source DSP");
        Marshal.FreeHGlobal(propertiesPtr);
    }

    private static void TestSet3dParameters()
    {
        _sourceDSP.setParameterFloat(0, 24f);

        DSP_PARAMETER_3DATTRIBUTES param3d = new DSP_PARAMETER_3DATTRIBUTES()
        {
            relative = new _3D_ATTRIBUTES()
            {
                position = new VECTOR()
                {
                    x = 0f,
                    y = 0f,
                    z = 0f
                },

                velocity = new VECTOR()
                {
                    x = 0f,
                    y = 0f,
                    z = 0f
                },

                forward = new VECTOR()
                {
                    x = 0f,
                    y = 0f,
                    z = 0f
                },

                up = new VECTOR()
                {
                    x = 0f,
                    y = 0f,
                    z = 0f
                }
            },

            absolute = new _3D_ATTRIBUTES()
            {
                position = new VECTOR()
                {
                    x = -5f,
                    y = -5f,
                    z = 0f
                },

                velocity = new VECTOR()
                {
                    x = 0f,
                    y = 0f,
                    z = 0f
                },

                forward = new VECTOR()
                {
                    x = 0f,
                    y = 0f,
                    z = 0f
                },

                up = new VECTOR()
                {
                    x = 0f,
                    y = 0f,
                    z = 0f
                }
            }
        };

        Set3dParameters(_sourceDSP, param3d);
    }

    private static void TestSetRoomProperties()
    {
        // set the room properties
        RoomProperties roomProperties = new RoomProperties()
        {
            // listener position
            positionX = 0f,
            positionY = 0f,
            positionZ = 0f,

            // room dimensions
            dimensionsX = 4f,
            dimensionsY = 5f,
            dimensionsZ = 4f,

            // listener orientation
            rotationX = 0f,
            rotationY = 0f,
            rotationZ = 0f,
            rotationW = 0f,

            // surface materials of all sides of the room
            materialLeft = SurfaceMaterial.ConcreteBlockPainted,
            materialRight = SurfaceMaterial.ConcreteBlockPainted,
            materialBottom = SurfaceMaterial.LinoleumOnConcrete,
            materialTop = SurfaceMaterial.ConcreteBlockPainted,
            materialFront = SurfaceMaterial.WoodPanel,
            materialBack = SurfaceMaterial.GlassThin,

            // reverb parameters
            reflectivity = 0f,
            reverbGainDb = 1f,
            
            
            reverbBrightness = -1f,
            reverbTime = .1f
        };

        UpdateAudioRoom(_listenerDSP, roomProperties);
    }

    private static void UpdateAudioRoom(FMOD.DSP listenerPlugin, RoomProperties roomProperties)
    {
        int roomPropertiesSize = Marshal.SizeOf(typeof(RoomProperties));
        IntPtr roomPropertiesPtr = Marshal.AllocHGlobal(roomPropertiesSize);
        Marshal.StructureToPtr(roomProperties, roomPropertiesPtr, false);
        listenerPlugin.setParameterData(1, GetBytes(roomPropertiesPtr,
                                                                       roomPropertiesSize));
        Marshal.FreeHGlobal(roomPropertiesPtr);
    }

    private static void Wait()
    {
        Console.WriteLine("Press a key");
        Console.ReadLine();
    }

    [STAThread]
    private static void Main(string[] args)
    {
        // initialization
        Factory.System_Create(out _fmod);
        Check(_fmod.init(32, INITFLAGS.NORMAL, IntPtr.Zero), "FMOD initialization");

        Check(_fmod.loadPlugin("resonanceaudio.dll", out _raHandle), "Loading Resonance Audio plugin");
        Check(_fmod.getNestedPlugin(_raHandle, 0, out _listenerHandle), "Getting handle of Listener nested plugin");
        Check(_fmod.getNestedPlugin(_raHandle, 1, out _soundFieldHandle), "Getting handle of Near Field nested plugin");
        Check(_fmod.getNestedPlugin(_raHandle, 2, out _sourceHandle), "Getting handle of Source nested plugin");

        Check(_fmod.createDSPByPlugin(_listenerHandle, out _listenerDSP), "Listener DSP creation");
        Check(_fmod.createDSPByPlugin(_soundFieldHandle, out _soundFieldDSP), "Near Field DSP creation");
        Check(_fmod.createDSPByPlugin(_sourceHandle, out _sourceDSP), "Source DSP creation");

       Check(_fmod.createChannelGroup("world", out _worldGroup), "Creating channel group");
        _fmod.getMasterChannelGroup(out _masterGroup);
      Check(_masterGroup.addGroup(_worldGroup, true, out DSPConnection dc), "Adding new channel group to master group");

        Check(_worldGroup.addDSP(CHANNELCONTROL_DSP_INDEX.TAIL, _listenerDSP), "Applying Listener DSP on channel group");

        Check(_fmod.createSound("sound.wav", MODE.DEFAULT, out _sound), "Loading sound");
        Check(_fmod.playSound(_sound, _worldGroup, true, out _channel), "Sound playback");

        Check(_channel.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.TAIL, _soundFieldDSP), "Applying Near Field DSP on channel");
        Check(_channel.addDSP(FMOD.CHANNELCONTROL_DSP_INDEX.TAIL, _sourceDSP), "Applying Source DSP on channel");

        TestSetRoomProperties();
        TestSet3dParameters();

        // start playback
        _channel.setPaused(false);

        Wait();
        _fmod.release();
    }

}

```

}

---

<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:** [November 20, 2019, 9:30pm UTC](https://qa.fmod.com/t/resonance-audio-source-doesnt-work/15215/2 "2019-11-20T21:30:35Z")

</div>

Nothing stands out in the code provided. Are you using the fmod logging libs? They can provide more logging information for debugging.

Can you confirm that `propertiesPtr` is valid and that `GetBytes` is returning a valid byte array?
