mediaframe.mpeg1.audio.player
Class BigPipedInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--mediaframe.mpeg1.audio.player.BigPipedInputStream

public class BigPipedInputStream
extends java.io.InputStream

The BigPipedInputStream represents the Piped Input Stream. It receives the input data from a BigPipedOutputStream, puts them into the circle data buffer and returns when a client requests for the next portion of the data.
This class responds for convertion the audio samples into the uLaw representation for eight-bit eight khz ulaw decoder (browser).
This class implements volume and mute features (multiplies the digital sound data word by a volume value or returns uLaw zero if the mute equals true).

Version:
1.0 26.07.2002
Author:
Konstantin Belous

Field Summary
private  short[] buffer
          The circle buffer of audio samples.
(package private)  boolean bufferFilled
          True, if the decoding of the audio stream has been finished and the circle buffer has been filled with the audio samples.
private  boolean firstPause
          True for the first pause in the movie playback (normally if the player doesn't played any frames).
private  int inp
          The pointer for read in the circle buffer.
private  boolean isClosedByReader
          True, if the pipe has been already closed by BigPipedInputStream.
(package private)  boolean isClosedByWriter
          True, if the pipe has been already closed by BigPipedOutputStream.
private  int lastOutp
          The value of the pointer for write in the circle buffer during last read from the stream.
static boolean mute
          The mute state of the audio player.
private  int outp
          The pointer for write in the circle buffer.
(package private)  BigPipedOutputStream outputPipe
          The reference to the output stream in the pipe.
 boolean playing
          True if the audio player is playing the sound, false if the playback is paused.
static int ULAW_BIAS
          Constanta used in the linear -> uLaw computation.
static int ULAW_CLIP
          Constanta used in the linear -> uLaw computation.
static int[] ULAW_LUT
          Table of (roughly) logarithms base 2, used in the linear -> uLaw computation.
static byte ULAW_ZERO
          uLaw representation of zero.
static int Volume
          The volume of the audio signal.
private  int waiting_reader
          The amount of threads which waits the reader side.
private  int waiting_writer
          The amount of threads which waits the writer side.
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
BigPipedInputStream(int nBufferSize)
          Constructs a BigPipedInputStream class with the specified buffer size.
 
Method Summary
 void close()
          Closes the BigPipedInputStream
private static int[] computeUlawLut()
          Compute logarithm (roughly) table used in the linear -> uLaw mapping.
 void connect(BigPipedOutputStream src)
          Connects this object with the specified BigPipedOutputStream object in the pipe.
 int freeInBuffer()
          Returns the amount of audio samples that could be placed into the circle buffer.
 void notify_reader()
          Notifies the reader side for about the next portion of data.
 void notify_writer()
          Notifies the writer side that the circle buffer is ready for receiving samples.
 int read()
          Reads uLaw representation of the next sample of sound data from the circle buffer.
 int read(byte[] b, int off, int len)
          Reads uLaw representations of len samples of sound data from the circle buffer into the array b starting from the offset off.
(package private)  void receive(short b)
          Places the next auduo sample into the circle buffer.
 void wait_for_reader()
          Waits the reader until the circle buffer will be ready for receiving samples.
 void wait_for_writer()
          Waits the writer for the next portion of data.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inp

private int inp
The pointer for read in the circle buffer.


outp

private int outp
The pointer for write in the circle buffer.


lastOutp

private int lastOutp
The value of the pointer for write in the circle buffer during last read from the stream.


buffer

private short[] buffer
The circle buffer of audio samples.


isClosedByWriter

boolean isClosedByWriter
True, if the pipe has been already closed by BigPipedOutputStream.


isClosedByReader

private boolean isClosedByReader
True, if the pipe has been already closed by BigPipedInputStream.


outputPipe

BigPipedOutputStream outputPipe
The reference to the output stream in the pipe.


playing

public boolean playing
True if the audio player is playing the sound, false if the playback is paused.


Volume

public static int Volume
The volume of the audio signal.


mute

public static boolean mute
The mute state of the audio player.


bufferFilled

boolean bufferFilled
True, if the decoding of the audio stream has been finished and the circle buffer has been filled with the audio samples.


firstPause

private boolean firstPause
True for the first pause in the movie playback (normally if the player doesn't played any frames).


waiting_reader

private int waiting_reader
The amount of threads which waits the reader side.


waiting_writer

private int waiting_writer
The amount of threads which waits the writer side.


ULAW_ZERO

public static final byte ULAW_ZERO
uLaw representation of zero. (Both 127 or 255 map to zero.)

See Also:
Constant Field Values

ULAW_BIAS

public static final int ULAW_BIAS
Constanta used in the linear -> uLaw computation.

See Also:
Constant Field Values

ULAW_CLIP

public static final int ULAW_CLIP
Constanta used in the linear -> uLaw computation.

See Also:
Constant Field Values

ULAW_LUT

public static final int[] ULAW_LUT
Table of (roughly) logarithms base 2, used in the linear -> uLaw computation.

Constructor Detail

BigPipedInputStream

public BigPipedInputStream(int nBufferSize)
Constructs a BigPipedInputStream class with the specified buffer size.

Parameters:
nBufferSize - the size of a circle buffer.
Method Detail

read

public int read()
         throws java.io.IOException
Reads uLaw representation of the next sample of sound data from the circle buffer. Implements the volume feature (multiplies the sample value by a volume value) or returns uLaw zero value if the mute equals true.

Specified by:
read in class java.io.InputStream
Returns:
one byte from the circle buffer.
Throws:
java.io.IOException - raises if a error occurs.

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads uLaw representations of len samples of sound data from the circle buffer into the array b starting from the offset off. Implements the volume feature (multiplies the sample value by a volume value) or returns uLaw zero value if the mute equals true.

Overrides:
read in class java.io.InputStream
Parameters:
b - the array into which the data is read.
off - the start offset in the array b into which the data is written.
len - the maximum amount of bytes to read.
Returns:
the total amount of bytes read into the array, or -1 if there is no more data because the end of the file has been reached.
Throws:
java.io.IOException - raises if a error occurs.

freeInBuffer

public int freeInBuffer()
Returns the amount of audio samples that could be placed into the circle buffer.


connect

public void connect(BigPipedOutputStream src)
Connects this object with the specified BigPipedOutputStream object in the pipe.

Parameters:
src - the BigPipedOutputStream object.

close

public void close()
Closes the BigPipedInputStream

Overrides:
close in class java.io.InputStream

receive

void receive(short b)
       throws java.io.IOException
Places the next auduo sample into the circle buffer.

Parameters:
b - the next audio sample.
Throws:
java.io.IOException - raises if a error occurs.

notify_writer

public void notify_writer()
Notifies the writer side that the circle buffer is ready for receiving samples.


wait_for_reader

public void wait_for_reader()
                     throws java.io.InterruptedIOException
Waits the reader until the circle buffer will be ready for receiving samples.

Throws:
java.io.InterruptedIOException - when the current process has been interrupted by the another process.

notify_reader

public void notify_reader()
Notifies the reader side for about the next portion of data.


wait_for_writer

public void wait_for_writer()
                     throws java.io.InterruptedIOException
Waits the writer for the next portion of data.

Throws:
java.io.InterruptedIOException - when the current process has been interrupted by the another process.

computeUlawLut

private static int[] computeUlawLut()
Compute logarithm (roughly) table used in the linear -> uLaw mapping.

We compute this table (rather than store it) mostly to make the .class file a bit smaller, (and also to help avoid typos.)