sampled
Class AudioCapture

java.lang.Object
  extended by sampled.AudioCapture
All Implemented Interfaces:
AudioSource

public class AudioCapture
extends java.lang.Object
implements AudioSource

Use this class to capture audio directly from a microphone. The default i s 16kHz at 16bit. Other sampling and bit rates are possible, but capturing is limited to signed, little endian. Use the main program to list available mixer names; if no mixer name is specified on instantiation, the Java AudioSystem default is used.

Author:
sikoried

Field Summary
 java.lang.String mixerName
          name of the target mixer or null if default mixer
static java.lang.String synopsis
           
 
Constructor Summary
AudioCapture()
          Create the default capture object: 16kHz at 16bit
AudioCapture(int bitRate, int sampleRate)
          Create a specific capture object (bound to signed, little endian).
AudioCapture(java.lang.String mixerName)
          Create an AudioCapture object reading from the specified mixer.
AudioCapture(java.lang.String mixerName, boolean defaultMixerFallBack)
          Create an AudioCapture object reading from the specified mixer.
AudioCapture(java.lang.String mixerName, boolean defaultMixerFallBack, int bitRate, int sampleRate)
          Create an AudioCapture object reading from the specified mixer using the given sample rate and bit rate.
AudioCapture(java.lang.String mixerName, int bitRate, int sampleRate)
          Create an AudioCapture object reading from the specified mixer using the given sample rate and bit rate.
 
