3D Sound System

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

Previous topic - Next topic

fireside

Does the midi stuff take up much memory?  I was looking for something small, definitely, but midi music is super efficient for memory space.
click here->Fireside 7 Games<-

paulscode

#211
Cutting out the MIDI stuff from SoundSystemSmall was because of performance issues, not memory concerns.

MIDI is processed by Javasound.  Problem is, Javasound seems to (poorly) handle MIDI events and audio clip playback from a single thread, and because of this, whenever the thread is busy processing MIDI events, any playing audio clips skip.

In SoundSystem, MIDI only works well when OpenAL is the active library.  This allows Javasound to focus entirely on MIDI, while OpenAL handles all other audio playback.

Therefore, I removed MIDI support from SoundSystemSmall because OpenAL was removed.  I may go back at some point to see if I can get both MIDI and normal audio to play smoothly at the same time in Javasound, but for now there was no point in including MIDI support.  The small file size of MIDI music is useless if it can't be played at the same time as other sound effects.

fireside

OK, I'll probably use the larger library, then.  Have to see how things work out of course.  By the way, that code for the exact position of collision works great, so thanks a lot.  Gave me a great start on this game. 
click here->Fireside 7 Games<-

paulscode

I'll give MIDI another look tomorrow.  Maybe I'll see something I missed before.

paulscode

SoundSystemJPCT for new jPCT release.

JAR  (Source Code)

Removed the temporary work-around for the camera up-vector bug in the last version of jPCT.

EgonOlsen


paulscode

I've been on the edge of my seat waiting for the next release of jPCT  :D

JK, it was only one line of code I had to comment out.

paulscode

I have been informed of a new bug today.  Sometimes if an exception is thrown anywhere in a program (sometimes even if it is caught) before OpenAL has finished initializing, the OpenAL initialization times out, and SoundSystem automatically switches to JavaSound.  At the moment I have no idea what is causing this, but I am looking into it.  I always have trouble tracking down these "sometimes" bugs, since they can be difficult to replicate.  It is not a major problem, but one I'd like to eliminate if possible.  I'll post an update if I can figure out what's causing this to happen.

paulscode

I was able to replicate the problem, and I tracked it to the line of code:

AL.create()

Turns out it is not actually an infinite loop as I feared.  Instead, what seems to be happening is that this method gets called, and then if an exception occurs before it finishes, it takes several seconds longer to finish.  Very strange.  I don't see anything that I can do to prevent this from happening, as this appears to be an issue with OpenAL and not with my code.  I will just increase the length of time that SoundSystem waits for OpenAL to load before it gives up and switches to JavaSound (or throws a SoundSystemException if using the second constructor).  I'll post the update when I have time to FTP everything.

fireside

You haven't found any way of using the small version with midi have you?  Would it be risky to use another thread? 
click here->Fireside 7 Games<-

paulscode

I tried using a seperate thread (the MidiThread class), but it didn't improve the performance.  I think JavaSound is still running the MIDI events and audio mixing on a single thread that I have no control over.  Come to think of it, I should probably remove the MidiThread class since it didn't help at all.  I haven't had a lot of time to look at this again.  I'll try and spend some time looking into the problem this weekend.  What I would REALLY like to do is write my own synthesizer to play MIDI into an AudioInputStream context, so that MIDI files could be used like any other format rather than playing through that crappy JavaSound midi event interface.  I wasn't able to find a non-GPL library to use, but I'll search around again and see if I can find one.  I may end up just studying the source code for the GPL one to figure out what they are doing, and learn how to write my own synthesizer (not using the original source code), and therefore not be bound by the GPL license.

fireside

It might end up being the same size, though.  I suppose I get a little carried away with file size, but I like a small game that does a lot.  I might could skip music and use the small one.  It's a ways off, anyway.
click here->Fireside 7 Games<-

paulscode

I just now noticed a problem when playing a MIDI file in SoundSystem vs. playing it in a seperate player.  Sounds as if two instances of the file are playing simultaneously with a slight phase shift between them  ???  I hadn't noticed the problem before, since I hadn't actually played the test file in a seperate player, so I thought that is how it was supposed to sound.  There's most likely a bug in my code somewhere that I haven't noticed.  If the file is somehow being processed twice, it could be leading to the hang-up problem if JavaSound is having to work double-time (not to mention the conflicts that could occur due to the fact that only one MIDI output should be possible at one time on a given synthesizer).  I'll see if I can track down what is causing this double-playing.  I'll keep my fingers crossed that solving this will also solve the other problem.   :-X

paulscode

I fixed the "phase shift" problem, and that also solved the skipping but it didn't fix the hang-up problem.  I uploaded a demo applet to demonstrate.  It is just a modified version of the player applet I wrote a while back:

http://www.paulscode.com/demos/SoundSystem/23DEC2008/

To replicate the problem, start up the MIDI music, and then play one of the sound effects over and over again for a while (not too fast or you won't be able to hear what's going on).  You will see that randomly the sound effect will sometimes take up to a second or more from the time you press the button to when it actually plays.  Turn off the MIDI music, and the hang-up problem goes away.

I'm going to do some more work on this to see if I can somehow solve this problem, but if not, I'm affraid MIDI is just not ever going to be useful when using JavaSound to play other sound effects at the same time.

fireside

It wasn't working on my computer for some reason, it just kept scrolling.  What about streaming as opposed to keeping it in memory?  I'm pretty sure I've played java games that had music and sound effects.
click here->Fireside 7 Games<-