Unable to setup Resonance Audio from Low Level API


(Daniil) #1

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(FMOD_CHANNELCONTROL_DSP_TAIL, sourceDsp);
worldGroup->addDsp(FMOD_CHANNELCONTROL_DSP_TAIL, 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 cant hear anything, audio just isnt playing. I also noticed that if I setup reverb sends for channel I will be able to hear the reverb, but not the audio itself.

What I am doing incorrectly and how can I fix this issue?


(Cameron Baron) #2

The Source DSP should be added to the individual Channels that are used to play the Sounds. The Source DSP is basically a combination of a spatializer and a send (to the listener DSP).


(Daniil) #3

I tried to add Source DSP to the channel instead of the group and now I can actually hear the audio. But now the spatialization doesnt happen at all (I cant hear audio panning). My code:

FMOD::DSP* sourceDsp;
CHECK_ERR(system->createDSPByPlugin(sourcePlugin, &sourceDsp));
CHECK_ERR(sourceDsp->setParameterFloat(3, 16))); //updating max distance

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->addDsp(FMOD_CHANNELCONTROL_DSP_TAIL, sourceDsp);
channel->setPaused(false);

Do I need to configure something else?


(Cameron Baron) #4

At the moment set3DAttributes does not effect the Source DSP at all. To set the positioning you need to pass the information to the DSP using setParameterData.

You can see a C# example of this in the Resonance Audio-FMOD-Unity plugin:

There are plans to change this, but there isn’t any set date for that just yet.