[lib.audio-manager] added input volume + websocket buffer chain

This commit is contained in:
xdrm-brackets 2018-04-09 18:49:50 +02:00
parent e783de3675
commit cdd2c42129
1 changed files with 43 additions and 18 deletions

View File

@ -12,6 +12,8 @@ export default class AudioManager{
/* (2) Create the MASTER gain */ /* (2) Create the MASTER gain */
this.master = this.ctx.createGain(); this.master = this.ctx.createGain();
this.volume = this.ctx.createGain();
this.volume.gain.setValueAtTime(.65, 0); // input volume 65%
/* (3) Initialise input (typically bound from recorder) */ /* (3) Initialise input (typically bound from recorder) */
this.input = null; this.input = null;
@ -56,6 +58,9 @@ export default class AudioManager{
/* (6) Set up our filters' parameters */ /* (6) Set up our filters' parameters */
this.setUpFilters(); this.setUpFilters();
/* (7) Initialise coordinator to manage received */
this.stack = [];
@ -104,27 +109,28 @@ export default class AudioManager{
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Setup EQ#1 -> voice clarity */ /* (1) Setup EQ#1 -> voice clarity */
this.filters.voice_clarity.type = 'peaking'; this.filters.voice_clarity.type = 'peaking';
this.filters.voice_clarity.frequency.value = 3000; this.filters.voice_clarity.frequency.setValueAtTime(3000, this.ctx.currentTime);
this.filters.voice_clarity.Q.value = .8; this.filters.voice_clarity.Q.setValueAtTime(.8, this.ctx.currentTime);
this.filters.voice_clarity.gain.value = 2; this.filters.voice_clarity.gain.setValueAtTime(2, this.ctx.currentTime);
/* (2) Setup EQ#2 -> voice fullness */ /* (2) Setup EQ#2 -> voice fullness */
this.filters.voice_fullness.type = 'peaking'; this.filters.voice_fullness.type = 'peaking';
this.filters.voice_fullness.frequency.value = 200; this.filters.voice_fullness.frequency.setValueAtTime(200, this.ctx.currentTime);
this.filters.voice_fullness.Q.value = .8; this.filters.voice_fullness.Q.setValueAtTime(.8, this.ctx.currentTime);
this.filters.voice_fullness.gain.value = 2; this.filters.voice_fullness.gain.setValueAtTime(2, this.ctx.currentTime);
/* (3) Setup EQ#3 -> reduce voice presence */ /* (3) Setup EQ#3 -> reduce voice presence */
this.filters.voice_presence.type = 'peaking'; this.filters.voice_presence.type = 'peaking';
this.filters.voice_presence.frequency.value = 5000; this.filters.voice_presence.frequency.setValueAtTime(5000, this.ctx.currentTime);
this.filters.voice_presence.Q.value = .8; this.filters.voice_presence.Q.setValueAtTime(.8, this.ctx.currentTime);
this.filters.voice_presence.gain.value = -2; this.filters.voice_presence.gain.setValueAtTime(-2, this.ctx.currentTime);
/* (4) Setup EQ#3 -> reduce 'sss' metallic sound */ /* (4) Setup EQ#3 -> reduce 'sss' metallic sound */
this.filters.voice_sss.type = 'peaking'; this.filters.voice_sss.type = 'peaking';
this.filters.voice_sss.frequency.value = 7000; this.filters.voice_sss.frequency.setValueAtTime(7000, this.ctx.currentTime);
this.filters.voice_sss.Q.value = .8; this.filters.voice_sss.Q.setValueAtTime(.8, this.ctx.currentTime);
this.filters.voice_sss.gain.value = -8; this.filters.voice_sss.gain.setValueAtTime(-8, this.ctx.currentTime);
/* (2) Connect filters /* (2) Connect filters
@ -159,8 +165,11 @@ export default class AudioManager{
if( unlink === true ) if( unlink === true )
return this.input.connect(this.network.out); return this.input.connect(this.network.out);
/* (4) If linking -> connect input to filter stack */ /* (4) If linking -> connect input to volume */
this.input.connect(first_filter); this.input.connect(this.volume);
/* (5) If linking -> connect volume to filter stack */
this.volume.connect(first_filter);
/* (5) If linking -> connect stack end to network.out */ /* (5) If linking -> connect stack end to network.out */
last_filter.connect(this.network.out); last_filter.connect(this.network.out);
@ -177,6 +186,7 @@ export default class AudioManager{
/* (1) Bind audio stream /* (1) Bind audio stream
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) bind our audio stream to our source */ /* (1) bind our audio stream to our source */
console.log(_stream);
this.input = this.ctx.createMediaStreamSource(_stream); this.input = this.ctx.createMediaStreamSource(_stream);
@ -280,12 +290,27 @@ export default class AudioManager{
source.connect(gain); source.connect(gain);
gain.connect(this.master); gain.connect(this.master);
/* (7) Start playing */ /* (7) If not empty stack -> play stack */
source.start(this.ctx.currentTime); if( this.stack.length > 0 ){
this.stack.shift().start(this.ctx.currentTime);
return this.stack.push(source);
}
/* (8) If empty stack -> play + chain */
// chain stack
source.onended = function(){
this.dbg.data.packets_received++; this.dbg.data.packets_received++;
this.dbg.data.kB_received += _buffer.length * 16. / 8 / 1024; this.dbg.data.kB_received += _buffer.length * 16. / 8 / 1024;
return this.stack.length > 0 && this.stack.shift().start(this.ctx.curentTime);
}.bind(this);
// start playing
source.start(this.ctx.currentTime);
} }