public final class StdAudio extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
StdAudio.AudioEvent |
static interface |
StdAudio.AudioEventListener |
Modifier and Type | Field and Description |
---|---|
static int |
SAMPLE_RATE
The sample rate - 44,100 Hz for CD quality audio.
|
Modifier and Type | Method and Description |
---|---|
static void |
addAudioEventListener(StdAudio.AudioEventListener listener) |
static void |
clearAudioEventListeners()
Removes all audio event listeners from being notified of future
audio events, if any were present.
|
static void |
close()
Close standard audio.
|
static boolean |
isMuted()
Returns whether the audio system is currently muted.
|
static boolean |
isPaused()
Returns whether the audio system is currently paused.
|
static void |
loop(String filename)
Loop a sound file (in .wav or .au format) in a background thread.
|
static void |
main(String[] args)
Test client - play an A major scale to standard audio.
|
static double[] |
note(double hz,
double duration,
double amplitude)
Create a note (sine wave) of the given frequency (Hz), for the given
duration (seconds) scaled to the given volume (amplitude).
|
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(double[] input,
double duration)
Write an array of samples (between -1.0 and +1.0) to standard audio.
|
static void |
play(Note note,
double[] input,
double duration)
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 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 |
removeAudioEventListener(StdAudio.AudioEventListener listener)
Removes the given audio event listener from being notified of future
audio events, if it was present.
|
static void |
save(String filename,
double[] input)
Save the double array as a sound file (using .wav or .au format).
|
static void |
setMute(boolean mute)
Sets whether the audio system is muted.
|
static void |
setPaused(boolean pause)
Sets whether the audio system is paused.
|
public static final int SAMPLE_RATE
public static void addAudioEventListener(StdAudio.AudioEventListener listener)
public static void clearAudioEventListeners()
public static void close()
public static boolean isMuted()
public static boolean isPaused()
public static void loop(String filename)
public static double[] note(double hz, double duration, double amplitude)
public static void play(double in)
public static void play(double[] input)
public static void play(double[] input, double duration)
public static void play(Note note, double[] input, double duration)
public static void play(String filename)
public static double[] read(String filename)
public static void removeAudioEventListener(StdAudio.AudioEventListener listener)
public static void save(String filename, double[] input)
public static void setMute(boolean mute)
public static void setPaused(boolean pause)
public static void main(String[] args)