lundi 29 février 2016

Web Audio API latency on Android

I can only find one similar question to this on SO and it doesn't have an answer, so I'm hoping someone can shed some light on this!

I'm using the Web Audio API in my Intel XDK project but have found that although it works without any latency in desktop Chrome and on iPad (presumably iPhone too although I can't test this), there is very noticeable latency on Android - by latency I mean a delay of around 300ms between user initiation of a sound and playback. It's a consistent delay and affects all sound generated through the Web Audio API.

I was wondering whether there's some sort of parameter to set the latency? Usually it's set by how slow the processor is (i.e., slower processor = bigger buffer) but I have no idea how the Web Audio API actually works on that level.

Any help would be appreciated!

var context = new (window.AudioContext || window.webkitAudioContext)();

var bgs=[];var samps=[

  'sound/ting.mp3',
  'sound/ratchet1.mp3',
  'sound/blip.mp3',
  'sound/blipback.mp3',
  'sound/TelTing1.mp3',
  'sound/TelTing2.mp3',
  'sound/TelTing3.mp3',
  'sound/TelTing4.mp3',
  'sound/TelDialReturn.mp3',
  'sound/TelDialStop.mp3',
  'sound/TelDialSlow2.mp3',
  'sound/sea1.mp3'

];

var bufferLoader;

window.onload=function(){

  bufferLoader = new BufferLoader(
    context,samps,
    finishedLoading
    );

  bufferLoader.load();

  function finishedLoading(bufferList) {
  debug("Audio Loaded")
  soundloop=1;
  for(i=0;i<samps.length;i++){bgs[i]=bufferList[i]}
  play(0)
  }
}

var sourceA = null;
var gainNodeA = context.createGain()

function play(x) {
  sourceA = context.createBufferSource();
  sourceA.buffer = bgs[x];
  sourceA.connect(gainNodeA);
  gainNodeA.connect(context.destination)
  gainNodeA.gain.value=1;
  sourceA.start(0);
}




Aucun commentaire:

Enregistrer un commentaire