Top Description Fields Constructors Methods
javazoom.jl.decoder

public final Class Bitstream

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .ByteArrayInputStream, .IOException, .InputStream, .PushbackInputStream, .UnsupportedEncodingException

The Bistream class is responsible for parsing an MPEG audio bitstream. REVIEW: much of the parsing currently occurs in the various decoders. This should be moved into this class and associated inner classes.

Field Summary

Modifier and TypeField and Description
private int
bitindex

Number (0-31, from MSB to LSB) of next bit for get_bits()

private final int[]
public static final int
BITSTREAM_ERROR

The first bitstream error code.

public static final int
private static final int
BUFFER_INT_SIZE

Maximum size of the frame buffer.

private Crc16[]
private boolean
private byte[]
frame_bytes

The bytes read from the stream.

private final int[]
framebuffer

The frame buffer that holds the data for the current frame.

private int
framesize

Number of valid bytes in the frame buffer.

private final Header
private int
header_pos

Audio header position in stream.

pack-priv static byte
INITIAL_SYNC

Synchronization control constant for the initial synchronization to the start of a frame.

public static final int
INVALIDFRAME

Frame data are missing.

private byte[]
private Float
private boolean
private final PushbackInputStream
public static final int
STREAM_EOF

The end of the stream was reached.

public static final int
STREAM_ERROR

A problem occurred reading from the stream.

pack-priv static byte
STRICT_SYNC

Synchronization control constant for non-initial frame synchronizations.

private final byte[]
private int
syncword

The current specified syncword

public static final int
UNEXPECTED_EOF

The end of the stream was reached prematurely.

public static final int
UNKNOWN_ERROR

An undeterminable error occurred.

public static final int
UNKNOWN_SAMPLE_RATE

The header describes an unknown sample rate.

private int
wordpointer

Index into framebuffer where the next bits are retrieved.

Constructor Summary

AccessConstructor and Description
public
Bitstream(InputStream
The InputStream to read from.
in
)

Construct a IBitstream that reads data from a given InputStream.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close the Bitstream.

public void
closeFrame()

Close MP3 frame.

public int
get_bits(int number_of_bits)

Read bits from buffer into the lower bits of an unsigned int.

public InputStream

Returns:

ID3v2 InputStream or null if ID3v2 frames are not available.
getRawID3v2
()

Return raw ID3v2 frames + header.

public Float
public int

Returns:

size of ID3v2 tag frames.
header_pos
()

Return position of the first audio header.

public boolean
isSyncCurrentPosition(int syncmode)

Determines if the next 4 bytes of the stream represent a frame header.

public boolean
isSyncMark(int headerstring, int syncmode, int word)

private void
loadID3v2(InputStream
MP3 InputStream.
in
)

Load ID3v2 frames.

protected BitstreamException
newBitstreamException(int errorcode)

protected BitstreamException
newBitstreamException(int errorcode, Throwable throwable)

private void
nextFrame()

Read next MP3 frame.

pack-priv void
parse_frame()

Parses the data previously read with read_frame_data().

private void
parseID3v2Frames(byte[] bframes)

private String
parseText(byte[] bframes, int offset, int size, int skip)

pack-priv int
read_frame_data(int bytesize)

Reads the data for the next frame.

public int
readBits(int n)

private int
readBytes(byte[] b, int offs, int len)

Simlar to readFully, but doesn't throw exception when EOF is reached.

public int
public Header

Returns:

the Header describing details of the frame read, or null if the end of the stream has been reached.
readFrame
()

Reads and parses the next frame from the input source.

private int
readFully(byte[]
The byte array to read the specified number of bytes into.
b
,
int
The index in the array where the first byte read should be stored.
offs
,
int
the number of bytes to read.
len
)

Reads the exact number of bytes from the source input stream into a byte array.

private int

Returns:

size of ID3v2 frames + header
readID3v2Header
(InputStream
MP3 InputStream
in
)

Parse ID3v2 tag header to find out size of ID3v2 frames.

private Header

Returns:

MP3 frame header.
readNextFrame
()

Read next MP3 frame.

pack-priv void
set_syncword(int syncword0)

Set the word we want to sync the header to.

pack-priv int
syncHeader(byte syncmode)

Get next 32 bits from bitstream.

public void
unreadFrame()

Unreads the bytes read from the frame.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bitindexback to summary
private int bitindex

Number (0-31, from MSB to LSB) of next bit for get_bits()

bitmaskback to summary
private final int[] bitmask
BITSTREAM_ERRORback to summary
public static final int BITSTREAM_ERROR

The first bitstream error code. See the DecoderErrors interface for other bitstream error codes.

BITSTREAM_LASTback to summary
public static final int BITSTREAM_LAST
BUFFER_INT_SIZEback to summary
private static final int BUFFER_INT_SIZE

Maximum size of the frame buffer.

crcback to summary
private Crc16[] crc
firstframeback to summary
private boolean firstframe
frame_bytesback to summary
private byte[] frame_bytes

The bytes read from the stream.

framebufferback to summary
private final int[] framebuffer

The frame buffer that holds the data for the current frame.

framesizeback to summary
private int framesize

Number of valid bytes in the frame buffer.

header_posback to summary
private int header_pos

Audio header position in stream.

INITIAL_SYNCback to summary
pack-priv static byte INITIAL_SYNC

