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