ch.aplu.util
Class SoundRecorder

java.lang.Object
  extended by ch.aplu.util.SoundRecorder

public class SoundRecorder
extends java.lang.Object

Class for recording sound and save it to a WAV file.


Constructor Summary
SoundRecorder(javax.sound.sampled.AudioFormat audioFormat)
          Create a recorder instance with given audioFormat using the default sound device.
SoundRecorder(javax.sound.sampled.AudioFormat audioFormat, int mixerIndex)
           
SoundRecorder(int bufSize, javax.sound.sampled.AudioFormat audioFormat)
          Create a recorder instance with given audioFormat using the default sound device.
SoundRecorder(int bufSize, javax.sound.sampled.AudioFormat audioFormat, int mixerIndex)
          Create a recorder instance with given audioFormat using the given mixer index (sound device).
 
Method Summary
 void addSoundSampleListener(SoundSampleListener listener)
           
 void capture(java.io.ByteArrayOutputStream data)
          Start capturing the sound in a separate capture thread and store data in the given stream.
static java.lang.String[] getAvailableMixers()
          Return a list of the names of available mixers (sound devices).
 int getMixerIndex()
           
 void stopCapture()
          Stop the capturing process and return after the capture thread terminates.
 void writeWavFile(java.io.ByteArrayOutputStream data, java.io.File file)
          Write the sound data in the given stream into the given file in WAV format.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoundRecorder

public SoundRecorder(javax.sound.sampled.AudioFormat audioFormat)
Create a recorder instance with given audioFormat using the default sound device.


SoundRecorder

public SoundRecorder(int bufSize,
                     javax.sound.sampled.AudioFormat audioFormat)
Create a recorder instance with given audioFormat using the default sound device.


SoundRecorder

public SoundRecorder(javax.sound.sampled.AudioFormat audioFormat,
                     int mixerIndex)

SoundRecorder

public SoundRecorder(int bufSize,
                     javax.sound.sampled.AudioFormat audioFormat,
                     int mixerIndex)
Create a recorder instance with given audioFormat using the given mixer index (sound device). To find the mixer indices of all installed sound devices call getAvailableMixers().
Normally an installed sound device has two entries, one for playing and one for recording. You must use the index for the recording device.

Method Detail

addSoundSampleListener

public void addSoundSampleListener(SoundSampleListener listener)

capture

public void capture(java.io.ByteArrayOutputStream data)
             throws javax.sound.sampled.LineUnavailableException
Start capturing the sound in a separate capture thread and store data in the given stream. After the capture process is started, the method returns.

Throws:
javax.sound.sampled.LineUnavailableException - if the sound card is not available

stopCapture

public void stopCapture()
Stop the capturing process and return after the capture thread terminates.


writeWavFile

public void writeWavFile(java.io.ByteArrayOutputStream data,
                         java.io.File file)
Write the sound data in the given stream into the given file in WAV format.


getAvailableMixers

public static java.lang.String[] getAvailableMixers()
Return a list of the names of available mixers (sound devices). To select one of these mixers, use its index in this list when constructing the SoundRecorder instance.
Normally an installed sound device has two entries, one for playing and one for recording.


getMixerIndex

public int getMixerIndex()