Members
gen
low-level code generation for unit generators
Properties
accum
integer*
A number that is incremeneted everytime a ugen is created in order to provide a unique id.debug
boolean
When this flag is set, all callbacks generated will be logged to the console.closures
Set
Currently inappropriately named, this property contains key/value pairs which assign properties to the named, generated functions. These properties can the be called as methods or accessed more generally from within the generated callback.histories
Map
Stores references to all single-sample delays, so that they can record their input at the end of generated callback functions.memo
object
Once a ugen has generated it's associated output string, that string is placed in this object, assigned to key equalling the ugens unique id. Before asking any ugen to generate code, genish will check to see if there is already a memoized version stored in this object; if so, that will be used.data
object
A general storage area that is accessible from within generated callbacks.
Methods
createCallback
: This will codegen a callback function for the ugen passed as the first argument. If that ugen is dependent on other ugens, these in turn will also be asked to codegen until the entire graph is contained within the output callback function. If the debug flag is set then the function body will be printed to the console.- graph object or array A genish.js unit generator to be compiled. If an array of two ugens is passed, the resulting function will output a stereo signal.
- debug boolean When set, print the string representation of the generated function to the console.
getInputs
This method looks at the argument ugen and, assuming it has dependencies, calls their codegen methods so that their code is added to the final output function. It is only used internally during calls togen.createCallback()
. The basic codegen process is callinggetInputs
recursively until the entire graph has been resolved.- ugen object A genish.js unit generator.
Example
out = gen.createCallback( add(5,3) )
out() // 8
out = gen.createCallback( [ accum(.1), accum(.2) ] )
out() // [ 0, 0 ]
out() // [ .1, .2 ]
out() // [ .2, .4 ]
out() // [ .3, .6 ] etc...
Methods
abs(signal)
Find the absolute value of a signal using Math.abs
Category: arithmetic
Parameters:
Name | Type | Description |
---|---|---|
signal |
number | ugen |
Returns:
ugen
accum(incrementopt, resetopt, propsopt)
accum
is used to increment a stored value between a provided range that
defaults to {0,1}. If the accumulator values passes its maximum, it wraps.
accum()
is very similar to the counter
ugen, but is slightly more
efficient. Additionally, the min
and max
properties of accum
are fixed
values, while they can be specified with signals in counter
.
Category: integrator
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
increment |
ugen | number |
<optional> |
1 | The amount to increase the accumulator's internal value by on each sample |
reset |
ugen | number |
<optional> |
0 | When |
props |
Object |
<optional> |
{} | An optional dictionary containing a |
acos(radians) → {ugen}
Calculates the arccosine of the input (interpreted as radians) using
Javascript's Math.acos()
function
Category: trigonometry
Parameters:
Name | Type | Description |
---|---|---|
radians |
ugen | number |
Returns:
- Type
- ugen
ad(attackTime, decayTime, propsopt) → {ugen}
Creates an envelope with an attack and a decay stage, both measured in samples.
Properties
shape
string ('linear' or 'exponential', default 'exponental') determines the shape of the attack / decay.alpha
number (default 5) An extra number used to determine windowing. In the case of 'exponential' envelopes, this determines the amount of curvature in the envelope. For 'linear' envelopes this number has no effect.
Methods
trigger
: Re-trigger the envelope.isComplete
: test if the envelope is completed
Category: envelope
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
attackTime |
ugen | number | Attack time measured in samples, defaults to 44100. |
||
decayTime |
ugen | number | Decay time measured in samples, defaults to 44100. |
||
props |
Object |
<optional> |
{ shape: 'exponential', alpha: 5 } | the initial property values |
Returns:
- Type
- ugen
Example
myenv = ad( 44, 88200 )
play(
mul( myenv, cycle( 330 ) )
)
// wait some time for decay and then run to re-trigger
myenv.trigger()
add(args)
Adds an unlimited number of signals (numbers or ugens)
Category: arithmetic
Parameters:
Name | Type | Description |
---|---|---|
args |
number | ugen |
Returns:
ugen
Example
out = gen.createCallback( add(1,2) )
// creates function body out = ( 3 )
out() // 3
adsr(attackTimeopt, decayTimeopt, sustainTimeopt, sustainLevelopt, releaseTimeopt)
Creates an envelope with attack, decay, sustatin and release stages, with
each duration measured in samples. Envelopes can automatically advance
through their entirety (default behavior) or can stop at the sustain stage
and what for a command to advance by setting the triggerRelease
property to
a value of 1
.
Properties
shape
string (default 'exponental') determines the shape of the attack / decay / release.alpha
number (default 5) An extra number used to determine windowing. In the case of 'exponential' envelopes, this determines the amount of curvature in the envelope. For 'linear' envelopes this number has no effect.triggerRelease
boolean (default false) This property determines if the envelope waits for arelease()
message before terminating the sustain segment and advancing to the release segment. By setting this value to1
, you can easily script release of the envelope to depend on user interaction. WhenreleaseTrigger
is true, thesustainTime
input has no effect on envelope.
Methods
trigger
: Re-trigger the envelope.release
: Move from the sustain stage to the release stage of the envelope. This method only has effect if thetriggerRelease
property to set totrue
on instantiation. Note that calling this method will not skip attack or decay stages... if called during the attack or decay stage the envelope will simply bypass the sustain stage and continue straight to the release after the decay is completed.
Category: envelope
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
attackTime |
ugen | number |
<optional> |
Attack time measured in samples, defaults to |
decayTime |
ugen | number |
<optional> |
Decay time measured in samples, defaults to |
sustainTime |
ugen | number |
<optional> |
Sustain time measured in samples, defaults to |
sustainLevel |
ugen | number |
<optional> |
Each stage of the envelope is controlled via a wavetable; the sustainLevel property dictates at one point in the wavetable the envelope rests before releasing. Thus, a value of .5 does not mean that the output of the envelope during sustain will be .5 (unless enveloping for the adsr is linear)... it will instead depend on the type enveloping used. Default is .6. |
releaseTime |
ugen | number |
<optional> |
Release time measured in samples, defaults to |
Example
myenv = adsr( 44, 22050, 22050, .6, 44100, { releaseTrigger:true })
play(
mul( myenv, cycle( 330 ) )
)
// wait until sustain and then run next line to release
myenv.release()
// re-trigger
myenv.retrigger()
and(a, b) → {ugen}
Returns 1 if both inputs do not equal 0.
Category: logic
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | Number | input signal |
b |
ugen | Number | input signal |
Returns:
- Type
- ugen
asin(radians) → {ugen}
Calculates the arcsine of the input (interpreted as radians) using
Javascript's Math.asin()
function
Category: trigonometry
Parameters:
Name | Type | Description |
---|---|---|
radians |
ugen | number |
Returns:
- Type
- ugen
atan(radians) → {ugen}
Calculates the arctangent of the input (interpreted as radians) using
Javascript's Math.atan()
function
Category: trigonometry
Parameters:
Name | Type | Description |
---|---|---|
radians |
ugen | number |
Returns:
- Type
- ugen
attack(attackTimeopt)
Attack FIXME: write documentation
Category: envelope
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
attackTime |
ugen |
<optional> |
44100 | The time (in samples) to fade 1 by 60 dB. |
- See:
bang(propertiesopt) → {ugen}
The bang ugen continuously outputs a minimum value (default 0) until its
trigger()
method is called. After triggering, the ugen will output its
maximum value (default 1) for a single sample before resetting and returning
to outputting its minimum. The bang ugen can be used, for example, to easily
re-trigger an envelope interactively, or to reset a counter/accum ugen.
Properties:
min
number (default 0) The 'resting state' of the bang ugen.max
number (default 1) The instantaneous state after triggering the bang ugen. This state will only last for one sample after triggering.
Methods:
trigger
: Change the state from the min property of the bang ugen to the max property for one sample.
Category: control
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
properties |
Object |
<optional> |
{ min: 0, max: 1 } | optional properties object |
Returns:
- Type
- ugen
bool(signal) → {ugen}
Converts signals to either 0 or 1. If the input signal does not equal 0 then output is 1; if input == 0 then output 0. Roughly equivalent to the following pseudocode:
Category: logic
Parameters:
Name | Type | Description |
---|---|---|
signal |
ugen | Number | the input signal |
Returns:
- Type
- ugen
Example
y = x !== 0 ? 1 : 0
ceil(value) → {ugen}
Rounds input up to nearest integer using Javascript's Math.ceil()
function
Category: numeric
Parameters:
Name | Type | Description |
---|---|---|
value |
ugen | number |
Returns:
- Type
- ugen
clamp(a, min, max)
Clamp constricts an input a
to a particular range. If input a
exceeds the
maximum, the maximum is returned. If input b
is less than the minimum, the
minimum is returned.
Category: range
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | Input signal to clamp. |
min |
ugen | number | Signal or number that sets minimum of range to clamp input to. |
max |
ugen | number | Signal or number that sets maximum of range to clamp input to. |
conditional(control, a, b) → {ugen}
Conditional FIXME: write function and parameters description
Category: routing
Parameters:
Name | Type | Description |
---|---|---|
control |
ugen | number | |
a |
ugen | number | |
b |
ugen | number |
Returns:
- Type
- ugen
cos(radians) → {ugen}
Calculates the cosine of the input (interpreted as radians) using
Javascript's Math.cos()
function
Category: trigonometry
Parameters:
Name | Type | Description |
---|---|---|
radians |
ugen | number |
Returns:
- Type
- ugen
counter(incrementopt, minopt, maxopt, resetopt, propsopt)
counter()
is used to increment a stored value between a provided range that
defaults to {0,1}. If the counter's interval value passes either range
boundary, it is wrapped. counter()
is very similar to the accum
ugen, but
is slightly less efficient. Additionally, the min
and max
properties of
accum
are fixed values, while they can be specified with signals in
counter
, enabling mix/max to change over time.
Category: integrator
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
increment |
ugen | number |
<optional> |
1 | The amount to increase the counter's internal value by on each sample |
min |
ugen | number |
<optional> |
0 | The minimum value of the accumulator |
max |
ugen | number |
<optional> |
0 | The maximum value of the accumulator |
reset |
ugen | number |
<optional> |
0 | When |
props |
Object |
<optional> |
{} | An optional dictionary containing a |
cycle(frequency)
Cycle creates a sine oscillator running at a provided frequency. The oscillator runs via an interpolated wavetable lookup.
Category: waveform
Parameters:
Name | Type | Description |
---|---|---|
frequency |
ugen | number |
Returns:
ugen
data(value)
Data objects serve as containers for storing numbers; these numbers can be read using calls to peek()
and the data object can be written to using calls to poke()
.
The constructor can be called with three different argumensts. If a
dataArray is passed as the first argument, this array becomes the data
object's underlying data source. If a dataLength integer is passed, a
Float32Array is created using the provided length. If a audioFileToLoad
string is passed, the data object attempts to load the file at the provided
URL and generates a JavaScript Promise that used with the then()
method.
When the data
constructor is called passing in the path of a file to
load, a JavaScript Promise is created that will be resovled when the
audiofile has been loaded. then()
provides a callback function to be
executed when resolution is complete. You can use this to delay starting
playback of a graph until all data dependencies have been loaded.
Category: buffer
Parameters:
Name | Type | Description |
---|---|---|
value |
Array | Integer | String |
Example
audiofile = data( 'myaudiofile.wav' ).then( ()=> {
out = gen.createCallback( peek( audiofile, phasor(.1) ) )
})
dcblock(signal) → {ugen}
dcblock
remove DC offset from an input signal using a one-pole high-pass filter.
Category: filter
Parameters:
Name | Type | Description |
---|---|---|
signal |
ugen |
Returns:
- Type
- ugen
decay(decayTypeopt, propsopt) → {ugen}
Decay FIXME: add documentation
Category: envelope
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
decayType |
ugen | number |
<optional> |
44100 | |
props |
Object |
<optional> |
{ initValue: 1} |
Returns:
- Type
- ugen
delay(in, delayTime, properties)
Creates a delay line that delays an input signal by an argument number of samples.
Properties
size
number (default 512) determines the length of the delay line.interp
interp (default 'linear') Set the interpolation used to access non-integer indices in the delay line. Currently can be 'linear' or 'none'.
Category: feedback
Parameters:
Name | Type | Description |
---|---|---|
in |
ugen | number | The signal to be delayed. |
delayTime |
Number | The amount of time to delay the incoming signal. |
properties |
Object | A dictionary of properties to assign to the ugen; see below. |
delta(input) → {ugen}
Delta FIXME: Add documentation
Category: delay
Parameters:
Name | Type | Description |
---|---|---|
input |
ugen | number |
Returns:
- Type
- ugen
div(a, b)
Divides ugen or number a by ugen or number b.
Category: arithmetic
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | |
b |
ugen | number |
Returns:
ugen
Example
out = gen.createCallback( div( cos(0), 2 ) )
// creates function body out = ( gen.cos(0) / 2 )
out() // .5
env(lengthopt, propsopt) → {ugen}
Envelope FIXME: Add documentation
Category: buffer
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
length |
ugen | number |
<optional> |
11025 | |
props |
Object |
<optional> |
{ type: 'Triangular', bufferLength: 1024, alpha: 0.15 } |
Returns:
- Type
- ugen
eq(a, b) → {ugen}
Returns whichever value is lesser.
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
eq(a, b) → {ugen}
Returns 1 if two inputs are equal, otherwise returns 0.
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
floor(a) → {ugen}
Rounds input down to nearest integer by performing a bitwise or with 0.
Category: numeric
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number |
Returns:
- Type
- ugen
Example
out = gen.createCallback( round( in() ) )
// creates function body: out = ( in1 | 0 )
fold(a, min, max)
Fold constricts an input a
to a particular range. Given a range of {0,1}
and an input signal of {.8,.9,1,1.1,1.2}, fold will return {.8,.9,1,.9,.8}.
Category: range
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | Input signal to fold. |
min |
ugen | number | Signal or number that sets minimum of range to fold input to. |
max |
ugen | number | Signal or number that sets maximum of range to fold input to. |
gate(control, input, properties)
gate()
routes signal from one of its outputs according to an input
control signal, which defines an index for output. The various outputs are
all stored in the mygate.outputs
array. The code example to the right shows
a signal alternating between left and right channels using the gate
ugen.
Properties
outputs
string : An array of outputs that can be used as inputs to other ugens.
Category: routing
Parameters:
Name | Type | Description |
---|---|---|
control |
ugen | number | Selects the output index that the input signal travels through. |
input |
Integer | Signal that is passed through one of various outlets. |
properties |
Object | A dictionary of optional parameters to assign to the gate object. The main property is |
Example
inputSignal = mul( phasor(330), .1 )
controlSignal = gt( phasor(2), .5 )
g = gate( controlSignal, inputSignal, { count:4 })
gen.createCallback([ g.outputs[0], g.outputs[1] ])
gt(a, b) → {ugen}
Returns 1 if a
is greater than b
, otherwise returns 0
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
gte(a, b) → {ugen}
Returns 1 if a
is greater or equal than b
, otherwise returns 0
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
gtp(a, b) → {ugen}
Returns a
if a
is greater than b
, otherwise returns 0
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
history()
History is used to create single-sample delays and feedback. It records one
sample at a time of a ugen passed to its in()
method, and then outputs the
last recorded sample via its .out
property.
Single-sample delays are one of the justifications for the existence of genish.js; this is an important ugen.
Since history
is a browser global variable, this function is aliased
to ssd
Properties
out
: ugen Theout
property is a simple ugen that outputs the last recorded sample of the history object.
Methods
in
ugen ugen A genish.js unit generator (or graph) to be recorded.
Category: feedback
Example
// a randomly pitched oscillator and a delay line
frequencyControl = sah( add( 220, mul( noise(),880 ) ), noise(), .99995 )
osc = mul( cycle( frequencyControl ), .025 )
feedback = ssd()
// feed feedback into our delay by inputting the feedback.out property
echo = delay( add( osc, feedback.out ), 11025, { size: 22050 } )
// record the output of the echo and our feedback using a call to feedback.in()
mixer = feedback.in( mix( echo, feedback.out, .925 ) )
gen.createCallback( mixer )
ifelse(control, a, b) → {ugen}
ifelse
can be called in two ways. In the first, it is functionally
identical to the switch
ugen: if a given control input is true, the second
input to ifelse
is outputted. Otherwise, the third input is outputted.
The other option is to pass multiple conditional / output pairs. These will
be used to create an appropriate if/else block in the final callback. If
there is a single final output with no accompanying condition, this will be
the end else
of the control structure. For example:
Most importantly (and as implied by the pseudocode) we can use ifelse
to create DSP that only runs under certain conditions. For example,
given the following in the genish.js playground:
Category: routing
Parameters:
Name | Type | Description |
---|---|---|
control |
ugen | number | When |
a |
ugen | number | Signal that is available to output. |
b |
ugen | number | Signal that is available to ouput. |
Returns:
- Type
- ugen
Examples
ie = ifelse(
lt( 0,1 ), 440,
gt( 1,.5 ), 880,
1200
)
gen.createCallback( ie )
// ...outputs a function with the following control block (in pseudocode):
let ifelse_0
if( 0 < 1 ) {
ifelse_0 = 440
}else if( 1 > .5 ) {
ifelse_0 = 880
}else{
ifelse_0 = 1200
}
osc = phasor( .5 )
play(
ifelse(
lt( osc, -.5 ), cycle( 220 ),
lt( osc, 0 ) , phasor( 330 ),
lt( osc, .5 ) , train( 440 ),
cycle(550)
)
)
// ... we are only running two oscillators at any given time,
// our control phasor and whatever is held in the current executing block
// of our `ifelse` ugen.
input()
genish.js creates optimized audio callback functions; the input
ugen
creates a argument to a genish callback function that can be manipulated. For
example, if we wanted a sine oscillator that let us control its frequency and
amplitude, we could use:
Category: control
Example
frequency = input()
gain = input()
osc = mul( cycle( frequency ), gain )
callback = gen.createCallback( osc )
// one sample of output with a 440 Hz frequency, .5 gain
callback( 440, .5 )
// another sample using 220 Hz frequency, .25 gain
callback( 220, .25 )
lt(a, b) → {ugen}
Returns 1 if a
is less than b
, otherwise returns 0.
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
lte(a, b) → {ugen}
Returns 1 if a
is lesser or equal than b
, otherwise returns 0
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
ltp(a, b) → {ugen}
Returns a
if a
is lesser than b
, otherwise returns 0
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
max(a, b) → {ugen}
Returns whichever value is greater.
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
memo(input, name) → {ugen}
Memo FIXME: Write documentation
Category:
Parameters:
Name | Type | Description |
---|---|---|
input |
ugen | |
name |
String |
Returns:
- Type
- ugen
mix(a, b, topt) → {ugen}
Mix two signals a
and b
Category:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
a |
ugen | number | one signal to mix |
||
b |
ugen | number | other signal to mix |
||
t |
ugen | number |
<optional> |
0.5 | the relative amount between both |
Returns:
- Type
- ugen
mod(a, b)
Divides ugen or number a by ugen or number b and returns the remainder.
Category: arithmetic
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | |
b |
ugen | number |
Returns:
ugen
Example
out = gen.createCallback( mod( cos(0), .51 ) )
// creates function body out = ( gen.cos(0) % .51 )
out() // .49
mstosamps(time) → {ugen}
Convert time in microseconds to samples
Category: utilities
Parameters:
Name | Type | Description |
---|---|---|
time |
ugen | number | Time in milliseconds |
Returns:
- Type
- ugen
mtof(midi, propsopt) → {ugen}
Convert midi note numbers to frequency
Category: utilities
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
midi |
ugen | number | the note midi number |
||
props |
Object |
<optional> |
{ tuning: 440 } |
Returns:
an ugen that outputs the frequency
- Type
- ugen
mul(a, b)
Multiples two number or ugens together.
Category: arithmetic
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | |
b |
ugen | number |
Returns:
ugen
Example
out = gen.createCallback( mul( cos(0), 5 ) )
// creates function body out = ( gen.cos(0) * 5 )
out() // 5
neq(a, b) → {ugen}
Returns 1 if two inputs are NOT equal, otherwise returns 0.
Category: comparison
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | one element to compare |
b |
ugen | number | other element to compare |
Returns:
- Type
- ugen
noise() → {ugen}
Noise outputs a pseudo-random signal between {0,1}. The signal is generated
via Javascript's Math.random()
function.
Category: waveform
Returns:
- Type
- ugen
not(signal) → {ugen}
An input of 0 returns 1 while all other values return 0.
Category: logic
Parameters:
Name | Type | Description |
---|---|---|
signal |
ugen | number | the input signal |
Returns:
- Type
- ugen
Example
y = x !== 0 ? 0 : 1
pan(left, right, pan)
Pan two signals
Category: utility
Parameters:
Name | Type | Description |
---|---|---|
left |
ugen | number | The left input signal |
right |
ugen | number | The right input signal |
pan |
ugen | number |
param(value) → {ugen}
The param
ugen exposes a single number for interactive control via
assignment to its value
property. In the example below, the frequency of a
sine oscillator is controlled via a param
ugen:
Category: control
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The initial value for the param ugen. |
Returns:
- Type
- ugen
Example
pattern = [ 440, 660, 880, 1100 ]
idx = 0
frequency = param( pattern[ idx ] )
play( cycle( frequency ) )
// change frequency every 100ms (approximately, setInterval is not sample accurate)
intrvl = setInterval( ()=> {
frequency.value = pattern[ idx++ % pattern.length ]
}, 100 )
peek(data, index, propertiesopt)
Peek reads from an input data object. It can index the data object using on of two modes. If the mode property is set to samples than index provides an integer index to lookup in the data object. If the mode property is set to phase then the index should be a signal in the range of {0,1}.
The peek
ugen has the following properties:
mode
{String}: determines how indexing is performed. Options are 'phase' and 'samples'.interp
{string}: determines what interpolation is used when performing the lookup. Options are 'linear' and 'none'boundmode
{string}: determines what to do when the buffer ends. Options arewrap
,clam
orignore
Category: buffer
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
data | the |
||
index |
Integer | the index to be read |
||
properties |
Object |
<optional> |
{ mode: 'phase', interp: 'linear', boundmode: 'wrap'} | initial properties object. |
Example
// create a sliding, interpolated frequency signal running between four values
d = data( [440,880,220,1320] )
p = peek( d, phasor(.1) )
c = cycle( p ) // feed sine osc frequency with signal
phasor(frequencyopt, resetopt, propsopt)
A phasor accumulates phase, as determined by its frequency, and wraps between
0 and 1. This creates a sawtooth wave, but with a dc offset of 1 (no negative
numbers). If a range of {-1,1} is needed you can use an accum()
object with
the increment 1/gen.samplerate * frequency
and the desired min/max
properties.
Category: waveform
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
frequency |
ugen | number |
<optional> |
1 | |
reset |
ugen | number |
<optional> |
0 | |
props |
Object |
<optional> |
{ max: 1, min: -1 } |
Returns:
ugen
poke(data, value, index)
Poke writes values to a index on a data
object.
Category: buffer
Parameters:
Name | Type | Description |
---|---|---|
data |
data | A |
value |
Number | The number to write to the ugen's |
index |
Integer | The index to write to |
pow(base, exp)
Raises a base to an exponent using Math.pow
function
Category: arithmetic
Parameters:
Name | Type | Description |
---|---|---|
base |
ugen | number | |
exp |
ugen | number |
Returns:
ugen
prop(propName, value) → {ugen}
Set a property of a ugen
Category: utilities
Parameters:
Name | Type | Description |
---|---|---|
propName |
String | |
value |
Object |
Returns:
- Type
- ugen
rate(input, rate) → {ugen}
Rate FIXME: Write documentation
Category: utilities
Parameters:
Name | Type | Description |
---|---|---|
input |
ugen | number | |
rate |
ugen | number |
Returns:
- Type
- ugen
round(a) → {ugen}
Rounds input up or down to nearest integer using Javascript's Math.round()
function
Category: numeric
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number |
Returns:
- Type
- ugen
sah(input, control, thresholdopt, propsopt) → {ugen}
Sample and hold
Category: ?
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
input |
ugen | number | |||
control |
ugen | number | |||
threshold |
ugen | number |
<optional> |
0 | |
props |
Object |
<optional> |
{ init: 0 } |
Returns:
- Type
- ugen
selector(control, inputs) → {ugen}
Selector is basically the same as switch()
but allows you to have an
arbitrary number of inputs to choose between.
Category: routing
Parameters:
Name | Type | Description |
---|---|---|
control |
ugen | number | Determines which input signal is passed to the ugen's output. |
inputs |
ugen | number | After the |
Returns:
- Type
- ugen
sign(value) → {ugen}
Returns 1 for positive input and -1 for negative input. Zero returns itself.
Uses JavaScript's Math.sign()
function.
Category: numeric
Parameters:
Name | Type | Description |
---|---|---|
value |
ugen | number |
Returns:
- Type
- ugen
sin(radians) → {ugen}
Calculates the sine of the input (interepreted as radians) using Javascript's
Math.sin()
function
Category: trigonometry
Parameters:
Name | Type | Description |
---|---|---|
radians |
ugen | number |
Returns:
- Type
- ugen
slide(signal, length) → {ugen}
slide
is a logarithmically scaled low-pass filter to smooth discontinuities
between values. It is especially useful to make continuous transitions from
discrete events; for example, sliding from one note frequency to the next.
The second argument to slide
determines the length, in samples, of
transitions.
Category: filter
Parameters:
Name | Type | Description |
---|---|---|
signal |
ugen | |
length |
integer | Length of slide in samples. |
Returns:
- Type
- ugen
sub(args)
Subtract. It accepts a variable number of signals.
Category: arithmetic
Parameters:
Name | Type | Description |
---|---|---|
args |
number | ugen |
Returns:
ugen
Example
out = gen.createCallback( sub( abs(.1),1,2 ) )
// creates function body out = ( .1 - 3 )
out() // -2.9
switch(control, a, b) → {ugen}
A control input determines which of two additional inputs is passed to the
output. Note that in the genish.js playground this is globally referred to as
the ternary
ugen, so as not to conflict with JavaScript's switch
control
structure.
Category: routing
Parameters:
Name | Type | Description |
---|---|---|
control |
ugen | number | When |
a |
ugen | number | Signal that is available to output. |
b |
ugen | number | Signal that is available to ouput. |
Returns:
- Type
- ugen
t60(fadeTime)
t60
provides a multiplier that, when applied to a signal every sample,
fades it by 60db (at which point it is effectively inaudible). Although the
example below shows t60
in action, it would actually be much more efficient
to calculate t60 once since the time used (88200) is static.
Category: envelope
Parameters:
Name | Type | Description |
---|---|---|
fadeTime |
ugen | The time (in samples) to fade 1 by 60 dB. |
Example
lastsample = ssd(1)
// update fade with previous output * t60
// we could also use: Math.exp( -6.907755278921 / 88200 ) instead of t60( 88200 )
fade = mul( lastsample.out, t60( 88200 ) )
// record current value of fade
lastsample.in( fade )
play( mul( lastsample.out, cycle( 330 ) ) )
tan(radians) → {ugen}
Calculates the tangent of the input (interpreted as radians) using
Javascript's Math.tan()
function
Category: trigonometry
Parameters:
Name | Type | Description |
---|---|---|
radians |
ugen | number |
Returns:
- Type
- ugen
train(frequency, pulsewidthopt)
train()
creates a pulse train driven by an input frequency signal and input
pulsewidth signal. The pulse train is created using the genish expression
displayed at right.
Category: waveform
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
frequency |
ugen | number | |||
pulsewidth |
ugen | number |
<optional> |
0.5 | Pulsewidth. A pulsewidth of .5 means the oscillator will spend 50% of its time outputting 1 and 50% of its time outputting 0. A pulsewidth of .2 means the oscillator spends 20% of its time outputting 1 and 80% outputting 0. |
Example
pulseTrain = lt( accum( div( inputFrequency, sampleRate ) ), inputPulsewidth )
wrap(a, min, max)
Wrap constricts an input a
to a particular range. Given a range of {0,1}
and an input signal of {.8,.9,1,1.1,1.2}, fold will return {.8,.9,0,.1,.2}.
Category: range
Parameters:
Name | Type | Description |
---|---|---|
a |
ugen | number | Input signal to wrap. |
min |
ugen | number | Signal or number that sets minimum of range to wrap input to. |
max |
ugen | number | Signal or number that sets maximum of range to wrap input to. |