Hi Guys,
I have a problem about automatically mute game music, I tested the low level sample codes (output_ports), it works fines. But I want to play sound with eventInstance, so I wrote some codes to your studio sample cdoes(simple_event) to test the attachChannelGroupToPort interface, unfortunately it is not working, I can hear the voice form the video captured by GameDVR. This is my codes below, do you have any ideas about it ?
// 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;
FMOD_RESULT result = loopingAmbienceInstance->getChannelGroup(&loopingAmbience);
ERRCHECK(result);
result = lowLevelSystem->attachChannelGroupToPort(FMOD_DURANGO_PORT_TYPE_MUSIC, FMOD_PORT_INDEX_NONE, loopingAmbience);
ERRCHECK(result);
/////////End mod
do
{
Common_Update();
if (Common_BtnPress(BTN_ACTION1))
I cannot see where you have created loopingAmbienceInstance or where you call playSound, but be aware you cannot attach the master bus to a port. Have you tried creating a new channelgroup for the event?
Also make sure the event isn’t also being routed through another effect/bus that isn’t using that port.
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;
You don’t touch the channel group of the event but the group bus it is under. It’s recommended to have a group bus in your FMOD Studio project that you then change in the way mentioned above:
The problem is with using the event instances channelgroup.
We recommend having a dedicated Bus, setup in Studio, to contain any and all events you want playing through a specific port. This will allow you to call [Bus::lockChannelGroup][1], which will force the channelgroup to be created and persist until [Bus::unlockChannelGroup][2] is called. Then get the channelgroup from the Bus and continue as you had previously.
Make sure you are using the correct FMOD_PORT_TYPE for each platform, PS4 & Xbox One use different values and on PC (if you are building for it) you will want to bypass it all.
Until now, we tested on XBoxOne, as the upgrade of the PS4 version was not completed.
We just finished the upgrade of the PS4, and tested it.
and everything work fine.
copyright musics are played during gameplay, but not when recording a video using the share button.
It seems strange that it works on PS4 but not Xbox One while no errors occur.
Are you able to attach the debug output log after setting the following (either before or after system init):