CDBoi
CDBoi

Reputation: 11

Can't get basic oscillator to make noise using the Web Audio API?

Can't get the oscillator to make noise? Think I'm missing something obvious but no idea really. Following https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createOscillator

<!DOCTYPE html>
<html>
  <head>
    <title>Audio API</title>
  </head>
  <body>
    <script>
      var audioContext = new (window.AudioContext || window.webkitAudioContext)();

      var oscillator = audioContext.createOscillator();

      oscillator.type = 'square';
      oscillator.frequency.value = 3000;
      oscillator.start();
    </script>
  </body>
</html>

Upvotes: 0

Views: 54

Answers (1)

rafaelcastrocouto
rafaelcastrocouto

Reputation: 12161

You need to connect the oscillator node to an audio destination:

 oscillator.frequency.value = 3000;
 oscillator.connect( audioContext.destination );
 oscillator.start();

Upvotes: 1

Related Questions