A sound attached to a moving node

Hello,



I have a simple game where a helicopter (controlled by a player) flies over a terrain a shoots computer controlled enemy helicopters.



Now I would like to add a simple chopper sound to all helicopter nodes. The sounds should be attached to the corresponding helicopters and change their locations along with them. I have tried to go through tutorials and examples but couldn't find anything like that. Is there an easy way how to attach a sound to a particular node?



Thanks for any help.

Filip

there is: RangedAudioTracker



        AudioTrack chopchopchop = AudioSystem.getSystem().createAudioTrack("chopchopchop.wav", false);
        chopchopchop .setType(TrackType.POSITIONAL);
        chopchopchop .setLooping(true);

        RangedAudioTracker tracker = new RangedAudioTracker(chopchopchop );
        tracker.setPlayRange(800);     // play with these values
        tracker.setStopRange(1000); // play with these values
        tracker.setFadeTime(2.0f);     // play with these values
        tracker.setToTrack(helicopter.getNode());        // set an emitter for the sound
        tracker.setTrackIn3D(true);
        tracker.setMaxVolume(1.0f);



and then to check if the Sound is audible to the player (the camer position) do the following in the update() Method:


  
        if (lastUpdate + 50 < currentTime) {  // no need to do the check every Frame i think.
            lastUpdate = currentTime;
            tracker.checkTrackAudible(display.getRenderer().getCamera().getLocation());
        }



See also TestJmexAudio.

Thanks :slight_smile: That's what I have been looking for.

Unfortunately, when I move my camera close enough to make the sound audible, OpenAL throws this exception:


org.lwjgl.openal.OpenALException: OpenAL error: Invalid Operation (40964)
   at org.lwjgl.openal.Util.checkALError(Util.java:64)
   at org.lwjgl.openal.AL10.alSourcei(AL10.java:764)
   at com.jmex.audio.openal.OpenALMemoryAudioPlayer.play(OpenALMemoryAudioPlayer.java:112)
   at com.jmex.audio.AudioTrack.play(AudioTrack.java:113)
   at com.jmex.audio.RangedAudioTracker.checkTrackAudible(RangedAudioTracker.java:153)



Since I don't know what the 40964 code means, I have no idea where to look for the problem source.
Any ideas?

Filip

Sorry, my fault.  I have forgotten to call AudioSystem.getSystem().update() at the update() method.



Everything works great now.

Good to hear :slight_smile:

hmm,

now i remember i had this problem too, thats why i added the 50 ms delay beween checkTrackAudible() hehe :).



I am using StandardGame and Gamestates, and StandardGame already calls Audiosystem.update() .

But i guess Audiosystem.update(), need to be called in the GameStates update() Method also…



Sending the checkTrackAudible() Call to the GameTaskQueueManager didnt help much, the 'Invalid Operation' error was gone, but some sounds sometimes didn't play when they should have.