npm install lfo-for-modvThis project is a little and simple JavaScript library that will implement LFOs in JavaScript.
LFO stands for Low Frequency Oscillator. It's basically just a device which oscillates between two values on a certain frequency and following a given waveform.
Note: In this library, there is no limitation concerning the frequency, but it can behave strangely at a high frequency
#### Instantiation
First of all, include the LFO script before your other scripts.
``html`
To create an LFO, you just have to create a new instace of LFO :
`javascript`
var my_lfo = new LFO ();
The LFO function take an object as argument, containing these parameters :freq
- : the frequency of the oscillatoramplitude
- : the amplitude of the oscillatorwaveform
- : the custom waveform function. This function take a number between 0 and 2PI as argument and must return a number between 0 and 1.
Example :
`javascript`
var my_lfo = new LFO ({
freq: 1.3,
amplitude: 2,
waveform: function (x) {
if (x <= Math.PI) {
return -1;
} else {
return 1;
}
}
//Same as :
//waveform: "square"
});
This code will create a new LFO with a frequency of 1.3Hz, an amplitude of 2 and which will produce a square signal.
Note: Every parameter is optional
#### Waveform functions
There are some waveform functions that are preset in the library : sine (default value), triangle, square, sawtooth and noise.
#### Getting the current value
To retrieve the current value of an LFO, just use the value function :
`javascript`
var v = my_lfo.value();
#### Changing parameters
To change parameters of an LFO, use the set function which takes the same argument as the constructor of the class :
`javascript``
my_lfo.set({
freq: 0.7
});
- Clean up the code
- Make an ES6 module (that's going to be fun)