Author Topic: 3D Sound System  (Read 296059 times)

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: 3D Sound System
« Reply #210 on: November 16, 2008, 06:41:47 pm »
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<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #211 on: November 16, 2008, 07:38:06 pm »
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.
« Last Edit: November 16, 2008, 07:42:56 pm by paulscode »

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: 3D Sound System
« Reply #212 on: November 16, 2008, 11:57:47 pm »
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<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #213 on: November 17, 2008, 12:59:44 am »
I'll give MIDI another look tomorrow.  Maybe I'll see something I missed before.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #214 on: November 26, 2008, 11:23:11 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 3D Sound System
« Reply #215 on: November 26, 2008, 11:35:31 pm »
Now that was fast... ;D

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #216 on: November 26, 2008, 11:56:00 pm »
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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #217 on: December 16, 2008, 01:47:26 am »
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.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #218 on: December 16, 2008, 04:28:04 am »
I was able to replicate the problem, and I tracked it to the line of code:

Code: [Select]
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.

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: 3D Sound System
« Reply #219 on: December 17, 2008, 09:43:10 pm »
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<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #220 on: December 18, 2008, 01:14:24 am »
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.

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: 3D Sound System
« Reply #221 on: December 18, 2008, 02:21:20 am »
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<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #222 on: December 18, 2008, 02:33:05 am »
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

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 3D Sound System
« Reply #223 on: December 24, 2008, 02:00:48 am »
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.

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: 3D Sound System
« Reply #224 on: December 24, 2008, 05:07:34 am »
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<-