Audio buffer is not passed to ScriptProcessorNode after iPhone is locked and unlocked
arpitvjaiswal opened this issue · 1 comments
arpitvjaiswal commented
Hi,
Steps to reproduce:
- In
audioinput-demo's www/js/webaudio-demo.js
, replacefilterNode
with a processor node.
var processorNode;
/**
* Start capturing audio.
*/
var startCapture = function() {
try {
if (window.audioinput && !window.audioinput.isCapturing()) {
getMicrophonePermission(function() { // See utils.js
// Connect the audioinput to the speaker(s) in order to hear the captured sound.
// We're using a filter here to avoid too much feedback looping...
// Start with default values and let the plugin handle conversion from raw data to web audio.
consoleMessage("Microphone input starting...");
window.audioinput.start({
streamToWebAudio: true
});
consoleMessage("Microphone input started!");
// UPDATED CODE
processorNode = audioinput.getAudioContext().createScriptProcessor(4096, 1, 1);
processorNode.addEventListener('audioprocess', function(event) {
var inputBuffer = event.inputBuffer;
console.log('New Buffer', inputBuffer);
});
audioinput.connect(processorNode);
processorNode.connect(audioinput.getAudioContext().destination);
consoleMessage("Capturing audio!");
disableStartButton();
}, function(deniedMsg) {
consoleMessage(deniedMsg);
}, function(errorMsg) {
consoleMessage(errorMsg);
});
}
else {
alert("Already capturing!");
}
}
catch (ex) {
alert("startCapture exception: " + ex);
}
};
/**
* Stop capturing audio.
*/
var stopCapture = function() {
if (window.audioinput && window.audioinput.isCapturing()) {
window.audioinput.stop();
if (filterNode) filterNode.disconnect();
if (processorNode) processorNode.disconnect();
window.audioinput.disconnect();
disableStopButton();
}
consoleMessage("Stopped!");
};
- Build the sample for ios afterwards and run it on iOS device.
- Connect to safari browser console, and run Web Audio demo. On start, the browser console shows messages on receiving audio buffer.
[Log] Microphone input started! (cordova.js, line 1413)
[Log] Capturing audio! (cordova.js, line 1413)
[Log] New Buffer – AudioBuffer {length: 4096, duration: 0.08533333333333333, sampleRate: 48000, …} (cordova.js, line 1413)
AudioBuffer {length: 4096, duration: 0.08533333333333333, sampleRate: 48000, numberOfChannels: 1, gain: 1, …}
- Lock the phone and unlock after a couple seconds. Run the Web Audio demo again.
Expectation - Same logs as before
Observation - The processor's onaudioprocess
callback is not called. Log shows as following:
[Log] Microphone input starting... (cordova.js, line 1413)
[Log] Microphone input started! (cordova.js, line 1413)
[Log] Capturing audio! (cordova.js, line 1413)
edimuj commented
Since this is on iOS, I think think there is an issue with the webaudio audiocontext is disabled when the device is locked, and it isn't automatically enabled again when it is unlocked. If I remeber correctly one must call resume on the audiocontext from within a user interaction (tap).