Class AudioCapture
- 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 AudioCapture extends LiveSoundActor
This actor sequentially outputs audio samples that are captured from the audio input port of the computer. The audio input port typically corresponds to either the microphone input, line-in, or cd audio from the cdrom or dvd drive. It is not possible to select the desired input port under Java. This must be done from the operating system. This actor should be fired often enough to prevent overflow of the internal audio capture buffer. Overflow should be avoided, since it will result in loss of data. Each captured audio sample is converted to a double that may range from -1.0 to 1.0. Thus, the output type of this actor is DoubleToken.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 playback is active. If this actor is used in conjunction with an AudioPlayer actor, changing a parameter will cause the corresponding parameter value of the AudioPlayer 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 the desired sample rate, in Hz. The default value is 8000. Allowable values are 8000, 11025, 22050, 44100, and 48000 Hz. Note that Java does not support 96000 Hz operation, even if the audio hardware supports it.
- bitsPerSample should be set to the desired bit resolution. The default value is 16. Allowable values are 8 and 16. Note that Java does not support 20 or 24 bit audio, even if the audio hardware supports it.
- channels should be set to desired number of audio channels. The default value is 1 (for mono audio). Allowable values are 1 and 2 (for stereo). Note that more than two channels of audio is not currently supported in Java, even if the audio hardware supports it.
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.
There are security issues involved with accessing files and audio resources in applets. Applets are not allowed to capture audio from the audio input port (e.g., the microphone) by default since this could present a security risk. Therefore, the actor will not run in an applet by default. The .java.policy file may be modified to grant applets more privileges.
Note: Requires Java 2 v1.3.0 or later.
- Since:
- Ptolemy II 1.0
- Version:
- $Id$
- Author:
- Brian K. Vogel, Christopher Hylands, Steve Neuendorffer
- See Also:
LiveSound
,AudioPlayer
,SoundReader
,SoundWriter
- Pt.AcceptedRating:
- Yellow (chf)
- Pt.ProposedRating:
- Yellow (vogel)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description TypedIOPort
output
The output port.Parameter
output_tokenProductionRate
The output rate.TypedIOPort
trigger
The trigger port.-
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 AudioCapture(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 java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.void
initialize()
Read parameter values and begin the sound capture process.boolean
postfire()
Capture and output a single audio sample on each channel.void
wrapup()
Stop capturing audio.-
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, 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, 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
_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, 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
-
-
-
-
Field Detail
-
trigger
public TypedIOPort trigger
The trigger port.
-
output
public TypedIOPort output
The output port. This will always produce double data, between -1.0 and 1.0.
-
output_tokenProductionRate
public Parameter output_tokenProductionRate
The output rate.
-
-
Constructor Detail
-
AudioCapture
public AudioCapture(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the given container and name. In addition to invoking the base class constructors, construct the parameters and initialize them to their default values.- 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
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new actor.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class contains an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
initialize
public void initialize() throws IllegalActionException
Read parameter values and begin the sound capture process. An exception will occur if there is a problem starting the audio capture. This will occur if another AudioCapture actor has already started capturing.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classLiveSoundActor
- Throws:
IllegalActionException
- If there is a problem starting audio capture.
-
postfire
public boolean postfire() throws IllegalActionException
Capture and output a single audio sample on each channel. This method causes audio samples to be captured from the audio input device (e.g., the microphone or line-in). One token is written to the output port in an invocation. This method should be invoked often enough to prevent overflow of the internal audio capture buffer. Overflow should be avoided, since it will result in loss of data. This method will block until the samples have been read, so it is not possible to invoke this method too frequently.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True
- Throws:
IllegalActionException
- If audio cannot be captured.
-
wrapup
public void wrapup() throws IllegalActionException
Stop capturing audio. Free up any system resources involved in the capturing process.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classLiveSoundActor
- Throws:
IllegalActionException
- May be thrown by derived classes.
-
-