
AudioWriteBuffer |
ptolemy.actor.lib.javasound.AudioWriteBuffer |
This actor writes audio samples to a buffer and saves the buffer
to a sound file on wrapup. In each iteration, if there is a token
available on the <i>data</i> and <i>address</i> ports, then the
data DoubleToken is written to the buffer location specified by
the address IntToken. The valid address range is 0 to
<i>bufferLength</i> -1. If an invalid address is specified, then
the data value will be ignored and no data will be written.
The audio samples in the buffer will be written to the sound file
specified by the <i>pathName</i> parameter on wrapup.
<p>
Any existing file with the same name will be silently
overwritten. The data port is of type DoubleToken. Each DoubleToken
read from the data 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) audio is
supported but stereo is not supported.
<p>
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.
<p>
<ul>
<li><i>pathName</i> should be set to the name of the output
file. Any existing file with the same name will be silently
overwritten. Relative filenames are supported. The default value is
"outfile.wav". 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. For example,
to write samples to a Sun AU format file with the name "test.au"
in the directory "c:\tmp", this parameter should be set to the
value c:\tmp\test.au. To write samples to a file with name "test.au"
in the current directory, this parameter should be set to the value
test.au.
<li><i>channels</i> should be set to desired number of audio
channels. Allowable values are 1 (for mono) and 2 (for stereo).
The default value is 1. Only single-channel audio is currently
supported. This limitation will be removed in a future version
of this actor.
<li><i>sampleRate</i> should be set to desired sample rate,
in Hz. The DoubleTokens read in by this actor will be
interpreted as having this sample rate. Allowable values are
8000, 11025, 22050, 44100, and 48000. The default value is 8000.
<li><i>bitsPerSample</i> should be set to desired bit
resolution. Allowable values are 8 and 16. The default value is 16.
</ul>
<p>
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.
<p>
Note: Requires Java 2 v1.3.0 or later.
<p>FIXME: this should extend AudioWriter
Author(s): Brian K. Vogel
Version:$Id: AudioWriteBuffer.doc.html,v 1.1 2006/02/22 18:40:26 mangal Exp $
Pt.Proposed Rating:Red (vogel)
Pt.Accepted Rating:Red (vogel)
address
The address port, which is a multiport.
data
The data port, which is a multiport.
bufferLength
The length of the audio buffer to use. The default value
is 8000.
overwrite
The write mode to use. If this parameter is set to true, then
a write to a buffer element overwrites the old value in the
buffer. Otherwise, a write adds the new value to the old value
of the buffer element.
sampleRate
The desired sample rate to use, in Hz. Valid values
include: 8000, 11025, 22050, 44100, and 48000.
The default value of the sample rate is an IntToken equal
to 8000.
<p>
An exception will be thrown if an illegal value is used.
bitsPerSample
The desired number of bits per sample. The default value is
an IntToken equal to 16. Supported values are 8 and 16.
An exception will be thrown if an illegal value is
used.
channels
The number of audio channels to use. Supported values are
1 (single channel) and 2 (stereo).
The default value is an IntToken equal to 1.
An exception will be thrown if an illegal value is used.