as requested. im skipping the usual FMOD setup code as that works fine without the resonance plugin code.
FMOD_RESULT res = m_fmod_system->loadPlugin("libresonanceaudio.so",&m_resonanceHandle, 0);
ERRCHECK(res);
res = m_fmod_system->createDSPByPlugin(m_resonanceHandle, &m_resonanceDSP);
ERRCHECK(res);
int count;
res = m_fmod_system->getNumNestedPlugins(m_resonanceHandle, &count);
ERRCHECK(res);
unsigned int m_pluginHandles[3];
for(int i = 0; i < count; ++i)
{
res = m_fmod_system->getNestedPlugin(m_resonanceHandle, i, &m_pluginHandles[i]);
ERRCHECK(res);
that gets us the handles of all the nested plugins. we figure out which handle is which by doing
res = m_fmod_system->getPluginInfo(m_pluginHandles[i], &ptype, name, namelen, &ver);
ERRCHECK(res);
and string comparing against the names of the plugins, which are.
Resonance Audio Listener
Resonance Audio Source
Resonance Audio Soundfield
we then attach the Resonance Audio Listener DSP to the channel group we want to use for spatial audio. group here is the spatial channel group.
FMOD_RESULT res = group->addDSP(0, m_resAudioListenerDSP);
ERRCHECK( res );
res = m_resAudioListenerDSP->setActive(true);
ERRCHECK( res );
I also set the main plugin active here, because its not clear if the nested Resonance Audio Listener is the same as the main plugin.
res = m_resonanceDSP->setActive(true);
ERRCHECK( res );
in an attempt to give the plugin some data that would be immediately noticable ive set the room values to
m_room.dimensions[0] = 100.0f;
m_room.dimensions[1] = 100.0f;
m_room.dimensions[3] = 100.0f;
m_room.material_names[0] = vraudio::MaterialName::kMetal;
m_room.material_names[1] = vraudio::MaterialName::kMetal;
m_room.material_names[2] = vraudio::MaterialName::kMetal;
m_room.material_names[3] = vraudio::MaterialName::kMetal;
m_room.material_names[4] = vraudio::MaterialName::kMetal;
m_room.material_names[5] = vraudio::MaterialName::kMetal;
m_room.reverb_brightness = 1.5f;
m_room.reverb_time = 1.5f;
m_room.reverb_gain = 1.5f;
FMOD_RESULT res = m_resonanceDSP->setParameterData(1, &m_room, sizeof(vraudio::RoomProperties));
ERRCHECK( res );
when playing an audio source that we want to play via the spatial channel group. calling playSound then attaching the Resonance Audio Source plugin DSP to the channel associated to the sound.
FMOD_RESULT res = m_fmod_system->playSound(sound, channelGroup, false,&channel);
ERRCHECK(res);
FMOD_RESULT res = m_fmod_system->createDSPByPlugin(m_resAudioSourceHandle, &audioclip.m_resonanceAudioSourceDSP);
ERRCHECK(res);
int numDsps = 0;
res = channel->getNumDSPs(&numDsps);
ERRCHECK(res);
res = channel->addDSP(numDsps, audioclip.m_resonanceAudioSourceDSP);
ERRCHECK(res);
res = audioclip.m_resonanceAudioSourceDSP->setActive(true);
ERRCHECK(res);
finally each frame im updating the position of the Resonance Audio Source DSP plugin using
m_attrs.absolute.forward.x = 0.0f;
m_attrs.absolute.forward.y = 0.0f;
m_attrs.absolute.forward.z = 1.0f;
m_attrs.absolute.up.x = 0.0f;
m_attrs.absolute.up.y = 1.0f;
m_attrs.absolute.up.z = 0.0f;
m_attrs.absolute.velocity.x = 0.0f;
m_attrs.absolute.velocity.y = 0.0f;
m_attrs.absolute.velocity.z = 0.0f;
m_attrs.absolute.position.x = x;
m_attrs.absolute.position.y = y;
m_attrs.absolute.position.z = z;
m_attrs.relative.forward.x = 0.0f;
m_attrs.relative.forward.y = 0.0f;
m_attrs.relative.forward.z = 1.0f;
m_attrs.relative.up.x = 0.0f;
m_attrs.relative.up.y = 1.0f;
m_attrs.relative.up.z = 0.0f;
m_attrs.relative.velocity.x = 0.0f;
m_attrs.relative.velocity.y = 0.0f;
m_attrs.relative.velocity.z = 0.0f;
m_attrs.relative.position.x = x;
m_attrs.relative.position.y = y;
m_attrs.relative.position.z = z;
// magic number 7 from querying the input param list for the Audio Source DSP
FMOD_RESULT res = audioClip.m_resonanceAudioSourceDSP->setParameterData(7, &m_attrs, sizeof(FMOD_DSP_PARAMETER_3DATTRIBUTES));
ERRCHECK(res);
we’re just giving simple values here as the sound is simply orbiting the user as an example at this point.changing these values has no effect on the output of the audio, suspect its further upstream
so, when compiling this code out, everything works as expected with bare FMOD, adding this in gives no audio output. hopefully we’re just missing a parameter set somewhere.