Class AudioCue
- All Implemented Interfaces:
AudioMixerTrack,AutoCloseable
AudioCue class functions as a data line, where the
audio data played directly from memory. AudioCue is modeled
upon javax.sound.sampled.Clip but with additional capabilities.
It can play multiple instances concurrently, and offers individual
dynamic controls for volume, panning and speed for each concurrently
playing instance.
An AudioCue is created using the static factory method
makeAudioCue. When doing so, the media data is loaded
either from a "CD Quality" wav file (44100 fps, 16-bit, stereo,
little-endian) or a float array of stereo PCM normalized to the
range -1 to 1, at 44100 fps. Once loaded, the media data is
immutable.
AudioCue achieves concurrent playback by treating state at
two levels. A distinction is made between the AudioCue
which holds the audio data, and a playback instance which
controls a cursor that traverses over that data and corresponds to
a single sounding playback. Methods that dynamically affect
playback (volume, pan, speed) operate at the instance level. When
using the factory method to create an AudioCue, the
maximum number of simultaneously playing instances to be supported
is set, along with the data source.
An AudioCue is either open or closed. Upon opening, an
output line is obtained from the system. That line will either be
held directly by the AudioCue or provided indirectly by an
AudioMixer, in which case 'opening' refers to the act
of registering as an AudioMixerTrack with an
AudioMixer. Upon closing, the AudioCue releases the
system audio line, or if registered with an AudioMixer,
unregisters. Opening and closing events are broadcast to registered
listeners implementing the methods
AudioCueListener.audioCueOpened and
AudioCueListener.audioCueClosed.
The line used for output is a
javax.sound.sampled.SourceDataLine. The format specified
for the line is 44100 fps, 16-bit, stereo, little-endian, a format
also known as "CD Quality". This format is one of the most widely
supported and is the only format available for output via
AudioCue. If a javax.sound.sampled.Mixer is not
specified, the default behavior is to obtain the line from the
system's default Mixer, with a buffer size of 1024 frames
(4192 bytes). The line will be run from within a dedicated thread,
with a thread priority of HIGHEST. Given that the
processing of audio data usually progresses much faster than time
it takes to play the media, this thread can be expected to spend
most of its time in a blocked state, which allows maximizing the
thread priority without impacting overall performance. An
alternative Mixer, buffer length or thread priority can be
specified as parameters to the open method.
An instance can either be active or not active,
and, if active, can either be running or not running.
Instances are initially held in a pool as 'available instances'.
An instance becomes active when it is removed from that pool.
Methods which remove an instance from the pool either return an
int identifier or -1 if there are no available instances.
An active instance can receive commands pertaining to the cursor's
location in the audio data, to starting or stopping, as well as
volume, pan, and speed changes, and other commands. An inactive
instance can only receive a command that withdraws it from the
'available instances' pool. An instance that is running
is one that is currently being played.
Each instance holds its own state variables for volume, pan and speed, cursor location, and looping. Methods are provided for changing these values. If the methods are called while the instance is not running, the new value is stored immediately and will take affect when the instance is restarted. If the instance is running, and the change is for volume, pan, or speed, the new value will be arrived at incrementally, with the increments occurring behind the scenes on a per frame basis. This is done to prevent discontinuities in the signal that might result in audible clicks. If a running instance's property is updated before the incremental changes have completed, the new target value takes precedence, and a new increment is created based on the current, in-progress value.
An instance may be played on a fire-and-forget basis, in
which case it is automatically returned to the pool of available
instances (active == false). Alternatively, the instance can be
allowed to stay active upon completion. The behavior upon play
completion is controlled by the public method
setRecycleWhenDone(int, boolean), where int is the
instance identifier. When a play method is called, the
recycledWhenDone value is set to true by default.
When obtainInstance is used, the recycledWhenDone
value is set to false.
Examples: (assumes the audioCue is open)
// (1) Fire-and-Forget, with default values.
audioCue.play(); // (vol = 1, pan = 0, speed = 1, loop = 0)
// instance will be recycled upon completion.
// (2) Fire-and-forget, with explicit values
int play0 = audioCue.play(0.5, -0.75, 2, 1);
// will play at "half" volume, "half way" to the left pan,
// double the speed, and will loop back and play again one time.
// Instance will be recycled upon completion, however, the
// play0 variable allows one to make further changes to the
// instance if executed prior to the completion of the
// playback.
// (3) Using obtainInstance()
int footstep = footstepCue.obtainInstance();
for (int i = 0; i < 10; i++) {
// play the successive footsteps more quietly
footstepCue.setVolume(footstep, 1 - (i * 0.1));
// successive footsteps will travel from left to right
footstepCue.setPan(footstep, -1 + (i * 0.2));
// cursor must be manually placed at the beginning
footstepCue.setFramePosition(footstep, 0);
footstepCue.start(footstep);
Thread.sleep(1000); // Allow time between each footstep start.
// This assumes that the cue is shorter than 1 second in
// in length and each start will stop on its own.
}
// Another instance might be associated with a slightly
// different speed, for example 1.1, implying a different
// individual with a slightly lighter foot fall.
More extensive examples can be found in the companion github project audiocue-demo.
- Since:
- 2.0.0
- Version:
- 2.0.0
- Author:
- Philip Freihofner
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AudioFormatAjavax.sound.sampled.AudioFormat, set to the only format used byAudioCue, also known as 'CD quality.' The type is signed PCM, with a rate of 44100 frames per second, with 16 bit encoding for each PCM value, stereo, and with the constituent bytes of each PCM value given in little-endian order.static final intA value indicating the default number of PCM frames in a buffer used inAudioCuePlayerfor processing media output.static final Line.InfoAn immutablejavax.sound.sampled.Line.Infothat is used when obtaining aSourceDataLinefor media output.static final intA value indicating the number of frames over which the pan setting changes incrementally when a new pan value is given.static final intA value indicating the number of frames over which the speed setting changes incrementally when a new speed value is given.static final intA value indicating the number of frames over which the volume changes incrementally when a new volume is given. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAudioCueListener(AudioCueListener listener) Registers anAudioCueListenerto receive notifications of events pertaining to theAudioCueand its playing or playable instances.voidclose()Releases resources allocated for media play.longGets the media length in sample frames.doublegetFramePosition(int instanceID) Returns the current sample frame number.booleangetIsActive(int instanceID) Returnstrueif the designated instance is active,falseif not.booleangetIsPlaying(int instanceID) Returnstrueif instance is playing,falseif notlongGets the media length in microseconds.getName()Returns the name associated with theAudioCue.doublegetPan(int instanceID) Returns a double in the range [-1, 1] where -1 corresponds to 100% left, 1 corresponds to 100% right, and 0 corresponds to center.float[]Returns a copy of the signed, normalized float PCM array for thisAudioCue.doublegetSpeed(int instanceID) Returns a factor indicating the current rate of play of theAudioCueinstance relative to normal play.doublegetVolume(int instanceID) Returns a value indicating the current volume setting of anAudioCueinstance, ranging [0..1].booleanIndicates if the track is or is not being included in theAudioMixermedia out.static AudioCuemakeStereoCue(float[] cue, String name, int polyphony) Creates and returns a newAudioCue.static AudioCuemakeStereoCue(URL url, int polyphony) Creates and returns a newAudioCue.intObtains anintinstance identifier from a pool of available instances and marks this instance as 'active'.voidopen()Readies thisAudioCuefor media play by instantiating, registering, and running the inner classAudioCuePlayerwith default settings.voidopen(int bufferFrames) Readies thisAudioCuefor media play by instantiating, registering, and running the inner classAudioCuePlayerwith a custom buffer size.voidopen(AudioMixer audioMixer) Registers anAudioMixer, instead of an inner classAudioCuePlayer, to handle the media play.voidReadies thisAudioCuefor media play by instantiating, registering, and running the inner classAudioCuePlayerwith explicit settings for thejavax.sound.sampled.Mixer, the number of PCM frames used in an internal buffer, and the priority level for the thread created to handle the media play.intplay()Obtains anAudioCueinstance and if theAudioCuehas been opened, starts playing from the beginning, with default values: full volume, center pan and at normal speed, and returns anintidentifying the instance, or, returns -1 if noAudioCueinstance is available.intplay(double volume) Obtains anAudioCueinstance and if theAudioCuehas been opened, starts playing from the beginning, at the given volume, at the default center pan, and at the default normal speed, and returns anintidentifying the instance, or, returns -1 if noAudioCueinstance is available.intplay(double volume, double pan, double speed, int loop) Obtains anAudioCueinstance and if theAudioCuehas been opened, starts playing from the beginning, at the given volume, pan, speed and number of repetitions, and returns anintidentifying the instance, or, returns -1 if noAudioCueinstance is available.float[]Reads one buffer of normalized audio data frames of the track.voidreleaseInstance(int instanceID) Releases anAudioCueinstance, making it available as a new concurrently playing instance.voidremoveAudioCueListener(AudioCueListener listener) Removes anAudioCueListenerfrom receiving notifications of events pertaining to theAudioCueand its playing instances.voidsetFractionalPosition(int instanceID, double normal) Repositions the play position ("play head") of the designatedAudioCueinstance to the frame that corresponds to the specified elapsed fractional part the total audio cue length.voidsetFramePosition(int instanceID, double frame) Sets the play position ("play head") to a specified sample frame location.voidsetLooping(int instanceID, int loops) Sets the number of times the media will restart from the beginning, after completing, or specifies infinite looping via the value -1.voidsetMicrosecondPosition(int instanceID, int microseconds) Repositions the play position ("play head") of the designatedAudioCueinstance to the frame that corresponds to the specified elapsed time in microseconds.voidSets the name of theAudioCue.voidsetPan(int instanceID, double pan) Sets the pan of the instance, where 100% left corresponds to -1, 100% right corresponds to 1, and center = 0.voidsetPanType(AudioCueFunctions.PanType panType) Assigns the type of panning to be used.voidsetRecycleWhenDone(int instanceID, boolean recycleWhenDone) Sets an internal flag which determines what happens when the designated instance finishes playing.voidsetSpeed(int instanceID, double speed) Sets the play speed of theAudioCueinstance.voidsetTrackRunning(boolean trackRunning) Used to set whether or not thisAudioMixerTrackis to be included in theAudioMixermedia out.voidsetVolType(AudioCueFunctions.VolType volType) Assigns a function to map linear volume settings to volume factors used to control the sound cue's amplitude.voidsetVolume(int instanceID, double volume) Sets the volume of the instance.voidstart(int instanceID) Plays the specifiedAudioCueinstance from its current position in the data, using existing volume, pan, and speed settings.voidstop(int instanceID) Sends message to indicate that the playing of the instance associated with theintidentifier should be halted.
-
Field Details
-
audioFormat
Ajavax.sound.sampled.AudioFormat, set to the only format used byAudioCue, also known as 'CD quality.' The type is signed PCM, with a rate of 44100 frames per second, with 16 bit encoding for each PCM value, stereo, and with the constituent bytes of each PCM value given in little-endian order. -
info
An immutablejavax.sound.sampled.Line.Infothat is used when obtaining aSourceDataLinefor media output. -
DEFAULT_BUFFER_FRAMES
public static final int DEFAULT_BUFFER_FRAMESA value indicating the default number of PCM frames in a buffer used inAudioCuePlayerfor processing media output.- See Also:
-
VOLUME_STEPS
public static final int VOLUME_STEPSA value indicating the number of frames over which the volume changes incrementally when a new volume is given.- See Also:
-
SPEED_STEPS
public static final int SPEED_STEPSA value indicating the number of frames over which the speed setting changes incrementally when a new speed value is given.- See Also:
-
PAN_STEPS
public static final int PAN_STEPSA value indicating the number of frames over which the pan setting changes incrementally when a new pan value is given.- See Also:
-
-
Method Details
-
getName
Returns the name associated with theAudioCue.- Returns:
- the name as a
String
-
setName
Sets the name of theAudioCue.- Parameters:
name- - aStringto associate with thisAudioCue
-
addAudioCueListener
Registers anAudioCueListenerto receive notifications of events pertaining to theAudioCueand its playing or playable instances.Notifications occur on the thread which processes the audio signal, and includes events such as the starting, stopping, and looping of instances. Implementations of the methods that receive these notifications should be coded for brevity in order to minimize extraneous processing on the audio thread.
- Parameters:
listener- - an object implementing theAudioCueListenerinterface
-
removeAudioCueListener
Removes anAudioCueListenerfrom receiving notifications of events pertaining to theAudioCueand its playing instances.- Parameters:
listener- - an object implementing theAudioCueListenerinterface
-
setVolType
Assigns a function to map linear volume settings to volume factors used to control the sound cue's amplitude.- Parameters:
volType- - a member of theenum AudioCue.VolType- See Also:
-
setPanType
Assigns the type of panning to be used.- Parameters:
panType- - a member of theenum AudioCue.PanType- See Also:
-
makeStereoCue
Creates and returns a newAudioCue. This method allows the direct insertion of afloatPCM array as an argument, where the data is presumed to be stereo signed, normalized floats with a sample rate of 44100 frames per second. The name for this cue is set by thenameargument. The maximum number of concurrent playing instances is set with thepolyphonyargument.- Parameters:
cue- - afloatarray of audio data in "CD Quality" format, scaled to the range [-1, 1]name- - aStringto be associated with theAudioCuepolyphony- - anintspecifying the maximum number of concurrent instances- Returns:
- AudioCue
-
makeStereoCue
public static AudioCue makeStereoCue(URL url, int polyphony) throws UnsupportedAudioFileException, IOException Creates and returns a newAudioCue. The file designated by theURLargument is loaded and held in memory. Only one format, known as "CD Quality", is supported: 44100 frames per second, 16-bit encoding, stereo, little-endian. The maximum number of concurrent playing instances is given as thepolyphonyargument. The file name is derived from theURLargument, but can be changed via the methodsetName.- Parameters:
url- - aURLfor the source filepolyphony- - anintspecifying the maximum number of concurrent instances- Returns:
- AudioCue
- Throws:
UnsupportedAudioFileException- if the media being loaded is not 44100 fps, 16-bit, stereo, little-endianIOException- if unable to load the file
-
getPcmCopy
public float[] getPcmCopy()Returns a copy of the signed, normalized float PCM array for thisAudioCue.- Returns:
- a
float[]new copy of the internal array of the PCM for theAudioCue
-
open
Readies thisAudioCuefor media play by instantiating, registering, and running the inner classAudioCuePlayerwith default settings. Internally, the registeredAudioCuePlayerinstance obtains and configures ajavax.sound.sampled.SourceDataLineto write to the default systemjavax.sound.sampled.Mixer, and will make use of the default internal buffer size of 1024 PCM frames, and will run with the default thread priority setting of 10.Once completed, this
AudioCueis marked open and theAudioCueListener.audioCueOpenedmethod is called on every registeredAudioCueListener.NOTE: data can be read from an
AudioCueeven if it is not open. The data that is read from an unopenedAudioCuewill not be written to aSourceDataLineand will not be heard.- Throws:
IllegalStateException- if thisAudioCueis already openLineUnavailableException- if unable to obtain aSourceDataLinefor the player, which could occur if the Mixer does not support theAudioFormatimplemented byAudioCue- See Also:
-
open
Readies thisAudioCuefor media play by instantiating, registering, and running the inner classAudioCuePlayerwith a custom buffer size. As the performance of the AudioCuePlayer is subject to tradeoffs based upon the size of an internal buffer, a number of frames other than the default of 1024 can be specified with this method. A lower value responds more quickly to dynamic requests, but is more prone to underflow which can result in audible drop outs. The registeredAudioCuePlayerinstance obtains and configures ajavax.sound.sampled.SourceDataLineto write to the default systemjavax.sound.sampled.Mixer, and will run with the default thread priority setting of 10.Once completed, this
AudioCueis marked open and theAudioCueListener.audioCueOpenedmethod is called on every registeredAudioCueListener.NOTE: data can be read from an
AudioCueeven if it is not open. The data that is read from an unopenedAudioCuewill not be written to aSourceDataLineand will not be heard.- Parameters:
bufferFrames- - anintspecifying the size of the internal buffer in PCM frames- Throws:
IllegalStateException- if thisAudioCueis already openLineUnavailableException- if unable to obtain aSourceDataLinefor the player, which could occur if the Mixer does not support theAudioFormatimplemented byAudioCue- See Also:
-
open
Readies thisAudioCuefor media play by instantiating, registering, and running the inner classAudioCuePlayerwith explicit settings for thejavax.sound.sampled.Mixer, the number of PCM frames used in an internal buffer, and the priority level for the thread created to handle the media play. Internally, the registeredAudioCuePlayerinstance obtains and configures ajavax.sound.sampled.SourceDataLineto write to the providedjavax.sound.sampled.Mixerrather than the default system Mixer. As the performance of the AudioCuePlayer is subject to tradeoffs based upon the size of an internal buffer, a number of frames other than the default of 1024 can be specified. A lower value responds more quickly to dynamic requests, but is more prone to underflow which can result in audible drop outs. While the default thread priority setting of 10 is generally safe given that to audio processing spending a majority of its time in a blocked state, this method allows specification of a lower priority setting.Once completed, this
AudioCueis marked open and theaudioCueOpenedmethod is called on every registeredAudioCueListener.NOTE: data can be read from an
AudioCueeven if it is not open. The data that is read from an unopenedAudioCuewill not be written to aSourceDataLineand will not be heard.- Parameters:
mixer- - ajavax.sound.sampled.Mixer. Ifnull, the system default mixer is used.bufferFrames- - anintspecifying the size of the internal buffer in PCM framesthreadPriority- - anintspecifying the priority level of the thread, clamped to the range 1 to 10 inclusive- Throws:
IllegalArgumentException- if the thread priority is not in the range MIN_PRIORITY to MAX_PRIORITY.IllegalStateException- if thisAudioCueis already openLineUnavailableException- if unable to obtain aSourceDataLinefor the player, which could occur if the Mixer does not support theAudioFormatimplemented byAudioCue- See Also:
-
open
Registers anAudioMixer, instead of an inner classAudioCuePlayer, to handle the media play. ThisAudioCuewill be added as anAudioMixerTrackto the registeredAudioMixer, and the buffer size and the thread priority of theAudioMixerwill take effect for media play.Once completed, the
AudioCueis marked open and theAudioCueListener.audioCueOpenedmethod is called on every registeredAudioCueListener.NOTE: data can be read from an
AudioCueeven if it is not open. The data that is read from an unopenedAudioCuewill not be written to aSourceDataLineand will not be heard.- Parameters:
audioMixer- - theAudioMixerthat will handle media output for thisAudioCue- Throws:
IllegalStateException- if theAudioCueis already open- See Also:
-
close
public void close()Releases resources allocated for media play. If theAudioCuewas opened as a stand alone cue, its inner classAudioPlayerrunnable will be allowed to end, and allocated resources will be cleaned up. If theAudioCuewas opened as a track on anAudioMixer, the track will be removed from theAudioMixer.Once completed, the
AudioCueis marked closed and theAudioCueListener.audioCueClosedmethod is called on every registeredAudioCueListener.- Specified by:
closein interfaceAutoCloseable- Throws:
IllegalStateException- if player is already closed- See Also:
-
getFrameLength
public long getFrameLength()Gets the media length in sample frames.- Returns:
- length in sample frames
-
getMicrosecondLength
public long getMicrosecondLength()Gets the media length in microseconds.- Returns:
- length in microseconds
-
obtainInstance
public int obtainInstance()Obtains anintinstance identifier from a pool of available instances and marks this instance as 'active'. If no playable instances are available, the method returns -1.The instance designated by this identifier is not automatically recycled back into the pool of available instances when it finishes playing. To put the instance back in the pool of available instances, the method
releaseInstancemust be called. To change the behavior so that the instance is returned to the pool when it plays completely to the end, usesetRecycleWhenDone(int, boolean).When executed, the
AudioCueListener.instanceEventOccurredmethod will be called with an argument ofAudioCueInstanceEvent.Type.OBTAIN_INSTANCE.- Returns:
- an
intinstance ID for an active instance, or -1 if no instances are available - See Also:
-
releaseInstance
public void releaseInstance(int instanceID) Releases anAudioCueinstance, making it available as a new concurrently playing instance. Once released, and back in the pool of available instances, an instance cannot receive updates.When executed, the
AudioCueListener.instanceEventOccurredmethod will be called with an argument ofAudioCueInstanceEvent.Type.RELEASE_EVENT.- Parameters:
instanceID- - anintidentifying the instance to be released- See Also:
-
play
public int play()Obtains anAudioCueinstance and if theAudioCuehas been opened, starts playing from the beginning, with default values: full volume, center pan and at normal speed, and returns anintidentifying the instance, or, returns -1 if noAudioCueinstance is available.If an
AudioCueinstance is available to play, theAudioCueListener.instanceEventOccurredmethod will be called twice, with argumentsAudioCueInstanceEvent.Type.OBTAIN_INSTANCEandAudioCueInstanceEvent.Type.START_INSTANCE. This instance will be set to automatically recycle back into the pool of available instances when playing completes.NOTE: the
playmethod can be called on an unopenedAudioCue. If unopened, theAudioCuePlayer.readTrackmethod will advance theAudioCueCursorand return a buffer of PCM data when called, but will not write the data to the sound system.- Returns:
- an
intidentifying the playing instance, or -1 if no instance is available - See Also:
-
play
public int play(double volume) Obtains anAudioCueinstance and if theAudioCuehas been opened, starts playing from the beginning, at the given volume, at the default center pan, and at the default normal speed, and returns anintidentifying the instance, or, returns -1 if noAudioCueinstance is available.If an
AudioCueinstance is available to play, theAudioCueListener.instanceEventOccurredmethod will be called twice, with argumentsAudioCueInstanceEvent.Type.OBTAIN_INSTANCEandAudioCueInstanceEvent.Type.START_INSTANCE. This instance will be set to automatically recycle back into the pool of available instances when playing completes.NOTE: the
playmethod can be called on an unopenedAudioCue. If unopened, theAudioCuePlayer.readTrackmethod will advance theAudioCueCursorand return a buffer of PCM data when called, but will not write the data to the sound system.- Parameters:
volume- - adoublein the range [0, 1]- Returns:
- an
intidentifying the playing instance, or -1 if no instance is available - See Also:
-
play
public int play(double volume, double pan, double speed, int loop) Obtains anAudioCueinstance and if theAudioCuehas been opened, starts playing from the beginning, at the given volume, pan, speed and number of repetitions, and returns anintidentifying the instance, or, returns -1 if noAudioCueinstance is available.If an
AudioCueinstance is available for play back, theAudioCueListener.instanceEventOccurredmethod will be called twice, with argumentsAudioCueInstanceEvent.Type.OBTAIN_INSTANCEandAudioCueInstanceEvent.Type.START_INSTANCE. This instance will be set to automatically recycle back into the pool of available instances when playing completes.NOTE: the
playmethod can be called on an unopenedAudioCue. If unopened, theAudioCuePlayer.readTrackmethod will advance theAudioCueCursorand return a buffer of PCM data when called, but will not write the data to the sound system.- Parameters:
volume- - adoublewithin the range [0, 1]pan- - adoublewithin the range [-1, 1]speed- - adoublefactor that is multiplied to the frame rateloop- - anintthat specifies a number of additional plays (looping)- Returns:
- an
intidentifying the playing instance, or -1 if no instance is available - See Also:
-
start
public void start(int instanceID) Plays the specifiedAudioCueinstance from its current position in the data, using existing volume, pan, and speed settings.If an
AudioCueinstance is able to start, theAudioCueListener.instanceEventOccurredmethod will be called with the argumentAudioCueInstanceEvent.Type.START_INSTANCE.If the
AudioCuehas not been opened, calls toAudioMixerTrack.readTrack()can be used to advance the cursors and produce a buffer-length float[] array of the mix of all the playing instances without sending the data on to aSourceDataLineto be heard.- Parameters:
instanceID- - anintused to identify anAudioCueinstance- Throws:
IllegalStateException- if instance is not active or if instance is already playing- See Also:
-
stop
public void stop(int instanceID) Sends message to indicate that the playing of the instance associated with theintidentifier should be halted. Calling this method on an already stopped instance does nothing. The instance is left in an open state.The
AudioCueListener.instanceEventOccurredmethod will be called with the argumentAudioCueInstanceEvent.Type.STOP_INSTANCE.- Parameters:
instanceID- - anintused to identify anAudioCueinstance- Throws:
IllegalStateException- if instance is not active- See Also:
-
getFramePosition
public double getFramePosition(int instanceID) Returns the current sample frame number. The frame count is zero-based. The position may lie in between two frames.- Parameters:
instanceID- - anintused to identify anAudioCueinstance- Returns:
- a
doublecorresponding to the current sample frame position - Throws:
IllegalStateException- if instance is not active- See Also:
-
setFramePosition
public void setFramePosition(int instanceID, double frame) Sets the play position ("play head") to a specified sample frame location. The frame count is zero-based. The play position can be a fractional amount, lying between two frames.The input frame position will be clamped to a value that lies within or at the start or end of the media data. When the instance is next started, it will commence from this position.
An instance cannot have its position changed if it is currently playing. An attempt to do so will throw an
IllegalStateException.- Parameters:
instanceID- - anintused to identify anAudioCueinstanceframe- - adoublegiving the frame position from which play will commence if thestartmethod is executed- Throws:
IllegalStateException- if instance is not active or if the instance is playing- See Also:
-
setMicrosecondPosition
public void setMicrosecondPosition(int instanceID, int microseconds) Repositions the play position ("play head") of the designatedAudioCueinstance to the frame that corresponds to the specified elapsed time in microseconds. The new play position can be a fractional amount, lying between two frames.The input microsecond position will be clamped to a frame that lies within or is located at the start or end of the media data. When the instance is next started, it will commence from this position.
An instance cannot have its position changed if it is currently playing. An attempt to do so will throw an
IllegalStateException.- Parameters:
instanceID- - anintused to identify anAudioCueinstancemicroseconds- - anintin microseconds that corresponds to a position in the audio media- Throws:
IllegalStateException- if instance is not active or if instance is playing- See Also:
-
setFractionalPosition
public void setFractionalPosition(int instanceID, double normal) Repositions the play position ("play head") of the designatedAudioCueinstance to the frame that corresponds to the specified elapsed fractional part the total audio cue length. The new play position can be a fractional amount, lying between two frames.The fractional position argument is clamped to the range [0..1], where 1 corresponds to 100% of the media. When restarted, the instance will commence from the new sample frame position.
An instance cannot have its position changed if it is currently playing. An attempt to do so will throw an
IllegalStateException.- Parameters:
instanceID- - anintused to identify theAudioCueinstancenormal- - adoublein the range [0..1] that corresponds to a position in the media- Throws:
IllegalStateException- if instance is not active or if instance is playing- See Also:
-
getVolume
public double getVolume(int instanceID) Returns a value indicating the current volume setting of anAudioCueinstance, ranging [0..1].- Parameters:
instanceID- - anintused to identify theAudioCueinstance- Returns:
- volume factor as a
double - Throws:
IllegalStateException- if instance is not active- See Also:
-
setVolume
public void setVolume(int instanceID, double volume) Sets the volume of the instance. Volumes can be altered while an instance is either playing or stopped. When a volume change is presented while the instance is playing, a smoothing algorithm used to prevent signal discontinuities that could result in audible clicks. If a second volume change arrives before the first change is completed, the most recent volume change takes precedence.Arguments are clamped to the range [0..1], with 0 denoting silence and 1 denoting the natural volume of the sample. In other words, the volume control can only diminish the volume of the media, not amplify it. Internally, the volume argument is used as a factor that is directly multiplied against the media's PCM values.
- Parameters:
instanceID- - anintused to identify theAudioCueinstancevolume- - afloatin the range [0, 1] multiplied against the audio values- Throws:
IllegalStateException- if instance is not active- See Also:
-
getPan
public double getPan(int instanceID) Returns a double in the range [-1, 1] where -1 corresponds to 100% left, 1 corresponds to 100% right, and 0 corresponds to center.The calculations used to apply the pan are determined by the
PanType.- Parameters:
instanceID- - anintused to identify theAudioCueinstance- Returns:
- the current pan value, ranging [-1, 1]
- Throws:
IllegalStateException- if instance is not active- See Also:
-
setPan
public void setPan(int instanceID, double pan) Sets the pan of the instance, where 100% left corresponds to -1, 100% right corresponds to 1, and center = 0. The pan setting can either be changed while a cue is either playing or stopped. If the instance is playing, a smoothing algorithm used to prevent signal discontinuities that result in audible clicks. If a second pan change arrives before the first change is completed, the most recent pan change takes precedence.Arguments are clamped to the range [-1, 1]. The calculations used to apply the pan are determined by the
PanType.- Parameters:
instanceID- - anintused to identify theAudioCueinstancepan- - adoubleranging from -1 to 1- Throws:
IllegalStateException- if instance is not active- See Also:
-
getSpeed
public double getSpeed(int instanceID) Returns a factor indicating the current rate of play of theAudioCueinstance relative to normal play.- Parameters:
instanceID- - anintused to identify anAudioCueinstance- Returns:
- a
floatfactor indicating the speed at which theAudioCueinstance is being played in the range [0.125, 8] - Throws:
IllegalStateException- if instance is not active
-
setSpeed
public void setSpeed(int instanceID, double speed) Sets the play speed of theAudioCueinstance. A faster speed results in both higher-pitched frequency content and a shorter duration. Play speeds can be altered in while a cue is either playing or stopped. If the instance is playing, a smoothing algorithm used to prevent signal discontinuities. If a second speed change arrives before the first change is completed, the most recent speed change takes precedence.A speed of 1 will play the
AudioCueinstance at its originally recorded speed. A value of 2 will double the play speed, and a value of 0.5 will halve the play speed. Arguments are clamped to values ranging from 8 times slower to 8 times faster than unity, a range of [0.125, 8].- Parameters:
instanceID- - anintused to identify anAudioCueinstancespeed- -adoublefactor ranging from 0.125 to 8- Throws:
IllegalStateException- if instance is not active
-
setLooping
public void setLooping(int instanceID, int loops) Sets the number of times the media will restart from the beginning, after completing, or specifies infinite looping via the value -1. Note: an instance set to loop 2 times will play back a total of 3 times.- Parameters:
instanceID- - anintused to identify anAudioCueinstanceloops- - anintthat specifies the number of times an instance will return to the beginning and play the instance anew- Throws:
IllegalStateException- if instance is not active
-
setRecycleWhenDone
public void setRecycleWhenDone(int instanceID, boolean recycleWhenDone) Sets an internal flag which determines what happens when the designated instance finishes playing. Iftruethe instance will be added to the pool of available instances and will not accept updates. Iffalsethen the instance will remain available for updates.By default, an instance that is obtained and started via the
playmethod automatically recycles, and an instance obtained viagetInstancedoes not. In both cases the behavior can be changed by setting this flag.- Parameters:
instanceID- - anintused to identify anAudioCueinstancerecycleWhenDone- - abooleanthat designates whether to recycle the instance or not when the instance plays through to completion- Throws:
IllegalStateException- if the instance is not active
-
getIsActive
public boolean getIsActive(int instanceID) Returnstrueif the designated instance is active,falseif not. An active instance is one which is not in the pool of available instances, but is open to receiving commands. It may or may not be playing at any given moment.- Parameters:
instanceID- - anintused to identify anAudioCueinstance- Returns:
trueif the instance is active,falseif not- See Also:
-
getIsPlaying
public boolean getIsPlaying(int instanceID) Returnstrueif instance is playing,falseif not- Parameters:
instanceID- - anintused to identify anAudioCueinstance- Returns:
trueif instance is playing,falseif not
-
isTrackRunning
public boolean isTrackRunning()Description copied from interface:AudioMixerTrackIndicates if the track is or is not being included in theAudioMixermedia out. If the method returnstrue, this track is included in the mix. Iffalse, the track is ignored, as if a 'mute' button had been pressed.- Specified by:
isTrackRunningin interfaceAudioMixerTrack- Returns:
trueif the track is being included in the mix, otherwisefalse
-
setTrackRunning
public void setTrackRunning(boolean trackRunning) Description copied from interface:AudioMixerTrackUsed to set whether or not thisAudioMixerTrackis to be included in theAudioMixermedia out. When set totrue, thisAudioMixerTrackwill be included in the audio mix. When set tofalse, this track will be ignored, and not included in the audio mix, as if a 'mute' button had been pressed.- Specified by:
setTrackRunningin interfaceAudioMixerTrack- Parameters:
trackRunning- - iftrue, this track will be included in the audio mix, iffalsethis track will not be included
-
readTrack
public float[] readTrack()Description copied from interface:AudioMixerTrackReads one buffer of normalized audio data frames of the track.- Specified by:
readTrackin interfaceAudioMixerTrack- Returns:
- one buffer of normalized audio frames
-