APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.media.sound

public final Class SoftMixingClip

extends SoftMixingDataLine
implements Clip
Class Inheritance
All Implemented Interfaces
javax.sound.sampled.Clip, javax.sound.sampled.DataLine, javax.sound.sampled.Line, java.lang.AutoCloseable
Imports
java.io.ByteArrayOutputStream, .IOException, .InputStream, java.util.Arrays, javax.sound.sampled.AudioFormat, .AudioInputStream, .AudioSystem, .Clip, .DataLine, .LineEvent, .LineUnavailableException

Clip implementation for the SoftMixingMixer.
Author
Karl Helgason

Field Summary

Modifier and TypeField and Description
private boolean
private float
private float
private int
private float
private int
private int
private int
private float
private boolean
private boolean
private AudioFloatInputStream
private int
private byte[]
private final InputStream
private AudioFormat
private int
private boolean
private int
private int
private boolean
private int
private int
private int
private int
private boolean
private int
private AudioFormat
private float[]
Inherited from com.sun.media.sound.SoftMixingDataLine:
CHORUS_SENDcontrol_mutexeff1gaineff2gaininfoleftgainlistenersmixerrightgain

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
available()

Implements javax.sound.sampled.DataLine.available.

Obtains the number of bytes of data currently available to the application for processing in the data line's internal buffer.

public void
close()

Implements javax.sound.sampled.Line.close.

Closes the line, indicating that any system resources in use by the line can be released.

public void
drain()

Implements javax.sound.sampled.DataLine.drain.

Drains queued data from the line by continuing data I/O until the data line's internal buffer has been emptied.

public void
flush()

Implements javax.sound.sampled.DataLine.flush.

Flushes queued data from the line.

public int
getBufferSize()

Implements javax.sound.sampled.DataLine.getBufferSize.

Obtains the maximum number of bytes of data that will fit in the data line's internal buffer.

public AudioFormat
getFormat()

Implements javax.sound.sampled.DataLine.getFormat.

Obtains the current format (encoding, sample rate, number of channels, etc.) of the data line's audio data.

public int
getFrameLength()

Implements javax.sound.sampled.Clip.getFrameLength.

Obtains the media length in sample frames.

public int
getFramePosition()

Implements javax.sound.sampled.DataLine.getFramePosition.

Obtains the current position in the audio data, in sample frames.

public float
getLevel()

Implements javax.sound.sampled.DataLine.getLevel.

Obtains the current volume level for the line.

public long
getLongFramePosition()

Implements javax.sound.sampled.DataLine.getLongFramePosition.

Obtains the current position in the audio data, in sample frames.

public long
getMicrosecondLength()

Implements javax.sound.sampled.Clip.getMicrosecondLength.

Obtains the media duration in microseconds.

public long
getMicrosecondPosition()

Implements javax.sound.sampled.DataLine.getMicrosecondPosition.

Obtains the current position in the audio data, in microseconds.

public boolean
isActive()

Implements javax.sound.sampled.DataLine.isActive.

Indicates whether the line is engaging in active I/O (such as playback or capture).

public boolean
isOpen()

Implements javax.sound.sampled.Line.isOpen.

Indicates whether the line is open, meaning that it has reserved system resources and is operational, although it might not currently be playing or capturing sound.

public boolean
isRunning()

Implements javax.sound.sampled.DataLine.isRunning.

Indicates whether the line is running.

public void
loop(int count)

Implements javax.sound.sampled.Clip.loop.

Starts looping playback from the current position.

public void
open(AudioInputStream stream)

Implements javax.sound.sampled.Clip.open.

Opens the clip with the format and audio data present in the provided audio input stream.

public void
open(AudioFormat format, byte[] data, int offset, int bufferSize)

Implements javax.sound.sampled.Clip.open.

Opens the clip, meaning that it should acquire any required system resources and become operational.

public void
open()

Implements javax.sound.sampled.Line.open.

Opens the line, indicating that it should acquire any required system resources and become operational.

protected void
protected void
public void
setFramePosition(int frames)

Implements javax.sound.sampled.Clip.setFramePosition.

Sets the media position in sample frames.

public void
setLoopPoints(int start, int end)

Implements javax.sound.sampled.Clip.setLoopPoints.

Sets the first and last sample frames that will be played in the loop.

public void
setMicrosecondPosition(long microseconds)

Implements javax.sound.sampled.Clip.setMicrosecondPosition.

Sets the media position in microseconds.

public void
start()

Implements javax.sound.sampled.DataLine.start.

Allows a line to engage in data I/O.

public void
stop()

Implements javax.sound.sampled.DataLine.stop.

Stops the line.

Inherited from com.sun.media.sound.SoftMixingDataLine:
addLineListenercalcVolumegetControlgetControlsgetLineInfoisControlSupportedremoveLineListenersendEvent

