[lib.audio-manager] tweaked + pushed 4096 to 8192

This commit is contained in:
xdrm-brackets 2018-04-09 23:41:36 +02:00
parent 3aab1a93ba
commit 151e76b30a
1 changed files with 28 additions and 5 deletions

View File

@ -1,6 +1,6 @@
export default class AudioManager{ export default class AudioManager{
static get BUFFER_SIZE(){ return 4096; } static get BUFFER_SIZE(){ return 8192; }
constructor(){ constructor(){
@ -61,6 +61,8 @@ export default class AudioManager{
/* (7) Initialise coordinator to manage received */ /* (7) Initialise coordinator to manage received */
this.stack = []; this.stack = [];
this.stack_size = 2; this.stack_size = 2;
this.fade_in = 0.1;
this.fade_out = 0.1;
@ -98,6 +100,8 @@ export default class AudioManager{
}.bind(this.dbg), this.dbg.interval*1000); }.bind(this.dbg), this.dbg.interval*1000);
this.test = true;
} }
@ -260,11 +264,30 @@ export default class AudioManager{
/* (5) Send buffer through websocket */ /* (5) Send buffer through websocket */
this.ws.send(buf16); this.ws.send(buf16);
/* (6) Read input buffer */ /* (6) Pop too large stack */
this.stack.length > 0 && this.stack.shift().start(this.ctx.currentTime); this.stack.length > this.stack_size && this.stack.pop();
/* (7) Read input buffer stack */
if( this.stack.length > 0 ){
// 1. extract our nodes
let tmp = this.stack.shift();
let source_node = tmp[0];
let gain_node = tmp[1];
// 2. set default gain to fade-in
// ( this.test === true ) && gain_node.gain.setValueAtTime(0.1, this.ctx.currentTime);
// ( this.test === true ) && gain_node.gain.exponentialRampToValueAtTime(1, this.ctx.currentTime+AudioManager.CHUNK_DURATION*this.fade_in);
// 3. set final gain to fadeout
// ( this.test === true ) && gain_node.gain.setValueAtTime(1, this.ctx.currentTime+AudioManager.CHUNK_DURATION*(1-this.fade_out));
// ( this.test === true ) && gain_node.gain.exponentialRampToValueAtTime(0.1, this.ctx.currentTime+AudioManager.CHUNK_DURATION );
source_node.start(this.ctx.currentTime);
}
/* (7) Pop stack if exceeded */ /* (7) Pop stack if exceeded */
this.stack.length > this.stack_size && this.stack.pop();
@ -300,7 +323,7 @@ export default class AudioManager{
gain.connect(this.master); gain.connect(this.master);
/* (7) Push in buffer stack */ /* (7) Push in buffer stack */
this.stack.push(source); this.stack.push([source, gain]);
} }