TK.AudioMath

TK.AudioMath provides a couple of functions for turning linear values into logarithmic ones and vice versa. If you need an easy convertion between dB or Hz and a linear scale mixin this class.

Source:

Methods

coef2db(coef, min, max, reverse, factor) → {number}

Calculates a value in decibels from a value between 0.0 and 1.0 and some lower and upper boundaries in decibels.

Parameters:
Name Type Description
coef number

A value between 0.0 and 1.0.

min number

The minimum value in decibels.

max number

The maximum value in decibels.

reverse boolean

If the scale is reversed.

factor number

Changes the deflection of the logarithm if other than 1.0.

Source:
Returns:

The result in decibels.

Type
number

coef2freq(coef, min, max, reverse, factor) → {number}

Calculates a value in hertz from a value between 0.0 and 1.0 and some lower and upper boundaries in hertz.

Parameters:
Name Type Description
coef number

A value between 0.0 and 1.0.

min number

The minimum value in hertz.

max number

The maximum value in hertz.

reverse boolean

If the scale is reversed.

factor number

Changes the deflection of the logarithm if other than 1.0.

Source:
Returns:

The result in hertz.

Type
number

db2coef(value, min, max, reverse, factor) → {number}

Calculates a linear value between 0.0 and 1.0 from a value and its lower and upper boundaries in decibels.

Parameters:
Name Type Description
value number

The value in decibels.

min number

The minimum value in decibels.

max number

The maximum value in decibels.

reverse boolean

If the scale is reversed.

factor number

Changes the deflection of the logarithm if other than 1.0.

Source:
Returns:

A value between 0.0 (min) and 1.0 (max).

Type
number

db2gain(value, factoropt)

Calculates 10^(value / factor). Transforms a dBFS value to the corresponding gain.

Parameters:
Name Type Attributes Default Description
value number

A decibel value in dBFS.

factor number <optional>
20

The factor.

Source:

db2scale(value, min, max, reverse, factor) → {number}

Calculates a linear value between 0.0 and scale. from a value and its lower and upper boundaries in decibels.

Parameters:
Name Type Description
value number

The value in decibels.

min number

The minimum value in decibels.

max number

The maximum value in decibels.

reverse boolean

If the scale is reversed.

factor number

Changes the deflection of the logarithm if other than 1.0.

Source:
Returns:

A value between 0.0 and scale.

Type
number

freq2coef(value, min, max, reverse) → {number}

Calculates a linear value between 0.0 and 1.0 from a value and its lower and upper boundaries in hertz.

Parameters:
Name Type Description
value number

The value in hertz.

min number

The minimum value in hertz.

max number

The maximum value in hertz.

reverse boolean

If the scale is reversed.

Source:
Returns:

A value between 0.0 (min) and 1.0 (max).

Type
number

freq2scale(value, min, max, reverse) → {number}

Calculates a linear value between 0.0 and scale from a value and its lower and upper boundaries in hertz.

Parameters:
Name Type Description
value number

The value in hertz.

min number

The minimum value in hertz.

max number

The maximum value in hertz.

reverse boolean

If the scale is reversed.

Source:
Returns:

A value between 0.0 and scale.

Type
number

gain2db(value, factoropt)

Calculates factor * log10(value). Transforms a gain value to the corresponding dBFS value.

Parameters:
Name Type Attributes Default Description
value number

A gain factor.

factor number <optional>
20

The factor.

Source:

scale2db(value, min, max, reverse, factor) → {number}

Calculates a value in decibels from a value between 0.0 and scale and some lower and upper boundaries in decibels.

Parameters:
Name Type Description
value number

A value between 0.0 and scale.

min number

The minimum value in decibels.

max number

The maximum value in decibels.

reverse boolean

If the scale is reversed.

factor number

Changes the deflection of the logarithm if other than 1.0.

Source:
Returns:

The result in decibels.

Type
number

scale2freq(value, min, max, reverse, factor) → {number}

Calculates a value in hertz from a value between 0.0 and scale and some lower and upper boundaries in hertz.

Parameters:
Name Type Description
value number

A value between 0.0 and scale.

min number

The minimum value in hertz.

max number

The maximum value in hertz.

reverse boolean

If the scale is reversed.

factor number

Changes the deflection of the logarithm if other than 1.0.

Source:
Returns:

The result in hertz.

Type
number