org.tritonus.share.sampled.convert
Class TSimpleFormatConversionProvider

java.lang.Object
  extended byjavax.sound.sampled.spi.FormatConversionProvider
      extended byorg.tritonus.share.sampled.convert.TFormatConversionProvider
          extended byorg.tritonus.share.sampled.convert.TSimpleFormatConversionProvider
Direct Known Subclasses:
GSMFormatConversionProvider, Mp3LameFormatConversionProvider, PCM2PCMConversionProvider, SampleRateConversionProvider, TEncodingFormatConversionProvider, TMatrixFormatConversionProvider

public abstract class TSimpleFormatConversionProvider
extends TFormatConversionProvider

This is a base class for FormatConversionProviders that can convert from each source encoding/format to each target encoding/format. If this is not the case, use TEncodingFormatConversionProvider or TMatrixFormatConversionProvider.

Overriding classes must provide a constructor that calls the protected constructor of this class and override AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream). The latter method should be able to handle the case that all fields are NOT_SPECIFIED and provide appropriate default values.

Author:
Matthias Pfisterer

Field Summary
 
Fields inherited from class org.tritonus.share.sampled.convert.TFormatConversionProvider
EMPTY_ENCODING_ARRAY, EMPTY_FORMAT_ARRAY
 
Constructor Summary
protected TSimpleFormatConversionProvider(Collection sourceFormats, Collection targetFormats)
           
 
Method Summary
protected  void disable()
          Disables this FormatConversionProvider.
protected static boolean doMatch(float f1, float f2)
           
protected static boolean doMatch(int i1, int i2)
          Utility method to check whether these values match, taking into account AudioSystem.NOT_SPECIFIED.
protected  Collection getCollectionSourceEncodings()
           
protected  Collection getCollectionSourceFormats()
           
protected  Collection getCollectionTargetEncodings()
           
protected  Collection getCollectionTargetFormats()
           
protected  int getFrameSize(AudioFormat.Encoding encoding, float sampleRate, int sampleSize, int channels, float frameRate, boolean bigEndian, int oldFrameSize)
          Calculates the frame size for the given format description.
 AudioFormat.Encoding[] getSourceEncodings()
           
 AudioFormat.Encoding[] getTargetEncodings()
           
 AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat)
          This implementation assumes that the converter can convert from each of its source encodings to each of its target encodings.
 AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat)
          This implementation assumes that the converter can convert from each of its source formats to each of its target formats.
protected  boolean isAllowedSourceEncoding(AudioFormat.Encoding sourceEncoding)
           
protected  boolean isAllowedSourceFormat(AudioFormat sourceFormat)
           
protected  boolean isAllowedTargetEncoding(AudioFormat.Encoding targetEncoding)
           
protected  boolean isAllowedTargetFormat(AudioFormat targetFormat)
           
 boolean isSourceEncodingSupported(AudioFormat.Encoding sourceEncoding)
           
 boolean isTargetEncodingSupported(AudioFormat.Encoding targetEncoding)
           
protected  AudioFormat replaceNotSpecified(AudioFormat sourceFormat, AudioFormat targetFormat)
          Utility method, replaces all occurences of AudioSystem.NOT_SPECIFIED in targetFormat with the corresponding value in sourceFormat.
 
Methods inherited from class org.tritonus.share.sampled.convert.TFormatConversionProvider
getAudioInputStream, getMatchingFormat, isConversionSupported
 
Methods inherited from class javax.sound.sampled.spi.FormatConversionProvider
getAudioInputStream, isConversionSupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TSimpleFormatConversionProvider

protected TSimpleFormatConversionProvider(Collection sourceFormats,
                                          Collection targetFormats)
Method Detail

disable

protected void disable()
Disables this FormatConversionProvider. This may be useful when e.g. native libraries are not present. TODO: enable method, better implementation


getSourceEncodings

public AudioFormat.Encoding[] getSourceEncodings()
Specified by:
getSourceEncodings in class FormatConversionProvider

getTargetEncodings

public AudioFormat.Encoding[] getTargetEncodings()
Specified by:
getTargetEncodings in class FormatConversionProvider

isSourceEncodingSupported

public boolean isSourceEncodingSupported(AudioFormat.Encoding sourceEncoding)
Overrides:
isSourceEncodingSupported in class FormatConversionProvider

isTargetEncodingSupported

public boolean isTargetEncodingSupported(AudioFormat.Encoding targetEncoding)
Overrides:
isTargetEncodingSupported in class FormatConversionProvider

getTargetEncodings

public AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat)
This implementation assumes that the converter can convert from each of its source encodings to each of its target encodings. If this is not the case, the converter has to override this method.

Specified by:
getTargetEncodings in class FormatConversionProvider

getTargetFormats

public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding,
                                      AudioFormat sourceFormat)
This implementation assumes that the converter can convert from each of its source formats to each of its target formats. If this is not the case, the converter has to override this method.

Specified by:
getTargetFormats in class FormatConversionProvider

isAllowedSourceEncoding

protected boolean isAllowedSourceEncoding(AudioFormat.Encoding sourceEncoding)

isAllowedTargetEncoding

protected boolean isAllowedTargetEncoding(AudioFormat.Encoding targetEncoding)

isAllowedSourceFormat

protected boolean isAllowedSourceFormat(AudioFormat sourceFormat)

isAllowedTargetFormat

protected boolean isAllowedTargetFormat(AudioFormat targetFormat)

getCollectionSourceEncodings

protected Collection getCollectionSourceEncodings()

getCollectionTargetEncodings

protected Collection getCollectionTargetEncodings()

getCollectionSourceFormats

protected Collection getCollectionSourceFormats()

getCollectionTargetFormats

protected Collection getCollectionTargetFormats()

doMatch

protected static boolean doMatch(int i1,
                                 int i2)
Utility method to check whether these values match, taking into account AudioSystem.NOT_SPECIFIED.

Returns:
true if any of the values is AudioSystem.NOT_SPECIFIED or both values have the same value.

doMatch

protected static boolean doMatch(float f1,
                                 float f2)
See Also:
doMatch(int,int)

replaceNotSpecified

protected AudioFormat replaceNotSpecified(AudioFormat sourceFormat,
                                          AudioFormat targetFormat)
Utility method, replaces all occurences of AudioSystem.NOT_SPECIFIED in targetFormat with the corresponding value in sourceFormat. If targetFormat does not contain any fields with AudioSystem.NOT_SPECIFIED, it is returned unmodified. The endian-ness and encoding remain the same in all cases.

If any of the fields is AudioSystem.NOT_SPECIFIED in both sourceFormat and targetFormat, it will remain not specified.

This method uses getFrameSize(...) (see below) to set the new frameSize, if a new AudioFormat instance is created.

This method isn't used in TSimpleFormatConversionProvider - it is solely there for inheriting classes.


getFrameSize

protected int getFrameSize(AudioFormat.Encoding encoding,
                           float sampleRate,
                           int sampleSize,
                           int channels,
                           float frameRate,
                           boolean bigEndian,
                           int oldFrameSize)
Calculates the frame size for the given format description. The default implementation returns AudioSystem.NOT_SPECIFIED if either sampleSize or channels is AudioSystem.NOT_SPECIFIED, otherwise sampleSize*channels/8 is returned.

If this does not reflect the way to calculate the right frame size, inheriting classes should overwrite this method if they use replaceNotSpecified(...). It is not used elsewhere in this class.