Broken spatialization when using Resonance Audio from FMOD Low Level API

400 Views Asked by At

I am struggling to enable Resonance Audio sound spatialization when using Resonance Audio plugin for FMOD and trying to setup DSPs manually, without FMOD Studio.

My code for plugin loading and DSPs' setup:

auto system = audio->fmod->system; //instance of FMOD::System
unsigned int resHandle;
CHECK_ERR(system->loadPlugin("../lib/resonanceaudio.dll", &resHandle, 0));

//0 = Resonance Audio Listener
//1 = Resonance Audio Soundfield
//2 = Resonance Audio Source
unsigned int listenerPlugin, sourcePlugin;
system->getNestedPlugin(resHandle, 0, &listenerPlugin);
system->getNestedPlugin(resHandle, 2, &sourcePlugin);

FMOD::DSP* listenerDsp;
CHECK_ERR(system->createDSPByPlugin(listenerPlugin, &listenerDsp));
FMOD::DSP* sourceDsp;
CHECK_ERR(system->createDSPByPlugin(sourcePlugin, &sourceDsp));

//This a channel group routed from the Master group
//I want to spatialize all sounds which are played in this group
FMOD::ChannelGroup *worldGroup = nullptr;
system->createChannelGroup("World", &worldGroup);
FMOD::ChannelGroup *masterGroup = nullptr;
system->getMasterChannelGroup(&masterGroup);
masterGroup->addGroup(worldGroup);

//Adding Resonance Audio dsps to the group
worldGroup->addDsp(0, sourceDsp);
worldGroup->addDsp(1, listenerDsp);

//Setting listener's position at (0, 0, 0)
system->set3DListenerAttributes(0, FMOD_VECTOR{0, 0, 0}, 0, FMOD_VECTOR{0, 0, 1}, FMOD_VECTOR{0, 1, 0});

<loading sound> 

FMOD::Channel* channel = nullptr;
CHECK_ERR(system->playSound(sound, worldGroup, true, &channel));
channel->setMode(FMOD_3D);
channel->set3DAttributes(FMOD_VECTOR{4, 0, 3}, nullptr);
channel->setPaused(false);

<somewhere in update loop>
   system->update();

But after all of this I dont hear any audio at all.

I assume the mistake is on my side so I tried to repeat the same setup in FMOD Studio. As I did in code I placed Resonance Audio Source before the Resonance Audio Listener at the master track of the event and everything worked correctly (at least in FMOD Studio, didnt try it in game).

How can I fix this issue?

1

There are 1 best solutions below

5
On

From what I think you should be calling:

System::getMasterChannelGroup

To get an instance of the master channel group and then assigning the Resonance audio DSPs to the master channel group.

//This a channel group routed from the Master group
//I want to spatialize all sounds which are played in this group
FMOD::ChannelGroup *worldGroup>;
<worldGroup setup>

From this I was not entirely sure what you meant as I cannot see where you have setup the ChannelGroup routing from the master channel. If the solution I have provided is incorrect, then please provide further insight into the code I have mentioned above.