org.tritonus.sampled.convert
Class SampleRateConversionProvider.SampleRateConverterStream

java.lang.Object
  extended by java.io.InputStream
      extended by javax.sound.sampled.AudioInputStream
          extended by org.tritonus.sampled.convert.SampleRateConversionProvider.SampleRateConverterStream
All Implemented Interfaces:
java.io.Closeable, FloatSampleInput
Enclosing class:
SampleRateConversionProvider

public static class SampleRateConversionProvider.SampleRateConverterStream
extends AudioInputStream
implements FloatSampleInput

SampleRateConverterStream


Field Summary
static int LINEAR_INTERPOLATION
          Conversion algorithm
static int RESAMPLE
          Conversion algorithm
static int SAMPLE_AND_HOLD
          Conversion algorithm
 
Constructor Summary
SampleRateConversionProvider.SampleRateConverterStream(AudioInputStream sourceStream, AudioFormat targetFormat)
           
SampleRateConversionProvider.SampleRateConverterStream(FloatSampleInput sourceInput, AudioFormat targetFormat, long frameLength)
           
 
Method Summary
 int available()
           
 void close()
           
 void flush()
          Flushes the internal buffers
 int getChannels()
           
 int getConversionAlgorithm()
           
 int getFrameSize()
           
 float getSampleRate()
           
 int getSourceFrameSize()
           
 float getTargetSampleRate()
           
 boolean isClosed()
           
 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)
          Read nLength bytes that will be the converted samples of the original inputStream.
 void read(FloatSampleBuffer outBuffer)
          Fill the entire buffer with audio data.
 void read(FloatSampleBuffer outBuffer, int offset, int count)
          Main read method.
 void reset()
           
 void setConversionAlgorithm(int algo)
           
 void setTargetSampleRate(float sr)
           
 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
 

Field Detail

SAMPLE_AND_HOLD

public static final int SAMPLE_AND_HOLD
Conversion algorithm

See Also:
Constant Field Values

LINEAR_INTERPOLATION

public static final int LINEAR_INTERPOLATION
Conversion algorithm

See Also:
Constant Field Values

RESAMPLE

public static final int RESAMPLE
Conversion algorithm

See Also:
Constant Field Values
Constructor Detail

SampleRateConversionProvider.SampleRateConverterStream

public SampleRateConversionProvider.SampleRateConverterStream(AudioInputStream sourceStream,
                                                              AudioFormat targetFormat)

SampleRateConversionProvider.SampleRateConverterStream

public SampleRateConversionProvider.SampleRateConverterStream(FloatSampleInput sourceInput,
                                                              AudioFormat targetFormat,
                                                              long frameLength)
Method Detail

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 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 outBuffer,
                 int offset,
                 int count)
Main read method. It blocks until all samples are converted or the source stream is at its end or closed.
The sourceStream's sample rate is converted following the current setting of conversionAlgorithm. At most outBuffer.getSampleCount() are converted. In general, if outBuffer.getSampleCount()) is less after processing this function, then it is an indicator that it was the last block to be processed.

Specified by:
read in interface FloatSampleInput
Parameters:
outBuffer - the buffer that the converted samples will be written to.
offset - the start index, in samples, where to start filling the buffer
count - the number fo samples to fill into the buffer
Throws:
java.lang.IllegalArgumentException - when outBuffer's channel count does not match
See Also:
setConversionAlgorithm(int)

getFrameSize

public int getFrameSize()

getSourceFrameSize

public int getSourceFrameSize()

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
Read nLength bytes that will be the converted samples of the original inputStream. When nLength is not an integral number of frames, this method may read less than nLength bytes.

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()
Specified by:
close in interface java.io.Closeable
Overrides:
close in class AudioInputStream

isClosed

public boolean isClosed()

flush

public void flush()
Flushes the internal buffers


setTargetSampleRate

public void setTargetSampleRate(float sr)

setConversionAlgorithm

public void setConversionAlgorithm(int algo)

getTargetSampleRate

public float getTargetSampleRate()

getConversionAlgorithm

public int getConversionAlgorithm()