org.tritonus.sampled.convert
Class SampleRateConversionProvider.SampleRateConverterStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjavax.sound.sampled.AudioInputStream
          extended byorg.tritonus.sampled.convert.SampleRateConversionProvider.SampleRateConverterStream
All Implemented Interfaces:
Closeable
Enclosing class:
SampleRateConversionProvider

public static class SampleRateConversionProvider.SampleRateConverterStream
extends AudioInputStream

SampleRateConverterStream


Field Summary
static int LINEAR_INTERPOLATION
          Conversion algorithm
static int RESAMPLE
          Conversion algorithm
static int SAMPLE_AND_HOLD
          Conversion algorithm
 
Fields inherited from class javax.sound.sampled.AudioInputStream
format, frameLength, framePos, frameSize, stream
 
Constructor Summary
SampleRateConversionProvider.SampleRateConverterStream(AudioInputStream sourceStream, AudioFormat targetFormat)
           
 
Method Summary
 int available()
           
 void close()
           
 void flush()
          Flushes the internal buffers
 int getConversionAlgorithm()
           
 int getFrameSize()
           
 int getSourceFrameSize()
           
 float getTargetSampleRate()
           
 boolean isClosed()
           
 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.
 int read(FloatSampleBuffer outBuffer)
          Main read method.
 void reset()
           
 void setConversionAlgorithm(int algo)
           
 void setTargetSampleRate(float sr)
           
 long skip(long nSkip)
           
protected  long sourceBytes2targetBytes(long sourceBytes)
           
protected  double sourceFrames2targetFrames(double sourceFrames)
           
protected  long targetBytes2sourceBytes(long targetBytes)
           
protected  double targetFrames2sourceFrames(double targetFrames)
           
 
Methods inherited from class javax.sound.sampled.AudioInputStream
getFormat, getFrameLength
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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)
Method Detail

read

public int read(FloatSampleBuffer outBuffer)
         throws IOException
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 the return value (and outBuffer.getSampleCount()) is less after processing this function, then it is an indicator that it was the last block to be processed.

Parameters:
outBuffer - the buffer that the converted samples will be written to.
Returns:
number of samples in outBuffer ( == outBuffer.getSampleCount()) or -1. A return value of 0 is only possible when outBuffer has 0 samples.
Throws:
IllegalArgumentException - when outBuffer's channel count does not match
IOException
See Also:
setConversionAlgorithm(int)

sourceFrames2targetFrames

protected double sourceFrames2targetFrames(double sourceFrames)

targetFrames2sourceFrames

protected double targetFrames2sourceFrames(double targetFrames)

sourceBytes2targetBytes

protected long sourceBytes2targetBytes(long sourceBytes)

targetBytes2sourceBytes

protected long targetBytes2sourceBytes(long targetBytes)

getFrameSize

public int getFrameSize()

getSourceFrameSize

public int getSourceFrameSize()

read

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

read

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

read

public int read(byte[] abData,
                int nOffset,
                int nLength)
         throws 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:
IOException

skip

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

available

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

mark

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

reset

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

markSupported

public boolean markSupported()
Overrides:
markSupported in class AudioInputStream

close

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

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()