EDIT 3:
It was only a Firefox issue, works in Chrome, so problem solved, see the answer below. Thank you Chris for your help!
EDIT 2:
Following Chris's advice I changed one line on getUserMedia call, but it doesn't works for now, maybe I'm using a wrong syntax but this feature is undocumented:
if(navigator.getUserMedia){
navigator.getUserMedia(
{ audio: { optional: [{ echoCancellation: false }] } }
,function(stream){ init_stream(stream); }
,function(err){ console.log('The following gUM error occured: ' + err); }
);
}
Also, you can now follow progresses here:
http://jsfiddle.net/stratboy/aapafrbu/1/
EDIT 1:
I'm currently playing a keyboard > mixer > behringer UCA222 > mac (usb). My current code to see some data is the following. I see data changing for channel left but not for channel right, and despite what I'm doing on the mixer. What can be the reason?
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_left = audiocontext.createAnalyser();
var analyser_right = audiocontext.createAnalyser();
var splitter = audiocontext.createChannelSplitter(2);
var index = 0;
function init_stream(stream){
window.audiosource = audiocontext.createMediaStreamSource(stream);
audiosource.connect(splitter);
splitter.connect(analyser_left,0);
splitter.connect(analyser_right,1);
listen();
}
function listen(){
requestAnimationFrame(listen);
analyser_left.fftSize = 256;
var leftBufferLength = analyser_left.frequencyBinCount;
var leftDataArray = new Uint8Array(leftBufferLength);
analyser_left.getByteTimeDomainData(leftDataArray);
$('.monitor_left').html(JSON.stringify(leftDataArray));
analyser_right.fftSize = 256;
var rightBufferLength = analyser_right.frequencyBinCount;
var rightDataArray = new Uint8Array(rightBufferLength);
analyser_right.getByteTimeDomainData(rightDataArray);
$('.monitor_right').html(JSON.stringify(rightDataArray));
}
if(navigator.getUserMedia){
navigator.getUserMedia(
{ audio: true }
,function(stream){ init_stream(stream); }
,function(err){ console.log('The following gUM error occured: ' + err); }
);
}
I'd like to play my guitar into the computer and analyze the sounds via the web audio API. I know it's possible to use the microphone, but what about a real instrument plugged in?