Non-looping sound with new system

I've been messing about with the new sound system, and so far it's worked well for engine noise, wind noise etc. that loop continuously with only the position and volume changing.



However I can't work out how to make a positional sound that doesn't loop automatically, but only when something happens. For example - a gun firing sound. I want it to do nothing much until I get a firing event, then play once, rewind and wait, ready to play on the next firing event. I tried just setting looping to false on the AudioTrack, then calling play() (or setEnabled(true) then play()) on firing, but this does not play the sound again.



It would be great to have just a couple more example sounds in TestJmexAudio, just to demonstrate a triggered sound like I described, and maybe to show the use of environmental and headspace sounds as well as positional and music.



One change I had to make to the code - I needed to zero the velocity calculation in Ear.applyPosition(), because I am listening to the engine sounds of a plane, from an Ear that tracks the plane. This should give no doppler shift since the ear and sound source always have the same velocity, but in fact the sound is pitch shifted according to plane speed. Maybe a setting on Ear for "useVelocity" would be useful for cases like this (if it is set true, then velocity is just left as 0)? I don't really mind losing doppler shifting just for now.


I think you need to call stop before play to fix that.

In your case, the sound source AudioTrack should have the same velocity setting as the ear, making them not moving, relatively speaking.  That should work if things are done correctly.



I agree about samples.  We need some "free to use" samples.  Anyone have some to donate?



We do non-looping sounds a lot at work without issue.  I will put together a test this weekend to show how to do that properly.

Ah it’s good that it should work, so I think either I’ve missed something, or the RangedAudioTracker isn’t setting the AudioTrack velocity?



I’ve been getting samples at http://freesound.iua.upf.edu/. They had some pretty good engine sounds for planes, and some ok gun noises I’ve messed about with in Audacity. Sound in general seems to be working pretty well now :slight_smile: I hacked in the non-looping sounds - I had to stop using RangedAudioTracker, then I just manually set the sound positions and it works. If I use a RangedAudioTracker it seems to cause even non-looping sounds to loop. Hopefully I can see what I’m doing wrong from your test :slight_smile:



I’ve noticed one issue with POSITIONAL sounds, when I run for quite a while (and sometimes very rarely on startup) I get extremely choppy sound, cutting in and out at high speed. I’m just guessing but it sounds a little like the buffer repeatedly under-running. It doesn’t seem to fix itself, it will keep playing the right sound but with the chopping for as long as I can bear to listen to it :slight_smile: Restarting the game will fix it. It’s not something I’ve had from other audio apps on my system, or from the openal stuff I’ve done before (although that wasn’t doing nearly as much at once).

Is the game getting choppy at all?

Nope it just sounds bad. It looks smooth, and the frame rates seem the same as when sound is normal.

Ah, I didn't know you were using RangedAudioTracker.  That is meant for environmental audio, like anvils clanking at the blacksmithy or birds chirping in the forest, etc.  (iow, looping sounds…  When the sound ends, it will detect you are in range and it will kick it off again.)