'Reproduce tones and white noise (simultaneously)

I'm working on an app that needs to reproduce 4 tones (each with different frequency and volume) and 1 white noise simultaneously (with its own volume). I am able to reproduce the 4 tones simultaneously, but the white noise is reproduce when the other 4 stop.

This is my snippet right now...

let frequencies = [
  {volume: 10, frequency: 500},
  {volume: 20, frequency: 2500},
  {volume: 30, frequency: 7500},
  {volume: 5, frequency: 9000},
]

async function play() {
  await Tone.start()

  frequencies.forEach((f) => {
    const synth = new Tone.Synth().toDestination()
    synth.volume.value = f.volume
    synth.triggerAttackRelease(f.frequency, 3);
  })

  addWhiteNoise();
}

function addWhiteNoise() {
  const noise = new Tone.Noise('white').start(Tone.now() + 1);
  noise.volume.value = -10

  const autoFilter = new Tone.AutoFilter({
    frequency: "200n",
    baseFrequency: 200,
    octaves: 8,
  }).toDestination().start()

  noise.connect(autoFilter)
  autoFilter.start()
}
<script src="https://unpkg.com/[email protected]/build/Tone.js"></script>
<button onclick="play()">Play</button>

If you know of any library capable of what I describe in an easier way please let me know.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source