How to use the standardized-audio-context.OscillatorNode function in standardized-audio-context

To help you get started, we’ve selected a few standardized-audio-context examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vitaliy-bobrov / js-rocks / src / app / audio / effects / lfo.ts View on Github external
constructor(context: AudioContext, private type: LFOType = 'sine') {
    this.osc = new OscillatorNode(context, {
      type: LFO.isAllowedType(type) ? (type as TOscillatorType) : undefined,
      frequency: 0.5
    });

    // Add one to the output signals, making the range [0, 2].
    this.offsetNode = new ConstantSourceNode(context, { offset: 1 });
    this.offsetNode.start();
    // Divide the result by 2, making the range [0, 1].
    this.rangeNode = new GainNode(context, { gain: 0.5 });
    this.depthNode = new GainNode(context);

    // Map the oscillator's output range from [-1, 1] to [0, 1].
    this.osc.connect(this.offsetNode.offset as any);
    this.offsetNode.connect(this.rangeNode).connect(this.depthNode);
  }