Field Detail

_activeback to summary
private boolean _active
_eff1gainback to summary
private float _eff1gain
_eff2gainback to summary
private float _eff2gain
_framepositionback to summary
private int _frameposition
_leftgainback to summary
private float _leftgain
_loopcountback to summary
private int _loopcount
_loopendback to summary
private int _loopend
_loopstartback to summary
private int _loopstart
_rightgainback to summary
private float _rightgain
activeback to summary
private boolean active
active_sgback to summary
private boolean active_sg
afisback to summary
private AudioFloatInputStream afis
bufferSizeback to summary
private int bufferSize
databack to summary
private byte[] data
datastreamback to summary
private final InputStream datastream
formatback to summary
private AudioFormat format
framepositionback to summary
private int frameposition
frameposition_sgback to summary
private boolean frameposition_sg
framesizeback to summary
private int framesize
in_nrofchannelsback to summary
private int in_nrofchannels
loop_sgback to summary
private boolean loop_sg
loopcountback to summary
private int loopcount
loopendback to summary
private int loopend
loopstartback to summary
private int loopstart
offsetback to summary
private int offset
openback to summary
private boolean open
out_nrofchannelsback to summary
private int out_nrofchannels
outputformatback to summary
private AudioFormat outputformat
readbufferback to summary
private float[] readbuffer

Constructor Detail

SoftMixingClipback to summary
pack-priv SoftMixingClip(SoftMixingMixer mixer, DataLine.Info info)

Method Detail

availableback to summary
public int available()

Implements javax.sound.sampled.DataLine.available.

Doc from javax.sound.sampled.DataLine.available.

Obtains the number of bytes of data currently available to the application for processing in the data line's internal buffer. For a source data line, this is the amount of data that can be written to the buffer without blocking. For a target data line, this is the amount of data available to be read by the application. For a clip, this value is always 0 because the audio data is loaded into the buffer when the clip is opened, and persists without modification until the clip is closed.

Note that the units used are bytes, but will always correspond to an integral number of sample frames of audio data.

An application is guaranteed that a read or write operation of up to the number of bytes returned from available() will not block; however, there is no guarantee that attempts to read or write more data will block.

Annotations
@Override
closeback to summary
public void close()

Implements javax.sound.sampled.Line.close.

Doc from javax.sound.sampled.Line.close.

Closes the line, indicating that any system resources in use by the line can be released. If this operation succeeds, the line is marked closed and a CLOSE event is dispatched to the line's listeners.

Annotations
@Override
drainback to summary
public void drain()

Implements javax.sound.sampled.DataLine.drain.

Doc from javax.sound.sampled.DataLine.drain.

Drains queued data from the line by continuing data I/O until the data line's internal buffer has been emptied. This method blocks until the draining is complete. Because this is a blocking method, it should be used with care. If drain() is invoked on a stopped line that has data in its queue, the method will block until the line is running and the data queue becomes empty. If drain() is invoked by one thread, and another continues to fill the data queue, the operation will not complete. This method always returns when the data line is closed.

Annotations
@Override
flushback to summary
public void flush()

Implements javax.sound.sampled.DataLine.flush.

Doc from javax.sound.sampled.DataLine.flush.

Flushes queued data from the line. The flushed data is discarded. In some cases, not all queued data can be discarded. For example, a mixer can flush data from the buffer for a specific input line, but any unplayed data already in the output buffer (the result of the mix) will still be played. You can invoke this method after pausing a line (the normal case) if you want to skip the "stale" data when you restart playback or capture. (It is legal to flush a line that is not stopped, but doing so on an active line is likely to cause a discontinuity in the data, resulting in a perceptible click.)

Annotations
@Override
getBufferSizeback to summary
public int getBufferSize()

Implements javax.sound.sampled.DataLine.getBufferSize.

Doc from javax.sound.sampled.DataLine.getBufferSize.

Obtains the maximum number of bytes of data that will fit in the data line's internal buffer. For a source data line, this is the size of the buffer to which data can be written. For a target data line, it is the size of the buffer from which data can be read. Note that the units used are bytes, but will always correspond to an integral number of sample frames of audio data.

Annotations
@Override
getFormatback to summary
public AudioFormat getFormat()

Implements javax.sound.sampled.DataLine.getFormat.

Doc from javax.sound.sampled.DataLine.getFormat.

Obtains the current format (encoding, sample rate, number of channels, etc.) of the data line's audio data.

