Class StdAudio

Object
  extended by StdAudio

public final class StdAudio
extends Object

Standard audio. This class provides a basic capability for creating, reading, and saving audio.

The audio format uses a sampling rate of 44,100 (CD quality audio), 16-bit, monaural.

For additional documentation, see Section 1.5 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

Author:
Robert Sedgewick, Kevin Wayne

Field Summary
static int SAMPLE_RATE
          The sample rate - 44,100 Hz for CD quality audio.
 
Method Summary
static void close()
          Close standard audio.
static void loop(String filename)
          Loop a sound file (in .wav, .mid, or .au format) in a background thread.
static void main(String[] args)
          Test client - play an A major scale to standard audio.
static void play(double in)
          Write one sample (between -1.0 and +1.0) to standard audio.
static void play(double[] input)
          Write an array of samples (between -1.0 and +1.0) to standard audio.
static void play(String filename)
          Play a sound file (in .wav, .mid, or .au format) in a background thread.
static double[] read(String filename)
          Read audio samples from a file (in .wav or .au format) and return them as a double array with values between -1.0 and +1.0.
static void save(String filename, double[] input)
          Save the double array as a sound file (using .wav or .au format).
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SAMPLE_RATE

public static final int SAMPLE_RATE
The sample rate - 44,100 Hz for CD quality audio.

See Also:
Constant Field Values
Method Detail

close

public static void close()
Close standard audio.


play

public static void play(double in)
Write one sample (between -1.0 and +1.0) to standard audio. If the sample is outside the range, it will be clipped.


play

public static void play(double[] input)
Write an array of samples (between -1.0 and +1.0) to standard audio. If a sample is outside the range, it will be clipped.


read

public static double[] read(String filename)
Read audio samples from a file (in .wav or .au format) and return them as a double array with values between -1.0 and +1.0.


play

public static void play(String filename)
Play a sound file (in .wav, .mid, or .au format) in a background thread.


loop

public static void loop(String filename)
Loop a sound file (in .wav, .mid, or .au format) in a background thread.


save

public static void save(String filename,
                        double[] input)
Save the double array as a sound file (using .wav or .au format).


main

public static void main(String[] args)
Test client - play an A major scale to standard audio.