How to use virtual-audio-graph - 10 common examples

To help you get started, we’ve selected a few virtual-audio-graph 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 miselaytes-anton / web-audio-experiments / packages / guitar-app / src / index.js View on Github external
'use strict';

const {createStore} = require('redux');
const {isEmpty} = require('lodash')
const {default: createVirtualAudioGraph} = require('virtual-audio-graph');
const {makeDistortionCurve, getGuitarSoundBuffer, stateToGraph} = require('./utils');
const reducer = require('./reducer')
const ui = require('./ui')

const audioContext = new AudioContext();

const virtualAudioGraph = createVirtualAudioGraph({
  audioContext,
  output: audioContext.destination,
});

// update using virtualAudioGraph
const updateAudioNodes = state => virtualAudioGraph.update(stateToGraph(state));

// update using plain Web Audio API
const nodes = {};
const updateAudioNodes2 = state => {
  if (isEmpty(nodes)) {
    // creating nodes
    nodes.volume = audioContext.createGain();
    nodes.distortion = audioContext.createWaveShaper();
    nodes.distortion.oversample = state.distortion[2].oversample;
    nodes.guitar = audioContext.createBufferSource();
github benji6 / andromeda / src / plugins / instruments / Ariadne.js View on Github external
1: oscillator(0, {
    detune: carrierDetune,
    frequency,
    startTime,
    stopTime,
    type: carrierOscType,
  }),
  2: gainNode({destination: 'frequency', key: 1}, {gain: 1024}),
  3: oscillator(2, {
    detune: modulatorDetune,
    frequency: frequency * modulatorRatio,
    startTime,
    stopTime,
    type: modulatorOscType,
  }),
  masterGain: gainNode(['output'], {gain: masterGain}),
  masterPan: stereoPanner(['masterGain'], {pan: masterPan}),
}))
github benji6 / andromeda / src / plugins / effects / Delay / index.js View on Github external
const updateAudioGraph = virtualAudioGraph => ({
  delayTime,
  dryLevel,
  feedback,
  highCut,
  lowCut,
  pingPong,
  wetLevel,
}) => virtualAudioGraph.update({
  0: gain('output', {gain: wetLevel}),
  1: stereoPanner(0, {pan: -1}),
  2: stereoPanner(0, {pan: 1}),
  3: delay([2, 8], {delayTime, maxDelayTime}),
  4: gain(3, {gain: feedback}),
  5: delay(pingPong ? [1, 3] : [0, 8], {delayTime, maxDelayTime}),
  6: biquadFilter(5, {frequency: highCut}),
  7: biquadFilter(6, {frequency: lowCut, type: 'highpass'}),
  8: gain(7, {gain: feedback}),
  9: gain('output', {gain: dryLevel}),
  input: gain([8, 9], {gain: 1}, 'input'),
})
github benji6 / andromeda / src / plugins / effects / Reverb / index.js View on Github external
bufferPromise.then(buffer => virtualAudioGraph.update({
    0: gain('output', {gain: dryLevel}),
    1: biquadFilter('output', {frequency: highCut}),
    2: biquadFilter(1, {frequency: lowCut, type: 'highpass'}),
    3: gain(2, {gain: wetLevel}),
    4: gain(3, {gain: 0.5}),
    5: convolver(4, {buffer}, 'input'),
    input: gain([0, 5]),
  }))
  reverbTypeToBufferPromise[reverbType] = bufferPromise
