Documentation of 'edu.princeton.cs.algs4.StdAudio' Java class
StdAudio
edu.princeton.cs.algs4

Class StdAudio



  • public final class StdAudio
    extends java.lang.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 Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int SAMPLE_RATE
      The sample rate - 44,100 Hz for CD quality audio.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void close()
      Closes standard audio.
      static void loop(java.lang.String filename)
      Loops an audio file (in .wav, .mid, or .au format) in a background thread.
      static void main(java.lang.String[] args)
      Test client - play an A major scale to standard audio.
      static void play(double sample)
      Writes one sample (between -1.0 and +1.0) to standard audio.
      static void play(double[] samples)
      Writes the array of samples (between -1.0 and +1.0) to standard audio.
      static void play(java.lang.String filename)
      Plays an audio file (in .wav, .mid, or .au format) in a background thread.
      static double[] read(java.lang.String filename)
      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 void save(java.lang.String filename, double[] samples)
      Saves the double array as an audio file (using .wav or .au format).
      • Methods inherited from class java.lang.Object

        equals, 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()
        Closes standard audio.
      • play

        public static void play(double sample)
        Writes 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:
        java.lang.IllegalArgumentException - if the sample is Double.NaN
      • play

        public static void play(double[] samples)
        Writes 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:
        java.lang.IllegalArgumentException - if any sample is Double.NaN
        java.lang.IllegalArgumentException - if samples is null
      • read

        public static double[] read(java.lang.String filename)
        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.
        Parameters:
        filename - the name of the audio file
        Returns:
        the array of samples
      • save

        public static void save(java.lang.String filename,
                                double[] samples)
        Saves 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:
        java.lang.IllegalArgumentException - if unable to save filename
        java.lang.IllegalArgumentException - if samples is null
      • play

        public static void play(java.lang.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:
        java.lang.IllegalArgumentException - if unable to play filename
        java.lang.IllegalArgumentException - if filename is null
      • loop

        public static void loop(java.lang.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:
        java.lang.IllegalArgumentException - if filename is null
      • main

        public static void main(java.lang.String[] args)
        Test client - play an A major scale to standard audio.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.