// https://github.com/resonance-audio/resonance-audio-fmod-sdk/blob/master/UnityIntegration/Assets/ResonanceAudio/Scripts/FmodResonanceAudio.cs
FMOD::DSP* UAudioSubsystem::InitializeDsp()
{
FMOD::Studio::System* System = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
if (System == nullptr)
{
LOG(this, LogAudio, Warning, TEXT("Failed to initialize DSP"));
return nullptr;
}
int NumBanks = 0;
FMOD_RESULT Result = System->getBankCount(&NumBanks);
if (Result > FMOD_OK)
{
LOG(this, LogAudio, Warning, TEXT("Failed to initialize DSP"));
return nullptr;
}
const TSharedPtr<FMOD::Studio::Bank*> Banks(new FMOD::Studio::Bank*[NumBanks]);
Result = System->getBankList(Banks.Get(), NumBanks, &NumBanks);
if (Result > FMOD_OK)
{
LOG(this, LogAudio, Warning, TEXT("Failed to initialize DSP"));
return nullptr;
}
for (int i = 0; i < NumBanks; i++)
{
FMOD::Studio::Bank* CurrentBank = Banks.Get()[i];
int NumBuses = 0;
Result = CurrentBank->getBusCount(&NumBuses);
if (Result > FMOD_OK)
{
continue;
}
const TSharedPtr<FMOD::Studio::Bus*> Buses(new FMOD::Studio::Bus*[NumBuses]);
Result = CurrentBank->getBusList(Buses.Get(), NumBuses, &NumBuses);
if (Result > FMOD_OK)
{
continue;
}
System->flushCommands();
for (int j = 0; j < NumBuses; j++)
{
FMOD::Studio::Bus* CurrentBus = Buses.Get()[j];
const TSharedPtr<char> Path(new char[128]);
int PathLength = 0;
Result = CurrentBus->getPath(Path.Get(), 128, &PathLength);
if (Result > FMOD_OK)
{
continue;
}
System->getBus(Path.Get(), &CurrentBus);
System->flushCommands();
const TSharedPtr<FMOD::ChannelGroup*> Group(new FMOD::ChannelGroup*[1]);
Result = CurrentBus->getChannelGroup(Group.Get());
if (Result > FMOD_OK)
{
continue;
}
System->flushCommands();
if (Group.Get()[0] != nullptr)
{
FMOD::ChannelGroup* CurrentGroup = Group.Get()[0];
int NumDsp = 0;
Result = CurrentGroup->getNumDSPs(&NumDsp);
if (Result > FMOD_OK)
{
continue;
}
const TSharedPtr<FMOD::DSP*> Dsp(new FMOD::DSP*[1]);
for (int k = 0; k < NumDsp; k++)
{
Result = CurrentGroup->getDSP(k, Dsp.Get());
if (Result > FMOD_OK)
{
continue;
}
FMOD::DSP* CurrentDsp = Dsp.Get()[0];
const TSharedPtr<char> DspName(new char[128]);
int UnusedInt = 0;
unsigned UnusedUint = 0;
Result = CurrentDsp->getInfo(DspName.Get(), &UnusedUint, &UnusedInt, &UnusedInt, &UnusedInt);
if (Result > FMOD_OK)
{
continue;
}
if (strcmp(DspName.Get(), "Resonance Audio Listener") == 0)
{
LOG(this, LogAudio, Log, TEXT("Successfully initialized Resonance Audio Listener DSP"));
return CurrentDsp;
}
}
}
}
}
LOG(this, LogAudio, Warning, TEXT("Failed to initialize DSP"));
return nullptr;
}