ptolemy.actor.lib.javasound
Class SoundPlayer

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.javasound.SoundActor
                              extended by ptolemy.actor.lib.javasound.SoundPlayer
All Implemented Interfaces:
java.io.Serializable, 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:

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.

Note: Requires Java 2 v1.3.0 or later.

Since:
Ptolemy II 6.1
Version:
$Id: SoundPlayer.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
LiveSound, AudioCapture, AudioReader, AudioWriter, Serialized Form
Accepted Rating:
Red (eal)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  byte[] _playbackData
          Byte buffer used for playback data.
protected  javax.sound.sampled.SourceDataLine _sourceDataLine
          The data line being used for playback.
 TypedIOPort input
          The input port.
 
Fields inherited from class ptolemy.actor.lib.javasound.SoundActor
_bufferSize, _bytesPerSample, _channels, _isExecuting, _sampleRate, bufferSize, bytesPerSample, channels, sampleRate
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
SoundPlayer(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()
          Read an input array and send to the audio hardware.
 void wrapup()
          Stop audio playback and free up any audio resources used for audio playback.
 
Methods inherited from class ptolemy.actor.lib.javasound.SoundActor
_doubleArrayToByteArray, attributeChanged
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

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).


_playbackData

private byte[] _playbackData
Byte buffer used for playback data.


_sourceDataLine

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

Constructor Detail

SoundPlayer

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

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

initialize

public void initialize()
                throws 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 SoundPlayer actor is playing audio.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class SoundActor
Throws:
IllegalActionException - If there is a problem beginning audio playback.

postfire

public boolean postfire()
                 throws IllegalActionException
Read an input array and send to the audio hardware. If the audio buffer cannot accept the samples, then this method will stall the calling thread until it can.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - If there is a problem playing audio.

wrapup

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

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class SoundActor
Throws:
IllegalActionException - If there is a problem stopping audio playback.