Hi,
I put my codes below, it is similar to your simple codes(FMOD Studio API Xbox One\api\studio\examples\simple_event.cpp). But I didn’t call playSound to play sound, I use the EventInstance::start to play, is it possible to automatically mute game music when we use EventInstance::start interface to play sound?
If an event in a bus, how to play it to the music port? Could you send me a demo?
This is my codes, could you help me to check if there are some issues in it ?
int FMOD_Main()
{
void *extraDriverData = NULL;
Common_Init(&extraDriverData);
FMOD::Studio::System* system = NULL;
ERRCHECK( FMOD::Studio::System::create(&system) );
// The example Studio project is authored for 5.1 sound, so set up the system output mode to match
FMOD::System* lowLevelSystem = NULL;
ERRCHECK( system->getLowLevelSystem(&lowLevelSystem) );
FMOD_SPEAKERMODE speakermode;
FMOD_RESULT result = lowLevelSystem->getSoftwareFormat(0, &speakermode, 0);
ERRCHECK( lowLevelSystem->setSoftwareFormat(0, FMOD_SPEAKERMODE_5POINT1, 0) );
ERRCHECK( system->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, extraDriverData) );
FMOD::Studio::Bank* masterBank = NULL;
ERRCHECK( system->loadBankFile(Common_MediaPath("Master Bank.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank) );
FMOD::Studio::Bank* stringsBank = NULL;
ERRCHECK( system->loadBankFile(Common_MediaPath("Master Bank.strings.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank) );
FMOD::Studio::Bank* ambienceBank = NULL;
ERRCHECK( system->loadBankFile(Common_MediaPath("Surround_Ambience.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &ambienceBank) );
FMOD::Studio::Bank* menuBank = NULL;
ERRCHECK( system->loadBankFile(Common_MediaPath("UI_Menu.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &menuBank) );
FMOD::Studio::Bank* weaponsBank = NULL;
ERRCHECK( system->loadBankFile(Common_MediaPath("Weapons.bank"), FMOD_STUDIO_LOAD_BANK_NORMAL, &weaponsBank) );
// Get the Looping Ambience event
FMOD::Studio::EventDescription* loopingAmbienceDescription = NULL;
ERRCHECK( system->getEvent("event:/Ambience/Country", &loopingAmbienceDescription) );
FMOD::Studio::EventInstance* loopingAmbienceInstance = NULL;
ERRCHECK( loopingAmbienceDescription->createInstance(&loopingAmbienceInstance) );
// Get the 4 Second Surge event
FMOD::Studio::EventDescription* cancelDescription = NULL;
ERRCHECK( system->getEvent("event:/UI/Cancel", &cancelDescription) );
FMOD::Studio::EventInstance* cancelInstance = NULL;
ERRCHECK( cancelDescription->createInstance(&cancelInstance) );
// Get the Single Explosion event
FMOD::Studio::EventDescription* explosionDescription = NULL;
ERRCHECK( system->getEvent("event:/Explosions/Single Explosion", &explosionDescription) );
// Start loading explosion sample data and keep it in memory
ERRCHECK( explosionDescription->loadSampleData() );
////////// Begin mod
ERRCHECK(system->flushCommands());
FMOD::ChannelGroup * loopingAmbience;
result = loopingAmbienceInstance->getChannelGroup(&loopingAmbience);
ERRCHECK(result);
char name[256];
loopingAmbience->getName(name, 256);
result = lowLevelSystem->attachChannelGroupToPort(FMOD_DURANGO_PORT_TYPE_MUSIC, FMOD_PORT_INDEX_NONE, loopingAmbience);
ERRCHECK(result);
ERRCHECK(system->flushCommands());
/////////End mod
do
{
Common_Update();
if (Common_BtnPress(BTN_ACTION1))
{
// One-shot event
FMOD::Studio::EventInstance* eventInstance = NULL;
ERRCHECK( explosionDescription->createInstance(&eventInstance) );
ERRCHECK( eventInstance->start() );
// Release will clean up the instance when it completes
ERRCHECK( eventInstance->release() );
}
if (Common_BtnPress(BTN_ACTION2))
{
ERRCHECK( loopingAmbienceInstance->start() );
}
if (Common_BtnPress(BTN_ACTION3))
{
ERRCHECK( loopingAmbienceInstance->stop(FMOD_STUDIO_STOP_IMMEDIATE) );
}
if (Common_BtnPress(BTN_ACTION4))
{
// Calling start on an instance will cause it to restart if it's already playing
ERRCHECK( cancelInstance->start() );
}
ERRCHECK( system->update() );
Common_Draw("==================================================");
Common_Draw("Simple Event Example.");
Common_Draw("Copyright (c) Firelight Technologies 2012-2017.");
Common_Draw("==================================================");
Common_Draw("");
Common_Draw("Press %s to fire and forget the explosion", Common_BtnStr(BTN_ACTION1));
Common_Draw("Press %s to start the looping ambience", Common_BtnStr(BTN_ACTION2));
Common_Draw("Press %s to stop the looping ambience", Common_BtnStr(BTN_ACTION3));
Common_Draw("Press %s to start/restart the cancel sound", Common_BtnStr(BTN_ACTION4));
Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
Common_Sleep(50);
} while (!Common_BtnPress(BTN_QUIT));
ERRCHECK( weaponsBank->unload() );
ERRCHECK( menuBank->unload() );
ERRCHECK( ambienceBank->unload() );
ERRCHECK( stringsBank->unload() );
ERRCHECK( masterBank->unload() );
ERRCHECK( system->release() );
Common_Close();
return 0;
}