使用FMOD低级API的Resonance Audio时空间化不足

时间:2018-06-08 08:47:52

标签: audio-player fmod resonance-audio

在为FMOD使用Resonance Audio插件并尝试手动设置DSP而没有FMOD Studio时,我正在努力启用Resonance Audio声音空间化。

我的插件加载和DSP设置代码:

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();

但毕竟我听不到任何音频。

我认为错误就在我这边,所以我试着在FMOD Studio中重复相同的设置。正如我在代码中所做的那样,我在事件主轨道上的Resonance Audio Listener之前放置了Resonance Audio Source,一切正常(至少在FMOD Studio中,没有在游戏中尝试过)。

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

我认为你应该致电:

System::getMasterChannelGroup

获取master channel group的实例,然后将Resonance音频DSP分配给主通道组。

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

由此我不完全确定你的意思,因为我无法看到你从主通道设置ChannelGroup路由的位置。如果我提供的解决方案不正确,那么请进一步了解我上面提到的代码。