SIP Communicator: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.media.protocol.portaudio
Class PortAudioManager

java.lang.Object
  extended by net.java.sip.communicator.impl.media.protocol.portaudio.PortAudioManager

public class PortAudioManager
extends Object

Manages PortAudio stream creation and setting necessary properties when using them.

Author:
Damian Minkov

Field Summary
static int NUM_SAMPLES
          20ms in 8kHz is 160 samples.
 
Method Summary
 int getFilterLength()
          Number of samples of echo to cancel (should generally correspond to 100-500 ms)
 int getFrameSize()
          Number of samples to process at one time (should correspond to 10-20 ms).
 InputPortAudioStream getInputStream(int deviceIndex, double sampleRate, int channels)
          Creates input stream from the device with given index.
static PortAudioManager getInstance()
          Gets the only instance of PortAudioManager, if its not already created will be created.
 OutputPortAudioStream getOutputStream(int deviceIndex, double sampleRate, int channels)
          Creates output stream from the device with given index.
 OutputPortAudioStream getOutputStream(int deviceIndex, double sampleRate, int channels, long sampleFormat)
          Creates output stream from the device with given index.
static double getSuggestedLatency()
          Returns the default values of the latency to be used when openning new streams.
 boolean isEnabledDeNoise()
          Is noise reduction enabled.
 boolean isEnabledEchoCancel()
          Is echo cancel enabled.
 void setDeNoise(boolean enabled)
          Enables or disables noise suppression.
 void setEchoCancel(boolean enabled, int frameSize, int filterLength)
          Enables or disables echo cancel.
static void setSuggestedLatency(double aSuggestedLatency)
          Changes the suggested latency.
 void stoppedInputPortAudioStream(MasterPortAudioStream st)
          Input stream is stopped.
 void stoppedOutputPortAudioStream(OutputPortAudioStream st)
          Output stream is stopped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_SAMPLES

public static final int NUM_SAMPLES
20ms in 8kHz is 160 samples.

See Also:
Constant Field Values
Method Detail

getInstance

public static PortAudioManager getInstance()
                                    throws PortAudioException
Gets the only instance of PortAudioManager, if its not already created will be created.

Returns:
the static instance.
Throws:
PortAudioException - if portaudio cannot be initialized for some reason.

getInputStream

public InputPortAudioStream getInputStream(int deviceIndex,
                                           double sampleRate,
                                           int channels)
                                    throws PortAudioException
Creates input stream from the device with given index.

Parameters:
deviceIndex - the device index.
sampleRate - the sample rate to use, its the sample rate of the input stream.
channels - the channels that the stream will serve.
Returns:
the stream.
Throws:
PortAudioException - if opening of the stream failes.

getOutputStream

public OutputPortAudioStream getOutputStream(int deviceIndex,
                                             double sampleRate,
                                             int channels)
                                      throws PortAudioException
Creates output stream from the device with given index.

Parameters:
deviceIndex - the device index.
sampleRate - the sample rate to use, its the sample rate of the output stream.
channels - the channels that the stream will serve.
Returns:
the stream.
Throws:
PortAudioException - if opening of the stream failes.

stoppedOutputPortAudioStream

public void stoppedOutputPortAudioStream(OutputPortAudioStream st)
Output stream is stopped.

Parameters:
st - the stream that is stopped.

stoppedInputPortAudioStream

public void stoppedInputPortAudioStream(MasterPortAudioStream st)
Input stream is stopped.

Parameters:
st - the input stream that is stopped.

getOutputStream

public OutputPortAudioStream getOutputStream(int deviceIndex,
                                             double sampleRate,
                                             int channels,
                                             long sampleFormat)
                                      throws PortAudioException
Creates output stream from the device with given index.

Parameters:
deviceIndex - the device index.
sampleRate - the sample rate to use, its the sample rate of the output stream.
channels - the channels that the stream will serve.
sampleFormat - the format the will be used by the stream.
Returns:
the stream.
Throws:
PortAudioException - if opening of the stream failes.

setEchoCancel

public void setEchoCancel(boolean enabled,
                          int frameSize,
                          int filterLength)
Enables or disables echo cancel.

Parameters:
enabled - should we enable or disable echo cancelation
frameSize - Number of samples to process at one time (should correspond to 10-20 ms)
filterLength - Number of samples of echo to cancel (should generally correspond to 100-500 ms)

setDeNoise

public void setDeNoise(boolean enabled)
Enables or disables noise suppression.

Parameters:
enabled - should we enable or disable noise suppression.

getSuggestedLatency

public static double getSuggestedLatency()
Returns the default values of the latency to be used when openning new streams.

Returns:
the latency.

setSuggestedLatency

public static void setSuggestedLatency(double aSuggestedLatency)
Changes the suggested latency.

Parameters:
aSuggestedLatency - the suggestedLatency to set.

isEnabledEchoCancel

public boolean isEnabledEchoCancel()
Is echo cancel enabled.

Returns:
true if echo cancel is enabled, false otherwise.

isEnabledDeNoise

public boolean isEnabledDeNoise()
Is noise reduction enabled.

Returns:
true if noise reduction is enabled, false otherwise.

getFrameSize

public int getFrameSize()
Number of samples to process at one time (should correspond to 10-20 ms).

Returns:
the frameSize.

getFilterLength

public int getFilterLength()
Number of samples of echo to cancel (should generally correspond to 100-500 ms)

Returns:
the filterLength.

SIP Communicator: the OpenSource Java VoIP and Instant Messaging client.

SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.