3D Sound System

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

Previous topic - Next topic

JavaMan

QuoteDo you only have the problem after stopping the applet with Esc, or does it also happen if you close the tab while the applet is running?

It happens either way. While the applet is running, if I first press the esc key and then click the x the firefox window just closes.

Also, I tried it on ie, and the same thing happened. Except I had gone to the jpct site in one window clicked on the forums button, (which opened up in a new window) and tried out the applet. When I pressed esc and then closed the applet's window, both the applet's window and the first IE window closed.   ::)

If I just close the tab while the applet is running, firefox locks up, and I have to end it manually through xp's task manager.

Hope this helps.

Jman

raft

i once had implemented moving sounds for karga using java sound. it basicly worked in tests but doesnt sound that good. it then seemed unnecessary to me and i decided not to use it in karga . if it may help i can send post the source.

note; the code has almost no comments. i dont have time to write comments and i dont even remember what i did exactly

paulscode

Sure, I'd like to see your code, raft.  I might find something useful.  I haven't sat down to look at the Javasound stuff much yet, hopefully I will have more time tomorrow.

raft

ok then :) here it is: http://www.aptalkarga.com/download/karga_sound.zip

there are a few other karga classes to compile the source but they are no big deal. Logger is also in download directory.

SoundBank is the top level sound class. it loads the sounds and running sounds instances are created with it
SoundsInfo is the configuration class. dont get fooled when you see all of its fields are final and null. they're filled in externall by jibx. (there is information about this in karga thread)
PointSound is the class which implements moving sounds.
AmbientSound is self explanatory

btw, i correct myself: all of these classes even the PointSound are used in karga at the moment. i simply create PointSound only for main user. in that case source and dest positions are always the same, so it behaves like an AmbientSound

hope this helps,
r a f t

paulscode

#64
Quote from: JavaMan on April 15, 2008, 10:06:28 PM
It happens either way. While the applet is running, if I first press the esc key and then click the x the firefox window just closes.

Also, I tried it on ie, and the same thing happened. Except I had gone to the jpct site in one window clicked on the forums button, (which opened up in a new window) and tried out the applet. When I pressed esc and then closed the applet's window, both the applet's window and the first IE window closed.   ::)

If I just close the tab while the applet is running, firefox locks up, and I have to end it manually through xp's task manager.

Ok, I'd like to try and isolate the problem to see if it is specific to:
a) SoundManager
b) How I'm using jPCT
c) How I'm creating an applet

So I've created a couple more applets I'd like you to run.  The first is the helicopter applet with all the SoundManager stuff commented out:
LINK NO LONGER EXISTS

And the second is an applet without any jPCT, only SoundManager:
LINK NO LONGER EXISTS

JavaMan

Hi,
When I close the tab for the first applet(whether I pressed esc first or not) with just jpct, firefox closes out. I also had a completely different firefox window open to a university site and it closed as well.

On the other hand, the SoundManager only applet works fine. The tab closes out properly.

Jman

paulscode

