GAGE sound and writing a basic sound player

I took a look at GAGE, thanks jbanes! It mentions calling the render method often. I’ve been thinking about playing audio, writing my own small audio player class as well. My question is - How do I roughly design such a thing?

I know an average computer (400Mhz) can play an mp3 without taxing the cpu. The only thing I can come up with is using a thread to keep the audio stream going. My limited experience with threads is that even putting in a Thread.yield(), I’m going to use 100% CPU time.

I want to have a very good idea that my audio is taking up, say 9% of the CPU. Obviously, the system its running on may use less or more, but I want a ball park to know how much CPU I’ll have left for doing other ‘stuff’.

What approach can you use so that the java app isn’t sucking up the cpu, just to play the audio?

I’d prefer to not have to rely on external native timing libraries, but if thats what needs to be done, so be it.

Suggestions?

Dr. A>

Use Thread.sleep(long millis) instead of Thread.yield(). You wan’t to adjust the time you sleep with the size of your buffer. Have a look at OggPlayer.playInNewThread(long updateIntervalMillis) for an example.