javascriptaudiosignal-processingmididigital-analog-converter

Modeling an analog psuedo random LFO signal (low pass filtering in Javascript)


I'm writing a Javascript program to programmatically create MIDI signals for procedurally generated music that uses external inputs to modify/manipulate the sound in response to changes in an environment.

One of the things I'm trying to do is figure out how to program an analog pseudo random low frequency oscillator (LFO) signal like the dashed line in the image below:

enter image description here

This signal will drive MIDI effects like pitch bend or modulation.

The function should take a single value input that controls how dramatically the signal fluctuates. When the input is 0, the resulting signal should be 0, or a flat line. And as the input value increases, the signal should become proportionally more and more erratic.

I feel like I have an idea of how to generate a step function (like the solid line in the image above) that achieves those goals, but I have no idea how to "smooth" it (i.e. low pass filter it) to get a continuous curve like the dashed line. Ultimately that smoothed/continuous/analog function would be sampled, say, every 100 ms and broad cast as a new MIDI pitch bend instruction, etc.


Solution

  • I would just use an existing animation library, such as TweenJS. https://www.createjs.com/docs/tweenjs/modules/TweenJS.html These libraries are normally meant for visual use, but they can be used generically as well.

    Untested, but try something like this:

    const cc = {
      modwheel: 0
    };
    createjs.Tween.get(cc).to({modwheel: 127}, 1000);
    

    Then, just observe the cc.modhweel property every 100ms or whatever "frame" you want.

    See also: https://stackoverflow.com/a/13501577/362536