Synchronization control constant for the initial synchronization to the start of a frame.

INVALIDFRAMEback to summary
public static final int INVALIDFRAME

Frame data are missing.

rawid3v2back to summary
private byte[] rawid3v2
replayGainScaleback to summary
private Float replayGainScale
single_ch_modeback to summary
private boolean single_ch_mode
sourceback to summary
private final PushbackInputStream source
STREAM_EOFback to summary
public static final int STREAM_EOF

The end of the stream was reached.

STREAM_ERRORback to summary
public static final int STREAM_ERROR

A problem occurred reading from the stream.

STRICT_SYNCback to summary
pack-priv static byte STRICT_SYNC

Synchronization control constant for non-initial frame synchronizations.

syncbufback to summary
private final byte[] syncbuf
syncwordback to summary
private int syncword

The current specified syncword

UNEXPECTED_EOFback to summary
public static final int UNEXPECTED_EOF

The end of the stream was reached prematurely.

UNKNOWN_ERRORback to summary
public static final int UNKNOWN_ERROR

An undeterminable error occurred.

UNKNOWN_SAMPLE_RATEback to summary
public static final int UNKNOWN_SAMPLE_RATE

The header describes an unknown sample rate.

wordpointerback to summary
private int wordpointer

Index into framebuffer where the next bits are retrieved.

Constructor Detail

Bitstreamback to summary
public Bitstream(InputStream in)

Construct a IBitstream that reads data from a given InputStream.

Parameters
in:InputStream

The InputStream to read from.

Method Detail

closeback to summary
public void close() throws BitstreamException

Close the Bitstream.

closeFrameback to summary
public void closeFrame()

Close MP3 frame.

get_bitsback to summary
public int get_bits(int number_of_bits)

Read bits from buffer into the lower bits of an unsigned int. The LSB contains the latest read bit of the stream. (1 <= number_of_bits <= 16)

getRawID3v2back to summary
public InputStream getRawID3v2()

Return raw ID3v2 frames + header.

Returns:InputStream

ID3v2 InputStream or null if ID3v2 frames are not available.

getReplayGainScaleback to summary
public Float getReplayGainScale()
header_posback to summary
public int header_pos()

Return position of the first audio header.

Returns:int

size of ID3v2 tag frames.

isSyncCurrentPositionback to summary
public boolean isSyncCurrentPosition(int syncmode) throws BitstreamException

Determines if the next 4 bytes of the stream represent a frame header.

isSyncMarkback to summary
public boolean isSyncMark(int headerstring, int syncmode, int word)
loadID3v2back to summary
private void loadID3v2(InputStream in)

Load ID3v2 frames.

Parameters
in:InputStream

MP3 InputStream.

Author
JavaZOOM
newBitstreamExceptionback to summary
protected BitstreamException newBitstreamException(int errorcode)
newBitstreamExceptionback to summary
protected BitstreamException newBitstreamException(int errorcode, Throwable throwable)
nextFrameback to summary
private void nextFrame() throws BitstreamException

Read next MP3 frame.

parse_frameback to summary
pack-priv void parse_frame() throws BitstreamException

Parses the data previously read with read_frame_data().

parseID3v2Framesback to summary
private void parseID3v2Frames(byte[] bframes)
parseTextback to summary
private String parseText(byte[] bframes, int offset, int size, int skip)
read_frame_databack to summary
pack-priv int read_frame_data(int bytesize) throws BitstreamException

Reads the data for the next frame. The frame is not parsed until parse frame is called.

readBitsback to summary
public int readBits(int n)
readBytesback to summary
private int readBytes(byte[] b, int offs, int len) throws BitstreamException

Simlar to readFully, but doesn't throw exception when EOF is reached.

readCheckedBitsback to summary
public int readCheckedBits(int n)
readFrameback to summary
public Header readFrame() throws BitstreamException

Reads and parses the next frame from the input source.

Returns:Header

the Header describing details of the frame read, or null if the end of the stream has been reached.

readFullyback to summary
private int readFully(byte[] b, int offs, int len) throws BitstreamException

Reads the exact number of bytes from the source input stream into a byte array.

Parameters
b:byte[]

The byte array to read the specified number of bytes into.

offs:int

The index in the array where the first byte read should be stored.

len:int

the number of bytes to read.

Exceptions
BitstreamException:
is thrown if the specified number of bytes could not be read from the stream.
readID3v2Headerback to summary
private int readID3v2Header(InputStream in) throws IOException

Parse ID3v2 tag header to find out size of ID3v2 frames.

Parameters
in:InputStream

MP3 InputStream

Returns:int

size of ID3v2 frames + header

Author
JavaZOOM
readNextFrameback to summary
private Header readNextFrame() throws BitstreamException

Read next MP3 frame.

Returns:Header

MP3 frame header.

set_syncwordback to summary
pack-priv void set_syncword(int syncword0)

Set the word we want to sync the header to. In Big-Endian byte order

syncHeaderback to summary
pack-priv int syncHeader(byte syncmode) throws BitstreamException

Get next 32 bits from bitstream. They are stored in the headerstring. syncmod allows Synchro flag ID The returned value is False at the end of stream.

unreadFrameback to summary
public void unreadFrame() throws BitstreamException

Unreads the bytes read from the frame.