From 09d0f55666075df6a93696b2d7ed5d061e0c997f Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 6 Apr 2018 14:26:15 +0200 Subject: [PATCH] [lib.audio-manager] added pop() notification sound --- webpack/lib/audio-manager.js | 54 ++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/webpack/lib/audio-manager.js b/webpack/lib/audio-manager.js index 76f31ae..eef3997 100644 --- a/webpack/lib/audio-manager.js +++ b/webpack/lib/audio-manager.js @@ -164,8 +164,7 @@ export default class AudioManager{ } - - /* (2) Binds an input stream + /* (3) Binds an input stream * ---------------------------------------------------------*/ bindRecorderStream(_stream){ @@ -182,7 +181,7 @@ export default class AudioManager{ } - /* (3) Send chunks (Float32Array) + /* (4) Send chunks (Float32Array) * ---------------------------------------------------------*/ send(_audioprocess){ @@ -202,7 +201,7 @@ export default class AudioManager{ this.dbg.data.kB_sent += buf16.length * 16. / 8 / 1024; } - /* (4) Play received chunks (Int16Array) + /* (5) Play received chunks (Int16Array) * ---------------------------------------------------------*/ receive(_buffer){ @@ -237,7 +236,7 @@ export default class AudioManager{ } - /* (4) Convert Float32Array to Int16Array + /* (6) Convert Float32Array to Int16Array * * @buf32 Input * @@ -260,7 +259,7 @@ export default class AudioManager{ } - /* (2) Convert Int16Array to Float32Array + /* (7) Convert Int16Array to Float32Array * * @buf16 Input * @@ -322,7 +321,7 @@ export default class AudioManager{ - /* (x) Access microphone + launch all + /* (9) Access microphone + launch all * ---------------------------------------------------------*/ launch(wsAddress='wss://ws.douscord.xdrm.io/audio/2'){ @@ -357,7 +356,7 @@ export default class AudioManager{ } - /* (x) Shut down microphone + kill all + /* (10) Shut down microphone + kill all * ---------------------------------------------------------*/ kill(){ @@ -375,4 +374,43 @@ export default class AudioManager{ + /* (11) Play a POP notification + * + ---------------------------------------------------------*/ + pop(){ + + + /* (1) Base data */ + let base_freq = 150; + let mods = [0, 75, 75]; // freq modulations (from base_freq) + let time_range = 0.05; // time between each modulation + let start = this.ctx.currentTime + 0.1; + + /* (2) Build oscillator */ + let osc = this.ctx.createOscillator(); + osc.type = 'triangle'; + + /* (3) Create local gain to lower volume */ + let local = this.ctx.createGain(); + local.gain.setValueAtTime(0.3, 0); + + /* (4) Connect all nodes to output */ + osc.connect(local); + local.connect(this.master); + + /* (5) Bind frequencies over time */ + for( let i in mods ) + osc.frequency.setValueAtTime(base_freq+mods[i], start + i*time_range ); + + /* (6) Start playing */ + osc.start( start ); + + /* (7) Set when to stop playing */ + osc.stop( start + time_range*mods.length ); + + } + + + + } \ No newline at end of file