views:

22

answers:

2

The libraries I founded so far only have methods to decode from a file or InputStream, I have a ByteBuffer with ogg vorbis data and I need it decoded to PCM without having to write it to a file first.

+2  A: 

There seem to be 2 parts to this problem. 1) Getting Java Sound to deal with OGG Vorbis format. 2) Avoiding the File.

For (1), the Java Sound API allows the addition of extra formats via the Service Provider Interface. The idea is to put an encoder/decoder into a Jar and use a standard path and format of file to identify the class that does the encoding/decoding.

For (2), it is simply a matter of supplying an InputStream and required AudioFormat to the relevant methods of the AudioSystem static functions. E.G. (Pseudo code..)

byte[] b = byteBuffer.array();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
InputStream is = new InputStream(bais);
AudioInputStrream aisOgg = AudioSystem.getAudioInputStream(is);        
AudioInputStrream aisPcm = AudioSystem.
    getAudioInputStream(pcmAudioFormat, aisOgg);
Andrew Thompson
oh I didn't knew I could create a inputstream from a bytearray thanks, but I really only had 1 problem, the pcm is going directly to openal, java spi won't touch it.
Anon
A: 

You can use ByteArrayInputStream which is a subclass of InputStream. If your stream is very large you probably will have to write to file.

Dave