3D Sound System

Started by paulscode, March 11, 2008, 02:38:51 AM

Previous topic - Next topic

JavaMan

Hi, I tried out the applet. It looks cool all those cubes flying around. :o Is the applet supposed to play sound? I don't hear anything.

Jman

EgonOlsen

Me neither. Boxes yes, sound no. This is on a (quite crappy) Dell machine with some SoundMAX onboard sound. The console doesn't print out anything helpful either... ???

JavaMan

I'm using a Dell with a SoundMax onboard card as well.

Jonas

Hi

Works fine for me -> soundblaster live!

Cool stuff.. ;D
Simple things should be simple, complex things should be possible - Alan Kay

EgonOlsen

#19
It kinda works on the EEEPC...the 3d effect is working, but the sounds are all broken. Then again, this happens with all OpenAL stuff on this machine, so i wouldn't worry too much about it.
I should really test it on a "real" PC, but i'm too lazy to boot it right now... ;D

paulscode

I ran some tests on a few of my other machines, and found a laptop that the sound doesn't play on either.  I am going to get on the lwjgl forums and see if I can find out anything about this.  I let you know what I learn.  Thanks for the feedback!

Kearnan

#21
Fun applet.  It worked fine and the sound was great (weird and fun) but great!  Nice job.  Note: Using the Realtek AC'97 audio that came with my Asus Motherboard (basic sound stuff)  Sound was fine, 3D and all.

paulscode

#22
I have been looking into the no-sound problem occurring on some machines, and I believe the problem is not related to OpenAL.  It seems to only be an issue with the lwjgl AppletLoader natives jar's.  When running the exact same code in an application using the natives dll's instead, it works perfectly (at least on the test laptop where I experienced this issue).  Here is a link to the Source Culling demo in an application:
LINK NO LONGER EXISTS

It would be great if those of you who were not hearing any sound could run the application and see if it works.  I am currently writing a couple of bare-bones example sourcecodes to post on the lwjgl forum and ask about this issue.  For now it doesn't seem there is much I can do, as this appears to be an lwjgl issue.

I am continuing to clean up the SoundManager class.  I have noticed an exception that is randomly getting thrown when playing a source.  It seems to happen only once, when the program first starts running, then never again afterwards.  It shows up on the Java console as an exception in method SoundManager.play() line 1015.  It seems to occurr more often on the laptop than on my main computer.  It could be related to an insufficient number of voices available on the sound card and OpenAL culling some without telling me.  I am looking into this problem as well.  For now I am just catching the exception and ignoring it, until I can figure out what is causing the error and how to correct it.

One other Exception is a null Pointer exception in paint() line 212.  I know what is causing this (simple logic error), and will have it corrected in the next SoundManager demo.

JavaMan

Hi, I tried it out. The sound works in the app.

QuoteOne other Exception is a null Pointer exception in paint() line 212.  I know what is causing this (simple logic error), and will have it corrected in the next SoundManager demo.
I'm not sure if this is right, but, judging from the output, I think the problem with the paint could be you are trying to paint to the Canvas and the framebuffer is still being loaded?  ::) So, the Canvas isn't in the frame yet. Just a suggestion.

Anyways, the sound comes through clean. It sounds like a battleground.

Jman


paulscode

Quote from: JavaMan on March 30, 2008, 12:38:44 PM
I'm not sure if this is right, but, judging from the output, I think the problem with the paint could be you are trying to paint to the Canvas and the framebuffer is still being loaded?  ::) So, the Canvas isn't in the frame yet.

Thanks, that is a good thing to remember.  However in this case, the "Null Pointer" in question is the SoundManager object, not the Canvas.  This problem is a result of an ugly hack I made to overcome the problem of not being able to play a sound from an applets "init()" method.  The reason you are also seeing it in the application is that I coppied and pasted the code from the applet, and just changed jApplet to jFrame and added a main method.

The error is in this ugly "run once" loop I created to make all the sounds start playing at different times:

        if( runOnce )
        {
            // Play the sounds:
            for( int x = 0; x < OBJECT_COUNT; x++ )
            {
                soundManager.play( "sound_" + x );  // <<-------------EXCEPTION ON THIS LINE
                try
                {
                    // Sleep for a bit, so we dont peg the CPU:
                    Thread.sleep( 1000 / OBJECT_COUNT );
                } catch( Exception e ){}
            }
            runOnce = false;
        }

