Class: GranularEngine

GranularEngine

Granular synthesis TimeEngine implementing the scheduled interface. The grain position (grain onset or center time in the audio buffer) is optionally determined by the engine's currentPosition attribute.

Example that shows a GranularEngine (with a few parameter controls) driven by a Scheduler and a PlayControl: https://rawgit.com/wavesjs/waves-audio/master/examples/granular-engine/index.html

Constructor

new GranularEngine(options)

Parameters:
Name Type Default Description
options Object {}

Parameters

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

Audio buffer

periodAbs Number <optional>
0.01

Absolute grain period in sec

periodRel Number <optional>
0

Grain period relative to absolute duration

periodVar Number <optional>
0

Amout of random grain period variation relative to grain period

periodMin Number <optional>
0.001

Minimum grain period

position Number <optional>
0

Grain position (onset time in audio buffer) in sec

positionVar Number <optional>
0.003

Amout of random grain position variation in sec

durationAbs Number <optional>
0.1

Absolute grain duration in sec

durationRel Number <optional>
0

Grain duration relative to grain period (overlap)

attackAbs Number <optional>
0

Absolute attack time in sec

attackRel Number <optional>
0.5

Attack time relative to grain duration

attackShape String <optional>
'lin'

Shape of attack

releaseAbs Number <optional>
0

Absolute release time in sec

releaseRel Number <optional>
0.5

Release time relative to grain duration

releaseShape Number <optional>
'lin'

Shape of release

expRampOffset String <optional>
0.0001

Offset (start/end value) for exponential attack/release

resampling Number <optional>
0

Grain resampling in cent

resamplingVar Number <optional>
0

Amout of random resampling variation in cent

gain Number <optional>
1

Linear gain factor

centered Boolean <optional>
true

Whether the grain position refers to the center of the grain (or the beginning)

cyclic Boolean <optional>
false

Whether the audio buffer and grain position 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 granularEngine = new audio.GranularEngine();

scheduler.add(granularEngine);

Extends

Members

attackAbs :Number

Absolute attack time in sec

Type:
  • Number
Default Value:
  • 0
Source:

attackRel :Number

Attack time relative to grain duration

Type:
  • Number
Default Value:
  • 0.5
Source:

attackShape :String

Shape of attack ('lin' for linear ramp, 'exp' for exponential ramp)

Type:
  • String
Default Value:
  • 'lin'
Source:

buffer :AudioBuffer

Audio buffer

Type:
  • AudioBuffer
Default Value:
  • null
Source:

(readonly) bufferDuration :Number

Get buffer duration (excluding wrapAroundExtension)

Type:
  • Number
Source:

centered :Boolean

Whether the grain position refers to the center of the grain (or the beginning)

Type:
  • Boolean
Default Value:
  • true
Source:

(readonly) currentPosition :Number

Current position

Type:
  • Number
Source:

cyclic :Boolean

Whether the audio buffer and grain position are considered as cyclic

Type:
  • Boolean
Default Value:
  • false
Source:

durationAbs :Number

Absolute grain duration in sec

Type:
  • Number
Default Value:
  • 0.1
Source:

durationRel :Number

Grain duration relative to grain period (overlap)

Type:
  • Number
Default Value:
  • 0
Source:

expRampOffset :Number

Offset (start/end value) for exponential attack/release

Type:
  • Number
Default Value:
  • 0.0001
Source:

gain :Number

Linear gain factor

Type:
  • Number
Default Value:
  • 1
Source:

periodAbs :Number

Absolute grain period in sec

Type:
  • Number
Default Value:
  • 0.01
Source:

periodMin :Number

Minimum grain period

Type:
  • Number
Default Value:
  • 0.001
Source:

periodRel :Number

Grain period relative to absolute duration

Type:
  • Number
Default Value:
  • 0
Source:

periodVar :Number

Amout of random grain period variation relative to grain period

Type:
  • Number
Default Value:
  • 0
Source:

position :Number

Grain position (onset time in audio buffer) in sec

Type:
  • Number
Default Value:
  • 0
Source:

positionVar :Number

Amout of random grain position variation in sec

Type:
  • Number
Default Value:
  • 0.003
Source:

releaseAbs :Number

Absolute release time in sec

Type:
  • Number
Default Value:
  • 0
Source:

releaseRel :Number

Release time relative to grain duration

Type:
  • Number
Default Value:
  • 0.5
Source:

releaseShape :String

Shape of release ('lin' for linear ramp, 'exp' for exponential ramp)

Type:
  • String
Default Value:
  • 'lin'
Source:

resampling :Number

Grain resampling in cent

Type:
  • Number
Default Value:
  • 0
Source:

resamplingVar :Number

Amout of random resampling variation in cent

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

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 grain. This function can be called at any time (whether the engine is scheduled or not) to generate a single grain according to the current grain parameters.

Parameters:
Name Type Description
time Number

grain synthesis audio time

Source:
Returns:
  • period to next grain
Type
Number