Class SoundPlayer

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class SoundPlayer
    extends SoundActor
    This actor plays audio samples provided on the input port. The audio samples that are supplied to this actor should be doubles in the range -1.0 to 1.0, provided as a DoubleMatrix, where the first index of the matrix represents the channel and the second index is the sample number. That is, each row is a sequence of samples for the channel corresponding to the row number. Any input value that is outside of the valid range will be hard-clipped to fall within the range [-1.0, 1.0] before it is written to the audio output port of the computer.

    The parameters are as follows:

    • sampleRate should be set to desired sample rate, in Hz. The default value is 8000. Allowable values are 8000, 11025, 22050, 44100, and 48000 Hz.
    • bytesPerSample gives the resolution of audio samples. This is an integer that defaults to 2, meaning 16-bit samples.
    • channels should be set to desired number of audio channels. Allowable values are 1 (for mono) and 2 (for stereo). The default value is 1. Some sound cards support more than two audio channels, but this is not supported in Java. FIXME: If this differs from the input dimensions?
    • transferSize The number of samples that will be transferred to the audio driver together. This is an integer with default 128.
    • sampleRate The requested buffer size in the audio hardware. This affects how far ahead of real time the model can get. There is no harm in making this large because this actor will overwrite previously queued values if necessary. This is an integer that defaults to 8000, representing a buffer with 8000 samples per channel. At an 8 kHz sample rate, this corresponds to one second of sound.

    All of these parameters are shared by all audio actors that use the audio hardware, so changing them in one of those actors will cause it to change in all.

    Since:
    Ptolemy II 6.1
    Version:
    $Id$
    Author:
    Edward A. Lee
    See Also:
    LiveSound, AudioCapture, AudioReader, AudioWriter
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • input

        public TypedIOPort input
        The input port. This port must receive double matrix tokens (in the range of -1.0 to 1.0).
      • _sourceDataLine

        protected javax.sound.sampled.SourceDataLine _sourceDataLine
        The data line being used for playback.