(In case you were wondering, this loop is also why there is a one-second pause before the graphics start drawing)

The reason for the exception, is that apparently "paint()" gets called from a seperate thread.  Therefore, it tries to access the SoundManager object before it is fully instantiated.  The reason you only see the exception once (or a couple of times on a slower cpu), is that after sleeping a bit at the end of the loop, the SoundManager finished being created, and is no longer null.  (This is quite obvious in retrospect).

Now obviously the "paint()" method is NOT the right place to be doing this anyway (really dumb hack on my part).  The correct way to do this is to get rid of that "run once" stuff, remove the loop from the "paint()" method, and stick it at the top of the method that runs the main game loop after creating the Sound Manager (so both are on the same thread).

At any rate, the next demo I make won't have this problem.

JavaMan

Ok, that makes sense.

Quote
Now obviously the "paint()" method is NOT the right place to be doing this anyway (really dumb hack on my part).  The correct way to do this is to get rid of that "run once" stuff, remove the loop from the "paint()" method, and stick it at the top of the method that runs the main game loop after creating the Sound Manager (so both are on the same thread).

I agree, but then again its just a demo program.  ;)

Jman




paulscode

As my computer programming instructor used to say, "There are two ways to solve every problem.  There's the right way, and then there's Paul's way". ;D  I tend to think outside the box a little too much, and sometimes that results in problems like this one.

paulscode

I have posted some questions about applets vs. applications on the lwjgl forums, so I am just waiting for a response before I can provide more information about that issue.  In the mean time, I have been tackling the other things that SoundManager needs fixed.  Operating on the assumption that the exception showing up randomly is related to OpenAl running out of channels and quietly culling sources, I added in some checks in the "new source" method, and a couple of other places, that dynamicly change the value for maximum source number based on available voice channels.  So far I have not gotten the exception in any of my tests, so I believe that problem is now fixed.  I have also located the logic error that was making the SoundManager forget which sources were playing before being culled, so I have removed that temporary hack, and the SoundManager now behaves exactly the way it should.  One final thing I am adding is "priority sources".  These sources will not be subject to culling based on distance (such as background music).

So at this point, this project is nearly complete.  The next release should be perfectly functionable in just about any project (although probably more compatible if used in applications than if used in applets).  Only restriction is you need to keep the number of active sound sources to 500 or less at any given time.  I am just waiting on the verdict from the lwjgl forums before I release the source.  I am going to do a bit of streamlining and commenting in the meantime.

Just so I have something to do, I am considering rewriting another SoundManager completely from scratch, using a different approach.  In the current SoundManager, the whole focus is on sources, and culling or reactivating them based on distance from listener.  I want to try a different approach, focused on soundcard voice channels rather than on sources.  In this new approach, I would set up all the active channels I could when the sound manager is created.  Then when a source requests to play, it will play on the next available channel.  If no channels are open, it will not play, and if it is a looping source, it will wait for a channel to open up.  Calling "play()" will not actually play the sound, it will just set a flag telling SoundManager that the user requested to play the sound.  Then on a seperate thread, the Sound Manager will sort the sounds by distance, then go down the list and start playing as many as it can on the available channels.

The whole point of making another SoundManager would be just to see which method is faster and can handle more sources.  If the new SoundManager works better, I will discard the old one and release the new one.  If not, at least it will be good programming practice  ;D

paulscode

Update on the lwjgl appletloader sound issue.

First of all, I loaded up two ratty old dell notebooks I had in storage, and both experience the same no-sound issue for my applet.  So that makes 3 out of my 6 test machines that experience the problem. :o

I have been having a long discussion on the lwjgl forums, and today I got a link to an applet written by "javalwjgl".  He is using the lwjgl binding of OpenAL, and the applet is being loaded with the appletloader:

http://kappa.javaunlimited.net/betashot/betashot.html

The sound for it works on my problem laptops.  So this would seem to indicate that the problem is correctable, and I am doing something incorrectly in my Java code, the html code, and/or which jar's I am loading.  I just need to figure out what he did differently with his applet, and figure out how to incorporate that change into mine.

fireside

Cool game, but why did I get a warning at the start?  I thought that got fixed somehow with the applet loader?  I didn't get a warning on your applet.
click here->Fireside 7 Games<-