[lib.audio-manager] added pop() notification sound

This commit is contained in:
xdrm-brackets 2018-04-06 14:26:15 +02:00
parent 017903cd91
commit 09d0f55666
1 changed files with 46 additions and 8 deletions

View File

@ -164,8 +164,7 @@ export default class AudioManager{
} }
/* (3) Binds an input stream
/* (2) Binds an input stream
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
bindRecorderStream(_stream){ bindRecorderStream(_stream){
@ -182,7 +181,7 @@ export default class AudioManager{
} }
/* (3) Send chunks (Float32Array) /* (4) Send chunks (Float32Array)
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
send(_audioprocess){ send(_audioprocess){
@ -202,7 +201,7 @@ export default class AudioManager{
this.dbg.data.kB_sent += buf16.length * 16. / 8 / 1024; this.dbg.data.kB_sent += buf16.length * 16. / 8 / 1024;
} }
/* (4) Play received chunks (Int16Array) /* (5) Play received chunks (Int16Array)
* *
---------------------------------------------------------*/ ---------------------------------------------------------*/
receive(_buffer){ receive(_buffer){
@ -237,7 +236,7 @@ export default class AudioManager{
} }
/* (4) Convert Float32Array to Int16Array /* (6) Convert Float32Array to Int16Array
* *
* @buf32<Float32Array> Input * @buf32<Float32Array> Input
* *
@ -260,7 +259,7 @@ export default class AudioManager{
} }
/* (2) Convert Int16Array to Float32Array /* (7) Convert Int16Array to Float32Array
* *
* @buf16<Int16Array> Input * @buf16<Int16Array> 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'){ 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(){ 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 );
}
} }