If the line is not open and has never been opened, it returns the default format. The default format is an implementation specific audio format, or, if the DataLine.Info object, which was used to retrieve this DataLine, specifies at least one fully qualified audio format, the last one will be used as the default format. Opening the line with a specific audio format (e.g. SourceDataLine#open(AudioFormat)) will override the default format.

Annotations
@Override
getFrameLengthback to summary
public int getFrameLength()

Implements javax.sound.sampled.Clip.getFrameLength.

Doc from javax.sound.sampled.Clip.getFrameLength.

Obtains the media length in sample frames.

Annotations
@Override
getFramePositionback to summary
public int getFramePosition()

Implements javax.sound.sampled.DataLine.getFramePosition.

Doc from javax.sound.sampled.DataLine.getFramePosition.

Obtains the current position in the audio data, in sample frames. The frame position measures the number of sample frames captured by, or rendered from, the line since it was opened. This return value will wrap around after 2^31 frames. It is recommended to use getLongFramePosition instead.

Annotations
@Override
getLevelback to summary
public float getLevel()

Implements javax.sound.sampled.DataLine.getLevel.

Doc from javax.sound.sampled.DataLine.getLevel.

Obtains the current volume level for the line. This level is a measure of the signal's current amplitude, and should not be confused with the current setting of a gain control. The range is from 0.0 (silence) to 1.0 (maximum possible amplitude for the sound waveform). The units measure linear amplitude, not decibels.

Annotations
@Override
getLongFramePositionback to summary
public long getLongFramePosition()

Implements javax.sound.sampled.DataLine.getLongFramePosition.

Doc from javax.sound.sampled.DataLine.getLongFramePosition.

Obtains the current position in the audio data, in sample frames. The frame position measures the number of sample frames captured by, or rendered from, the line since it was opened.

Annotations
@Override
getMicrosecondLengthback to summary
public long getMicrosecondLength()

Implements javax.sound.sampled.Clip.getMicrosecondLength.

Doc from javax.sound.sampled.Clip.getMicrosecondLength.

Obtains the media duration in microseconds.

Annotations
@Override
getMicrosecondPositionback to summary
public long getMicrosecondPosition()

Implements javax.sound.sampled.DataLine.getMicrosecondPosition.

Doc from javax.sound.sampled.DataLine.getMicrosecondPosition.

Obtains the current position in the audio data, in microseconds. The microsecond position measures the time corresponding to the number of sample frames captured by, or rendered from, the line since it was opened. The level of precision is not guaranteed. For example, an implementation might calculate the microsecond position from the current frame position and the audio sample frame rate. The precision in microseconds would then be limited to the number of microseconds per sample frame.

Annotations
@Override
isActiveback to summary
public boolean isActive()

Implements javax.sound.sampled.DataLine.isActive.

Doc from javax.sound.sampled.DataLine.isActive.

Indicates whether the line is engaging in active I/O (such as playback or capture). When an inactive line becomes active, it sends a START event to its listeners. Similarly, when an active line becomes inactive, it sends a STOP event.

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Implements javax.sound.sampled.Line.isOpen.

Doc from javax.sound.sampled.Line.isOpen.

Indicates whether the line is open, meaning that it has reserved system resources and is operational, although it might not currently be playing or capturing sound.

Annotations
@Override
isRunningback to summary
public boolean isRunning()

Implements javax.sound.sampled.DataLine.isRunning.

Doc from javax.sound.sampled.DataLine.isRunning.

Indicates whether the line is running. The default is false. An open line begins running when the first data is presented in response to an invocation of the start method, and continues until presentation ceases in response to a call to stop or because playback completes.

Annotations
@Override
loopback to summary
public void loop(int count)

Implements javax.sound.sampled.Clip.loop.

Doc from javax.sound.sampled.Clip.loop.

Starts looping playback from the current position. Playback will continue to the loop's end point, then loop back to the loop start point count times, and finally continue playback to the end of the clip.

If the current position when this method is invoked is greater than the loop end point, playback simply continues to the end of the clip without looping.

A count value of 0 indicates that any current looping should cease and playback should continue to the end of the clip. The behavior is undefined when this method is invoked with any other value during a loop operation.

If playback is stopped during looping, the current loop status is cleared; the behavior of subsequent loop and start requests is not affected by an interrupted loop operation.

Annotations
@Override
openback to summary
public void open(AudioInputStream stream) throws LineUnavailableException, IOException

Implements javax.sound.sampled.Clip.open.

Doc from javax.sound.sampled.Clip.open.

Opens the clip with the format and audio data present in the provided audio input stream. Opening a clip means that it should acquire any required system resources and become operational. If this operation input stream. If this operation succeeds, the line is marked open and an OPEN event is dispatched to the line's listeners.

Invoking this method on a line which is already open is illegal and may result in an IllegalStateException.

Note that some lines, once closed, cannot be reopened. Attempts to reopen such a line will always result in a LineUnavailableException.

Annotations
@Override
Exceptions
LineUnavailableException:
if the line cannot be opened due to resource restrictions
IOException:
if an I/O exception occurs during reading of the stream
openback to summary
public void open(AudioFormat format, byte[] data, int offset, int bufferSize) throws LineUnavailableException

Implements javax.sound.sampled.Clip.open.

Doc from javax.sound.sampled.Clip.open.

Opens the clip, meaning that it should acquire any required system resources and become operational. The clip is opened with the format and audio data indicated. If this operation succeeds, the line is marked as open and an OPEN event is dispatched to the line's listeners.

Invoking this method on a line which is already open is illegal and may result in an IllegalStateException.

Note that some lines, once closed, cannot be reopened. Attempts to reopen such a line will always result in a LineUnavailableException.

Annotations
@Override
Exceptions
LineUnavailableException:
if the line cannot be opened due to resource restrictions
openback to summary
public void open() throws LineUnavailableException

Implements javax.sound.sampled.Line.open.

Doc from javax.sound.sampled.Line.open.

Opens the line, indicating that it should acquire any required system resources and become operational. If this operation succeeds, the line is marked as open, and an OPEN event is dispatched to the line's listeners.

Note that some lines, once closed, cannot be reopened. Attempts to reopen such a line will always result in an LineUnavailableException.

Some types of lines have configurable properties that may affect resource allocation. For example, a DataLine must be opened with a particular format and buffer size. Such lines should provide a mechanism for configuring these properties, such as an additional open method or methods which allow an application to specify the desired settings.

This method takes no arguments, and opens the line with the current settings. For SourceDataLine and TargetDataLine objects, this means that the line is opened with default settings. For a Clip, however, the buffer size is determined when data is loaded. Since this method does not allow the application to specify any data to load, an IllegalArgumentException is thrown. Therefore, you should instead use one of the open methods provided in the Clip interface to load data into the Clip.

For DataLine's, if the DataLine.Info object which was used to retrieve the line, specifies at least one fully qualified audio format, the last one will be used as the default format.

Annotations
@Override
Exceptions
LineUnavailableException:
if the line cannot be opened due to resource restrictions
processAudioLogicback to summary
protected void processAudioLogic(SoftAudioBuffer[] buffers)

Implements abstract com.sun.media.sound.SoftMixingDataLine.processAudioLogic.

Annotations
@Override
processControlLogicback to summary
protected void processControlLogic()

Implements abstract com.sun.media.sound.SoftMixingDataLine.processControlLogic.

Annotations
@Override
setFramePositionback to summary
public void setFramePosition(int frames)

Implements javax.sound.sampled.Clip.setFramePosition.

Doc from javax.sound.sampled.Clip.setFramePosition.

Sets the media position in sample frames. The position is zero-based; the first frame is frame number zero. When the clip begins playing the next time, it will start by playing the frame at this position.

To obtain the current position in sample frames, use the getFramePosition method of DataLine.

Annotations
@Override
setLoopPointsback to summary
public void setLoopPoints(int start, int end)

Implements javax.sound.sampled.Clip.setLoopPoints.

Doc from javax.sound.sampled.Clip.setLoopPoints.

Sets the first and last sample frames that will be played in the loop. The ending point must be greater than or equal to the starting point, and both must fall within the size of the loaded media. A value of 0 for the starting point means the beginning of the loaded media. Similarly, a value of -1 for the ending point indicates the last frame of the media.

Annotations
@Override
setMicrosecondPositionback to summary
public void setMicrosecondPosition(long microseconds)

Implements javax.sound.sampled.Clip.setMicrosecondPosition.

Doc from javax.sound.sampled.Clip.setMicrosecondPosition.

Sets the media position in microseconds. When the clip begins playing the next time, it will start at this position. The level of precision is not guaranteed. For example, an implementation might calculate the microsecond position from the current frame position and the audio sample frame rate. The precision in microseconds would then be limited to the number of microseconds per sample frame.

To obtain the current position in microseconds, use the getMicrosecondPosition method of DataLine.

Annotations
@Override
startback to summary
public void start()

Implements javax.sound.sampled.DataLine.start.

Doc from javax.sound.sampled.DataLine.start.

Allows a line to engage in data I/O. If invoked on a line that is already running, this method does nothing. Unless the data in the buffer has been flushed, the line resumes I/O starting with the first frame that was unprocessed at the time the line was stopped. When audio capture or playback starts, a START event is generated.

Annotations
@Override
stopback to summary
public void stop()

Implements javax.sound.sampled.DataLine.stop.

Doc from javax.sound.sampled.DataLine.stop.

Stops the line. A stopped line should cease I/O activity. If the line is open and running, however, it should retain the resources required to resume activity. A stopped line should retain any audio data in its buffer instead of discarding it, so that upon resumption the I/O can continue where it left off, if possible. (This doesn't guarantee that there will never be discontinuities beyond the current buffer, of course; if the stopped condition continues for too long, input or output samples might be dropped.) If desired, the retained data can be discarded by invoking the flush method. When audio capture or playback stops, a STOP event is generated.

Annotations
@Override