Class AudioPlayer
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
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.
- 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. Some sound cards support 96000 Hz operation, but this is not supported in Java.
- bitsPerSample should be set to desired bit resolution. The default value is 16. Allowable values are 8 and 16. Some sound cards support 20 and 24 bit audio, but this is not supported in Java.
- 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.
If more than one AudioPlayer actor is used in model, the sounds produced by these actors will be interleaved. This may make sense, for example, if the actor is used in a ModalModel.
- Since:
- Ptolemy II 1.0
- Version:
- $Id$
- Author:
- Brian K. Vogel, Steve Neuendorffer
- See Also:
LiveSound
,AudioCapture
,AudioReader
,AudioWriter
- Pt.AcceptedRating:
- Yellow (chf)
- Pt.ProposedRating:
- Green (neuendor)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description TypedIOPort
input
The input port.Parameter
input_tokenConsumptionRate
The input rate.-
Fields inherited from class ptolemy.actor.lib.javasound.LiveSoundActor
_bitsPerSample, _bufferSize, _channels, _isExecuting, _sampleRate, _transferSize, bitsPerSample, bufferSize, channels, sampleRate, transferSize
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description AudioPlayer(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
initialize()
Obtain access to the audio playback hardware, and start playback.boolean
postfire()
Read a block of inputs as given by the transferSize parameter from each input channel and send them to the audio hardware.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
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, 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
_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, 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
-
-
-
-
Field Detail
-
input
public TypedIOPort input
The input port. This port must receive double tokens (in the range of -1.0 to 1.0);
-
input_tokenConsumptionRate
public Parameter input_tokenConsumptionRate
The input rate.
-
-
Constructor Detail
-
AudioPlayer
public AudioPlayer(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.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classLiveSoundActor
- Throws:
IllegalActionException
- If there is a problem beginning audio playback.
-
prefire
public boolean prefire() throws IllegalActionException
Return true if the actor has enough data to fire.- Specified by:
prefire
in interfaceExecutable
- Overrides:
prefire
in classAtomicActor<TypedIOPort>
- Returns:
- True if this actor is ready for firing, false otherwise.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
postfire
public boolean postfire() throws IllegalActionException
Read a block of inputs as given by the transferSize parameter from each input channel and send them to the audio hardware. If the audio buffer cannot accept them, then this method will stall the calling thread until it can.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- 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 interfaceInitializable
- Overrides:
wrapup
in classLiveSoundActor
- Throws:
IllegalActionException
- If there is a problem stopping audio playback.
-
-