org.tritonus.share.sampled
Class FloatInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by javax.sound.sampled.AudioInputStream
          extended by org.tritonus.share.sampled.FloatInputStream
All Implemented Interfaces:
java.io.Closeable, FloatSampleInput

public class FloatInputStream
extends AudioInputStream
implements FloatSampleInput

An implementation of AudioInputStream that implements the FloatSampleInput interface. This is a convenience class to instantly make any AudioInputStream capable of fulfilling the FloatSampleInput interface, or vice versa: make an existing FloatSampleInput class compatible with AudioInputStream.

All calls to FloatSampleInput.read() will cause implicit conversion to FloatSampleBuffer. If the underlying stream implementes FloatSampleInput, the FloatSampleInput.read method is used for reading.


Constructor Summary
FloatInputStream(AudioInputStream sourceStream)
          Create a new FloatInputStream that shadows the sourceStream.
FloatInputStream(FloatSampleInput sourceInput, AudioFormat format, long frameLength)
          Create a new FloatInputStream that will make the specified FloatSampleInput a complete AudioInputStream.
FloatInputStream(java.io.InputStream sourceStream, AudioFormat format, long frameLength)
          Create a new FloatInputStream that shadows the sourceStream.
 
Method Summary
 int available()
           
 void close()
           
 int getChannels()
           
 float getSampleRate()
           
 boolean isDone()
          Determine if this stream has reached its end.
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] abData)
           
 int read(byte[] abData, int nOffset, int nLength)
          If an underlying InputStream is available, read from it, otherwise read from an underlying FloatSampleInput stream and convert to a byte array.
 void read(FloatSampleBuffer outBuffer)
          Fill the entire buffer with audio data.
 void read(FloatSampleBuffer buffer, int offset, int sampleCount)
          Fill the specified portion of the buffer with the next audio data to be read.
 void reset()
           
 long skip(long nSkip)
           
 
Methods inherited from class javax.sound.sampled.AudioInputStream
getFormat, getFrameLength
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FloatInputStream

public FloatInputStream(AudioInputStream sourceStream)
Create a new FloatInputStream that shadows the sourceStream.

Parameters:
sourceStream -
Throws:
java.lang.IllegalArgumentException - if the stream's format is not compatible

FloatInputStream

public FloatInputStream(java.io.InputStream sourceStream,
                        AudioFormat format,
                        long frameLength)
Create a new FloatInputStream that shadows the sourceStream.

Parameters:
sourceStream -
format - the native format of sourceStream
frameLength - the length in frames of the streams, or AudioSystem.NOT_SPECIFIED if not known or unlimited.
Throws:
java.lang.IllegalArgumentException - if the stream's format is not compatible

FloatInputStream

public FloatInputStream(FloatSampleInput sourceInput,
                        AudioFormat format,
                        long frameLength)
Create a new FloatInputStream that will make the specified FloatSampleInput a complete AudioInputStream.

Parameters:
sourceInput -
format - the native format for the read(byte[]) method
frameLength - the length in frames of the stream, or AudioSystem.NOT_SPECIFIED if not known or unlimited.
Throws:
java.lang.IllegalArgumentException - if the format is not compatible
Method Detail

read

public void read(FloatSampleBuffer outBuffer)
Description copied from interface: FloatSampleInput
Fill the entire buffer with audio data. If fewer samples are read, this method will use buffer.changeSampleCount() to adjust the size of the buffer. If no samples can be written to the buffer, the buffer's sample count will be set to 0.

The buffer's channel count and sample rate may not be changed by the implementation of this method.

Specified by:
read in interface FloatSampleInput
Parameters:
outBuffer - the buffer to be filled

read

public void read(FloatSampleBuffer buffer,
                 int offset,
                 int sampleCount)
Description copied from interface: FloatSampleInput
Fill the specified portion of the buffer with the next audio data to be read. If fewer samples are read, this method will use buffer.changeSampleCount() to adjust the size of the buffer. If no samples can be written to the buffer, the buffer's sample count will be set to offset.

The buffer's channel count and sample rate may not be changed by the implementation of this method.

Specified by:
read in interface FloatSampleInput
Parameters:
buffer - the buffer to be filled
offset - the start index, in samples, where to start filling the buffer
sampleCount - the number fo samples to fill into the buffer

getChannels

public int getChannels()
Specified by:
getChannels in interface FloatSampleInput
Returns:
the number of audio channels of the audio data that this stream provides. If it can support a variable number of channels, this method returns AudioSystem.NOT_SPECIFIED.

getSampleRate

public float getSampleRate()
Specified by:
getSampleRate in interface FloatSampleInput
Returns:
the sample rate of the audio data that this stream provides. If it can support different sample rates, this method returns a negative number, e.g. AudioSystem.NOT_SPECIFIED.

isDone

public boolean isDone()
Description copied from interface: FloatSampleInput
Determine if this stream has reached its end. If true, subsequent calls to read() will return 0-sized buffers.

Specified by:
isDone in interface FloatSampleInput
Returns:
true if this stream reached its end.

read

public int read()
         throws java.io.IOException
Overrides:
read in class AudioInputStream
Throws:
java.io.IOException

read

public int read(byte[] abData)
         throws java.io.IOException
Overrides:
read in class AudioInputStream
Throws:
java.io.IOException
See Also:
read(byte[], int, int)

read

public int read(byte[] abData,
                int nOffset,
                int nLength)
         throws java.io.IOException
If an underlying InputStream is available, read from it, otherwise read from an underlying FloatSampleInput stream and convert to a byte array.

Overrides:
read in class AudioInputStream
Throws:
java.io.IOException

skip

public long skip(long nSkip)
          throws java.io.IOException
Overrides:
skip in class AudioInputStream
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Overrides:
available in class AudioInputStream
Throws:
java.io.IOException

mark

public void mark(int readlimit)
Overrides:
mark in class AudioInputStream

reset

public void reset()
           throws java.io.IOException
Overrides:
reset in class AudioInputStream
Throws:
java.io.IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class AudioInputStream

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class AudioInputStream
Throws:
java.io.IOException