After making that "No Sound" helicopter applet and running it, I immediately noticed that it is running at quite a bit faster framerate than the one with sound.  That means SoundManager has some significant overhead, which prompted me to think of ways to streamline and optimize.  I took a really close look at the class and how things work, and wrote down a full page of notes on some minor changes I could make to speed things up.  There is one major change I am going to make as well:
    As things are now, in cases where all the sources change position each frame (such as when the camera is moving), the source manager thread is getting woke up every frame to re-sort the list.  Because the source-manager thread calls AL functions (to cull and reactivate sources), it is synchronized with the command thread which also calls AL functions.  The user's game thread is synchronized with the command thread, because the user calls "tick()" every frame to queue commands for moving sources.  THEREFORE the game thread has to potentially wait for the source-manager thread to re-sort the threads list every frame.
    Now I can't think of any way around this three-thread synchronization.  Even if I had absolutely all AL calls running in one thread, all three threads would still need to be synchronized with each other.  For example, when the user says "Play my source", a command must be queued (synchronization between game thread and command thread), then that command has to run by the source-management thread to see if that source is able to play or if it should be culled(synchronization between command thread and source-management thread).  This dependency occurrs regardless of which thread actually plays the source.
    So basically, potentially each frame, the user has to wait to access the command queue, while the the command thread is in the middle of executing the queued "move source" commands, which requires the command queue to wait to access the source list, which the source-management thread is using during the re-sort cycle.  I know, my head is aching, too (did I mention I hate threads?)  :D
    Anyway, I did think of a (really obvious) way to reduce the sort time, which should improve overall performance.  Right now, there is a source map (sources stored by name) and a source list (used for sorting, culling, reactivating).  Since the only purpose of the source list is to play the closest sources, there is no reason for it to contain inactive sources (except for culled looping-sources).  All I need to do is to only put sources into the list when they are playing, then when they finish playing or are stopped, or when non-looping sources are culled, remove them from the list.  That should greatly reduce the time it takes to re-sort the source list (Except in cases where all the sources were looping-sources - there would be no improvement then).
    I did notice another potential problem.  Right now, the user can dynamically change MANAGEMENT_MODEL in their program at any time.  However, this variable is used in the source-management thread, so I need to make sure updating MANAGEMENT_MODEL is done in a synchronized method rather than letting the user acces the varriable directly.  This is true for a couple of other varriables as well.  Easy fix - I just need to make these varriables private and create synchronized "get" and "set" interface methods.

paulscode

#67
Quote from: JavaMan on April 16, 2008, 10:48:40 PM
When I close the tab for the first applet(whether I pressed esc first or not) with just jpct, firefox closes out. I also had a completely different firefox window open to a university site and it closed as well.

On the other hand, the SoundManager only applet works fine. The tab closes out properly.
Hmm.  Slightly different problem, but still there.  That is odd.  Let's see if it is a jPCT issue or an lwjgl issue.  Could you please try this applet which runs in software mode and doesn't use the lwjgl appletloader, and let me know if it also has a problem?
LINK NO LONGER EXISTS

JavaMan

When I close the tab firefox, doesn't close out, so maybe it is lwjgl?

Jman

paulscode

Quote from: JavaMan on April 17, 2008, 12:25:41 AM
When I close the tab firefox, doesn't close out, so maybe it is lwjgl?
Yes, looks like a problem with lwjgl graphics (i.e. hardware mode) running in an applet.

JavaMan

Didn't you have trouble with the applet loader earlier?

Jman

paulscode

#71
Quote from: JavaMan on April 17, 2008, 01:39:52 AM
Didn't you have trouble with the applet loader earlier?
Yes, I did.  I was going to upload a version of the helicopter applet run without the applet loader, but my main pc got hit with a virus this afternoon, and I am in the middle of recovery (typing from one of my test machines at the moment).  I'll post a link after I fix my pc, so we can see if it is specific to the applet loader or lwjgl in general.

-- EDIT --
Never mind, I can't create an lwjgl applet without the appletloader afterall, because you can't control how the browser starts up the JVM (requires argument -Djava.library.path=c:\lwjgl\native\win32 to load the native dll's).  Unless someone else knows how to run a lwjgl applet without the appletloader?

EgonOlsen

What are you doing, when the user presses escape? And about the loader: You always need some stuff that loads the native parts. If not done by the appletloader, you have to write it yourself, which will lead to another applet loader...

JavaMan

#73
QuoteUnless someone else knows how to run a lwjgl applet without the appletloader?

I was reading about it and this page has some information on giving command line arguments to the JVM through the html page.

jdk6.dev.java.net/plugin2/#COMMAND_LINE_ARGS

Jman

EgonOlsen

Quote from: JavaMan on April 17, 2008, 01:07:22 PM
QuoteUnless someone else knows how to run a lwjgl applet without the appletloader?

I was reading about it and this page has some information on giving command line arguments to the JVM through the html page.

jdk6.dev.java.net/plugin2/#COMMAND_LINE_ARGS

Jman
Unfortunately, this new plugin is Firefox3 und IE7 only. It doesn't work in Firefox2, which will still offer the old plugin only.