Squeak Class Documentation category index | class index  
 
Envelope
  category: Sound-Synthesis
  superclass: Object
  subclasses: VolumeEnvelope RandomEnvelope PitchEnvelope

An envelope models a three-stage progression for a musical note: attack, sustain, decay. Envelopes can either return the envelope value at a given time or can update some target object using a client-specified message selector.

The points instance variable holds an array of (time, value) points, where the times are in milliseconds. The points array must contain at least two points. The time coordinate of the first point must be zero and the time coordinates of subsequent points must be in ascending order, although the spacing between them is arbitrary. Envelope values between points are computed by linear interpolation.

The scale slot is initially set so that the peak of envelope matches some note attribute, such as its loudness. When entering the decay phase, the scale is adjusted so that the decay begins from the envelope's current value. This avoids a potential sharp transient when entering the decay phase.

The loopStartIndex and loopEndIndex slots contain the indices of points in the points array; if they are equal, then the envelope holds a constant value for the sustain phase of the note. Otherwise, envelope values are computed by repeatedly looping between these two points.

The loopEndMSecs slot can be set in advance (as when playing a score) or dynamically (as when responding to interactive inputs from a MIDI keyboard). In the latter case, the value of scale is adjusted to start the decay phase with the current envelope value. Thus, if a note ends before its attack is complete, the decay phase is started immediately (i.e., the attack phase is never completed).

For best results, amplitude envelopes should start and end with zero values. Otherwise, the sharp transient at the beginning or end of the note may cause audible clicks or static. For envelopes on other parameters, this may not be necessary.

instance methods
  accessing
  attackTime
centerPitch:
decayEndIndex
decayTime
duration
duration:
loopEndIndex
loopStartIndex
name
points
scale
scale:
target
target:
updateSelector
updateSelector:
volume:

  applying
  computeValueAtMSecs:
reset
showOnDisplay
sustainEnd:
updateTargetAt:
valueAtMSecs:

  private
  checkParameters
computeIncrementAt:between:and:scale:
incrementalComputeValueAtMSecs:
indexOfPointAfterMSecs:startingAt:
interpolate:between:and:
setPoints:loopStart:loopEnd:

  storing
  storeOn:

class methods
  instance creation
  example
exponentialDecay:
points:loopStart:loopEnd:

instance methods
  accessing top  
 

attackTime

Return the time taken by the attack phase.


 

centerPitch:

Set the center pitch of a pitch-controlling envelope. This default implementation does nothing.


 

decayEndIndex


 

decayTime

Return the time taken by the decay phase.


 

duration

Return the time of the final point.


 

duration:

Set the note duration to the given number of seconds.


 

loopEndIndex


 

loopStartIndex


 

name

Answer a name for the receiver. This is used generically in the title of certain inspectors, such as the referred-to inspector, and specificially by various subsystems. By default, we let the object just print itself out..


 

points


 

scale


 

scale:


 

target


 

target:


 

updateSelector


 

updateSelector:


 

volume:

Set the maximum volume of a volume-controlling envelope. This default implementation does nothing.


  applying top  
 

computeValueAtMSecs:

Return the value of this envelope at the given number of milliseconds from its onset. Return zero for times outside the time range of this envelope.


 

reset

Reset the state for this envelope.


 

showOnDisplay

Envelope example showOnDisplay


 

sustainEnd:

Set the ending time of the sustain phase of this envelope; the decay phase will start this point. Typically derived from a note's duration.


 

updateTargetAt:

Send my updateSelector to the given target object with the value of this envelope at the given number of milliseconds from its onset. Answer true if the value changed.


 

valueAtMSecs:

Return the value of this envelope at the given number of milliseconds from its onset. Return zero for times outside the time range of this envelope.


  private top  
 

checkParameters

Verify that the point array, loopStartIndex, and loopStopIndex obey the rules.


 

computeIncrementAt:between:and:scale:

Compute the current and increment values for the given time between the given inflection points.


 

incrementalComputeValueAtMSecs:

Compute the current value, per-step increment, and the time of the next inflection point.


 

indexOfPointAfterMSecs:startingAt:

Return the index of the first point whose time is greater that mSecs, starting with the given index. Return nil if mSecs is after the last point's time.


 

interpolate:between:and:

Return the scaled, interpolated value for the given time between the given time points.


 

setPoints:loopStart:loopEnd:


  storing top  
 

storeOn:

Append to the argument aStream a sequence of characters that is an
expression whose evaluation creates an object similar to the receiver.


class methods
  instance creation top  
 

example

Envelope example showOnDisplay


 

exponentialDecay:

(Envelope exponentialDecay: 0.95) showOnDisplay


 

points:loopStart:loopEnd: