-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebaudio.js
More file actions
27 lines (23 loc) · 852 Bytes
/
webaudio.js
File metadata and controls
27 lines (23 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"use strict";
window.AudioContext = window.AudioContext || window.webkitAudioContext;
function CreateAudioContext()
{
let audioCtx = new AudioContext();
console.log("Created AudioContext, sampleRate = " + audioCtx.sampleRate);
audioCtx.dest = audioCtx.createGain();
audioCtx.dest.connect(audioCtx.destination);
//if(audioCtx.audioWorklet) audioCtx.audioWorklet.addModule('audio-processors.js');
return audioCtx;
}
let gAudioCtx;
function GetAudioContext()
{
if(!gAudioCtx) gAudioCtx = CreateAudioContext();
return gAudioCtx;
}
let gMicrophoneSource;
async function GetMicrophoneSource() {
if(gMicrophoneSource) return gMicrophoneSource;
const stream = await navigator.mediaDevices.getUserMedia({audio: true, video: false});
return gMicrophoneSource = GetAudioContext().createMediaStreamSource(stream);
}