[lib.audio-manager] chromium/webkit fix (must connect scriptProcessor to output

This commit is contained in:
xdrm-brackets 2018-04-10 00:53:17 +02:00
parent 9f6bc383bf
commit 04c6e37527
1 changed files with 53 additions and 29 deletions

View File

@ -54,6 +54,7 @@ export default class AudioManager{
/* (5) Bind network controller to send() function */
this.network.out.onaudioprocess = this.send.bind(this);
/*Chrome fix*/this.network.out.connect(this.output);
/* (6) Set up our filters' parameters */
this.setUpFilters();
@ -99,9 +100,6 @@ export default class AudioManager{
}.bind(this.dbg), this.dbg.interval*1000);
this.test = true;
}
@ -162,21 +160,24 @@ export default class AudioManager{
/* (1) Disconnect all by default */
this.input.disconnect();
/* (2) Get first filter */
/* (2) Also link to analyser */
this.input.connect(this.analyser);
/* (3) Get first filter */
let first_filter = this.filters.voice_clarity;
let last_filter = this.filters.voice_sss;
/* (3) If unlink -> connect directly to NETWORK output */
/* (4) If unlink -> connect directly to NETWORK output */
if( unlink === true )
return this.input.connect(this.network.out);
/* (4) If linking -> connect input to volume */
/* (5) If linking -> connect input to volume */
this.input.connect(this.volume);
/* (5) If linking -> connect volume to filter stack */
/* (6) If linking -> connect volume to filter stack */
this.volume.connect(first_filter);
/* (5) If linking -> connect stack end to network.out */
/* (7) If linking -> connect stack end to network.out */
last_filter.connect(this.network.out);
@ -190,8 +191,9 @@ export default class AudioManager{
/* (1) Bind audio stream
---------------------------------------------------------*/
console.log('BINDING', _stream);
/* (1) bind our audio stream to our source */
console.log(_stream);
this.input = this.ctx.createMediaStreamSource(_stream);
@ -200,9 +202,6 @@ export default class AudioManager{
/* (1) Link through filters */
this.linkFilters();
/* (2) Also link to analyser */
this.input.connect(this.analyser);
gs.get.audio_conn = 2; // voice connected
@ -406,7 +405,7 @@ export default class AudioManager{
}.bind(this);
/* (3) Debug */
this.ws.onopen = () => ( gs.get.audio_conn = 1 ); // listening
this.ws.onopen = () => gs.get.audio_conn !== 2 && (gs.get.audio_conn = 1); // listening
this.ws.onclose = () => ( gs.get.audio_conn = null ); // disconnected
@ -422,29 +421,54 @@ export default class AudioManager{
/* (1) Start websocket */
this.wsconnect(wsAddress);
if( navigator.mediaDevices && navigator.mediaDevices.getUserMedia ){
/* (2) Set our streaming binding function */
let streaming_binding = function(stream){
navigator.mediaDevices.getUserMedia({ audio: true })
.then( stream => {
// this.recorder = new MediaRecorder(stream);
this.recorder = new MediaRecorder(stream);
this.bindRecorderStream(stream);
this.recorder.onstart = () => console.warn('[audio] recording');
this.recorder.onstop = () => {
this.recorder.stream.getTracks().map( t => t.stop() );
this.recorder = null;
console.warn('[audio] stopped recording');
};
// this.recorder.onstart = () => console.warn('[audio] recording');
// start recording
this.recorder.start();
// this.recorder.onstop = () => {
// this.recorder.stream.getTracks().map( t => t.stop() );
// this.recorder = null;
// console.warn('[audio] stopped recording');
// };
})
.catch( e => console.warn('[audio] microphone permission issue', e) );
// // start recording
// this.recorder.start();
}else
console.warn('[audio] microphone not supported');
}.bind(this);
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
/* (3) If navigator.mediaDevices.getUserMedia */
if( navigator.mediaDevices && navigator.mediaDevices.getUserMedia ){
console.log('[audio] using "navigator.mediaDevices.getUserMedia"')
return navigator.mediaDevices.getUserMedia({ audio: true })
.then(streaming_binding)
.catch((e) => console.warn('[audio] microphone recorder issue', e));
}
/* (4) If old version */
if( navigator.getUserMedia ){
console.log('[audio] using "navigator.getUserMedia"')
return navigator.getUserMedia({ audio: true },
streaming_binding,
(e) => console.warn('[audio] microphone recorder issue', e));
}
console.warn('[audio] recorder not supported');
}