That works flawlessly. Oggs are decoded into a Clip (thus in ram) and playback is therefore instantly. However, the first time a sound is played there is a little delay, because the default mixer needs to be created (that delay should be removed by creating a mixer yourself).

If there are ~10 samples overlapping played at the same time the framerate goes also down by ~50%. But my machine is rather old (500mhz) and the framerate is approximative capped at somewhat over 60fps (in 5msec sleep steps - with my pc sleep is set to 15msec).

So it wouldn't be a problem with better timing and a maximum of let's say 8 sounds at the same time - even with a pc crappy as mine

oNyx, I tried using your suggestions to load ogg files for myself, and I can get the file to load and play now, but it sounds nothing like it's supposed to. Windows Media Player plays the sound fine, but when I use the code you suggested, it sounds like I've lost all the quality. Instead of a "boom" sound I get a "scratch" sound. Any idea what I might be doing wrong? I'm using all the code you suggested in this thread, except my decodeOgg() method looks like this:

publicbyte[] decodeOgg(InputStreaminput)throwsIOException{ByteArrayOutputStreambytearrayoutputstream = newByteArrayOutputStream();intconvsize=4096*2;byte[] convbuffer=newbyte[convsize]; // take 8k out of the data segment, not the stack

Infovi=newInfo(); // struct that stores all the static vorbis bitstream settingsCommentvc=newComment(); // struct that stores all the bitstream user commentsDspStatevd=newDspState(); // central working state for the packet->PCM decoderBlockvb=newBlock(vd); // local working space for packet->PCM decode

byte[] buffer;intbytes=0;

// Decode setup

oy.init(); // Now we can read pages

while(true) { // we repeat if the bitstream is chainedinteos=0;

// grab some data at the head of the stream. We want the first page// (which is guaranteed to be small and only contain the Vorbis// stream initial header) We need the first page to get the stream// serialno.

// Get the first page.if(oy.pageout(og)!=1) {// have we simply run out of data? If so, we're done.if(bytes<4096)break;

// error case. Must not be Vorbis dataSystem.err.println("Input does not appear to be an Ogg bitstream.");System.exit(1); }

// Get the serial number and set up the rest of decode.// serialno first; use it to set up a logical streamos.init(og.serialno());

// extract the initial header from the first page and verify that the// Ogg bitstream is in fact Vorbis data

// I handle the initial header first instead of just having the code// read all three Vorbis headers at once because reading the initial// header is an easy way to identify a Vorbis bitstream and it's// useful to see that functionality seperated out.

// At this point, we're sure we're Vorbis. We've set up the logical// (Ogg) bitstream decoder. Get the comment and codebook headers and// set up the Vorbis decoder

// The next two packets in order are the comment and codebook headers.// They're likely large and may span multiple pages. Thus we reead// and submit data until we get our two pacakets, watching that no// pages are missing. If a page is missing, error out; losing a// header page is the only place where missing data is fatal. */

if(result==1) {os.pagein(og); // we can ignore any errors here// as they'll also become apparent// at packetoutwhile(i<2) {result=os.packetout(op);if(result==0)break;if(result==-1) {// Uh oh; data at some point was corrupted or missing!// We can't tolerate that in a header. Die.System.err.println("Corrupt secondary header. Exiting.");System.exit(1); }vi.synthesis_headerin(vc,op);i++; } } }// no harm in not checking before adding moreindex=oy.buffer(4096);buffer=oy.data;try {bytes=input.read(buffer, index, 4096); }catch(Exceptione) {System.err.println(e);System.exit(1); }if(bytes==0 && i<2) {System.err.println("End of file before finding all Vorbis headers!");System.exit(1); }oy.wrote(bytes); }

// OK, got and parsed all three headers. Initialize the Vorbis// packet->PCM decoder.vd.synthesis_init(vi); // central decode statevb.init(vd); // local state for most of the decode// so multiple block decodes can// proceed in parallel. We could init// multiple vorbis_block structures// for vd here

float[][][] _pcm=newfloat[1][][];int[] _index=newint[vi.channels];// The rest is just a straight decode loop until end of streamwhile(eos==0) {while(eos==0) {intresult=oy.pageout(og);if(result==0)break; // need more dataif(result==-1) { // missing or corrupt data at this page positionSystem.err.println("Corrupt or missing data in bitstream; continuing..."); }else {os.pagein(og); // can safely ignore errors at// this pointwhile(true) {result=os.packetout(op);

// **pcm is a multichannel float vector. In stereo, for// example, pcm[0] is left, and pcm[1] is right. samples is// the size of each channel. Convert the float values// (-1.<=range<=1.) to whatever PCM format and write it out

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org