com.jme.sound.openAL.objects.util
Class OggInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bycom.jme.sound.openAL.objects.util.JMEAudioInputStream
              extended bycom.jme.sound.openAL.objects.util.OggInputStream

public class OggInputStream
extends JMEAudioInputStream

Decompresses an Ogg file.

How to use:
1. Create OggInputStream passing in the input stream of the packed ogg file
2. Fetch format and sampling rate using getFormat() and getRate(). Use it to initalize the sound player.
3. Read the PCM data using one of the read functions, and feed it to your player.

OggInputStream provides a read(ByteBuffer, int, int) that can be used to read data directly into a native buffer.


Field Summary
static int FORMAT_MONO16
          The mono 16 bit format
static int FORMAT_STEREO16
          The stereo 16 bit format
 
Fields inherited from class com.jme.sound.openAL.objects.util.JMEAudioInputStream
INVALID_OGG_MESSAGE
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
OggInputStream(java.io.InputStream input)
          Creates an OggInputStream that decompressed the specified ogg file.
 
Method Summary
 int available()
          Returns 0 after EOF is reached, otherwise always return 1.
 int getAudioChannels()
           
 int getChannels()
           
 int getFormat()
          Gets the format of the ogg file.
 com.jcraft.jorbis.Info getInfo()
           
 float getLength()
           
 int getRate()
          Gets the rate of the pcm audio.
static void main(java.lang.String[] args)
          Tests this class by decoding an ogg file to a byte buffer.
 boolean markSupported()
          OggInputStream does not support mark and reset.
 int rate()
           
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data from the input stream into an array of bytes.
 int read(java.nio.ByteBuffer b, int off, int len)
          Reads up to len bytes of data from the input stream into a ByteBuffer.
 void reset()
          OggInputStream does not support mark and reset.
protected  void setLength(float time)
           
 long skip(long n)
          Skips over and discards n bytes of data from the input stream.
 java.lang.String toString()
          Gets information on the ogg.
 
Methods inherited from class com.jme.sound.openAL.objects.util.JMEAudioInputStream
getFileName, setFileName
 
Methods inherited from class java.io.FilterInputStream
close, mark, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FORMAT_MONO16

public static final int FORMAT_MONO16
The mono 16 bit format

See Also:
Constant Field Values

FORMAT_STEREO16

public static final int FORMAT_STEREO16
The stereo 16 bit format

See Also:
Constant Field Values
Constructor Detail

OggInputStream

public OggInputStream(java.io.InputStream input)
               throws java.io.IOException
Creates an OggInputStream that decompressed the specified ogg file.

Method Detail

getFormat

public int getFormat()
Gets the format of the ogg file. Is either FORMAT_MONO16 or FORMAT_STEREO16


getRate

public int getRate()
Gets the rate of the pcm audio.


read

public int read()
         throws java.io.IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException

read

public int read(java.nio.ByteBuffer b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from the input stream into a ByteBuffer.

Specified by:
read in class JMEAudioInputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Returns 0 after EOF is reached, otherwise always return 1.

Programs should not count on this method to return the actual number of bytes that could be read without blocking.

Returns:
1 before EOF and 0 after EOF is reached.
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
OggInputStream does not support mark and reset. This function does nothing.

Throws:
java.io.IOException

markSupported

public boolean markSupported()
OggInputStream does not support mark and reset.

Returns:
false.

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data from the input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException

toString

public java.lang.String toString()
Gets information on the ogg.


main

public static void main(java.lang.String[] args)
Tests this class by decoding an ogg file to a byte buffer.


getInfo

public com.jcraft.jorbis.Info getInfo()

getChannels

public int getChannels()
Specified by:
getChannels in class JMEAudioInputStream

rate

public int rate()
Specified by:
rate in class JMEAudioInputStream

getAudioChannels

public int getAudioChannels()
Specified by:
getAudioChannels in class JMEAudioInputStream

setLength

protected void setLength(float time)
Specified by:
setLength in class JMEAudioInputStream

getLength

public float getLength()
Specified by:
getLength in class JMEAudioInputStream