Add scaling to LFOs
This commit is contained in:
34
src/API.ts
34
src/API.ts
@ -1558,7 +1558,7 @@ export class UserAPI {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
sine = (freq: number = 1, offset: number = 0): number => {
|
sine = (freq: number = 1, times: number = 1, offset: number = 0): number => {
|
||||||
/**
|
/**
|
||||||
* Returns a sine wave between -1 and 1.
|
* Returns a sine wave between -1 and 1.
|
||||||
*
|
*
|
||||||
@ -1567,11 +1567,11 @@ export class UserAPI {
|
|||||||
* @returns A sine wave between -1 and 1
|
* @returns A sine wave between -1 and 1
|
||||||
*/
|
*/
|
||||||
return (
|
return (
|
||||||
Math.sin(this.app.clock.ctx.currentTime * Math.PI * 2 * freq) + offset
|
(Math.sin(this.app.clock.ctx.currentTime * Math.PI * 2 * freq) + offset) * times
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
usine = (freq: number = 1, offset: number = 0): number => {
|
usine = (freq: number = 1, times: number = 1, offset: number = 0): number => {
|
||||||
/**
|
/**
|
||||||
* Returns a sine wave between 0 and 1.
|
* Returns a sine wave between 0 and 1.
|
||||||
*
|
*
|
||||||
@ -1580,10 +1580,10 @@ export class UserAPI {
|
|||||||
* @returns A sine wave between 0 and 1
|
* @returns A sine wave between 0 and 1
|
||||||
* @see sine
|
* @see sine
|
||||||
*/
|
*/
|
||||||
return (this.sine(freq, offset) + 1) / 2;
|
return ((this.sine(freq, offset) + 1) / 2) * times
|
||||||
};
|
};
|
||||||
|
|
||||||
saw = (freq: number = 1, offset: number = 0): number => {
|
saw = (freq: number = 1, times: number = 1, offset: number = 0): number => {
|
||||||
/**
|
/**
|
||||||
* Returns a saw wave between -1 and 1.
|
* Returns a saw wave between -1 and 1.
|
||||||
*
|
*
|
||||||
@ -1595,10 +1595,10 @@ export class UserAPI {
|
|||||||
* @see sine
|
* @see sine
|
||||||
* @see noise
|
* @see noise
|
||||||
*/
|
*/
|
||||||
return ((this.app.clock.ctx.currentTime * freq) % 1) * 2 - 1 + offset;
|
return (((this.app.clock.ctx.currentTime * freq) % 1) * 2 - 1 + offset) * times;
|
||||||
};
|
};
|
||||||
|
|
||||||
usaw = (freq: number = 1, offset: number = 0): number => {
|
usaw = (freq: number = 1, times: number = 1, offset: number = 0): number => {
|
||||||
/**
|
/**
|
||||||
* Returns a saw wave between 0 and 1.
|
* Returns a saw wave between 0 and 1.
|
||||||
*
|
*
|
||||||
@ -1607,10 +1607,10 @@ export class UserAPI {
|
|||||||
* @returns A saw wave between 0 and 1
|
* @returns A saw wave between 0 and 1
|
||||||
* @see saw
|
* @see saw
|
||||||
*/
|
*/
|
||||||
return (this.saw(freq, offset) + 1) / 2;
|
return ((this.saw(freq, offset) + 1) / 2) * times;
|
||||||
};
|
};
|
||||||
|
|
||||||
triangle = (freq: number = 1, offset: number = 0): number => {
|
triangle = (freq: number = 1, times: number = 1, offset: number = 0): number => {
|
||||||
/**
|
/**
|
||||||
* Returns a triangle wave between -1 and 1.
|
* Returns a triangle wave between -1 and 1.
|
||||||
*
|
*
|
||||||
@ -1620,10 +1620,10 @@ export class UserAPI {
|
|||||||
* @see sine
|
* @see sine
|
||||||
* @see noise
|
* @see noise
|
||||||
*/
|
*/
|
||||||
return Math.abs(this.saw(freq, offset)) * 2 - 1;
|
return (Math.abs(this.saw(freq, offset)) * 2 - 1) * times;
|
||||||
};
|
};
|
||||||
|
|
||||||
utriangle = (freq: number = 1, offset: number = 0): number => {
|
utriangle = (freq: number = 1, times: number = 1, offset: number = 0): number => {
|
||||||
/**
|
/**
|
||||||
* Returns a triangle wave between 0 and 1.
|
* Returns a triangle wave between 0 and 1.
|
||||||
*
|
*
|
||||||
@ -1632,11 +1632,12 @@ export class UserAPI {
|
|||||||
* @returns A triangle wave between 0 and 1
|
* @returns A triangle wave between 0 and 1
|
||||||
* @see triangle
|
* @see triangle
|
||||||
*/
|
*/
|
||||||
return (this.triangle(freq, offset) + 1) / 2;
|
return ((this.triangle(freq, offset) + 1) / 2) * times;
|
||||||
};
|
};
|
||||||
|
|
||||||
square = (
|
square = (
|
||||||
freq: number = 1,
|
freq: number = 1,
|
||||||
|
times: number = 1,
|
||||||
offset: number = 0,
|
offset: number = 0,
|
||||||
duty: number = 0.5
|
duty: number = 0.5
|
||||||
): number => {
|
): number => {
|
||||||
@ -1651,11 +1652,12 @@ export class UserAPI {
|
|||||||
*/
|
*/
|
||||||
const period = 1 / freq;
|
const period = 1 / freq;
|
||||||
const t = (Date.now() / 1000 + offset) % period;
|
const t = (Date.now() / 1000 + offset) % period;
|
||||||
return t / period < duty ? 1 : -1;
|
return (t / period < duty ? 1 : -1) * times;
|
||||||
};
|
};
|
||||||
|
|
||||||
usquare = (
|
usquare = (
|
||||||
freq: number = 1,
|
freq: number = 1,
|
||||||
|
times: number = 1,
|
||||||
offset: number = 0,
|
offset: number = 0,
|
||||||
duty: number = 0.5
|
duty: number = 0.5
|
||||||
): number => {
|
): number => {
|
||||||
@ -1667,10 +1669,10 @@ export class UserAPI {
|
|||||||
* @returns A square wave between 0 and 1
|
* @returns A square wave between 0 and 1
|
||||||
* @see square
|
* @see square
|
||||||
*/
|
*/
|
||||||
return (this.square(freq, offset, duty) + 1) / 2;
|
return ((this.square(freq, offset, duty) + 1) / 2) * times;
|
||||||
};
|
};
|
||||||
|
|
||||||
noise = (): number => {
|
noise = (times: number = 1): number => {
|
||||||
/**
|
/**
|
||||||
* Returns a random value between -1 and 1.
|
* Returns a random value between -1 and 1.
|
||||||
*
|
*
|
||||||
@ -1681,7 +1683,7 @@ export class UserAPI {
|
|||||||
* @see sine
|
* @see sine
|
||||||
* @see noise
|
* @see noise
|
||||||
*/
|
*/
|
||||||
return this.randomGen() * 2 - 1;
|
return (this.randomGen() * 2 - 1) * times;
|
||||||
};
|
};
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|||||||
@ -8,8 +8,11 @@ export const lfos = (application: Editor): string => {
|
|||||||
|
|
||||||
Low Frequency Oscillators (_LFOs_) are an important piece in any digital audio workstation or synthesizer. Topos implements some basic waveforms you can play with to automatically modulate your paremeters.
|
Low Frequency Oscillators (_LFOs_) are an important piece in any digital audio workstation or synthesizer. Topos implements some basic waveforms you can play with to automatically modulate your paremeters.
|
||||||
|
|
||||||
- <ic>sine(freq: number = 1, offset: number= 0): number</ic>: returns a sinusoïdal oscillation between <ic>-1</ic> and <ic>1</ic>.
|
- <ic>sine(freq: number = 1, times: number = 1, offset: number= 0): number</ic>: returns a sinusoïdal oscillation between <ic>-1</ic> and <ic>1</ic>.
|
||||||
- <ic>usine(freq: number = 1, offset: number= 0): number</ic>: returns a sinusoïdal oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_.
|
- <ic>freq</ic> : frequency in hertz.
|
||||||
|
- <ic>times</ic> : output value multiplier.
|
||||||
|
- <ic>offset</ic>: linear offset.
|
||||||
|
- <ic>usine(freq: number = 1, times: number = 1, offset: number= 0): number</ic>: returns a sinusoïdal oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_.
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
"Modulating the speed of a sample player using a sine LFO",
|
"Modulating the speed of a sample player using a sine LFO",
|
||||||
@ -17,8 +20,8 @@ ${makeExample(
|
|||||||
true
|
true
|
||||||
)};
|
)};
|
||||||
|
|
||||||
- <ic>triangle(freq: number = 1, offset: number= 0): number</ic>: returns a triangle oscillation between <ic>-1</ic> and <ic>1</ic>.
|
- <ic>triangle(freq: number = 1, times: number = 1, offset: number= 0): number</ic>: returns a triangle oscillation between <ic>-1</ic> and <ic>1</ic>.
|
||||||
- <ic>utriangle(freq: number = 1, offset: number= 0): number</ic>: returns a triangle oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_.
|
- <ic>utriangle(freq: number = 1, times: number = 1, offset: number= 0): number</ic>: returns a triangle oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_.
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
"Modulating the speed of a sample player using a triangle LFO",
|
"Modulating the speed of a sample player using a triangle LFO",
|
||||||
@ -26,8 +29,8 @@ ${makeExample(
|
|||||||
true
|
true
|
||||||
)}
|
)}
|
||||||
|
|
||||||
- <ic>saw(freq: number = 1, offset: number= 0): number</ic>: returns a sawtooth-like oscillation between <ic>-1</ic> and <ic>1</ic>.
|
- <ic>saw(freq: number = 1, times: number = 1, offset: number= 0): number</ic>: returns a sawtooth-like oscillation between <ic>-1</ic> and <ic>1</ic>.
|
||||||
- <ic>usaw(freq: number = 1, offset: number= 0): number</ic>: returns a sawtooth-like oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_.
|
- <ic>usaw(freq: number = 1, times: number = 1, offset: number= 0): number</ic>: returns a sawtooth-like oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_.
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
"Modulating the speed of a sample player using a saw LFO",
|
"Modulating the speed of a sample player using a saw LFO",
|
||||||
@ -35,8 +38,8 @@ ${makeExample(
|
|||||||
true
|
true
|
||||||
)}
|
)}
|
||||||
|
|
||||||
- <ic>square(freq: number = 1, offset: number= 0, duty: number = .5): number</ic>: returns a square wave oscillation between <ic>-1</ic> and <ic>1</ic>. You can also control the duty cycle using the <ic>duty</ic> parameter.
|
- <ic>square(freq: number = 1, times: number = 1, offset: number= 0, duty: number = .5): number</ic>: returns a square wave oscillation between <ic>-1</ic> and <ic>1</ic>. You can also control the duty cycle using the <ic>duty</ic> parameter.
|
||||||
- <ic>usquare(freq: number = 1, offset: number= 0, duty: number = .5): number</ic>: returns a square wave oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_. You can also control the duty cycle using the <ic>duty</ic> parameter.
|
- <ic>usquare(freq: number = 1, times: number = 1, offset: number= 0, duty: number = .5): number</ic>: returns a square wave oscillation between <ic>0</ic> and <ic>1</ic>. The <ic>u</ic> stands for _unipolar_. You can also control the duty cycle using the <ic>duty</ic> parameter.
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
"Modulating the speed of a sample player using a square LFO",
|
"Modulating the speed of a sample player using a square LFO",
|
||||||
@ -44,7 +47,7 @@ ${makeExample(
|
|||||||
true
|
true
|
||||||
)};
|
)};
|
||||||
|
|
||||||
- <ic>noise()</ic>: returns a random value between -1 and 1.
|
- <ic>noise(times: number = 1)</ic>: returns a random value between -1 and 1.
|
||||||
|
|
||||||
${makeExample(
|
${makeExample(
|
||||||
"Modulating the speed of a sample player using noise",
|
"Modulating the speed of a sample player using noise",
|
||||||
@ -54,5 +57,3 @@ ${makeExample(
|
|||||||
|
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user