com.cloudgarden.audio
Class AudioFormatConverter
java.lang.Object
|
+--com.cloudgarden.audio.DefaultAudioObject
|
+--com.cloudgarden.audio.DefaultAudioSource
|
+--com.cloudgarden.audio.DefaultAudioConnector
|
+--com.cloudgarden.audio.DefaultAudioConverter
|
+--com.cloudgarden.audio.AudioFormatConverter
- All Implemented Interfaces:
- AudioConnector, AudioConverter, AudioObject, AudioSink, AudioSource
- public class AudioFormatConverter
- extends DefaultAudioConverter
Basic audio format converter, which is guaranteed to
convert between any two javax.sound.sampled.AudioFormats - this is unlike the
javax.sound.sampled.AudioSystem conversion,
which sometimes can't provide the needed conversions.
The audio data is converted from the format of the source to the format of
the sink - therefore both setSource and setSink methods must be called,
or the AudioFormatConverter(AudioSource, AudioFormat) constructor
used to specify the source and the output audio format.
No internal buffer is used. This class can be used in "pull" or "push" mode:
"Pull" mode - read the converted data from the AudioFormatConverter - this will read
the data from the original source, convert it and provide the converted data.
"Push" mode - write the original data to the
AudioFormatConverter - this will write the converted data directly to the
sink.
Constructor Summary |
AudioFormatConverter()
|
AudioFormatConverter(AudioSource src,
javax.sound.sampled.AudioFormat fmt)
Creates a AudioConverterSource with an output AudioFormat specified by the
AudioFormat fmt parameter. |
AudioFormatConverter(AudioSource src,
javax.sound.sampled.AudioFormat fmt,
boolean interpolate)
Creates a AudioConverterSource with an output AudioFormat specified by the
AudioFormat fmt parameter. |
AudioFormatConverter(AudioSource src,
javax.sound.sampled.AudioFormat fmt,
boolean interpolate,
boolean smooth)
Creates a AudioConverterSource with an output AudioFormat specified by the
AudioFormat fmt parameter. |
AudioFormatConverter(AudioSource src,
AudioSink sink)
Converts from the src's AudioFormat to the sink's AudioFormat, with no interpolation or smoothing |
AudioFormatConverter(AudioSource src,
AudioSink sink,
boolean interpolate)
Converts from the src's AudioFormat to the sink's AudioFormat, with no smoothing |
AudioFormatConverter(AudioSource src,
AudioSink sink,
boolean interpolate,
boolean smooth)
Converts from the src's AudioFormat to the sink's AudioFormat, with interpolation and smoothing as specified. |
Method Summary |
void |
convert(byte[] src,
byte[] dest,
int srcLen,
int destLen,
boolean interpolate,
boolean smooth)
Converts an array of bytes of audio data from the source and
fills the given destination array with bytes converted to the sink's
audio format. |
int |
read(byte[] data,
int offset,
int len)
Used to read data from this source - called by the AudioSink which this
source is connected to (if its startGetting method is used) so need
not be called explicitly by an application. |
void |
setAudioFormat(javax.sound.sampled.AudioFormat fmt)
Sets the AudioFormat that the outgoing audio data will be in. |
void |
setIncomingAudioFormat(javax.sound.sampled.AudioFormat format)
|
void |
startSending()
This method does nothing since this class simply passes on anything
that is written to it immediately to its AudioSink |
void |
useLinearInterpolation(boolean use)
Sets use of linear interpolation in conversion when going from
a lower frequency to a higher frequency - better quality, but slower. |
void |
useSmoothing(boolean use)
Sets use of smoothing in conversion when going from
a higher frequency to a lower frequency - sometimes gives better quality,
than not smoothing, but slower. |
int |
write(byte[] data,
int offset,
int len)
Used to write data to this sink - called by the AudioSource which this
sink is connected to (if its startSending method is used) so need
not be called explicitly by an application. |
Methods inherited from class com.cloudgarden.audio.DefaultAudioObject |
addTransferListener, blockWhilePaused, blockWhileWaiting, bytesTransferred, canSetAudioFormat, getAudioFormat, getContentType, getLastException, isPaused, isWaiting, removeTransferListener, setPaused |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AudioFormatConverter
public AudioFormatConverter()
AudioFormatConverter
public AudioFormatConverter(AudioSource src,
AudioSink sink)
throws java.io.IOException
- Converts from the src's AudioFormat to the sink's AudioFormat, with no interpolation or smoothing
AudioFormatConverter
public AudioFormatConverter(AudioSource src,
AudioSink sink,
boolean interpolate)
throws java.io.IOException
- Converts from the src's AudioFormat to the sink's AudioFormat, with no smoothing
AudioFormatConverter
public AudioFormatConverter(AudioSource src,
AudioSink sink,
boolean interpolate,
boolean smooth)
throws java.io.IOException
- Converts from the src's AudioFormat to the sink's AudioFormat, with interpolation and smoothing as specified.
AudioFormatConverter
public AudioFormatConverter(AudioSource src,
javax.sound.sampled.AudioFormat fmt)
throws java.io.IOException
- Creates a AudioConverterSource with an output AudioFormat specified by the
AudioFormat fmt parameter. No interpolation or smoothing.
AudioFormatConverter
public AudioFormatConverter(AudioSource src,
javax.sound.sampled.AudioFormat fmt,
boolean interpolate)
throws java.io.IOException
- Creates a AudioConverterSource with an output AudioFormat specified by the
AudioFormat fmt parameter. No smoothing.
AudioFormatConverter
public AudioFormatConverter(AudioSource src,
javax.sound.sampled.AudioFormat fmt,
boolean interpolate,
boolean smooth)
throws java.io.IOException
- Creates a AudioConverterSource with an output AudioFormat specified by the
AudioFormat fmt parameter. Interpolation and smoothing as specified.
useLinearInterpolation
public void useLinearInterpolation(boolean use)
- Sets use of linear interpolation in conversion when going from
a lower frequency to a higher frequency - better quality, but slower.
Default is to not use interpolation.
useSmoothing
public void useSmoothing(boolean use)
- Sets use of smoothing in conversion when going from
a higher frequency to a lower frequency - sometimes gives better quality,
than not smoothing, but slower.
Default is to not use smoothing.
setAudioFormat
public void setAudioFormat(javax.sound.sampled.AudioFormat fmt)
throws java.io.IOException
- Sets the AudioFormat that the outgoing audio data will be in.
- Overrides:
setAudioFormat
in class DefaultAudioSource
- Following copied from interface:
com.cloudgarden.audio.AudioObject
- Throws:
java.io.IOException
- if unable to set the AudioFormat for any reason
(eg. if canSetAudioFormat returns false and setAudioFormat is used
to try to change the AudioFormat).- See Also:
AudioObject.getAudioFormat()
read
public int read(byte[] data,
int offset,
int len)
throws java.io.IOException
- Description copied from interface:
AudioSource
- Used to read data from this source - called by the AudioSink which this
source is connected to (if its startGetting method is used) so need
not be called explicitly by an application. Blocks if this source is paused.
Returns the number of bytes read, or END_OF_DATA if all the available
data has been read - eg if the end of a file has been reached, or if
the stopSending() method has been called.
- Following copied from interface:
com.cloudgarden.audio.AudioSource
- See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink)
,
AudioSink#startGetting
,
AudioObject.setPaused(boolean)
write
public int write(byte[] data,
int offset,
int len)
throws java.io.IOException
- Description copied from interface:
AudioSink
- Used to write data to this sink - called by the AudioSource which this
sink is connected to (if its startSending method is used) so need
not be called explicitly by an application. Blocks if this sink is paused.
- Following copied from interface:
com.cloudgarden.audio.AudioSink
- See Also:
AudioSink.setSource(com.cloudgarden.audio.AudioSource)
,
AudioSource.startSending()
,
AudioObject.setPaused(boolean)
convert
public void convert(byte[] src,
byte[] dest,
int srcLen,
int destLen,
boolean interpolate,
boolean smooth)
- Converts an array of bytes of audio data from the source and
fills the given destination array with bytes converted to the sink's
audio format. If interpolate is true, uses linear interpolation from low
to high frequencies. If smooth is true, smoothes from high to low frequencies.
setIncomingAudioFormat
public void setIncomingAudioFormat(javax.sound.sampled.AudioFormat format)
throws java.io.IOException
- Overrides:
setIncomingAudioFormat
in class DefaultAudioConverter
startSending
public void startSending()
throws java.io.IOException
- This method does nothing since this class simply passes on anything
that is written to it immediately to its AudioSink
- Overrides:
startSending
in class DefaultAudioSource
- Following copied from interface:
com.cloudgarden.audio.AudioSource
- Throws:
an
- IOException if the source is unable to start sending data - for example,
if an audio file is unable to be opened to supply the data to be sent.- See Also:
AudioSource.setSink(com.cloudgarden.audio.AudioSink)
,
AudioObject.drain()