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

net.java.sip.communicator.impl.neomedia.portaudio.streams
Class MasterPortAudioStream

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.portaudio.streams.MasterPortAudioStream

public class MasterPortAudioStream
extends Object

The master audio stream which opens the PortAudio stream and reads from it. We can have multiple slave input streams that are connected to this master stream.

Author:
Damian Minkov, Lubomir Marinov

Constructor Summary
MasterPortAudioStream(int deviceIndex, double sampleRate, int channels)
          Creates new stream.
 
Method Summary
 int getDeviceIndex()
          Returns the index of the device that we use.
 long getStream()
          Returns the pointer to the stream that we use for reading.
 boolean read(javax.media.Buffer buffer)
          Reads audio data from this MasterPortAudioStream into a specific Buffer blocking until audio data is indeed available.
 void setParams(OutputPortAudioStream out, boolean deNoiseEnabled, boolean echoCancelEnabled, int frameSize, int filterLength)
          Sets parameters to the underlying stream.
(package private)  void start(InputPortAudioStream slave)
          Starts this MasterPortAudioStream so that a specific InputPortAudioStream can read from it.
(package private)  void stop(InputPortAudioStream slave)
          Stops the reading of a specific InputPortAudioStream from this MasterPortAudioStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MasterPortAudioStream

public MasterPortAudioStream(int deviceIndex,
                             double sampleRate,
                             int channels)
                      throws PortAudioException
Creates new stream.

Parameters:
deviceIndex - the device to use.
channels - the channels to serve.
sampleRate - the sample rate.
Throws:
PortAudioException - if stream cannot be opened.
Method Detail

getDeviceIndex

public int getDeviceIndex()
Returns the index of the device that we use.

Returns:
the deviceIndex

getStream

public long getStream()
Returns the pointer to the stream that we use for reading.

Returns:
the stream pointer.

read

public boolean read(javax.media.Buffer buffer)
             throws PortAudioException
Reads audio data from this MasterPortAudioStream into a specific Buffer blocking until audio data is indeed available.

Parameters:
buffer - the Buffer into which the audio data read from this MasterPortAudioStream is to be returned
Throws:
PortAudioException - if an error occurs while reading

setParams

public void setParams(OutputPortAudioStream out,
                      boolean deNoiseEnabled,
                      boolean echoCancelEnabled,
                      int frameSize,
                      int filterLength)
Sets parameters to the underlying stream.

Parameters:
out - the connected output stream if echo cancel is enabled.
deNoiseEnabled - true if we want to enable noise reduction.
echoCancelEnabled - true to enable echo cancel.
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)

start

void start(InputPortAudioStream slave)
     throws PortAudioException
Starts this MasterPortAudioStream so that a specific InputPortAudioStream can read from it. When the first such InputPortAudioStream request the starting of this instance, this instance starts the native PortAudio stream it reads from.

Parameters:
slave - the InputPortAudioStream which has been started and wants to read audio from this instance
Throws:
PortAudioException - if anything wrong happens while starting the native PortAudio stream this instance is to read from

stop

void stop(InputPortAudioStream slave)
    throws PortAudioException
Stops the reading of a specific InputPortAudioStream from this MasterPortAudioStream. When the last such InputPortAudioStream stops reading from this instance, this instance closes the native PortAudio stream it reads from.

Parameters:
slave - the InputPortAudioStream which has been stopped and no longer wants to read audio from this instance
Throws:
PortAudioException - if anything wrong happens while stopping the native PortAudio stream this instance reads from

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

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