Class: SegmentEngine

SegmentEngine

Used with a buffer to serve audio files via granular synthesis.

The engine implements the "scheduled" and "transported" interfaces. When "scheduled", the engine generates segments more or less periodically (controlled by the periodAbs, periodRel, and perioVar attributes). When "transported", the engine generates segments at the position of their onset time.

Example that shows a SegmentEngine with a few parameter controls running in a Scheduler. https://rawgit.com/wavesjs/waves-audio/master/examples/segment-engine/index.html

Constructor

new SegmentEngine(optionsopt)

Parameters:
Name Type Attributes Default Description
options Object <optional>
{}

Default options

Properties
Name Type Attributes Default Description
buffer AudioBuffer <optional>
null

Audio buffer

periodAbs Number <optional>
0

Absolute segment period in sec

periodRel Number <optional>
1

Segment period relative to inter-segment distance

periodVar Number <optional>
0

Amout of random segment period variation relative to segment period

periodMin Number <optional>
0.001

Minimum segment period

positionArray Number <optional>
[0.0]

Array of segment positions (onset times in audio buffer) in sec

positionVar Number <optional>
0

Amout of random segment position variation in sec

durationArray Number <optional>
[0.0]

Array of segment durations in sec

durationAbs Number <optional>
0

Absolute segment duration in sec

durationRel Number <optional>
1

Segment duration relative to given segment duration or inter-segment distance

offsetArray Array <optional>
[0.0]

Array of segment offsets in sec

offsetAbs Number <optional>
-0.005

Absolute segment offset in sec

offsetRel Number <optional>
0

Segment offset relative to segment duration

delay Number <optional>
0.005

Time by which all segments are delayed (especially to realize segment offsets)

attackAbs Number <optional>
0.005

Absolute attack time in sec

attackRel Number <optional>
0

Attack time relative to segment duration

releaseAbs Number <optional>
0.005

Absolute release time in sec

releaseRel Number <optional>
0

Release time relative to segment duration

resampling Number <optional>
0

Segment resampling in cent

resamplingVar Number <optional>
0

Amout of random resampling variation in cent

gain Number <optional>
1

Linear gain factor

abortTime Number <optional>
0.005

fade-out time when aborted

segmentIndex Number <optional>
0

Index of the segment to synthesize (i.e. of this.positionArray/durationArray/offsetArray)

cyclic Bool <optional>
false

Whether the audio buffer and segment indices are considered as cyclic

wrapAroundExtension Number <optional>
0

Portion at the end of the audio buffer that has been copied from the beginning to assure cyclic behavior

Source:
Example
import * as audio from 'waves-audio';
const scheduler = audio.getScheduler();
const segmentEngine = new audio.SegmentEngine();

scheduler.add(segmentEngine);

Extends

Members

abortTime :Number

Fade-out time (when aborted)

Type:
  • Number
Default Value:
  • 0.005
Source:

attackAbs :Number

Absolute attack time in sec

Type:
  • Number
Default Value:
  • 0.005
Source:

attackRel :Number

Attack time relative to segment duration

Type:
  • Number
Default Value:
  • 0
Source:

buffer :AudioBuffer

Audio buffer

Type:
  • AudioBuffer
Default Value:
  • null
Source:

bufferDuration :Number

Get buffer duration (excluding wrapAroundExtension)

Type:
  • Number
Default Value:
  • 0
Source:

cyclic :Bool

Whether the audio buffer and segment indices are considered as cyclic

Type:
  • Bool
Default Value:
  • false
Source:

delay :Number

Time by which all segments are delayed (especially to realize segment offsets)

Type:
  • Number
Default Value:
  • 0.005
Source:

durationAbs :Number

Absolute segment duration in sec

Type:
  • Number
Default Value:
  • 0
Source:

durationArray :Number

Array of segment durations in sec

Type:
  • Number
Default Value:
  • [0.0]
Source:

durationRel :Number

Segment duration relative to given segment duration or inter-segment distance

Type:
  • Number
Default Value:
  • 1
Source:

gain :Number

Linear gain factor

Type:
  • Number
Default Value:
  • 1
Source:

monophonic :Number

Whether the last segment is aborted when triggering the next

Type:
  • Number
Default Value:
  • false
Source:

offsetAbs :Number

Absolute segment offset in sec

Type:
  • Number
Default Value:
  • -0.005
Source:

offsetArray :Array

Array of segment offsets in sec

offset > 0: the segment's reference position is after the given segment position offset < 0: the given segment position is the segment's reference position and the duration has to be corrected by the offset

Type:
  • Array
Default Value:
  • [0.0]
Source:

offsetRel :Number

Segment offset relative to segment duration

Type:
  • Number
Default Value:
  • 0
Source:

periodAbs :Number

Absolute segment period in sec

Type:
  • Number
Default Value:
  • 0
Source:

periodMin :Number

Minimum segment period

Type:
  • Number
Default Value:
  • 0.001
Source:

periodRel :Number

Segment period relative to inter-segment distance

Type:
  • Number
Default Value:
  • 1
Source:

periodVar :Number

Amout of random segment period variation relative to segment period

Type:
  • Number
Default Value:
  • 0
Source:

positionArray :Number

Array of segment positions (onset times in audio buffer) in sec

Type:
  • Number
Default Value:
  • [0.0]
Source:

positionVar :Number

Amout of random segment position variation in sec

Type:
  • Number
Default Value:
  • 0
Source:

releaseAbs :Number

Absolute release time in sec

Type:
  • Number
Default Value:
  • 0.005
Source:

releaseRel :Number

Release time relative to segment duration

Type:
  • Number
Default Value:
  • 0
Source:

resampling :Number

Segment resampling in cent

Type:
  • Number
Default Value:
  • 0
Source:

resamplingVar :Number

Amout of random resampling variation in cent

Type:
  • Number
Default Value:
  • 0
Source:

segmentIndex :Number

Index of the segment to synthesize (i.e. of this.positionArray/durationArray/offsetArray)

Type:
  • Number
Default Value:
  • 0
Source:

wrapAroundExtension :Number

Portion at the end of the audio buffer that has been copied from the beginning to assure cyclic behavior

Type:
  • Number
Default Value:
  • 0
Source:

Methods

abort(time)

Abort the current segment at given time, fade out duration

Parameters:
Name Type Description
time Number

abort time

Source:

connect(target)

Connect to an audio node (e.g. audioContext.destination)

Parameters:
Name Type Description
target AudioNode

Target audio node

Inherited From:
Source:

disconnect(target)

Disconnect from an audio node (e.g. audioContext.destination). If undefined disconnect from all target nodes.

Parameters:
Name Type Description
target AudioNode

Target audio node.

Inherited From:
Source:

trigger(time) → {Number}

Trigger a segment. This function can be called at any time (whether the engine is scheduled/transported or not) to generate a single segment according to the current segment parameters.

Parameters:
Name Type Description
time Number

segment synthesis audio time

Source:
Returns:

period to next segment

Type
Number