Method Summary
 void disableDCShift()
          turn DC shift off
 void disableInternalBuffer()
          Disable the use of the internal buffer (the internal buffer won't be used if read() receives a valid buffer.
 void disableScaling()
          Disable the [-1;1] scaling to retrieve the original numeric values of the signal.
 void enableDCShift(int contextSize)
          enables the DC shift or updates the instance for the given context size
 void enableInternalBuffer(int bufferSize)
          Enable the internal Buffer (instead of the local one)
 void enableScaling()
          Enable scaling of the signal to [-1;1] depending on its bit rate
 double[] getBuffer()
          Return the converted buffer containing (normalized) values
static java.lang.String[] getMixerList()
          Return a list of Strings matching the mixer names.
 boolean getPreEmphasis()
          Does the AudioSource perform pre-emphasis?
 byte[] getRawBuffer()
          Return the raw buffer; mind 8/16 bit and signed/unsigned conversion!
 int getSampleRate()
          Return the current sampling rate
static void main(java.lang.String[] args)
           
 int read(double[] buf)
          Read the next buf.length samples (blocking).
 void setPreEmphasis(boolean applyPreEmphasis, double a)
          Enable pre-emphasis with given factor
 void tearDown()
          Tear down the audio capture environment (free resources)
 java.lang.String toString()
          Return a string representation of the capture device
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mixerName

public java.lang.String mixerName
name of the target mixer or null if default mixer


synopsis

public static final java.lang.String synopsis
See Also:
Constant Field Values
Constructor Detail

AudioCapture

public AudioCapture()
             throws java.io.IOException
Create the default capture object: 16kHz at 16bit

Throws:
java.io.IOException

AudioCapture

public AudioCapture(int bitRate,
                    int sampleRate)
             throws java.io.IOException
Create a specific capture object (bound to signed, little endian).

Parameters:
bitRate - target bit rate (usually 8 or 16bit)
sampleRate - target sample rate (usually 8 or 16kHz)
Throws:
java.io.IOException

AudioCapture

public AudioCapture(java.lang.String mixerName)
             throws java.io.IOException
Create an AudioCapture object reading from the specified mixer. To obtain a mixer name, use AudioCapture.main and call w/ argument "-L"

Parameters:
mixerName - Name of the mixer to use; searches for any occurance of 'mixerName' in the available mixer names
Throws:
java.io.IOException

AudioCapture

public AudioCapture(java.lang.String mixerName,
                    boolean defaultMixerFallBack)
             throws java.io.IOException
Create an AudioCapture object reading from the specified mixer. To obtain a mixer name, use AudioCapture.main and call w/ argument "-L"

Parameters:
mixerName - Name of the mixer to use
defaultMixerFallBack - fall back to default mixer if desired mixer not available
Throws:
java.io.IOException

AudioCapture

public AudioCapture(java.lang.String mixerName,
                    boolean defaultMixerFallBack,
                    int bitRate,
                    int sampleRate)
             throws java.io.IOException
Create an AudioCapture object reading from the specified mixer using the given sample rate and bit rate. To obtain a mixer name, use AudioCapture.main and call w/ argument "-L"

Parameters:
mixerName - Name of the mixer to read from
defaultMixerFallBack - fall back to default mixer if desired mixer not available
bitRate - bit rate to use (usually 8 or 16 bit)
sampleRate - sample rate to read (usually 8000 or 16000)
Throws:
java.io.IOException

AudioCapture

public AudioCapture(java.lang.String mixerName,
                    int bitRate,
                    int sampleRate)
             throws java.io.IOException
Create an AudioCapture object reading from the specified mixer using the given sample rate and bit rate. To obtain a mixer name, use AudioCapture.main and call w/ argument "-L"

Parameters:
mixerName - Name of the mixer to read from
bitRate - bit rate to use (usually 8 or 16 bit)
sampleRate - sample rate to read (usually 8000 or 16000)
Throws:
java.io.IOException
Method Detail

disableDCShift

public void disableDCShift()
turn DC shift off


disableInternalBuffer

public void disableInternalBuffer()
Disable the use of the internal buffer (the internal buffer won't be used if read() receives a valid buffer.


disableScaling

public void disableScaling()
Disable the [-1;1] scaling to retrieve the original numeric values of the signal.


enableDCShift

public void enableDCShift(int contextSize)
enables the DC shift or updates the instance for the given context size


enableInternalBuffer

public void enableInternalBuffer(int bufferSize)
Enable the internal Buffer (instead of the local one)

Parameters:
bufferSize -

enableScaling

public void enableScaling()
Enable scaling of the signal to [-1;1] depending on its bit rate


getBuffer

public double[] getBuffer()
Return the converted buffer containing (normalized) values

Returns:

getMixerList

public static java.lang.String[] getMixerList()
Return a list of Strings matching the mixer names.

Returns:

getPreEmphasis

public boolean getPreEmphasis()
Description copied from interface: AudioSource
Does the AudioSource perform pre-emphasis?

Specified by:
getPreEmphasis in interface AudioSource

getRawBuffer

public byte[] getRawBuffer()
Return the raw buffer; mind 8/16 bit and signed/unsigned conversion!


getSampleRate

public int getSampleRate()
Return the current sampling rate

Specified by:
getSampleRate in interface AudioSource
Returns:
number of samples per second

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException

read

public int read(double[] buf)
         throws java.io.IOException
Read the next buf.length samples (blocking). Samples are normalized to [-1;1]

Specified by:
read in interface AudioSource
Parameters:
buf - double buffer; will try to read as many samples as fit in the buffer. If buf is null, the internal buffer will be used (call enableInternalBuffer in advance!)
Returns:
number of samples actually read
Throws:
java.io.IOException
See Also:
AudioFileReader.read

setPreEmphasis

public void setPreEmphasis(boolean applyPreEmphasis,
                           double a)
Enable pre-emphasis with given factor

Specified by:
setPreEmphasis in interface AudioSource
Parameters:
applyPreEmphasis - apply pre-emphasis?
a - the pre-emphasis factor: x'(n) = x(n) - a*x(n-1)

tearDown

public void tearDown()
              throws java.io.IOException
Tear down the audio capture environment (free resources)

Specified by:
tearDown in interface AudioSource
Throws:
java.io.IOException

toString

public java.lang.String toString()
Return a string representation of the capture device

Specified by:
toString in interface AudioSource
Overrides:
toString in class java.lang.Object