APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.backends.lwjgl.audio

public Class OggInputStream

extends InputStream
Class Inheritance
Imports
java.io.IOException, .InputStream, java.nio.Buffer, .ByteBuffer, .ByteOrder, org.lwjgl.BufferUtils, com.badlogic.gdx.Gdx, com.badlogic.gdx.utils.GdxRuntimeException, .StreamUtils, com.jcraft.jogg.Packet, .Page, .StreamState, .SyncState, com.jcraft.jorbis.Block, .Comment, .DspState, .Info

An input stream to read Ogg Vorbis.
Author
kevin

Field Summary

Modifier and TypeField and Description
pack-priv boolean
bigEndian

The true if we should be reading big endian

pack-priv byte[]
buffer

Temporary scratch buffer

private static final int
pack-priv int
bytes

The number of bytes read

private Comment
comment

The comment read from the OGG file

private byte[]
convbuffer

The buffer used to read OGG file

private int
convsize

The conversion buffer size

private DspState
dspState

The Vorbis DSP stat eused to decode the OGG

pack-priv boolean
endOfBitStream

True if we're reached the end of the current bit stream

private boolean
endOfStream

True if we're at the end of the available data

pack-priv boolean
inited

True if we're initialise the OGG info block

private InputStream
input

The stream we're reading the OGG file from

private Info
oggInfo

The audio information from the OGG header

private Packet
packet

The current packet page

private Page
page

The current OGG page

private ByteBuffer
pcmBuffer

The byte array store used to hold the data read from the ogg

private int
readIndex

The index into the byte array we currently read from

private StreamState
streamState

The Vorbis Stream State used to decode the OGG

private SyncState
syncState

The Vorbis SyncState used to decode the OGG

private int
total

The total number of bytes

private Block
vorbisBlock

The OGG block we're currently working with to convert PCM

Constructor Summary

AccessConstructor and Description
public
OggInputStream(InputStream
The input stream from which to read the OGG file
input
)

Create a new stream to decode OGG data

public
OggInputStream(InputStream
The input stream from which to read the OGG file
input
,
OggInputStream
The stream instance to reuse buffers from, may be null
previousStream
)

Create a new stream to decode OGG data, reusing buffers from another stream.

Method Summary

Modifier and TypeMethod and Description
public boolean
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

public int
public int

Returns:

The number of the bytes on the stream
getLength
()

Get the number of bytes on the stream

private boolean

Returns:

True if there was a page available
getPageAndPacket
()

Get a page and packet from that page

public int
private void
init()

Initialise the streams and thread involved in the streaming of OGG data

private void
initVorbis()

Initialise the vorbis decoding

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[] b, int off, int len)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public int
read(byte[] b)

Overrides java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b.

private void
readPCM()

Decode the OGG file as shown in the jogg/jorbis examples

Inherited from java.io.InputStream:
markmarkSupportednullInputStreamreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

bigEndianback to summary
pack-priv boolean bigEndian

The true if we should be reading big endian

bufferback to summary
pack-priv byte[] buffer

Temporary scratch buffer

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
bytesback to summary
pack-priv int bytes

The number of bytes read

commentback to summary
private Comment comment

The comment read from the OGG file

convbufferback to summary
private byte[] convbuffer

The buffer used to read OGG file

convsizeback to summary
private int convsize

The conversion buffer size

dspStateback to summary
private DspState dspState

The Vorbis DSP stat eused to decode the OGG

endOfBitStreamback to summary
pack-priv boolean endOfBitStream

True if we're reached the end of the current bit stream

endOfStreamback to summary
private boolean endOfStream

True if we're at the end of the available data

initedback to summary
pack-priv boolean inited

True if we're initialise the OGG info block

inputback to summary
private InputStream input

The stream we're reading the OGG file from

oggInfoback to summary
private Info oggInfo

The audio information from the OGG header

packetback to summary
private Packet packet

The current packet page

pageback to summary
private Page page

The current OGG page

pcmBufferback to summary
private ByteBuffer pcmBuffer

The byte array store used to hold the data read from the ogg

readIndexback to summary
private int readIndex

The index into the byte array we currently read from

streamStateback to summary
private StreamState streamState

The Vorbis Stream State used to decode the OGG

syncStateback to summary
private SyncState syncState

The Vorbis SyncState used to decode the OGG

totalback to summary
private int total

The total number of bytes

vorbisBlockback to summary
private Block vorbisBlock

The OGG block we're currently working with to convert PCM

Constructor Detail

OggInputStreamback to summary
public OggInputStream(InputStream input)

Create a new stream to decode OGG data

Parameters
input:InputStream

The input stream from which to read the OGG file

OggInputStreamback to summary
public OggInputStream(InputStream input, OggInputStream previousStream)

Create a new stream to decode OGG data, reusing buffers from another stream. It's not a good idea to use the old stream instance afterwards.

Parameters
input:InputStream

The input stream from which to read the OGG file

previousStream:OggInputStream

The stream instance to reuse buffers from, may be null

Method Detail

atEndback to summary
public boolean atEnd()
availableback to summary
public int available()

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

See Also
java.io.InputStream#available()
closeback to summary
public void close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

getChannelsback to summary
public int getChannels()
getLengthback to summary
public int getLength()

Get the number of bytes on the stream

Returns:int

The number of the bytes on the stream

getPageAndPacketback to summary
private boolean getPageAndPacket()

Get a page and packet from that page

Returns:boolean

True if there was a page available

getSampleRateback to summary
public int getSampleRate()
initback to summary
private void init()

Initialise the streams and thread involved in the streaming of OGG data

initVorbisback to summary
private void initVorbis()

Initialise the vorbis decoding

readback to summary
public int read()

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the 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.

readback to summary
public int read(byte[] b, int off, int len)

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

readback to summary
public int read(byte[] b)

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[0], the next one into b[1], and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected.

readPCMback to summary
private void readPCM()

Decode the OGG file as shown in the jogg/jorbis examples