github benji6 / andromeda / src / plugins / instruments / Prometheus / notesToGraph.js View on Github external
notes.reduce((acc, {frequency, gain, id, startTime, stopTime}) => {
    const noteGainId = `noteGain-${id}`
    acc[noteGainId] = gainNode('filter', {gain})

    for (let i = 0; i < oscillatorSingles.length; i++) {
      const oscillatorSingle = oscillatorSingles[i]
      acc[`oscSingle-${oscillatorSingle.id}-${id}`] = osc(noteGainId, Object.assign({}, oscillatorSingle, {frequency, startTime, stopTime}))
    }

    for (let i = 0; i < oscillatorSupers.length; i++) {
      const oscillatorSuper = oscillatorSupers[i]
      const {numberOfOscillators, type} = oscillatorSuper
      for (let j = 0; j < numberOfOscillators; j++) {
        acc[`oscSuper-${oscillatorSuper.id}-${j}-${id}`] = osc(noteGainId, {
          detune: oscillatorSuper.detune + (j - Math.floor(numberOfOscillators / 2)) * oscillatorSuper.spread,
          frequency,
          gain: oscillatorSuper.gain,
          pan: oscillatorSuper.pan,
          pitch: oscillatorSuper.pitch,
github benji6 / andromeda / src / plugins / effects / Delay / index.js View on Github external
feedback,
  highCut,
  lowCut,
  pingPong,
  wetLevel,
}) => virtualAudioGraph.update({
  0: gain('output', {gain: wetLevel}),
  1: stereoPanner(0, {pan: -1}),
  2: stereoPanner(0, {pan: 1}),
  3: delay([2, 8], {delayTime, maxDelayTime}),
  4: gain(3, {gain: feedback}),
  5: delay(pingPong ? [1, 3] : [0, 8], {delayTime, maxDelayTime}),
  6: biquadFilter(5, {frequency: highCut}),
  7: biquadFilter(6, {frequency: lowCut, type: 'highpass'}),
  8: gain(7, {gain: feedback}),
  9: gain('output', {gain: dryLevel}),
  input: gain([8, 9], {gain: 1}, 'input'),
})
github benji6 / andromeda / src / plugins / effects / Reverb / index.js View on Github external
bufferPromise.then(buffer => virtualAudioGraph.update({
    0: gain('output', {gain: dryLevel}),
    1: biquadFilter('output', {frequency: highCut}),
    2: biquadFilter(1, {frequency: lowCut, type: 'highpass'}),
    3: gain(2, {gain: wetLevel}),
    4: gain(3, {gain: 0.5}),
    5: convolver(4, {buffer}, 'input'),
    input: gain([0, 5]),
  }))
  reverbTypeToBufferPromise[reverbType] = bufferPromise
github benji6 / andromeda / src / plugins / instruments / Ariadne.js View on Github external
const oscBank = createNode(({
  carrierDetune,
  carrierOscType,
  gain,
  frequency,
  masterGain,
  masterPan,
  modulatorDetune,
  modulatorOscType,
  modulatorRatio,
  startTime,
  stopTime,
}) => ({
  0: gainNode(['masterPan'], {gain}),
  1: oscillator(0, {
    detune: carrierDetune,
    frequency,
    startTime,
    stopTime,
    type: carrierOscType,
  }),
  2: gainNode({destination: 'frequency', key: 1}, {gain: 1024}),
  3: oscillator(2, {
    detune: modulatorDetune,
    frequency: frequency * modulatorRatio,
    startTime,
    stopTime,
    type: modulatorOscType,
  }),
  masterGain: gainNode(['output'], {gain: masterGain}),
github benji6 / andromeda / src / plugins / effects / Delay / index.js View on Github external
const updateAudioGraph = virtualAudioGraph => ({
  delayTime,
  dryLevel,
  feedback,
  highCut,
  lowCut,
  pingPong,
  wetLevel,
}) => virtualAudioGraph.update({
  0: gain('output', {gain: wetLevel}),
  1: stereoPanner(0, {pan: -1}),
  2: stereoPanner(0, {pan: 1}),
  3: delay([2, 8], {delayTime, maxDelayTime}),
  4: gain(3, {gain: feedback}),
  5: delay(pingPong ? [1, 3] : [0, 8], {delayTime, maxDelayTime}),
  6: biquadFilter(5, {frequency: highCut}),
  7: biquadFilter(6, {frequency: lowCut, type: 'highpass'}),
  8: gain(7, {gain: feedback}),
  9: gain('output', {gain: dryLevel}),
  input: gain([8, 9], {gain: 1}, 'input'),
})
github benji6 / andromeda / src / plugins / instruments / Prometheus / notesToGraph.js View on Github external
const osc = createNode(({detune, frequency, gain, pan, pitch, startTime, stopTime, type}) => ({
  0: gainNode('output', {gain}),
  1: stereoPanner(0, {pan}),
  2: oscillator(1, {
    detune,
    frequency: pitchToFrequency(frequencyToPitch(frequency) + pitch),
    startTime,
    stopTime,
    type,
  }),
}))