Sound Positioning API

From EQUIS Lab Wiki

Jump to: navigation, search

This API can be used in a game to position the sounds.

Sound Positioning using a GPS system

This applies to an outdoor game that relies on the GPS positioning developed by Kurckzak and sound positioning. The game is composed of entities. Each entity is either a listener or an emitter. The listener is linked to the GPS properties.

Both emitter and listener rely on a sound API described further below. The emitter entity has several properties to manage the sounds it emits.

soundPositioningUML.png


To use this API in a game, the main class of the game must have one sound manager, one listener and one or several emitters.

gameUML.png

   using Positioning;
   using SoundPositioning;
   using Sound3D;
   class Game1
   {
      private ListenerEntity _listener;
      private List<EmitterEntity> _emitters;
      private ISoundManager _soundManager;
      private Hashtable _soundBank;
     protected override void Initialize()
     {
         _listener = new ListenerEntity(UserControl.GPS);
         _emitters = new List<EmitterEntity>();
         for (int i = 0; i < number; i++)
         {
             _emitters.Add(new EmitterEntity());
         }
     }
     protected override void LoadContent()
     {
         _soundBank.Add("soundName", "Content\\Audio\\soundName.wav");
         _soundManager = new OpenALSoundManager(_soundBank);
         _listener.InitAudio(_soundManager);
         foreach (EmitterEntity emitter in _emitters)
         {
             emitter.InitAudio(_soundManager);
             emitter.CurrentSound = "soundName"; // gives the emitter a sound
             emitter.Loop("soundName", true); // the sound will loop
         }
     }
     protected override void Update(GameTime gameTime)
     {
         float timeDelta = (float)gameTime.ElapsedGameTime.TotalSeconds;
         float timeTotal = (float)gameTime.TotalGameTime.TotalSeconds;
         _listener.Update(timeDelta, timeTotal);
         foreach(EmitterEntity emitter in _emitters)
         {
             emitter.Update(timeTotal);
         }
         _soundManager.Update(timeTotal);
     }
   }

Sound API

When elaborating a game based on sound positioning, one want to be able to manipulate the sounds so that they will fit to the game-play.

This API gives access to :

  • a listener which can be positioned and oriented in space,
  • sources that can be positioned, oriented, given sounds.
  • The sources are provided with a bunch of properties, such as :
    • the classical Play, Pause, Stop,
    • set the sound being played,
    • make a list of sounds that will be played in a row,
    • have a sound loop,
    • have a sound stop after an amount of time,
    • receive events when a sound starts, pauses, resumes or stops.

sound3DUML.png

GPS positioning system

This API was developed by Jason Kurckzak, I modified minor parts to adapt it to my API.

This API allows somebody to move around in the city and be localized. It uses separate hardware that has to be connected to the computer.

The control of the user can be either by GPS, completely manual (the code gives the bearing and the movement), or half manual (the bearing is given by the hardware, but the forward amount is given in the code).

positioningUML.png