edimuj / cordova-plugin-audioinput

This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.

Home Page:https://github.com/edimuj/app-audioinput-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug when working with different AudioContexts in WebAudio mode

phal0r opened this issue · comments

Hi @edimuj ,

thanks for this nice plugin. While testing I discovered a minor bug, that lead to the crash of my webapp running in cordova under iOS. I am using webaudio and your plugin to record audio and to prevent blocking hardware resources I close and release the audio context once the recording is finished. Subsequent calls to audioinput.start would fail with a strange error.

How to reproduce:

call to start recording

audioinput.start({
	streamToWebAudio: true,
	channels: audioinput.CHANNELS.STEREO,
	audioContext: recordingAudioContext,
	bufferSize: bufferSize
});

connect the audioinput to my audio graph and once finished i call

audioinput.stop();

The first call is being handled successfully, but the next calls, as mentioned before, will fail. I create a new recordingAudioContext on every new tap on the record button of the user. The problem is, that you create a gainnode as the connecting node to the rest of the audio graph, which is totally fine. But while calling audioinput.stop() the gainnode should eventually be discarded, since it is possible to pass a new audioContext on every call of audioinput.start.

Long story short:

  • the gainnode is created during the first call of start() with the provided audioContext
  • I pass a new audioContext on every subsequent call of start(), but the plugin wants to use the "old" gainnode, which belongs the old already closed audioContext, which fails with an exception

My current workaround:

manually discard the gainnode via audioinput._micGainNode = null;, so a new one is created automatically thus resolving the issue, but I guess the plugin should handle this internally :)

commented

Thanks, @phal0r for reporting this and for the thourogh explanation. I´ll look into this as soon as I can, but I’m currently busy with commercial projects. If you want it sooner than later, feel free to submit a PR.

Thanks for coming back to this bug :)

commented

And thank you for the thorough explanation of the error, made it simple for me to fix the issue.

commented

i am experiencing this problem in ios 11. i understand an update is applied for tis fix but in ios its still happening