Ok Malokhan,
I’ve uploaded the new version of GAGESound that allows you to work with OGG files. I haven’t completely tested it though, so you’re going to have to be my guinea piggy. Don’t you feel special.
You can download the new version from:
http://java.dnsalias.com/downloads/gagesound-1.2.zip
Note that this is different from the file available on the main page. Let me know if it works for you.
Now keep in mind that while the WaveEngine should now be able to load OGG files, it can only do so when the JOrbis SPI plugin is present. Also keep in mind that it will load the complete decoded clip into memory! i.e. You can save on the size of your download, but don’t expect to save on your memory footprint!
Streaming OGG music is a bit easier. I don’t recommend the music engine for this, but rather that you simply load the file and play the bytes like this:
import java.io.*;
import javax.sound.sampled.*;
public class Test
{
public static void main(String[] args) throws Exception
{
File file = new File(args[0]);
AudioFileFormat aff = AudioSystem.getAudioFileFormat(file);
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioInputStream din = null;
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false);
din = AudioSystem.getAudioInputStream(decodedFormat, in);
rawplay(decodedFormat, din);
in.close();
}
private static SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException
{
SourceDataLine res = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
res = (SourceDataLine) AudioSystem.getLine(info);
res.open(audioFormat);
return res;
}
private static void rawplay(AudioFormat targetFormat, AudioInputStream din) throws IOException, LineUnavailableException
{
byte[] data = new byte[4096];
SourceDataLine line = getLine(targetFormat);
line.start();
int nBytesRead = 0, nBytesWritten = 0;
while (nBytesRead != -1)
{
nBytesRead = din.read(data, 0, data.length);
if (nBytesRead != -1) nBytesWritten = line.write(data, 0, nBytesRead);
}
line.drain();
line.stop();
line.close();
din.close();
}
}
You should be able to rework that to make it stream a little better. If you’re using applications instead of Applets, I’d actually suggest decoding the data to disk, then memory mapping the data to a ByteBuffer. Just pump the data from a ByteBuffer into a SourceDataLine, and everything should work great. If you don’t have that luxury, then I suggest keeping in mind that Vorbis files will reduce your usable CPU cycles, and that it may only be workable on faster machines.
Any questions?