Web Audio API Stream: why isn't dataArray changing? -


edit 2: solved. see answer below.

edit 1:

i changed code little, added gain node, moved function. found if use microphone, work. still doesn't work usb audio input. idea? current code:

window.audiocontext = window.audiocontext || window.webkitaudiocontext;  window.onload = function(){    var audiocontext = new audiocontext();   var analyser = audiocontext.createanalyser();   var gainnode = audiocontext.creategain();    navigator.mediadevices.getusermedia({ audio:true, video:false }).then(function(stream){ //mediastream      var source = audiocontext.createmediastreamsource(stream);     source.connect(analyser);     analyser.connect(gainnode);     gainnode.connect(audiocontext.destination);      listen();    });    function listen(){      analyser.fftsize = 256;     var bufferlength = analyser.frequencybincount;     var dataarray = new uint8array(bufferlength);     var index = 0;      function write(){       requestanimationframe(listen);       analyser.getbytetimedomaindata(dataarray);       $('.monitor').html(json.stringify(dataarray) + ' -- ' + (index++));     }      write();   }  } 

old/original post:

my current code this, , connected kewboard via usb audio interface: i've got signal, tried other programs.. so:

window.audiocontext = window.audiocontext || window.webkitaudiocontext;  window.onload = function(){    var audiocontext = new audiocontext();   var analyser = audiocontext.createanalyser();    navigator.mediadevices.getusermedia({ audio:true, video:false }).then(function(stream){ //mediastream      var source = audiocontext.createmediastreamsource(stream);     source.connect(analyser);     analyser.connect(audiocontext.destination);      analyser.fftsize = 2048;     var bufferlength = analyser.frequencybincount;     var dataarray = new uint8array(bufferlength);      function listen(){       requestanimationframe(listen);       analyser.getbytetimedomaindata(dataarray);       $('.monitor').html(json.stringify(dataarray));     }      listen();    }); } 

while i'm playing keyboard, dataarray doesn't change @ all. why? i'm new things i'm doing wrong...

ok it's working. basic current test code following. html has nothing div.monitor write inside. testing on firefox. hardware keyboard > mixer > behringer uca222 > computer (usb). data when playing keyboard , i'm happy now.

there several differences original code, think important i'm saving media source globally (window.audiosource). there other posts here related issue, example this: chrome: onaudioprocess stops getting called after while , html5 microphone capture stops after 5 seconds in firefox.

window.audiocontext = window.audiocontext || window.webkitaudiocontext;  navigator.getusermedia = (navigator.getusermedia ||                           navigator.webkitgetusermedia ||                           navigator.mozgetusermedia ||                           navigator.msgetusermedia);  var audiocontext = new (window.audiocontext || window.webkitaudiocontext)(); var analyser = audiocontext.createanalyser();  if(navigator.getusermedia){   navigator.getusermedia(     { audio: true }     ,function(stream){       window.audiosource = audiocontext.createmediastreamsource(stream);       audiosource.connect(analyser);       listen();     }     ,function(err){ console.log('the following gum error occured: ' + err); }   ); }  function listen(){   requestanimationframe(listen);    analyser.fftsize = 256;   var bufferlength = analyser.frequencybincount;   var dataarray = new uint8array(bufferlength);   analyser.getbytetimedomaindata(dataarray);   $('.monitor').html(json.stringify(dataarray)); } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -