com.groovemanager.spi.floatEncoding
Class FloatConversionProvider

java.lang.Object
  extended by javax.sound.sampled.spi.FormatConversionProvider
      extended by com.groovemanager.spi.floatEncoding.FloatConversionProvider

public class FloatConversionProvider
extends javax.sound.sampled.spi.FormatConversionProvider

A FloatConversionProvider is an implementation of the FormatConversionProvider SPI. It provides conversion from and to PCM_SIGNED or PCM_FLOAT encoded data, where PCM_FLOAT stands for floating point samples normalized to +/- 1.0 either in 32 or 64 Bit.

Author:
Manu Robledo

Field Summary
private static javax.sound.sampled.AudioFormat.Encoding[] encodings
          The encodings supported by this provider
 
Constructor Summary
FloatConversionProvider()
          Constructs a new FloatConversionProvider
 
Method Summary
 javax.sound.sampled.AudioInputStream getAudioInputStream(javax.sound.sampled.AudioFormat.Encoding targetEncoding, javax.sound.sampled.AudioInputStream sourceStream)
           
 javax.sound.sampled.AudioInputStream getAudioInputStream(javax.sound.sampled.AudioFormat targetFormat, javax.sound.sampled.AudioInputStream sourceStream)
           
private static javax.sound.sampled.AudioFormat getDefaultConversionFormat(javax.sound.sampled.AudioFormat sourceFormat, javax.sound.sampled.AudioFormat.Encoding targetEncoding)
          If only the target encoding is given, but not the target format, get a default target format out of the source format and the target encoding
private  int getFormatLength()
          Get the number of possible formats
 javax.sound.sampled.AudioFormat.Encoding[] getSourceEncodings()
           
 javax.sound.sampled.AudioFormat.Encoding[] getTargetEncodings()
           
 javax.sound.sampled.AudioFormat.Encoding[] getTargetEncodings(javax.sound.sampled.AudioFormat sourceFormat)
           
 javax.sound.sampled.AudioFormat[] getTargetFormats(javax.sound.sampled.AudioFormat.Encoding targetEncoding, javax.sound.sampled.AudioFormat sourceFormat)
           
private  boolean isSourceFormatSupported(javax.sound.sampled.AudioFormat sourceFormat)
          Find out, if the given format is supported by this provider
private  boolean isSupportedPCMFormat(javax.sound.sampled.AudioFormat format)
          Find out, if the given format is a valid PCM encoded format that is being supported by this provider
 
Methods inherited from class javax.sound.sampled.spi.FormatConversionProvider
isConversionSupported, isConversionSupported, isSourceEncodingSupported, isTargetEncodingSupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

encodings

private static final javax.sound.sampled.AudioFormat.Encoding[] encodings
The encodings supported by this provider

Constructor Detail

FloatConversionProvider

public FloatConversionProvider()
Constructs a new FloatConversionProvider

Method Detail

getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream(javax.sound.sampled.AudioFormat.Encoding targetEncoding,
                                                                javax.sound.sampled.AudioInputStream sourceStream)
Specified by:
getAudioInputStream in class javax.sound.sampled.spi.FormatConversionProvider
See Also:
FormatConversionProvider.getAudioInputStream(javax.sound.sampled.AudioFormat.Encoding, javax.sound.sampled.AudioInputStream)

getAudioInputStream

public javax.sound.sampled.AudioInputStream getAudioInputStream(javax.sound.sampled.AudioFormat targetFormat,
                                                                javax.sound.sampled.AudioInputStream sourceStream)
Specified by:
getAudioInputStream in class javax.sound.sampled.spi.FormatConversionProvider
See Also:
FormatConversionProvider.getAudioInputStream(javax.sound.sampled.AudioFormat, javax.sound.sampled.AudioInputStream)

getDefaultConversionFormat

private static javax.sound.sampled.AudioFormat getDefaultConversionFormat(javax.sound.sampled.AudioFormat sourceFormat,
                                                                          javax.sound.sampled.AudioFormat.Encoding targetEncoding)
If only the target encoding is given, but not the target format, get a default target format out of the source format and the target encoding

Parameters:
sourceFormat - The source AudioFormat
targetEncoding - The target encoding
Returns:
An AudioFormat with the targetEncoding and similar attributes to the sourceFormat

getFormatLength

private int getFormatLength()
Get the number of possible formats

Returns:
Always 12 (2 PCM_FLOAT + 4 PCM_SIGNED) * 2 (endianess)

getSourceEncodings

public javax.sound.sampled.AudioFormat.Encoding[] getSourceEncodings()
Specified by:
getSourceEncodings in class javax.sound.sampled.spi.FormatConversionProvider
See Also:
FormatConversionProvider.getSourceEncodings()

getTargetEncodings

public javax.sound.sampled.AudioFormat.Encoding[] getTargetEncodings()
Specified by:
getTargetEncodings in class javax.sound.sampled.spi.FormatConversionProvider
See Also:
FormatConversionProvider.getTargetEncodings()

getTargetEncodings

public javax.sound.sampled.AudioFormat.Encoding[] getTargetEncodings(javax.sound.sampled.AudioFormat sourceFormat)
Specified by:
getTargetEncodings in class javax.sound.sampled.spi.FormatConversionProvider
See Also:
FormatConversionProvider.getTargetEncodings(javax.sound.sampled.AudioFormat)

getTargetFormats

public javax.sound.sampled.AudioFormat[] getTargetFormats(javax.sound.sampled.AudioFormat.Encoding targetEncoding,
                                                          javax.sound.sampled.AudioFormat sourceFormat)
Specified by:
getTargetFormats in class javax.sound.sampled.spi.FormatConversionProvider
See Also:
FormatConversionProvider.getTargetFormats(javax.sound.sampled.AudioFormat.Encoding, javax.sound.sampled.AudioFormat)

isSourceFormatSupported

private boolean isSourceFormatSupported(javax.sound.sampled.AudioFormat sourceFormat)
Find out, if the given format is supported by this provider

Parameters:
sourceFormat - The format to check for
Returns:
true, if the given format is supported, false otherwise

isSupportedPCMFormat

private boolean isSupportedPCMFormat(javax.sound.sampled.AudioFormat format)
Find out, if the given format is a valid PCM encoded format that is being supported by this provider

Parameters:
format - The AudioFormat to ask for
Returns:
true, if
- the sample rate is the same as the frame rate,
- the sample size in Bits is dividable by 8,
- the frame size is the sample size multiplied by the number of channels divided by 8.
false otherwise