Sounds are becoming cumulative

https://jme.dev.java.net/source/browse/jme/src/jmetest/TutorialGuide/HelloIntersection.java?rev=1.6&content-type=text/vnd.viewcvs-markup

I play a sound once… wait a bit… and when I try to play it again I hear it twice in a row. What I’ld like to happen is to hear the sound again but only once when I want to play it.



Sound gets queued up in FireBullet.performAction(float time) and played in simpleRender

Fixed a bug in spherical sound which has a non-looping sound continuously add to the queue on every play().

I changed the code to cute the current laser sound short if it’s currently playing, so I can play it again instantly in full but it doesn’t seem to work.



PS: When do I use .play and when do I use draw()? and is it correct to play my sounds in my rendering loop or is it ok to play them in the updating loop?

As I understand it, you should be calling draw and update every frame on your sounds just like the visual scenegraph stuff.



I use the newer programmable sound stuff though which has a nice event driven structure.

I’m trying to run the program the way you say it should work and not only do I hear a constant repeating laser sound, but my skybox doens’t look right. What I am doing wrong? It’s HelloIntersection in the CVS.



Basicly, how do I play a sound and play it only once?

I only said that I render and update my sound this way and that I am using the newer sound code. The old SphericalSound stuff is a bit dodgey and I wouldn’t recommend using it. If you want, I’ll rewrite this test of yours to use a newer method.

Please do :slight_smile:

Done. Also fixed up a few other issues related to the SkyBox.

Hi

I have modified HelloIntersection in order to make it work.

Sounds should (almost) always be attached to a SoundNode, so you shouldn’t be using play() that much, the only methods used for playing sounds are SoundNode.updateGeometricState(float, boolean) (in game update) and SoundAPIController.getRenderer().draw(SoundNode) (while redering 3D).

In order to fire events you should use SoundNode.onEvent(int) and not fireEvent.

Hey, I know you’re a busy man and all, but I think it would be neat if other people could use this sound stuff you’re written. I’m trying to document jME and the sound API doesn’t give me much to go on. If you ever have time and could javadoc the important parts of the API I’ld fill in the rest.





PS: How do I make the explosion sound, sound like it is coming from the target it’s hitting?

So you know I am a busy man , and all… 8-O

then no need to remind anyone :x that I am unemployed (again, and looking for a new job) :’(

Knowing that I still want to contribute to that engine even if sometimes I think what I have done could be much better and for sure well documented.

I 'll do my best.

But if You have More time than I have, it would be great for the community to add some documentation. For sure, I can answer all of your questions about the sound part.



PS: For sound coming from the hit object. It is quite like Spatials and nodes.



SoundNode snode=new SoundNode();
ProgrammableSound explosion=new ProgrammableSound();
URL hitURL = HelloIntersection.class.getClassLoader().getResource(
                "jmetest/data/sound/explosion.wav");
int hitid = SoundPool.compile(new URL[] { hitURL });
// Then we bind the programid we received to our explosion event id.
explosion.bindEvent(explosionEventID, hitid);

//to make it coming from target's position
explosion.setPosition(target.getLocalTranslation());
//set the max distance from where you still can hear the sound
explosion.setMaxDistance(100);//the value is not relative to the scene

snode.attachChild(explosion);

I made the changes you suggested. I added the line



programSound.setMaxDistance(25f);



when I first create the programSound and I have



programSound.setPosition(target.getWorldTranslation());



when the bullet hits the target and



programSound.setPosition(cam.getLocation());



When the bullet is fired. I don’t hear it come from any direction though, and it seems like I get backed up on the sound queueing if I go in and out of the 25 while the sound is playing. Much strangness.

Why don’t you create a ProgrammableSound for each sound source, one for the “gun” one for the “target” ?

I made your changes (2 programmable sounds) and still can’t hear my second sound correctly. If you could look at the code and tell me what I’m doing wrong that would be great.



There are just a few basic sound things that I need really:

  1. Make a sound play.
  2. Make a sound play that is softer the farther I am from it.
  3. Make a sound move around me while it is playing.
  4. Be able to stop sounds while they are playing.
  5. Play multiple sounds at once
  6. Hear sounds to my right in the right speaker more than the left.





    Everything else is sugar, but these are the basics any game needs.





    Edit: I had to use explosion.ogg because I can’t hear any .wav files, but can ogg.

Cep21 I have changed a little the event handling…

And tried your HelloIntersection class it is working for me. I can hear sound from left right far away etc.

If it is still not working on your computer please check if the samples are in mono format

How do I make sounds that are farther away sound softer?



When I change the maxDistance to 40, if I fire a bullet and move out of the 40 my explosion sound stops and when I move back into the 40 distance it starts playing again. Is this how it is suppost to work? How do I stop that from happening?

Yes it is how it is supposed to work



When you place a sound at some location in the world, you will have the sound played from that location. When you say that maxDistance is 40 you will virtually draw a sphere from THAT location in the world which size

is 40.

If the camera(listener) is outside of that sphere regarding the world relative coordinates the sound will not be played.

If the listener (or camera) enters that sphere at 40 or 39 units from the sphere’s center the sound will start to play softly, the more the listener approches the center of the sphere the louder the sound will be.



To stop that from happening just call stop() ?!!? or I don’t get your problem!?

My sound isn’t getting any softer. It’s the same level no matter how far I am. I suppose it’s just a me thing.

Have you tried to run the tests in jmetest.sound and approach the boxes,

if the sounds don’t get louder when you approch them it may be something comming from your sound card

As long as it’s working for someone. It’s very hard to tell the difference between coding it wrong and my machine playing it wrong. :frowning:

I’ll try the test when I get back home but I don’t remember them getting softer.