sound
Class SoundUtils

java.lang.Object
  extended by sound.SoundUtils

public class SoundUtils
extends java.lang.Object

Created by IntelliJ IDEA. User: Douglas Lyon Date: Dec 20, 2004 Time: 6:06:44 PM Copyright DocJava, Inc.


Field Summary
static javax.sound.midi.MidiChannel[] channels
           
static boolean DEBUG
           
 
Constructor Summary
SoundUtils()
           
 
Method Summary
static double[] bytesToSamples(byte[] byteArray, int offset, int length, int bytesPerSample, boolean signedData)
          Converts a byte array into an array of samples (a bouble).
static void checkAudio()
           
static javax.media.protocol.DataSource createDataSource(javax.media.Format format)
           
static void echo(double[] linearSamples)
           
static void echo(int numberOfEchos, double decay, double[] linearSamples)
           
static javax.sound.sampled.AudioFileFormat.Type findTargetType(java.lang.String strExtension)
          Trying to get an audio file type for the passed extension.
static int[] get16BitAudioData(javax.sound.sampled.AudioFormat format, byte[] audioBytes)
           
static javax.sound.sampled.AudioFormat get8khzMono8Format()
           
static javax.sound.sampled.AudioFileFormat.Type getAudioFileType()
           
static javax.sound.sampled.AudioFormat[] getAudioFormats(javax.sound.sampled.Port p)
           
static void getAuFilePlayAndDisplay()
           
static javax.media.protocol.DataSource getCaptureDataSource(javax.media.format.VideoFormat vf)
           
static javax.media.protocol.DataSource getCaptureDataSource(javax.media.format.VideoFormat vf, javax.media.format.AudioFormat af)
           
static javax.media.CaptureDeviceInfo[] getCaptureDeviceList()
           
static javax.media.CaptureDeviceInfo getDevice()
           
static double[] getDoubleData(javax.sound.sampled.AudioFormat format, byte[] audioBytes)
           
static javax.sound.sampled.LineListener getLineListener()
           
static javax.sound.sampled.Port getMicrophonePort()
           
static javax.sound.sampled.Mixer.Info getMixer()
           
static javax.sound.sampled.Mixer.Info getMixerInfo(java.lang.String strMixerName)
          TODO: This method tries to return a Mixer.Info whose name matches the passed name.
static javax.sound.sampled.AudioFileFormat.Type getSourceType()
           
static javax.sound.midi.Synthesizer getSynthesizer()
           
static javax.sound.sampled.TargetDataLine getTargetDataLine(javax.sound.sampled.Mixer.Info mixerInfo, javax.sound.sampled.AudioFormat audioFormat, int nBufferSize)
           
static boolean isPcm(javax.sound.sampled.AudioFormat.Encoding encoding)
          Checks if the encoding is PCM.
static void listMixersAndExit()
           
static void listMixersAndExit(boolean bPlayback)
          List Mixers.
static double[] littleEndianBytesToSamples(byte[] data, int offset, int length, int bytesPerSample, boolean signed)
          Converts a little-endian byte array into an array of samples (double).
static void main(java.lang.String[] args)
           
static void noteOff(int nNoteNumber)
           
static void noteOn(int nNoteNumber, int nVelocity)
           
static void out(java.lang.String strMessage)
          TODO:
static void play(int nn)
           
static void play(int[] ia, int dur)
           
static void play(int[] ia, int vel, int dur)
           
static void play(int nn, int dur)
           
static void play(int nn, int vel, int dur)
           
static void play(javax.sound.midi.Synthesizer synth, int nNoteNumber, int nVelocity, int nDuration)
           
static void playSound()
           
static void playSound(java.net.URL f)
           
static void playThread(int[] ia, int vel, int dur)
           
static void print(double[] ia)
           
static void print(int[] ia)
           
static void printAudioFileTargetTypes()
           
static void printFormatsOfMicrophone()
           
static void printMicrophoneInfo()
           
static void printSupportedTargetFileTypes()
           
static void showInfoDialog()
           
static void sleep(int nDuration)
           
static void testPlay()
           
static void testPlayClip()
           
static void testRecorder()
           
static int[] transpose(int[] ia, int bias)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

channels

public static javax.sound.midi.MidiChannel[] channels

DEBUG

public static boolean DEBUG
Constructor Detail

SoundUtils

public SoundUtils()
Method Detail

main

public static void main(java.lang.String[] args)

printFormatsOfMicrophone

public static void printFormatsOfMicrophone()

bytesToSamples

public static double[] bytesToSamples(byte[] byteArray,
                                      int offset,
                                      int length,
                                      int bytesPerSample,
                                      boolean signedData)
                               throws java.lang.ArrayIndexOutOfBoundsException
Converts a byte array into an array of samples (a bouble). Each consecutive bytes in the byte array are converted into a double, and becomes the next element in the double array. The size of the returned array is (length/bytesPerDouble). Currently, only 1 byte (8-bit) or 2 bytes (16-bit) samples are supported.

Parameters:
byteArray - a byte array
offset - which byte to start from
length - how many bytes to convert
bytesPerSample - the number of bytes per sample
signedData - whether the data is signed
Returns:
a double array, or null if byteArray is of zero length
Throws:
java.lang.ArrayIndexOutOfBoundsException

littleEndianBytesToSamples

