ptolemy.actor.lib.javasound
Class AudioPlayer

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.javasound.LiveSoundActor
                              extended byptolemy.actor.lib.javasound.AudioPlayer
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, LiveSoundListener, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, java.io.Serializable, ptolemy.actor.TypedActor

public class AudioPlayer
extends LiveSoundActor

This actor reads audio samples and plays them. Specifically, the input stream that this actor reads is interpreted as consisting of audio samples. This actor writes this stream of audio samples to the audio output port of the computer, which typically consists of the computer speaker or the headphones output. The audio samples that are supplied to this actor should be doubles in the range [-1.0, 1.0]. Thus, the input port of this actor is of type DoubleToken. Any input tokens that are outside of the valid range will be hard-clipped to fall within the range [-1.0, 1.0] before they are written to the audio output port of the computer.

This actor should be fired often enough to prevent underflow of the internal audio playback buffer. Underflow should be avoided, since it will result in audio discontinuities (heard as clicks) in the output. No exception will be thrown if underflow occurs.

The following parameters should be set accordingly. In all cases, an exception is thrown if an illegal parameter value is used. Note that these parameters may be changed while audio capture is active. If this actor is used in conjunction with an AudioCapture actor, changing a parameter of this actor will cause the corresponding parameter value of the AudioCapture actor to automatically be set to the same value. This behavior is required because the AudioCapture and AudioPlayer actors both share access to the audio hardware, which is associated with a single sample rate, bit resolution, and number of channels.

It should be noted that at most one AudioCapture and one AudioPlayer actor may be used simultaneously. Otherwise, an exception will occur. This restriction may be lifted in a future version of this actor.

Note: Requires Java 2 v1.3.0 or later.

Since:
Ptolemy II 1.0
Version:
$Id: AudioPlayer.java,v 1.30 2004/04/13 03:08:32 cxh Exp $
Author:
Brian K. Vogel, Steve Neuendorffer
See Also:
LiveSound, AudioCapture, AudioReader, AudioWriter, Serialized Form
Accepted Rating:
Yellow (chf)
Proposed Rating:
Green (neuendor)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.actor.TypedIOPort input
          The input port.
 ptolemy.data.expr.Parameter input_tokenConsumptionRate
          The input rate.
 
Fields inherited from class ptolemy.actor.lib.javasound.LiveSoundActor
_channels, _isExecuting, _transferSize, bitsPerSample, channels, sampleRate, transferSize
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
AudioPlayer(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void initialize()
          Obtain access to the audio playback hardware, and start playback.
 boolean postfire()
          At most one token is read from each channel and written to the audio output port of the computer, which is typically the computer speaker or the headphones output.
 boolean prefire()
          Return true if the actor has enough data to fire.
 void wrapup()
          Stop audio playback and free up any audio resources used for audio playback.
 
Methods inherited from class ptolemy.actor.lib.javasound.LiveSoundActor
_initializeAudio, attributeChanged, liveSoundChanged
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, fire, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, iterate, preinitialize, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

input

public ptolemy.actor.TypedIOPort input
The input port. This port must receive double tokens (in the range of -1.0 to 1.0);


input_tokenConsumptionRate

public ptolemy.data.expr.Parameter input_tokenConsumptionRate
The input rate.

Constructor Detail

AudioPlayer

public AudioPlayer(ptolemy.kernel.CompositeEntity container,
                   java.lang.String name)
            throws ptolemy.kernel.util.IllegalActionException,
                   ptolemy.kernel.util.NameDuplicationException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
ptolemy.kernel.util.IllegalActionException - If the actor cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

initialize

public void initialize()
                throws ptolemy.kernel.util.IllegalActionException
Obtain access to the audio playback hardware, and start playback. An exception will occur if there is a problem starting playback. This will occur if another AudioPlayer actor is playing audio.

Specified by:
initialize in interface ptolemy.actor.Executable
Overrides:
initialize in class LiveSoundActor
Throws:
ptolemy.kernel.util.IllegalActionException - If there is a problem beginning audio playback.

prefire

public boolean prefire()
                throws ptolemy.kernel.util.IllegalActionException
Return true if the actor has enough data to fire.

Throws:
ptolemy.kernel.util.IllegalActionException

postfire

public boolean postfire()
                 throws ptolemy.kernel.util.IllegalActionException
At most one token is read from each channel and written to the audio output port of the computer, which is typically the computer speaker or the headphones output.

Throws:
ptolemy.kernel.util.IllegalActionException - If there is a problem playing audio.

wrapup

public void wrapup()
            throws ptolemy.kernel.util.IllegalActionException
Stop audio playback and free up any audio resources used for audio playback.

Specified by:
wrapup in interface ptolemy.actor.Executable
Overrides:
wrapup in class LiveSoundActor
Throws:
ptolemy.kernel.util.IllegalActionException - If there is a problem stopping audio playback.