com.cloudgarden.audio
Class AudioMediaFormatConverter

java.lang.Object
  |
  +--com.cloudgarden.audio.DefaultAudioObject
        |
        +--com.cloudgarden.audio.DefaultAudioSource
              |
              +--com.cloudgarden.audio.DefaultAudioConnector
                    |
                    +--com.cloudgarden.audio.DefaultAudioConverter
                          |
                          +--com.cloudgarden.audio.AudioMediaFormatConverter
All Implemented Interfaces:
AudioConnector, AudioConverter, AudioObject, AudioSink, AudioSource, javax.media.protocol.BufferTransferHandler, javax.media.ControllerListener, javax.media.protocol.SourceTransferHandler

public class AudioMediaFormatConverter
extends DefaultAudioConverter
implements AudioConverter, javax.media.ControllerListener, javax.media.protocol.SourceTransferHandler, javax.media.protocol.BufferTransferHandler

Basic audio format converter, which is guaranteed to convert between any two AudioFormats provided both are 16-bit - this is unlike the javax.sound.sampled.AudioSystem conversion, which sometimes can't provide the needed conversions.

No internal buffer is used. This class can be used in "pull" or "push" mode:

"Pull" mode - call the setSource method (to provide the source of audio data) then read the converted data from the AudioConverter - this will read the data from the original source, convert it and provide the converted data.

"Push" mode - call the setSink method (to set the sink that will have the converted data written to it) then write the original data to the AudioConverter - this will write the converted data directly to the sink.


Fields inherited from class com.cloudgarden.audio.DefaultAudioConverter
srcContentType, srcFmt
 
Fields inherited from class com.cloudgarden.audio.DefaultAudioConnector
source
 
Fields inherited from class com.cloudgarden.audio.DefaultAudioSource
sending, sendThread, sink
 
Fields inherited from class com.cloudgarden.audio.DefaultAudioObject
contentType, exception, format, listeners, paused, pauseSync, running, waiting
 
Fields inherited from interface com.cloudgarden.audio.AudioObject
END_OF_DATA
 
Constructor Summary
AudioMediaFormatConverter()
           
AudioMediaFormatConverter(AudioSource src, AudioSink sink)
           
AudioMediaFormatConverter(AudioSource src, java.lang.String type)
           
 
Method Summary
 void controllerUpdate(javax.media.ControllerEvent controllerEvent)
           
 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 setSource(AudioSource src)
          Sets the source for this converter
 void setup()
           
 void startSending()
          This method starts the Processor
 void stopSending()
           
 void transferData(javax.media.protocol.PushBufferStream pushBufferStream)
           
 void transferData(javax.media.protocol.PushSourceStream pushSourceStream)
           
 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.DefaultAudioConverter
getIncomingAudioFormat, getIncomingContentType, setIncomingAudioFormat, setIncomingContentType
 
Methods inherited from class com.cloudgarden.audio.DefaultAudioConnector
getSource, write
 
Methods inherited from class com.cloudgarden.audio.DefaultAudioSource
drain, getSink, isSending, read, setAudioFormat, setBufferSize, setContentType, setSink
 
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
 
Methods inherited from interface com.cloudgarden.audio.AudioConverter
getIncomingAudioFormat, getIncomingContentType, setIncomingAudioFormat, setIncomingContentType
 
Methods inherited from interface com.cloudgarden.audio.AudioSource
getSink, isSending, read, setSink
 
Methods inherited from interface com.cloudgarden.audio.AudioObject
addTransferListener, canSetAudioFormat, drain, getAudioFormat, getContentType, isPaused, isWaiting, removeTransferListener, setAudioFormat, setContentType, setPaused
 
Methods inherited from interface com.cloudgarden.audio.AudioSink
getSource, write
 

Constructor Detail

AudioMediaFormatConverter

public AudioMediaFormatConverter()

AudioMediaFormatConverter

public AudioMediaFormatConverter(AudioSource src,
                                 java.lang.String type)
                          throws java.io.IOException,
                                 javax.media.MediaException

AudioMediaFormatConverter

public AudioMediaFormatConverter(AudioSource src,
                                 AudioSink sink)
                          throws java.io.IOException,
                                 javax.media.MediaException
Method Detail

setup

public void setup()
           throws java.io.IOException

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.
Specified by:
read in interface AudioSource
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.
Specified by:
write in interface AudioSink
Following copied from interface: com.cloudgarden.audio.AudioSink
See Also:
AudioSink.setSource(com.cloudgarden.audio.AudioSource), AudioSource.startSending(), AudioObject.setPaused(boolean)

setSource

public void setSource(AudioSource src)
               throws java.io.IOException
Sets the source for this converter
Specified by:
setSource in interface AudioSink
Overrides:
setSource in class DefaultAudioConverter
See Also:
DefaultAudioConnector.getSource()

startSending

public void startSending()
                  throws java.io.IOException
This method starts the Processor
Specified by:
startSending in interface AudioSource
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()

stopSending

public void stopSending()
Specified by:
stopSending in interface AudioSource
Overrides:
stopSending in class DefaultAudioSource
Following copied from interface: com.cloudgarden.audio.AudioSource
See Also:
AudioSource.startSending()

controllerUpdate

public void controllerUpdate(javax.media.ControllerEvent controllerEvent)
Specified by:
controllerUpdate in interface javax.media.ControllerListener

transferData

public void transferData(javax.media.protocol.PushSourceStream pushSourceStream)
Specified by:
transferData in interface javax.media.protocol.SourceTransferHandler

transferData

public void transferData(javax.media.protocol.PushBufferStream pushBufferStream)
Specified by:
transferData in interface javax.media.protocol.BufferTransferHandler