|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.Sink
ptolemy.actor.lib.javasound.AudioWriter
public class AudioWriter
This actor reads audio samples from the input port and writes the samples to the specified sound file. Any existing file with the same name will be silently overwritten. The input port is of type DoubleToken. Each DoubleToken read from the input port represents one sample of the audio data and should be in the range [-1.0, 1.0]. Any samples that are outside of this range will be hard-clipped to fall within this range before they are written to the sound file. Single channel (mono) and two channel (stereo) formats are supported. For single channel audio, tokens are written to channel 0 of the output port. For stereo , tokens are written to channel 0 (left) and channel 1 (right) of the output port.
The following parameters should be set to specify the format of the file to write. In all cases, an exception is thrown if an illegal parameter value is used. Note that if a parameter is changed while audio writing is active, all data written so far will be saved, and the sound file will be closed. Subsequent audio samples will then be written to a new sound file with the new parameter values.
There are security issues involved with accessing files and audio resources in applets. By default, applets are not allowed to write files. The .java.policy file may be modified to grant applets more privileges.
Note: Requires Java 2 v1.3.0 or later.
AudioReader,
AudioCapture,
AudioPlayer,
Serialized Form
| Yellow (chf) |
| Yellow (vogel) |
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class ptolemy.kernel.Entity |
|---|
Entity.ContainedObjectsIterator |
| Field Summary | |
|---|---|
private double[][] |
_audioPutArray
|
private int |
_channels
|
private int |
_curElement
|
private Token[][] |
_inArray
|
private int |
_putSampleSize
|
private boolean |
_safeToInitialize
|
private SoundWriter |
_soundWriter
|
Parameter |
bitsPerSample
The desired number of bits per sample. |
Parameter |
channels
The number of audio channels to use. |
StringAttribute |
pathName
The name of the file to write to. |
Parameter |
sampleRate
The desired sample rate to use, in Hz. |
| Fields inherited from class ptolemy.actor.lib.Sink |
|---|
input |
| 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 | |
|---|---|
AudioWriter(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
|
| Method Summary | |
|---|---|
private void |
_initializeWriter()
Initialize/Reinitialize audio resources. |
void |
attributeChanged(Attribute attribute)
Handle change requests for all parameters. |
java.lang.Object |
clone(Workspace workspace)
Clone the actor into the specified workspace. |
void |
initialize()
Open a new audio file for writing. |
int |
iterate(int count)
Invoke count iterations of this actor. |
boolean |
postfire()
If there is at least 1 token on channel 0 (and also on channel 1 if stereo mode is used), then read 1 token from the corresponding channels and write the token values to the specified sound file. |
void |
preinitialize()
Set up the number channels to use. |
void |
wrapup()
Close the specified file. |
| Methods inherited from class ptolemy.actor.TypedAtomicActor |
|---|
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints |
| 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 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, prefire, stop, stopFire, terminate |
| Methods inherited from interface ptolemy.actor.Initializable |
|---|
addInitializable, 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 |
|---|
public StringAttribute pathName
The audio format to use is determined by the file extension. E.g., "outfile.wav" will create a WAV format file. The supported file formats are AU, WAV, and, AIFF.
An exception will be occur if the path references an unsupported sound file.
public Parameter sampleRate
An exception will be thrown if an illegal value is used.
public Parameter bitsPerSample
public Parameter channels
private SoundWriter _soundWriter
private int _channels
private int _putSampleSize
private double[][] _audioPutArray
private int _curElement
private Token[][] _inArray
private boolean _safeToInitialize
| Constructor Detail |
|---|
public AudioWriter(CompositeEntity container,
java.lang.String name)
throws IllegalActionException,
NameDuplicationException
container - The container.name - The name of this actor.
IllegalActionException - If the actor cannot be contained
by the proposed container.
NameDuplicationException - If the container already has an
actor with this name.| Method Detail |
|---|
public void attributeChanged(Attribute attribute)
throws IllegalActionException
attributeChanged in class NamedObjattribute - The attribute that changed.
IllegalActionException - If the change is not
allowed.
public java.lang.Object clone(Workspace workspace)
throws java.lang.CloneNotSupportedException
clone in class AtomicActorworkspace - The workspace for the new object.
java.lang.CloneNotSupportedException - If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String),
NamedObj.setDeferringChangeRequests(boolean)
public void initialize()
throws IllegalActionException
initialize in interface Initializableinitialize in class AtomicActorIllegalActionException - If the file cannot be opened,
or if the parent class throws it.
public int iterate(int count)
throws IllegalActionException
This method should be called instead of the prefire(), fire(), and postfire() methods when this actor is used in a domain that supports vectorized actors.
iterate in interface Executableiterate in class AtomicActorcount - The number of iterations to perform.
IllegalActionException - If there is a problem
writing the audio sample(s) to the specified file.Executable
public boolean postfire()
throws IllegalActionException
postfire in interface Executablepostfire in class AtomicActorIllegalActionException - If there is a problem
writing the audio sample(s) to the specified file.
public void preinitialize()
throws IllegalActionException
preinitialize in interface Initializablepreinitialize in class AtomicActorIllegalActionException - If the parent class throws it.
public void wrapup()
throws IllegalActionException
wrapup in interface Initializablewrapup in class AtomicActorIllegalActionException - If there is a problem
closing the file.
private void _initializeWriter()
throws IllegalActionException
This method is synchronized since it is not safe to call SoundWriter methods while this method is executing.
IllegalActionException - If there is a problem
initializing the SoundWriter object.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||