void VFmodManager::SetPauseAll(bool bStatus) { if (IsInitialized()) { m_pMasterGroup->setPaused(bStatus); m_pMusicGroup->setPaused(bStatus); FMOD::EventCategory *pEventCategory = NULL; FMOD_ERRORCHECK(m_pEventSystem->getCategoryByIndex(-1, &pEventCategory)); pEventCategory->setPaused(bStatus); } }
// -------------------------------------------------------------------------- // // Misc // -------------------------------------------------------------------------- // void VFmodManager::OnHandleCallback(IVisCallbackDataObject_cl *pData) { if (pData->m_pSender==&Vision::Callbacks.OnEngineInit) { InitFmodSystem(); return; } if(pData->m_pSender == &Vision::Callbacks.OnEngineDeInit) { // release all resources before the engine deinitializes m_soundInstances.Clear(); m_events.Clear(); m_collisionMeshes.Clear(); m_reverbs.Clear(); m_bAnyStopped = false; DeInitFmodSystem(); return; } if (pData->m_pSender==&Vision::Callbacks.OnUpdateSceneFinished) { RunTick(Vision::GetTimer()->GetTimeDifference()); #ifdef _DEBUG_OUTPUT SoundInstances().DebugOutput(); Events().DebugOutput(); #endif return; } if (pData->m_pSender==&Vision::Callbacks.OnWorldInit) { if (!IsInitialized()) return; VASSERT(m_pSystem!=NULL); // notify the sound engine about the world extents float fRadius = 32000.0f; hkvAlignedBBox bbox; Vision::GetSceneManager()->GetSceneExtents(bbox); if (bbox.isValid()) fRadius = bbox.getBoundingSphere().m_fRadius; FMOD_ERRORCHECK(m_pSystem->setGeometrySettings(fRadius)); return; } if (pData->m_pSender==&Vision::Callbacks.OnWorldDeInit) { // stop all instances and dispose them if possible (i.e VFMOD_FLAG_NODISPOSE flag not set) SoundInstances().StopAll(true); Events().StopAll(true); // remove all collision meshes CollisionMeshes().Clear(); // remove all reverbs Reverbs().Clear(); m_bAnyStopped = false; return; } if (pData->m_pSender==&IVScriptManager::OnScriptProxyCreation) { VScriptCreateStackProxyObject * pScriptData = (VScriptCreateStackProxyObject *)pData; //process data only as far as not handled until now if (!pScriptData->m_bProcessed) { int iRetParams = 0; if (pScriptData->m_pInstance->IsOfType(V_RUNTIME_CLASS(VFmodSoundObject))) iRetParams = LUA_CallStaticFunction(pScriptData->m_pLuaState,"FireLight","VFmodSoundObject","Cast","O>O",pScriptData->m_pInstance); else if (pScriptData->m_pInstance->IsOfType(V_RUNTIME_CLASS(VFmodEvent))) iRetParams = LUA_CallStaticFunction(pScriptData->m_pLuaState,"FireLight","VFmodEvent","Cast","O>O",pScriptData->m_pInstance); if (iRetParams>0) { if(lua_isnil(pScriptData->m_pLuaState, -1)) lua_pop(pScriptData->m_pLuaState, iRetParams); else pScriptData->m_bProcessed = true; } } return; } if(pData->m_pSender==&IVScriptManager::OnRegisterScriptFunctions) { IVScriptManager* pSM = Vision::GetScriptManager(); if (pSM) { lua_State* pLuaState = ((VScriptResourceManager*)pSM)->GetMasterState(); if(pLuaState) { lua_getglobal(pLuaState, "Fmod"); int iType = lua_type(pLuaState, -1); lua_pop(pLuaState, 1); if(iType!=LUA_TUSERDATA) { luaopen_FireLight(pLuaState); int iRetParams = LUA_CallStaticFunction(pLuaState,"FireLight","VFmodManager","Cast","v>v", &VFmodManager::GlobalManager()); if (iRetParams==1) { if(lua_isnil(pLuaState, -1)) { lua_pop(pLuaState, iRetParams); } else { lua_setglobal(pLuaState, "Fmod"); return; } } } else { return; //already loaded } } Vision::Error.Warning("Unable to create Lua Fmod Module, lua_State is NULL or cast failed!"); } return; } #if defined(_VISION_MOBILE) // Pause Sound when in background if (pData->m_pSender == &Vision::Callbacks.OnLeaveForeground) { if (IsInitialized()) { // From the FMOD Ex documentation: // "Channels will not have their per channel pause state overwritten, // so that when a channelgroup is unpaused, the paused state of the channels will // correct as they were set on a per channel basis." m_pMasterGroup->getPaused(&m_bMasterGroupPausedInForeground); m_pMusicGroup->getPaused(&m_bMusicGroupPausedInForeground); m_pMasterGroup->setPaused(true); m_pMusicGroup->setPaused(true); // Get master event category and pause it as well FMOD::EventCategory *pEventCategory = NULL; FMOD_ERRORCHECK(m_pEventSystem->getCategoryByIndex(-1, &pEventCategory)); pEventCategory->getPaused(&m_bMasterEventCategoryPausedInForeground); pEventCategory->setPaused(true); } return; } if (pData->m_pSender == &Vision::Callbacks.OnEnterForeground) { if (IsInitialized()) { m_pMasterGroup->setPaused(m_bMasterGroupPausedInForeground); m_pMusicGroup->setPaused(m_bMusicGroupPausedInForeground); FMOD::EventCategory *pEventCategory = NULL; FMOD_ERRORCHECK(m_pEventSystem->getCategoryByIndex(-1, &pEventCategory)); pEventCategory->setPaused(m_bMasterEventCategoryPausedInForeground); } return; } #endif }
int main(int argc, char *argv[]) { FMOD::EventSystem *eventsystem; FMOD::EventGroup *eventgroup; FMOD::EventCategory *mastercategory; FMOD::Event *car; FMOD::EventParameter *rpm; FMOD::EventParameter *load; FMOD_RESULT result; int key; float rpm_val, rpm_min, rpm_max, rpm_increment, load_val, load_min, load_max, load_increment; printf("======================================================================\n"); printf("Parameters Example. Copyright (c) Firelight Technologies 2004-2014.\n"); printf("==============================-------=================================\n"); printf("This demonstrates the use of FMOD event parameters. It simply plays an\n"); printf("event, retrieves the parameters and allows the user to adjust them.\n"); printf("======================================================================\n\n"); ERRCHECK(result = FMOD::EventSystem_Create(&eventsystem)); ERRCHECK(result = eventsystem->init(64, FMOD_INIT_NORMAL, 0, FMOD_EVENT_INIT_NORMAL)); ERRCHECK(result = eventsystem->setMediaPath("..\\media\\")); ERRCHECK(result = eventsystem->load("examples.fev", 0, 0)); ERRCHECK(result = eventsystem->getGroup("examples/AdvancedTechniques", FMOD_EVENT_DEFAULT, &eventgroup)); ERRCHECK(result = eventgroup->getEvent("car", FMOD_EVENT_DEFAULT, &car)); ERRCHECK(result = eventsystem->getCategory("master", &mastercategory)); ERRCHECK(result = car->getParameter("load", &load)); ERRCHECK(result = load->getRange(&load_min, &load_max)); ERRCHECK(result = load->setValue(load_max)); ERRCHECK(result = car->getParameterByIndex(0, &rpm)); ERRCHECK(result = rpm->getRange(&rpm_min, &rpm_max)); ERRCHECK(result = rpm->setValue(1000.0f)); ERRCHECK(result = car->start()); printf("======================================================================\n"); printf("Press '<' or ',' to decrease RPM\n"); printf("Press '>' or '.' to increase RPM\n"); printf("Press '-' or '_' to decrease load\n"); printf("Press '+' or '=' to increase load\n"); printf("Press ESC to quit\n"); printf("======================================================================\n"); rpm_increment = (rpm_max - rpm_min) / UPDATE_INTERVAL; ERRCHECK(result = rpm->getValue(&rpm_val)); load_increment = (load_max - load_min) / UPDATE_INTERVAL; ERRCHECK(result = load->getValue(&load_val)); key = 0; do { if (_kbhit()) { key = _getch(); if (key == '<' || key == ',') { rpm_val -= rpm_increment; if (rpm_val < rpm_min) { rpm_val = rpm_min; } ERRCHECK(result = rpm->setValue(rpm_val)); } else if (key == '>' || key == '.') { rpm_val += rpm_increment; if (rpm_val > rpm_max) { rpm_val = rpm_max; } ERRCHECK(result = rpm->setValue(rpm_val)); } if (key == '-' || key == '_') { load_val -= load_increment; if (load_val < load_min) { load_val = load_min; } ERRCHECK(result = load->setValue(load_val)); } else if (key == '+' || key == '=') { load_val += load_increment; if (load_val > load_max) { load_val = load_max; } ERRCHECK(result = load->setValue(load_val)); } else if (key == ' ') { bool paused; ERRCHECK(result = mastercategory->getPaused(&paused)); paused = !paused; ERRCHECK(result = mastercategory->setPaused(paused)); } } ERRCHECK(result = eventsystem->update()); Sleep(15); printf("RPM = %.4f, load = %.4f \r", rpm_val, load_val); } while (key != 27); ERRCHECK(result = eventgroup->freeEventData()); ERRCHECK(result = eventsystem->release()); return 0; }