VFmodSoundObject *RPG_VisionEffectHelper::CreateSoundEffect(RPG_VisionEffectSoundParams const& params) { VASSERT(VFmodManager::GlobalManager().IsInitialized()); // ensure that the native Fmod system has been correctly initialized VFmodSoundResource *soundResource = static_cast<VFmodSoundResource *> (GetEffectResource("FmodSoundResource", params.m_soundFilename)); VASSERT_MSG(soundResource, params.m_soundFilename); if (soundResource) { VFmodSoundObject *soundObject = soundResource->CreateInstance(params.m_position, VFMOD_FLAG_NONE); VASSERT_MSG(soundObject->IsValid(), params.m_soundFilename); if (soundObject->IsValid()) { soundObject->Play(); } } return NULL; }
// -------------------------------------------------------------------------- // // Instances // -------------------------------------------------------------------------- // VFmodSoundObject* VFmodManager::CreateSoundInstance(const char *szFilename, int iResourceUsageFlags, int iInstanceFlags, int iPriority) { VFmodSoundResource *pRes = LoadSoundResource(szFilename, iResourceUsageFlags); if (!pRes) return NULL; // Note: Create all sound objects here as paused as we need to set AND update the // correct distance and attenuation first! Call Play() afterwards it set. VFmodSoundObject* pObj = pRes->CreateInstance(hkvVec3(0.0f,0.0f,0.0f), iInstanceFlags | VFMOD_FLAG_PAUSED, iPriority); if (pObj) { // Force sound source position update pObj->OnObject3DChanged(VisObject3D_cl::VIS_OBJECT3D_POSCHANGED); // Play if set if((iInstanceFlags & VFMOD_FLAG_PAUSED) == 0) pObj->Play(); } return pObj; }
// -------------------------------------------------------------------------- // // Resources // -------------------------------------------------------------------------- // VFmodSoundResource* VFmodManager::LoadSoundResource(const char *szFilename, int iUsageFlags) { VASSERT(szFilename!=NULL); VFmodSoundResource *pRes = NULL; bool bStream = (iUsageFlags & VFMOD_RESOURCEFLAG_STREAM)>0; if (!bStream) // streaming creates unique resources { if (szFilename[0]=='\\' || szFilename[0]=='/') szFilename++; // make absolute filenames comparable int iCount = m_pSoundResourceManager->GetResourceCount(); const unsigned int iFilenameHash = VPathHelper::GetHash(szFilename); for (int i=0;i<iCount;i++) { pRes = (VFmodSoundResource*)m_pSoundResourceManager->GetResourceByIndex(i); if (!pRes || !pRes->GetFilename() || !pRes->GetFilename()[0]) continue; if (!pRes->CompareFileName(szFilename, iFilenameHash)) continue; // additionally see whether flags match... if (iUsageFlags==pRes->m_iSoundFlags) return pRes; } } if (Vision::File.Exists(szFilename)) { // create a new resource (unique for streaming resources) pRes = new VFmodSoundResource(m_pSoundResourceManager, iUsageFlags); pRes->SetFilename(szFilename); pRes->EnsureLoaded(); return pRes; } return NULL; }