Checked Studio::EventInstance::isValid and when it is True,
ChannelGroup From EventInstance result is FMOD_OK.
and getDSP from ChannelGroup result is FMOD_OK.
But DSP::setMeteringEnabled(true, true) → FMOD_ERR_INVALID_HANDLE
Can’t get info from getMeteringInfo.
How can I get getMeteringInfo from DSP…?
Thanks for your feedback.
Here is source I’m doing…
#include "SoundManager.h"
ASoundManager* g_pSoundManager = nullptr;
// Sets default values
ASoundManager::ASoundManager()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
WindowSize = 512;
pDSP = nullptr;
pChannelGroup = nullptr;
g_pSoundManager = this;
bCreateInstance = false;
bCallTimeLineBeat = false;
bCallTimeLineMarker = false;
}
ASoundManager::~ASoundManager()
{
/*if (_sound)
{
pChannel->removeDSP(pDSP);
}*/
if (pDSP)
{
if (pChannelGroup)
pChannelGroup->removeDSP(pDSP);
pDSP->release();
}
if (pSystem)
{
pSystem->close();
pSystem->release();
}
}
// Called when the game starts or when spawned
void ASoundManager::BeginPlay()
{
Super::BeginPlay();
InitFMOD();
}
void ASoundManager::InitFMOD()
{
//FMOD_RESULT result;
//result = FMOD::System_Create(&pSystem);
////FMOD::Studio::System* pSystem1 = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
//if (result == FMOD_OK)
//{
// result = pSystem->init(FMOD_MAX_CHANNEL_WIDTH, FMOD_INIT_NORMAL, NULL);
// GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("init : %d"), result));
// pSystem->getMasterChannelGroup(&pChannelGroup);
// result = pChannelGroup->getDSP(0, &pDSP);
// GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("getDSP : %d"), result));
// result = pDSP->setActive(true);
// GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("setActive : %d"), result));
// result = pDSP->setMeteringEnabled(true, true);
// GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("setMeteringEnabled : %d"), result));
//}
PlayEvent(EventNameArray[0]);
/*pSystem->createDSPByType(FMOD_DSP_TYPE_FFT, &pDSP);
pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWTYPE, FMOD_DSP_FFT_WINDOW_HANNING);
pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWSIZE, WindowSize);
pSystem->getMasterChannelGroup(&pChannelGroup);
pChannelGroup->addDSP(0, pDSP);*/
}
// Called every frame
void ASoundManager::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FMOD_RESULT result;
//FMOD_RESULT result = pSystem->update();
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("FMOD update : %d"), result));
if (bCreateInstance)
{
if (pInstance->isValid())
{
result = pInstance->getChannelGroup(&pChannelGroup);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getChannelGroup : %d"), result));
result = pChannelGroup->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &pDSP);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getDSP : %d"), result));
if (pChannelGroup)
bCreateInstance = false;
}
//bCreateInstance = false;
/*result = pInstance->getChannelGroup(&pChannelGroup);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getChannelGroup : %d"), result));
result = pChannelGroup->getDSP(0, &pDSP);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getDSP : %d"), result));
result = pDSP->setMeteringEnabled(true, true);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("setMeteringEnabled : %d"), result));*/
//float fValue = 0.f, fFinalValue = 0.f;
////EventWrapper.Instance->getParameterByName("Timeline", &fValue, &fFinalValue);
//FMOD::Studio::System* StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
//StudioSystem->getParameterByName("Timeline", &fValue, &fFinalValue);
//GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red,
// FString::Printf(TEXT("fValue : %.3f fFinalValue : %.3f"), fValue, fFinalValue));
//int iPosition = 0;
//EventWrapper.Instance->getTimelinePosition(&iPosition);
//GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red,
// FString::Printf(TEXT("TimelIne Position : %d"), iPosition));
//result = EventWrapper.Instance->getChannelGroup(&pChannelGroup);
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("getChannelGroup : %d"), result));
//result = pChannelGroup->getDSP(0, &pDSP);
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("getDSP : %d"), result));
//result = pDSP->setMeteringEnabled(true, false);
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("setMeteringEnabled : %d"), result));
/*result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWTYPE, FMOD_DSP_FFT_WINDOW_HANNING);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("FMOD_DSP_FFT_WINDOWTYPE : %d"), result));
result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWSIZE, WindowSize);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("FMOD_DSP_FFT_WINDOWSIZE : %d"), result));*/
//FMOD_RESULT result;
/*result = FMOD::System_Create(&pSystem);
if (result == FMOD_OK)
{
result = pSystem->init(FMOD_MAX_CHANNEL_WIDTH, FMOD_INIT_NORMAL, NULL);
}
result = pSystem->createDSPByType(FMOD_DSP_TYPE_FFT, &pDSP);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("CreateDSP : %d"), result));
result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWTYPE, FMOD_DSP_FFT_WINDOW_RECT);
result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWSIZE, 512);
result = pDSP->setMeteringEnabled(true, false);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("setMeteringEnabled : %d"), result));
result = EventWrapper.Instance->getChannelGroup(&pChannelGroup);
result = pChannelGroup->addDSP(0, pDSP);*/
//result = pChannelGroup->getDSP(0, &pDSP);
//result = pChannelGroup->setDSPIndex(pDSP, 0);
//result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWTYPE, FMOD_DSP_FFT_WINDOW_RECT);
//result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWSIZE, 512);
/*GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("addDSP : %d"), result));*/
/*result = pSystem->createDSPByType(FMOD_DSP_TYPE_FFT, &pDSP);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("CreateDSP : %d"), result));
result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWTYPE, FMOD_DSP_FFT_WINDOW_RECT);
result = pDSP->setParameterInt(FMOD_DSP_FFT_WINDOWSIZE, 512);
result = EventWrapper.Instance->getChannelGroup(&pChannelGroup);
result = pChannelGroup->addDSP(0, pDSP);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("addDSP : %d"), result));*/
//result = pSystem->getMasterChannelGroup(&pChannelGroup);
//if (result != FMOD_RESULT::FMOD_OK)
/*GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getMasterChannelGroup : %d"), result));*/
//result = pChannelGroup->getDSP(0, &pDSP);
/*result = pChannelGroup->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &pDSP);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getDSP : %d"), result));*/
//result = pChannelGroup->addDSP(0, pDSP);
/*if (result != FMOD_RESULT::FMOD_OK)
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("addDSP Failed"));*/
/*result = pDSP->setMeteringEnabled(false, true);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("setMeteringEnabled : %d"), result));*/
//pInstance->getChannelGroup(&pChannelGroup);
//FMOD_RESULT result = pChannelGroup->getDSP(0, &pDSP);
//pDSP->setMeteringEnabled(false, true);
}
//pInstance->getChannelGroup(&pChannelGroup);
//pSystem->getMasterChannelGroup(&pChannelGroup);
if (pChannelGroup)
{
result = pDSP->setMeteringEnabled(true, true);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("setMeteringEnabled : %d"), result));
//FMOD_DSP_PARAMETER_FFT fft;
/*int NumParams = 0;
FMOD_DSP_METERING_INFO inputInfo, outputInfo;
result = pDSP->getMeteringInfo(&inputInfo, &outputInfo);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getMeteringInfo : %d"), result));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("numchannels : %d"), inputInfo.numchannels));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("numsamples : %d"), inputInfo.numsamples));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("rmslevel[0] : %d"), inputInfo.rmslevel[0]));*/
/*float fValue = 0.f, fFinalValue = 0.f;
FMOD::Studio::System* StudioSystem = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Runtime);
result = StudioSystem->getParameterByName("Timeline", &fValue, &fFinalValue);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getParameterByName : %d"), result));
GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red,
FString::Printf(TEXT("fValue : %.3f fFinalValue : %.3f"), fValue, fFinalValue));*/
/*result = pDSP->getNumParameters(&NumParams);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getNumParameters : %d"), result));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("Parameter Count : %d"), NumParams));*/
//pDSP->getParameterData(2, )
//FMOD_DSP_METERING_INFO InputInfo, OutputInfo;
//result = pDSP->getMeteringInfo(&InputInfo, &OutputInfo);
/*GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("getMeteringInfo : %d"), result));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("Input numsamples : %d"), InputInfo.numsamples));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("Input numchannels : %d"), InputInfo.numchannels));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("Output numsamples : %d"), OutputInfo.numsamples));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
*FString::Printf(TEXT("Output numchannels : %d"), OutputInfo.numchannels));*/
/*FMOD_DSP_PARAMETER_FFT* pFFT = new FMOD_DSP_PARAMETER_FFT;
char Test[40] = {};
result = pDSP->getParameterData(FMOD_DSP_FFT_SPECTRUMDATA, (void**)&pFFT, 0, 0, 0);
delete pFFT;*/
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red,
// *FString::Printf(TEXT("getParameterData : %d"), result));
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("Update Begin"));
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("ChannelCount : %d"), (int32)pFFT->numchannels));
/*for (int32 i = 0; i < pFFT->numchannels; ++i)
{
}*/
//pChannelGroup->getDSP(FMOD_CHANNELCONTROL_DSP_HEAD, &pDSP);
//if (pDSP)
//{
// //pDSP->setActive(true);
// //pDSP->setMeteringEnabled(false, true);
// float fVolume = 0.f;
// pChannelGroup->getVolume(&fVolume);
// int iDSP = 0;
// pChannelGroup->getNumDSPs(&iDSP);
// //GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Volume : %.3f"), fVolume));
// //GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("DSP : %d"), iDSP));
// FMOD_DSP_METERING_INFO Info = {};
// pDSP->getMeteringInfo(nullptr, &Info);
// //FMOD_DSP_PARAMETER_DESC* pDesc = {};
// //pDSP->getParameterInfo()
// //for (int32 i = 0; i < Info.numchannels; ++i)
// {
// GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Red, FString::Printf(TEXT("ChannelCount : %d Sample : %d rms : %.3f"), Info.numchannels, Info.numsamples, Info.rmslevel[0]));
// }
//}
}
}
void ASoundManager::PlayEvent(const FString& Name)
{
int32 iIndex = -1;
for (auto& ArrayValue : EventNameArray)
{
++iIndex;
if (ArrayValue == Name)
{
break;
}
}
if (iIndex == -1)
return;
if (pDSP)
{
/*pDSP->setActive(false);
if (pChannelGroup)
pChannelGroup->removeDSP(pDSP);*/
}
bCreateInstance = false;
EventWrapper = UFMODBlueprintStatics::PlayEvent2D(GetWorld(), EventArray[iIndex], true);
pInstance = EventWrapper.Instance;
pInstance->setUserData(this);
pInstance->setCallback(ASoundManager::OnCallback, FMOD_STUDIO_EVENT_CALLBACK_ALL);
//UFMODAudioComponent* AudioComponent;
//AudioComponent->GetParameter(TEXT("Timeline"));
//pInstance->setCallback(ASoundManager::OnCallback, FMOD_STUDIO_EVENT_CALLBACK_CREATED);
}
void ASoundManager::CallTimeLineBeat(const FTimelineBeatProperties& prop)
{
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Blue, TEXT("TimeLine Beat"));
}
void ASoundManager::CallTimeLineMarker(const FTimelineMarkerProperties& prop)
{
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("TimeLine Marker"));
}
FMOD_RESULT ASoundManager::OnCallback(FMOD_STUDIO_EVENT_CALLBACK_TYPE type,
FMOD_STUDIO_EVENTINSTANCE* event, void* parameters)
{
ASoundManager* pMgr = nullptr;
FMOD::Studio::EventInstance* Instance = (FMOD::Studio::EventInstance*)event;
Instance->getUserData((void**)&pMgr);
switch (type)
{
case FMOD_STUDIO_EVENT_CALLBACK_CREATED:
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("Instance Create Complete"));
g_pSoundManager->bCreateInstance = true;
g_pSoundManager->InitDSP();
break;
case FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_MARKER:
pMgr->CallTimeLineMarker(*((FTimelineMarkerProperties*)parameters));
break;
case FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_BEAT:
pMgr->CallTimeLineBeat(*((FTimelineBeatProperties*)parameters));
break;
default:
break;
}
return FMOD_OK;
}
FMOD_RESULT ASoundManager::CreateInstanceComplete(FMOD_STUDIO_EVENT_CALLBACK_TYPE type,
FMOD_STUDIO_EVENTINSTANCE* event, void* parameters)
{
FMOD::Studio::EventInstance* Instance = (FMOD::Studio::EventInstance*)event;
switch (type)
{
case FMOD_STUDIO_EVENT_CALLBACK_CREATED:
/*FMOD_RESULT result = Instance->getChannelGroup(&g_pSoundManager->pChannelGroup);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("getChannelGroup : %d"), result));
result = g_pSoundManager->pChannelGroup->addDSP(0, g_pSoundManager->pDSP);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("addDSP : %d"), result));
result = g_pSoundManager->pDSP->setActive(true);
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("setActive : %d"), result));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Intance : %d"), g_pSoundManager->pInstance));
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("DSP : %d"), g_pSoundManager->pDSP));*/
break;
}
return FMOD_OK;
}
FMOD_RESULT ASoundManager::OnTimeLineBeat(FMOD_STUDIO_EVENT_CALLBACK_TYPE type,
FMOD_STUDIO_EVENTINSTANCE* event, void* parameters)
{
FMOD::Studio::EventInstance* Instance = (FMOD::Studio::EventInstance*)event;
FMOD_STUDIO_TIMELINE_BEAT_PROPERTIES* pProp = (FMOD_STUDIO_TIMELINE_BEAT_PROPERTIES*)parameters;
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Blue, TEXT("TimeLine Beat"));
return FMOD_OK;
}
FMOD_RESULT ASoundManager::OnTimeLineMarker(FMOD_STUDIO_EVENT_CALLBACK_TYPE type,
FMOD_STUDIO_EVENTINSTANCE* event, void* parameters)
{
FMOD::Studio::EventInstance* Instance = (FMOD::Studio::EventInstance*)event;
FMOD_STUDIO_TIMELINE_MARKER_PROPERTIES* pProp = (FMOD_STUDIO_TIMELINE_MARKER_PROPERTIES*)parameters;
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, TEXT("TimeLine Marker"));
return FMOD_OK;
}
void ASoundManager::InitDSP()
{
}