Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Audio Spatialization in 3d context like Ogre  (Read 586 times)

0 Members and 1 Guest are viewing this topic.

Milerius

  • Newbie
  • *
  • Posts: 23
    • View Profile
Audio Spatialization in 3d context like Ogre
« on: May 18, 2017, 12:06:56 am »
Hello,

I'm currently doing a project for my school with Ogre3D, i use sfml audio for the sound.

I would like to play a 3D sound appropriately, based on my position on the map and the sound source's

position at the start of the game :
,

there is the place where the sound is played :




the skeleton play the sound when he is hitting the torso

there is the snippet of my code,

position of the skeleton in the 3d scene:
_cesar->setPosition(710.6, 30, 557.64);
 


set the listener, the listener is my camera.
       
sf::Listener::setGlobalVolume(50);
sf::Listener::setPosition(_cameraMan->getCamera()->getPosition().x,
_cameraMan->getCamera()->getPosition().y, _cameraMan->getCamera()->getPosition().z);
evt::EventManager::getSingletonPtr()->emit<evt::SoundEffectSpatialization>(effect::ImpactBoom, _cesar->getPosition(), true);
 

the _cameraman is my actual position in the map, the listener has his position.

Update of the listener at each frame:
     
_soundMgr->update(evt.timeSinceLastFrame,
TestScene::getSingletonPtr()->_cameraMan->getCamera()->getPosition(),
TestScene::getSingletonPtr()->_cameraMan->getCamera()->getDirection());
 
void SoundEffectsManager::update(float timeSinceLastFrame, const Ogre::Vector3& position,
const Ogre::Vector3& direction)
        {
            sf::Listener::setPosition(static_cast<float> (position.x),
                static_cast<float> (position.y),
                static_cast<float> (position.z));
            //sf::Listener::setDirection(direction.x, direction.y, direction.z);
        }
 
sound play:
  void SoundEffectsManager::playSound(const effect& effectId, const Ogre::Vector3& position, bool loop)
        {
            if (!_effects.isLoaded(effectId))
                _effects.loadResource(effectId, _effectsPath[effectId]);
            _sndBuffer = _effects.getResource(effectId);
            _snd.setBuffer(_sndBuffer);
            _snd.setVolume(100);
            _snd.setPosition(position.x, position.y, position.z);
            _snd.setRelativeToListener(true);

            //test
            _snd.setAttenuation(10.f);
            _snd.setMinDistance(5.f);
            //Volume factor = MinDistance / (MinDistance + Attenuation * (max(Distance, MinDistance) - MinDistance))



            _snd.setLoop(loop);

            _snd.play();
      }
 

I hear the sound the same way, whatever my position in the scene.
May be i do something wrong, let me know with some examples, sorry for my english!

Thanks you very much!
« Last Edit: May 18, 2017, 12:09:46 am by Milerius »