Multiple RangedAudioControllers on the same audiotrack?

Hey, I have 1 audiotrack that is played every time a shot is fired. If the player is the only 1 shooting everything is fine but if the enemy also starts shooting i also hear they're shots even when i'm not closeby.



To prevent this i'm using a RangedAudioTracker it now works fine if just 1 player/enemy is shooting but since both the player and enemy are linked to the same track it still doesent work out as i was hoping.



Is it possible to have just 1 audiotrack shared between them or should i create a new audiotrack for each tracker ?



Thanks, Hellmaster.

When playing an explosion, i set the new world position and then play the sound.

That way you should be able to use the same AudioTrack for the player and enemy i think.



// init

AudioTrack shot = AudioSystem.createAudioTrack("shot.wav", false);

shot.setType(TrackType.POSITIONAL);





// play

shot.setWorldPosition(Vector3f pos);

shot.play();

Yes thats exactly how i do it without RangedAudioTracker  i tried to do something similar with the tracker  but thats not working as intended.



Currently i have the following:



init stuff

audio = AudioSystem.getSystem();

      laserTrack = audio.createAudioTrack("audio/blaster.wav", false);
      laserTrack.setType(TrackType.POSITIONAL);
      laserTrack.setRelative(false);
      laserTrack.setLooping(false);

      laserTracker = new RangedAudioTracker(laserTrack, 300, 300);
      laserTracker.setTrackIn3D(true);
      laserTracker.setMaxVolume(0.3f);
      trackers.add(laserTracker);



play the sound:

   public void playLaserSound(Spatial emitter)
   {
      laserTracker.setToTrack(emitter);
      laserTrack.setWorldPosition(emitter.getWorldTranslation());
      laserTrack.play();
   }



and finally the update of the RangedAudioTracker

public void update(float tpf)
   {
      for (RangedAudioTracker tracker : trackers)
      {
         tracker.checkTrackAudible(DisplaySystem.getDisplaySystem()
               .getRenderer().getCamera().getLocation());
      }
   }

Hellmaster said:

   public void playLaserSound(Spatial emitter)
   {
      laserTracker.setToTrack(emitter);
                --> emitter.updateWorldVectors();  <-- make sure that the WorldTranslation is updated before reading it.
      laserTrack.setWorldPosition(emitter.getWorldTranslation());
      laserTrack.play();
   }




i often had problems that the WorldTranslation was not up to date (inside Controllers for example).
So, call updateWorldVectors before accessing it, maybe that helps already.

I also think there are some issues with reusing a single track in multiple places at once.  I think the solution would be to take the audio player out of the AudioTrack and instead let that class pull from a player pool.  I will probably look into such a change in the 2.0 branch in the next month or so, but comments are welcome as always.

I tried the upateWorldVectors() but unfortunately this does not solve the problem.

I also found out that the problem is not in the tracker but in the use of the same audiotrack as renanse says.



Ill try renanse suggestion now with some sort of pool to create and re-use audiotracks.



Hellmaster.

Hmm even though the sound is no longer playing ( at least i cant hear it )  isActive() and isPlaying() are allways returning true.



If i set my track to looping = false  i would expect that once the sound has reached the end isPlaying() would return false

How can i see if he is done playing ?



Hellmaster.