Package stdlib
Class StdAudio
java.lang.Object
stdlib.StdAudio
Standard audio. This class provides a basic capability for
  creating, reading, and saving audio. 
  
The audio format uses a sampling rate of 44,100 Hz, 16-bit, monaural.
For additional documentation, see Section 1.5 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
- Author:
- Robert Sedgewick, Kevin Wayne
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intThe sample rate: 44,100 Hz for CD quality audio.
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidclose()Closes standard audio.static voidDeprecated.static voidloopInBackground(String filename) Loops an audio file (in .wav, .mid, or .au format) in a background thread.static voidTest client - play an A major scale to standard audio.static voidplay(double sample) Writes one sample (between -1.0 and +1.0) to standard audio.static voidplay(double[] samples) Writes the array of samples (between -1.0 and +1.0) to standard audio.static voidDeprecated.replaced byplayInBackground(String filename)static voidplayInBackground(String filename) Plays an audio file (in .wav, .mid, or .au format) in a background thread.static double[]Reads audio samples from a file (in .wav or .au format) and returns them as a double array with values between -1.0 and +1.0.static voidSaves the double array as an audio file (using .wav or .au format).
- 
Field Details- 
SAMPLE_RATEThe sample rate: 44,100 Hz for CD quality audio.- See Also:
 
 
- 
- 
Method Details- 
closeCloses standard audio.
- 
playWrites one sample (between -1.0 and +1.0) to standard audio. If the sample is outside the range, it will be clipped.- Parameters:
- sample- the sample to play
- Throws:
- IllegalArgumentException- if the sample is- Double.NaN
 
- 
playWrites the array of samples (between -1.0 and +1.0) to standard audio. If a sample is outside the range, it will be clipped.- Parameters:
- samples- the array of samples to play
- Throws:
- IllegalArgumentException- if any sample is- Double.NaN
- IllegalArgumentException- if- samplesis- null
 
- 
readReads audio samples from a file (in .wav or .au format) and returns them as a double array with values between -1.0 and +1.0. The audio file must be 16-bit with a sampling rate of 44,100. It can be mono or stereo.- Parameters:
- filename- the name of the audio file
- Returns:
- the array of samples
 
- 
saveSaves the double array as an audio file (using .wav or .au format).- Parameters:
- filename- the name of the audio file
- samples- the array of samples
- Throws:
- IllegalArgumentException- if unable to save- filename
- IllegalArgumentException- if- samplesis- null
- IllegalArgumentException- if- filenameis- null
- IllegalArgumentException- if- filenameextension is not- .wavor- .au
 
- 
playDeprecated.replaced byplayInBackground(String filename)Plays an audio file (in .wav, .mid, or .au format) in a background thread.- Parameters:
- filename- the name of the audio file
- Throws:
- IllegalArgumentException- if unable to play- filename
- IllegalArgumentException- if- filenameis- null
 
- 
playInBackgroundPlays an audio file (in .wav, .mid, or .au format) in a background thread.- Parameters:
- filename- the name of the audio file
- Throws:
- IllegalArgumentException- if unable to play- filename
- IllegalArgumentException- if- filenameis- null
 
- 
loopDeprecated.replaced byloopInBackground(String filename)Loops an audio file (in .wav, .mid, or .au format) in a background thread.- Parameters:
- filename- the name of the audio file
- Throws:
- IllegalArgumentException- if- filenameis- null
 
- 
loopInBackgroundLoops an audio file (in .wav, .mid, or .au format) in a background thread.- Parameters:
- filename- the name of the audio file
- Throws:
- IllegalArgumentException- if- filenameis- null
 
- 
mainTest client - play an A major scale to standard audio.- Parameters:
- args- the command-line arguments
 
 
- 
loopInBackground(String filename)