public static double[] littleEndianBytesToSamples(byte[] data,
                                                  int offset,
                                                  int length,
                                                  int bytesPerSample,
                                                  boolean signed)
                                           throws java.lang.ArrayIndexOutOfBoundsException
Converts a little-endian byte array into an array of samples (double). Each consecutive bytes of a float are converted into a double, and becomes the next element in the double array. The number of bytes in the double is specified as an argument. The size of the returned array is (data.length/bytesPerSample).

Parameters:
data - a byte array
offset - which byte to start from
length - how many bytes to convert
bytesPerSample - the number of bytes per sample
signed - whether the data is signed
Returns:
a double array, or null if byteArray is of zero length
Throws:
java.lang.ArrayIndexOutOfBoundsException

getLineListener

public static javax.sound.sampled.LineListener getLineListener()

getAudioFormats

public static javax.sound.sampled.AudioFormat[] getAudioFormats(javax.sound.sampled.Port p)

getMicrophonePort

public static javax.sound.sampled.Port getMicrophonePort()

listMixersAndExit

public static void listMixersAndExit()

getMixer

public static javax.sound.sampled.Mixer.Info getMixer()

getSourceType

public static javax.sound.sampled.AudioFileFormat.Type getSourceType()

getAudioFileType

public static javax.sound.sampled.AudioFileFormat.Type getAudioFileType()

printSupportedTargetFileTypes

public static void printSupportedTargetFileTypes()

getAuFilePlayAndDisplay

public static void getAuFilePlayAndDisplay()

showInfoDialog

public static void showInfoDialog()

checkAudio

public static void checkAudio()

play

public static void play(int[] ia,
                        int vel,
                        int dur)

print

public static void print(double[] ia)

print

public static void print(int[] ia)

play

public static void play(int nn)

play

public static void play(int nn,
                        int dur)

play

public static void play(int nn,
                        int vel,
                        int dur)

playThread

public static void playThread(int[] ia,
                              int vel,
                              int dur)

play

public static void play(int[] ia,
                        int dur)

transpose

public static int[] transpose(int[] ia,
                              int bias)

getSynthesizer

public static javax.sound.midi.Synthesizer getSynthesizer()

testRecorder

public static void testRecorder()

getDoubleData

public static double[] getDoubleData(javax.sound.sampled.AudioFormat format,
                                     byte[] audioBytes)

get16BitAudioData

public static int[] get16BitAudioData(javax.sound.sampled.AudioFormat format,
                                      byte[] audioBytes)

echo

public static void echo(double[] linearSamples)

echo

public static void echo(int numberOfEchos,
                        double decay,
                        double[] linearSamples)

get8khzMono8Format

public static javax.sound.sampled.AudioFormat get8khzMono8Format()
Returns:
little endian 8khz linear 8bit format. Unsigned.

printMicrophoneInfo

public static void printMicrophoneInfo()

play

public static void play(javax.sound.midi.Synthesizer synth,
                        int nNoteNumber,
                        int nVelocity,
                        int nDuration)

noteOff

public static void noteOff(int nNoteNumber)

noteOn

public static void noteOn(int nNoteNumber,
                          int nVelocity)

sleep

public static void sleep(int nDuration)

getMixerInfo

public static javax.sound.sampled.Mixer.Info getMixerInfo(java.lang.String strMixerName)
TODO: This method tries to return a Mixer.Info whose name matches the passed name. If no matching Mixer.Info is found, null is returned.


listMixersAndExit

public static void listMixersAndExit(boolean bPlayback)
List Mixers. Only Mixers that support either TargetDataLines or SourceDataLines are listed, depending on the value of bPlayback.


out

public static void out(java.lang.String strMessage)
TODO:


getTargetDataLine

public static javax.sound.sampled.TargetDataLine getTargetDataLine(javax.sound.sampled.Mixer.Info mixerInfo,
                                                                   javax.sound.sampled.AudioFormat audioFormat,
                                                                   int nBufferSize)
                                                            throws javax.sound.sampled.LineUnavailableException
Throws:
javax.sound.sampled.LineUnavailableException

isPcm

public static boolean isPcm(javax.sound.sampled.AudioFormat.Encoding encoding)
Checks if the encoding is PCM.


findTargetType

public static javax.sound.sampled.AudioFileFormat.Type findTargetType(java.lang.String strExtension)
Trying to get an audio file type for the passed extension. This works by examining all available file types. For each type, if the extension this type promisses to handle matches the extension we are trying to find a type for, this type is returned. If no appropriate type is found, null is returned.


printAudioFileTargetTypes

public static void printAudioFileTargetTypes()

playSound

public static void playSound(java.net.URL f)

playSound

public static void playSound()

testPlay

public static void testPlay()

testPlayClip

public static void testPlayClip()

getCaptureDataSource

public static javax.media.protocol.DataSource getCaptureDataSource(javax.media.format.VideoFormat vf,
                                                                   javax.media.format.AudioFormat af)

getCaptureDataSource

public static javax.media.protocol.DataSource getCaptureDataSource(javax.media.format.VideoFormat vf)

getDevice

public static javax.media.CaptureDeviceInfo getDevice()

getCaptureDeviceList

public static javax.media.CaptureDeviceInfo[] getCaptureDeviceList()

createDataSource

public static javax.media.protocol.DataSource createDataSource(javax.media.Format format)