void Scene::setActiveCamera(Camera* camera) { // Make sure we don't release the camera if the same camera is set twice. if (_activeCamera != camera) { AudioListener* audioListener = AudioListener::getInstance(); if (_activeCamera) { // Unbind the active camera from the audio listener if (audioListener && (audioListener->getCamera() == _activeCamera)) { audioListener->setCamera(NULL); } SAFE_RELEASE(_activeCamera); } _activeCamera = camera; if (_activeCamera) { _activeCamera->addRef(); if (audioListener && _bindAudioListenerToCamera) { audioListener->setCamera(_activeCamera); } } } }
void AudioController::update(float elapsedTime) { AudioListener* listener = AudioListener::getInstance(); if (listener) { AL_CHECK( alListenerf(AL_GAIN, listener->getGain()) ); AL_CHECK( alListenerfv(AL_ORIENTATION, (ALfloat*)listener->getOrientation()) ); AL_CHECK( alListenerfv(AL_VELOCITY, (ALfloat*)&listener->getVelocity()) ); AL_CHECK( alListenerfv(AL_POSITION, (ALfloat*)&listener->getPosition()) ); } }
void Audio3DTest::drawDebugText(int x, int y) { _font->start(); static const int V_SPACE = 16; AudioListener* audioListener = AudioListener::getInstance(); drawVector3("Listener Position", audioListener->getPosition(), x, y); drawVector3("Listener Forward", audioListener->getOrientationForward(), x, y+=V_SPACE); drawVector3("Listener Up", audioListener->getOrientationUp(), x, y+=V_SPACE); drawVector3("Listener Velocity", audioListener->getVelocity(), x, y+=V_SPACE); _font->finish(); }
void LevelLoader::createCamera() { GameObject* shadyCamObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + "ShadyCamera" + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D()); Camera* cam = shadyCamObj->GetComponent<Camera>(); VERIFY(cam != nullptr, "Game camera object has Camera component"); ENGINE->GetSceneGraph3D()->SetMainCameraId(shadyCamObj->GetId()); SINGLETONS->GetGridManager()->SetShadyCamera((ShadyCamera*)cam); AudioListener* listener = shadyCamObj->GetComponent<AudioListener>(); ASSERT(listener != nullptr, "Game camera object has AudioListener component"); if (listener != nullptr) { listener->SetAsActiveListener(); } }
Scene::~Scene() { // Unbind our active camera from the audio listener if (_activeCamera) { AudioListener* audioListener = AudioListener::getInstance(); if (audioListener && (audioListener->getCamera() == _activeCamera)) { audioListener->setCamera(NULL); } SAFE_RELEASE(_activeCamera); } // Remove all nodes from the scene removeAllNodes(); }
void CSoundManager::move(Vector3 ePos, int instance, int index) { if(index == -1) index = m_nLastPlayedSound; if(instance == -1) instance = m_nLastPlayedInstance; Vector3 v = Vector3(g_nScreenWidth/2.0f, g_nScreenHeight/2.0f, 0); AudioListener listener; AudioEmitter emitter; const float SCALE = 500.0f; listener.SetPosition(v/SCALE); emitter.SetPosition(ePos/SCALE); if(instance >= 0 && instance < m_nInstanceCount[index]) m_pInstance[index][instance]->Apply3D(listener, emitter); } //move
Scene::~Scene() { // Unbind our active camera from the audio listener if (_activeCamera) { AudioListener* audioListener = AudioListener::getInstance(); if (audioListener && (audioListener->getCamera() == _activeCamera)) { audioListener->setCamera(NULL); } SAFE_RELEASE(_activeCamera); } // Remove all nodes from the scene removeAllNodes(); // Remove the scene from global list std::vector<Scene*>::iterator itr = std::find(__sceneList.begin(), __sceneList.end(), this); if (itr != __sceneList.end()) __sceneList.erase(itr); }
float PannerNode::ComputeDopplerShift() { double dopplerShift = 1.0; // Initialize to default value AudioListener* listener = Context()->Listener(); if (listener->DopplerFactor() > 0) { // Don't bother if both source and listener have no velocity. if (!mVelocity.IsZero() || !listener->Velocity().IsZero()) { // Calculate the source to listener vector. ThreeDPoint sourceToListener = mPosition - listener->Velocity(); double sourceListenerMagnitude = sourceToListener.Magnitude(); double listenerProjection = sourceToListener.DotProduct(listener->Velocity()) / sourceListenerMagnitude; double sourceProjection = sourceToListener.DotProduct(mVelocity) / sourceListenerMagnitude; listenerProjection = -listenerProjection; sourceProjection = -sourceProjection; double scaledSpeedOfSound = listener->DopplerFactor() / listener->DopplerFactor(); listenerProjection = min(listenerProjection, scaledSpeedOfSound); sourceProjection = min(sourceProjection, scaledSpeedOfSound); dopplerShift = ((listener->SpeedOfSound() - listener->DopplerFactor() * listenerProjection) / (listener->SpeedOfSound() - listener->DopplerFactor() * sourceProjection)); WebAudioUtils::FixNaN(dopplerShift); // Avoid illegal values // Limit the pitch shifting to 4 octaves up and 3 octaves down. dopplerShift = min(dopplerShift, 16.); dopplerShift = max(dopplerShift, 0.125); } } return dopplerShift; }
Movable *Level::createMovable (XmlFile *file, int type, std::string name, Movable *parent, XMLElement *element, bool createNow) { Movable *objObject = 0; if (type == GOT_ENTITY) { Entity *eEntity = new Entity (name); if (element != 0) eEntity->parseXML (file, element, parent); if (createNow == true) eEntity->create (parent); objObject = eEntity; } if (type == GOT_CAMERA) { Camera *cCamera = new Camera (name); if (element != 0) cCamera->parseXML (file, element, parent); if (createNow == true) cCamera->create (0, parent); objObject = cCamera; } if (type == GOT_PARTICLE_SYSTEM) { ParticleSystem *psSystem = new ParticleSystem (name); if (element != 0) psSystem->parseXML (file, element, parent); if (createNow == true) psSystem->create (parent); objObject = psSystem; } if (type == GOT_LIGHT) { Light *lLight = new Light (name); if (element != 0) lLight->parseXML (file, element, parent); if (createNow == true) lLight->create (parent); objObject = lLight; } if (type == GOT_ANIMATION_TRACK) { AnimationTrackObject *atoObject = new AnimationTrackObject (name); if (element != 0) atoObject->parseXML (file, element, parent); if (createNow == true) atoObject->create (parent); objObject = atoObject; aryAnimations.push_back (atoObject); } if (type == GOT_AUDIO_LISTENER) { AudioListener *alListener = new AudioListener (name); if (element != 0) alListener->parseXML (file, element, parent); if (createNow == true) alListener->create (parent); objObject = alListener; } if (type == GOT_SOUND) { Sound *sSound = new Sound (name); if (element != 0) sSound->parseXML (file, element, parent); if (createNow == true) sSound->create (parent); objObject = sSound; } if (type == GOT_OVERLAY) { Overlay *oOverlay = new Overlay (name); if (element != 0) oOverlay->parseXML (file, element, parent); if (createNow == true) oOverlay->create (parent); aryOverlays.push_back (oOverlay); objObject = oOverlay; } if (type == GOT_OVERLAY_ELEMENT) { OverlayElement *oOverlayElement = new OverlayElement (name); if (element != 0) oOverlayElement->parseXML (file, element, parent); if (createNow == true) oOverlayElement->create (parent); aryOverlayElements.push_back (oOverlayElement); objObject = oOverlayElement; } addMovable (objObject); return (objObject); }
void AudioController::update(long elapsedTime) { AudioListener* listener = AudioListener::getInstance(); if (listener) { #ifndef __ANDROID__ alListenerf(AL_GAIN, listener->getGain()); alListenerfv(AL_ORIENTATION, (ALfloat*)listener->getOrientation()); alListenerfv(AL_VELOCITY, (ALfloat*)&listener->getVelocity()); alListenerfv(AL_POSITION, (ALfloat*)&listener->getPosition()); #else if (!_listenerObject) { const SLInterfaceID interfaces[3] = {SL_IID_3DDOPPLER, SL_IID_3DLOCATION}; const SLboolean required[3] = {SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE}; SLresult result = (*_engineEngine)->CreateListener(_engineEngine, &_listenerObject, 2, interfaces, required); if (result != SL_RESULT_SUCCESS) { WARN_VARG("AudioController: failed to create listener (%u).", result); return; } result = (*_listenerObject)->Realize(_listenerObject, SL_BOOLEAN_FALSE); if (result != SL_RESULT_SUCCESS) { WARN("AudioController: failed to realize listener."); return; } // Get the doppler interface in order to set the listener's velocity. result = (*_listenerObject)->GetInterface(_listenerObject, SL_IID_3DDOPPLER, &_listenerDoppler); if (result != SL_RESULT_SUCCESS) { WARN("AudioController: Unable to retrieve listener doppler interface."); return; } // Get the location interface in order to set the listener's position and orientation. result = (*_listenerObject)->GetInterface(_listenerObject, SL_IID_3DLOCATION, &_listenerLocation); if (result != SL_RESULT_SUCCESS) { WARN("AudioController: Unable to retrieve listener location interface."); return; } } SLVec3D f; f.x = listener->getOrientationForward().x; f.y = listener->getOrientationForward().y; f.z = listener->getOrientationForward().z; SLVec3D a; a.x = listener->getOrientationUp().x; a.y = listener->getOrientationUp().y; a.z = listener->getOrientationUp().z; SLresult result = (*_listenerLocation)->SetOrientationVectors(_listenerLocation, &f, &a); if (result != SL_RESULT_SUCCESS) { WARN("AudioController: Unable to set listener orientation."); } SLVec3D p; p.x = listener->getPosition().x; p.y = listener->getPosition().y; p.z = listener->getPosition().z; result = (*_listenerLocation)->SetLocationCartesian(_listenerLocation, &p); if (result != SL_RESULT_SUCCESS) { WARN("AudioController: Unable to set listener location."); } SLVec3D v; v.x = listener->getVelocity().x; v.y = listener->getVelocity().y; v.z = listener->getVelocity().z; result = (*_listenerDoppler)->SetVelocityCartesian(_listenerDoppler, &v); if (result != SL_RESULT_SUCCESS) { WARN("AudioController: Unable to set listener velocity."); } #endif } }