Sound

Hi guys,

I´m trying to put sound in my game basing my code on SoundTestJavaSound. This eaxample runs fine but my code that is basically the same code doesn’t work.
Any ideas why?


        soundDriver = new SoundDriverImpl();
        soundDriver.setListenerVolume(1f);
        env.getView().setSoundDriver(soundDriver);
        
        MediaContainer mcWalk = new MediaContainer("src/Sounds/walk.ogg");
//        MediaContainer mcWalk = new MediaContainer(demoFolder.getResource("sounds/birds.ogg"));
        Sound sWalk = new BackgroundSound(mcWalk, 1);
        sWalk.setEnable(true);
        sWalk.setLoop(Sound.INFINITE_LOOPS);
        scene.addChild(sWalk);

Even if i try to use the sound from the test it doesn’t work.

Rafael

I think that for some reason it is not initializing cuz when i run the test it prints


JavaSound sound driver initialized with 61 availble sources
starting frame speed test
Init file...
convsize = 20480
buffer is size=248576, freq=8000, formatMONO16
Init file...
convsize = 10240
buffer is size=115968, freq=11025, formatSTEREO16

and when i run it in my game it only prints the first line

Hi,

Does the sample that works also work if you compile it in your environment? (I mean Xith3D version etc.)

Yuri

Yes Yuri

Another thing…

When i put a non existent file on MediaContainer in the test i get a error.


        MediaContainer mc2 = new MediaContainer("src/Sounds/walk.ogg"); // this file don't exist
        Sound sound2 = new BackgroundSound(mc2, 1);
        sound2.setEnable(true);
        sound2.setLoop(Sound.INFINITE_LOOPS);
        tf_2.addChild(sound2);

then i get this exception


java.io.FileNotFoundException: src\Sounds\walk.ogg (O sistema não pode encontrar o caminho especificado)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at com.xith3d.sound.loaders.OggLoader.load(OggLoader.java:180)
        at com.xith3d.scenegraph.MediaContainer.getSoundContainer(MediaContainer.java:112)
        at com.xith3d.sound.SoundProcessor.process(SoundProcessor.java:171)
        at com.xith3d.sound.SoundProcessor.processAll(SoundProcessor.java:268)
        at com.xith3d.render.Renderer.renderOnce(Renderer.java:421)
        at com.xith3d.render.Renderer.renderOnce(Renderer.java:448)
        at com.xith3d.render.Renderer.renderOnce(Renderer.java:463)
        at com.xith3d.scenegraph.VirtualUniverse.renderOnce(VirtualUniverse.java:158)
        at com.xith3d.scenegraph.View.renderOnce(View.java:593)
        at org.xith3d.render.base.Xith3DEnvironment.render(Xith3DEnvironment.java:785)
        at org.xith3d.render.loop.RenderLoop.invokeRendering(RenderLoop.java:640)
        at org.xith3d.render.loop.RenderLoop.loopIteration(RenderLoop.java:656)
        at org.xith3d.test.sound.SoundTesteJavaSound.loopIteration(SoundTesteJavaSound.java:161)
        at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:775)
        at java.lang.Thread.run(Thread.java:595)

But when i do the same thing with my code it runs without exception.
Do you think thta the problem is that it’s not reading the file?

I don’t have too much experiences with Sound. So I’m not of very much help. I could dig into the code to find it out, but it’s not cleverer than if you’d do that.

But it would definitely help some people (including me) if you’d translate the error message ;).

Marvin

I think you refer to this line

it says "The system could not find the specified path

When i try to force this exception in my code it does not appear.

Hi,

Something is definitely wrong in scene creation or initialization (say, if Sound is under “off” switch it will not play.

Can you post complete example that does not work? (explanation: I have Sound nodes working fine in my app using up-to-date CVS version of Xith3D)

Yuri

Hi Yuri,

I have just refreshed my cvs and it still doesn’t work

I’ll send you my code so you can take a better look and test the sound yourself

http://rapidshare.com/files/697800/ChemistryGame.rar.html

The sound is started in line 405

Rafael

I’m taking a look at it (having been studying a bit sound in Xith recently).

Some comments on your code :
line 386 : use Material.AMBIENT, not mat.AMBIENT
line 405 : typo, rename “urlWlak” to “urlWalk”
line 405 : path you provided is “Sounds/walk.ogg” but I see no folder sounds. I changed it to “walk.ogg”
same comments on path on line 196 and 199 (loading of Sala.ASE)
(I finally had to re-create the whole directory structure)
whole code : it’s a good habit to conform to standard Java coding conventions. A slight “Esc-Ctrl-F” in Eclipse does most of the work for you.

I’m having an ASE loading problem (texture). I’m working on that.

Coming soon with more news.

Textures do work now I’ll commit the AseMaterial changes.

Line 602 getDistance() is deprecated, so use getMinimumDistance() instead.

TODO for static geometry loaders : makes them use display lists (as implemented in PrecomputedAnimatedModel).

Amos those paths are there. It’s working for me like this. Maybe this is because i’m using netbeans.

How do i do that?

Thanks for the help

Rafael

Possibly they disappeared when you made the .rar archive… or the open-source linux rar extractor doesn’t re-create the file hierarchy

You just have to ask ^^ I’ll do that when I have time.

You’re welcome.

Another tip : if you can modify your scene, then use textures instead of meshes to display text on your cylinders. It will be 2x faster. (Text is a heck lot of polys).

Thank you very much ;D

Sure, i’ll modify it for textures now.

Does the sound work for you Amos?

Rafael

Done for the ASE loader, I’ll now test and commit.

It’s really valuable.

No but I haven’t debugged it yet… I considered performance and correct file loading in your game to be more important than sound… But wait once I have included Yuri’s faster texture loading in the toolkit I’ll debug your sound problem.

Isn’t it better to include it into the existing TextureLoader?

Hi,

[quote]Isn’t it better to include it into the existing TextureLoader?
[/quote]
I guess he is intergating it with existing texture loader.

But in the meantime I plan to play a bit with even better loading which may theoretically utilize some features of the driver.

…but for this I guess we will need something like a “lazy texture loading” which will run on Rendering thread (i.e. within the context of GLCanvas.display(…)

Yuri

I’ll check the cvs now

Got a big boost of performance without Text2D

Sure it is.

Rafael

Exactly so. Marvin, I’m surprised you thought me dumb enough not to take this opportunity ;D ;D ;D

Well good luck.