public class SegmentedEnvelope extends SequentialDataCommon
VariableRateMonoReader
. Here is an example that
generates an envelope that looks like a traditional ADSR envelope.
// Create an amplitude envelope and fill it with data.
double[] ampData = {
0.02, 0.9, // duration,value pair 0, "attack"
0.10, 0.5, // pair 1, "decay"
0.50, 0.0 // pair 2, "release"
};
SegmentedEnvelope ampEnvelope = new SegmentedEnvelope( ampData );
// Hang at end of decay segment to provide a "sustain" segment.
ampEnvelope.setSustainBegin( 1 );
ampEnvelope.setSustainEnd( 1 );
// Play the envelope using queueOn so that it uses the sustain and release information.
synth.add( ampEnv = new VariableRateMonoReader() );
ampEnv.dataQueue.queueOn( ampEnvelope );
As an alternative you could use an EnvelopeDAHDSR
.VariableRateMonoReader
,
EnvelopeDAHDSR
maxFrames, numFrames
Constructor and Description |
---|
SegmentedEnvelope(double[] pairs) |
SegmentedEnvelope(int maxFrames) |
Modifier and Type | Method and Description |
---|---|
void |
allocate(int maxFrames) |
int |
getChannelsPerFrame() |
double |
getRateScaler(int index,
double synthesisPeriod)
Get rate to play the data.
|
void |
read(double[] data) |
void |
read(int startFrame,
double[] data,
int startIndex,
int numToRead) |
double |
readDouble(int index)
Read the value of an envelope, not the duration.
|
void |
write(double[] data) |
void |
write(int startFrame,
double[] data,
int startIndex,
int numToWrite)
Write frames of envelope data.
|
void |
writeDouble(int index,
double value)
Write a value at the given index.
|
getMaxFrames, getNumFrames, getReleaseBegin, getReleaseEnd, getSustainBegin, getSustainEnd, setNumFrames, setReleaseBegin, setReleaseEnd, setSustainBegin, setSustainEnd
public SegmentedEnvelope(int maxFrames)
public SegmentedEnvelope(double[] pairs)
public void allocate(int maxFrames)
public void write(int startFrame, double[] data, int startIndex, int numToWrite)
startFrame
- Index of frame in envelope to write to.data
- Pairs of duration and value.startIndex
- Index of frame in data[] to read from.numToWrite
- Number of frames (pairs) to write.public void read(int startFrame, double[] data, int startIndex, int numToRead)
public void write(double[] data)
public void read(double[] data)
public double readDouble(int index)
readDouble
in interface SequentialData
readDouble
in class SequentialDataCommon
index
- sample index is ((frameIndex * channelsPerFrame) + channelIndex)public void writeDouble(int index, double value)
SequentialData
writeDouble
in interface SequentialData
writeDouble
in class SequentialDataCommon
index
- sample index is ((frameIndex * channelsPerFrame) + channelIndex)value
- the value to be writtenpublic double getRateScaler(int index, double synthesisPeriod)
SequentialData
getRateScaler
in interface SequentialData
getRateScaler
in class SequentialDataCommon
public int getChannelsPerFrame()
getChannelsPerFrame
in interface SequentialData
getChannelsPerFrame
in class SequentialDataCommon