public class SamplePlayer extends UGen
Sample
. Playback rate and loop points can
be controlled by UGen
s. The playback point in the Sample
can
also be directly controlled from UGen
to perform scrubbing. The
player can be set to a number of different loop modes. If constructed with a
Sample
argument, the number of outputs of SamplePlayer is determined
by the number of channels of the Sample
. Sample
playback can
use either linear or cubic interpolation.
TODO: Loop cross-fading has not been implemented yet.Modifier and Type | Class and Description |
---|---|
static class |
SamplePlayer.EnvelopeType
Used to determine whether the SamplePlayer updates control values at
sample rate (
SamplePlayer.EnvelopeType.FINE ) or just every frame (
SamplePlayer.EnvelopeType.COARSE ). |
static class |
SamplePlayer.InterpolationType
Used to determine what kind of interpolation is used when access samples.
|
static class |
SamplePlayer.LoopType
Used to determine which kind of loop the sample player will use.
|
UGen.OutputInitializationRegime, UGen.OutputPauseRegime
Modifier and Type | Field and Description |
---|---|
static float |
ADAPTIVE_INTERP_HIGH_THRESH |
static float |
ADAPTIVE_INTERP_LOW_THRESH |
protected SamplePlayer.EnvelopeType |
envelopeType |
protected boolean |
forwards
Flag for alternating loop mode to determine if playback is in forward or
reverse phase.
|
protected float[] |
frame
Array for temp storage.
|
protected SamplePlayer.InterpolationType |
interpolationType
The interpolation type.
|
protected boolean |
killOnEnd
Flag to determine whether the SamplePlayer should kill itself when it
gets to the end of the Sample.
|
protected float |
loopCrossFade
The loop cross fade in milliseconds.
|
protected float |
loopEnd
The loop end.
|
protected UGen |
loopEndEnvelope
The loop end envelope.
|
protected float |
loopStart
The loop start.
|
protected UGen |
loopStartEnvelope
The loop start envelope.
|
protected SamplePlayer.LoopType |
loopType
The loop type.
|
protected double |
position
The position in milliseconds.
|
protected UGen |
positionEnvelope
The position envelope.
|
protected double |
positionIncrement
The millisecond position increment per sample.
|
protected float |
rate
The rate.
|
protected UGen |
rateEnvelope
The rate envelope.
|
protected Sample |
sample
The Sample.
|
protected boolean |
startLoop
Flag to determine whether playback starts at the beginning of the sample
or at the beginning of the loop.
|
bufferSize, bufIn, bufOut, context, ins, outputInitializationRegime, outputPauseRegime, outs
Constructor and Description |
---|
SamplePlayer(AudioContext context,
int outs)
Instantiates a new SamplePlayer with given number of outputs.
|
SamplePlayer(AudioContext context,
Sample buffer)
Instantiates a new SamplePlayer with given Sample.
|
Modifier and Type | Method and Description |
---|---|
void |
calculateBuffer()
Called by the signal chain to update this UGen's ouput data.
|
protected void |
calculateNextPosition(int i)
Used at each sample in the perform routine to determine the next playback
position.
|
Sample |
getBuffer()
Deprecated.
|
Bead |
getEndListener()
Gets the current endListener.
|
SamplePlayer.EnvelopeType |
getEnvelopeType()
Gets the
SamplePlayer.EnvelopeType , either SamplePlayer.EnvelopeType.COARSE or
SamplePlayer.EnvelopeType.FINE . |
SamplePlayer.InterpolationType |
getInterpolationType()
Gets the
SamplePlayer.InterpolationType used for accessing samples. |
boolean |
getKillOnEnd()
Determines whether this SamplePlayer will kill itself at the end of the
Sample it is playing.
|
float |
getLoopCrossFade()
Gets the loop cross fade.
|
UGen |
getLoopEndEnvelope()
Deprecated.
Use
getLoopEndUGen() instead. |
UGen |
getLoopEndUGen()
Gets the loop end UGen.
|
UGen |
getLoopStartEnvelope()
Deprecated.
Use
getLoopStartUGen() instead. |
UGen |
getLoopStartUGen()
Gets the loop start UGen.
|
SamplePlayer.LoopType |
getLoopType()
Gets the loop type.
|
UGen |
getPitchEnvelope()
Deprecated.
use
getPitchUGen() instead. |
UGen |
getPitchUGen()
Gets the rate UGen (this method is provided so that SamplePlayer and
GranularSamplePlayer can be used interchangeably).
|
double |
getPosition()
Gets the playback position.
|
UGen |
getPositionEnvelope()
Deprecated.
Use
getRateUGen() instead. |
UGen |
getPositionUGen()
Gets the position UGen.
|
UGen |
getRateEnvelope()
Deprecated.
use
getRateUGen() instead. |
UGen |
getRateUGen()
Gets the rate UGen.
|
Sample |
getSample()
Gets the Sample.
|
float |
getSampleRate()
Gets the sample rate.
|
boolean |
inLoop()
Determines whether the playback position is within the loop points.
|
void |
reset()
Resets the position to the start of the Sample.
|
void |
reTrigger()
Re trigger the SamplePlayer from the beginning.
|
void |
setBuffer(Sample s)
Deprecated.
|
void |
setEndListener(Bead endListener)
Sets a
Bead that will be triggered when this SamplePlayer gets to
the end. |
void |
setEnvelopeType(SamplePlayer.EnvelopeType et)
Sets the
SamplePlayer.EnvelopeType . |
void |
setInterpolationType(SamplePlayer.InterpolationType interpolationType)
Sets the interpolation type.
|
void |
setKillOnEnd(boolean killOnEnd)
Sets/unsets option for SamplePlayer to kill itself when it reaches the
end of the Sample it is playing.
|
void |
setLoopCrossFade(float loopCrossFade)
Sets the loop cross fade.
|
void |
setLoopEnd(UGen loopEndUGen)
Sets the loop end UGen.
|
void |
setLoopEndEnvelope(UGen loopEndEnvelope)
Deprecated.
Use
setLoopEnd(UGen) instead. |
void |
setLoopPointsFraction(float start,
float end)
Sets both loop points to static values as fractions of the Sample length,
overriding any UGens that were controlling the loop points.
|
void |
setLoopStart(UGen loopStartUGen)
Sets the loop start UGen.
|
void |
setLoopStartEnvelope(UGen loopStartEnvelope)
Deprecated.
Use
setLoopStart(UGen) instead. |
void |
setLoopType(SamplePlayer.LoopType loopType)
Sets the loop type.
|
void |
setPitch(UGen rateUGen)
Sets the rate UGen (this method is provided so that SamplePlayer and
GranularSamplePlayer can be used interchangeably).
|
void |
setPitchEnvelope(UGen rateEnvelope)
Deprecated.
use
setPitch(UGen) instead. |
void |
setPosition(double position)
Sets the playback position.
|
void |
setPosition(UGen positionUGen)
Sets the position as a UGen.
|
void |
setPositionEnvelope(UGen positionEnvelope)
Deprecated.
Use
setPosition(UGen) instead. |
void |
setRate(UGen rateUGen)
Sets the rate to a UGen.
|
void |
setRateEnvelope(UGen rateEnvelope)
Deprecated.
use
setRate(UGen) instead. |
void |
setSample(Sample sample)
Sets the Sample.
|
void |
setToEnd()
Sets the playback position to the end of the Sample.
|
void |
setToLoopStart()
Sets the playback position to the loop start point.
|
void |
start(float msPosition)
Starts the sample at the given position.
|
addDependent, addInput, addInput, clearDependents, clearInputConnections, containsInput, crossfadeInput, getConnectedInputs, getContext, getEnvelopes, getIns, getNumberOfConnectedUGens, getNumberOfDependents, getOutBuffer, getOuts, getTimeTakenLastUpdate, getValue, getValue, getValueDouble, getValueDouble, initializeOuts, isTimerMode, isUpdated, noInputs, pause, printInBuffers, printInputList, printOutBuffers, removeAllConnections, removeConnection, removeDependent, setOutsToPause, setTimerMode, setValue, update, zeroIns, zeroOuts
getKillListener, getName, isDeleted, isPaused, kill, message, messageReceived, setKillListener, setName, start, toString
public static final float ADAPTIVE_INTERP_LOW_THRESH
public static final float ADAPTIVE_INTERP_HIGH_THRESH
protected Sample sample
protected double position
protected UGen positionEnvelope
protected UGen rateEnvelope
protected double positionIncrement
AudioContext
's sample rate and the Sample
's sample
rate.protected boolean forwards
protected SamplePlayer.EnvelopeType envelopeType
protected SamplePlayer.InterpolationType interpolationType
protected UGen loopStartEnvelope
protected UGen loopEndEnvelope
protected SamplePlayer.LoopType loopType
protected float loopCrossFade
protected boolean startLoop
protected boolean killOnEnd
protected float rate
protected float loopStart
protected float loopEnd
protected float[] frame
public SamplePlayer(AudioContext context, int outs)
context
- the AudioContext.outs
- the number of outputs.public SamplePlayer(AudioContext context, Sample buffer)
context
- the AudioContext.buffer
- the Sample.public void setSample(Sample sample)
public void setBuffer(Sample s)
public Sample getSample()
public Sample getBuffer()
public void setToEnd()
public boolean inLoop()
public void setToLoopStart()
public void start(float msPosition)
msPosition
- the position in milliseconds.public void reset()
public double getPosition()
public void setPosition(double position)
position
- the new position in milliseconds.@Deprecated public UGen getPositionEnvelope()
getRateUGen()
instead.public UGen getPositionUGen()
@Deprecated public void setPositionEnvelope(UGen positionEnvelope)
setPosition(UGen)
instead.positionEnvelope
- the new position envelope.public void setPosition(UGen positionUGen)
positionUGen
- the new position UGen.@Deprecated public UGen getRateEnvelope()
getRateUGen()
instead.public UGen getRateUGen()
@Deprecated public void setRateEnvelope(UGen rateEnvelope)
setRate(UGen)
instead.rateEnvelope
- the new rate envelope.public void setRate(UGen rateUGen)
rateUGen
- the new rate UGen.@Deprecated public UGen getPitchEnvelope()
getPitchUGen()
instead.public UGen getPitchUGen()
@Deprecated public void setPitchEnvelope(UGen rateEnvelope)
setPitch(UGen)
instead.rateEnvelope
- the new rate envelope.public void setPitch(UGen rateUGen)
rateUGen
- the new rate UGen.public SamplePlayer.EnvelopeType getEnvelopeType()
SamplePlayer.EnvelopeType
, either SamplePlayer.EnvelopeType.COARSE
or
SamplePlayer.EnvelopeType.FINE
.SamplePlayer.EnvelopeType
.public void setEnvelopeType(SamplePlayer.EnvelopeType et)
SamplePlayer.EnvelopeType
. The value SamplePlayer.EnvelopeType.COARSE
means that elements controlled by UGens will not be modified every
sample, but every sample frame. The value SamplePlayer.EnvelopeType.FINE
means
that values will be updated every sample. Use COARSE to save processing
resources, but use FINE if you want clean and sample accurate control of
values.et
- the SamplePlayer.EnvelopeType
.public SamplePlayer.InterpolationType getInterpolationType()
SamplePlayer.InterpolationType
used for accessing samples.public void setInterpolationType(SamplePlayer.InterpolationType interpolationType)
interpolationType
- the new interpolation type.public float getLoopCrossFade()
public void setLoopCrossFade(float loopCrossFade)
loopCrossFade
- the new loop cross fade in milliseconds.@Deprecated public UGen getLoopEndEnvelope()
getLoopEndUGen()
instead.public UGen getLoopEndUGen()
@Deprecated public void setLoopEndEnvelope(UGen loopEndEnvelope)
setLoopEnd(UGen)
instead.loopEndEnvelope
- the new loop end envelope.public void setLoopEnd(UGen loopEndUGen)
loopEndUGen
- the new loop end UGen.@Deprecated public UGen getLoopStartEnvelope()
getLoopStartUGen()
instead.public UGen getLoopStartUGen()
@Deprecated public void setLoopStartEnvelope(UGen loopStartEnvelope)
setLoopStart(UGen)
instead.loopStartEnvelope
- the new loop start envelope.public void setLoopStart(UGen loopStartUGen)
loopStartUGen
- the new loop start UGen.public void setLoopPointsFraction(float start, float end)
start
- the start value, as fraction of the Sample length.end
- the end value, as fraction of the Sample length.public SamplePlayer.LoopType getLoopType()
public void setLoopType(SamplePlayer.LoopType loopType)
loopType
- the new loop type.public float getSampleRate()
public void calculateBuffer()
UGen
UGen.bufIn
and putting data
into UGen.bufOut
in some way. UGen.bufIn
and UGen.bufOut
are 2D arrays of floats of the form float[numChannels][bufferSize]. The length of the buffers is given by
UGen.bufferSize
, and the number of channels of the input and output buffers are given by UGen.ins
and UGen.outs
respectively.calculateBuffer
in class UGen
public void setKillOnEnd(boolean killOnEnd)
killOnEnd
- true to kill on end.public boolean getKillOnEnd()
public void setEndListener(Bead endListener)
Bead
that will be triggered when this SamplePlayer gets to
the end. This occurs when the SamplePlayer's position reaches then end
when playing forwards in a non-looping mode, or reaches the the beginning
when playing backwards in a non-looping mode. It is never triggered in a
looping mode. As an alternative, you can use the method Bead.#setKillListener(Bead)
as long as setKillOnEnd(boolean)
is
set to true. In other words, you set this SamplePlayer to kill itself
when it reaches the end of the sample, and then use the functionality of
Bead
, which allows you to create a trigger whenever a Bead is
killed. Set to null to remove the current listener.endListener
- the Bead
that responds to this SamplePlayer reaching
its end.public Bead getEndListener()
{#setEndListener(Bead)}.
public void reTrigger()
protected void calculateNextPosition(int i)
i
- the index within the buffer loop.