0

I'd like to connect the oscillator output to the canvas draw() function to create an oscilloscope but I cant get the logic right how to properly connect the audiostream. I want to use the oscillator as source and connect it with the analyser, createMediaStreamSource(oscillator) result in a parameter not supported and just connecting like the script is now it is not doing anything.:

// create Oscilloscope                                                              ***OSCILLOSCOPE***
var analyser = audioCtx.createAnalyser();
var canvas = document.getElementById('scope');
var canvasCtx = canvas.getContext("2d");
var WIDTH = canvas.width;
var HEIGHT = canvas.height;

// setup scope buffer
analyser.fftSize = 2048;
var bufferLength = analyser.frequencyBinCount;
var dataArray = new Uint8Array(bufferLength);

// connect audiosource
oscillator.connect(analyser);
analyser.connect(audioCtx.destination); 

here's a fiddle of the whole idea: https://codepen.io/silconsystem/pen/xMMwgJ

I hope one of youze can put me in the right direction, thanx for your time in advance

Cheers, rob

aynber
  • 22,380
  • 8
  • 50
  • 63

1 Answers1

0

I fixed it, I just had to call the connection to the analyser when the oscillator is created in the startOsc() function. I'll update the fiddle when I get home for those interested.