-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
141 lines (131 loc) · 4.45 KB
/
index.html
File metadata and controls
141 lines (131 loc) · 4.45 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<title>Android Audio Amplifier</title>
<style type="text/css">
h1 {
font-family: Helvetica, Arial;
font-weight: bold;
font-size: 18px;
}
body, p{
background-color: black;
font-family: Helvetica, Arial;
font-size:10px;
}
canvas{
position:fixed;
top:50%;
left:50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<p id="list"></p>
<canvas id="wavedisplay" width="300" height="100"></canvas>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
try {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
audioContext = new AudioContext();
} catch(e) {
getElementById("list").html('Web Audio API is not supported in this browser');
}
try {
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
var hasMicrophoneInput = (navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
} catch(e) {
getElementById("list").html("getUserMedia() is not supported in your browser");
}
var audioContext = new AudioContext();
var canvas=document.getElementById("wavedisplay");
var ctx = canvas.getContext('2d');
var gain=audioContext.createGain();
gain.value=158489319.24611133;
var f1=audioContext.createBiquadFilter();
f1.type="highpass";
f1.frequency.value=3000;
var limiter=audioContext.createDynamicsCompressor();
limiter.threshold.value=0.0;
limiter.knee.value=0.0;
limiter.ratio.value=20.0;
limiter.attack.value=0.010;
limiter.release.value=0.050;
var analyser=audioContext.createAnalyser();
analyser.fftSize=2048;
var bufferLength=analyser.frequencyBinCount;
var dataArray = new Uint8Array(bufferLength);
function myPCMFilterFunction(inputSample) {
return inputSample ;
}
var errorCallback = function(e) {
getElementById("list").html("Error in getUserMedia: " + e);
};
navigator.getUserMedia({audio: true}, function(stream) {
var microphone = audioContext.createMediaStreamSource(stream);
microphone.connect(analyser);
analyser.connect(f1);
f1.connect(gain);
gain.connect(limiter)
limiter.connect(audioContext.destination);
}, errorCallback);
/*
var bufferSize = 512;
var myPCMProcessingNode = audioContext.createScriptProcessor(bufferSize, 1, 1);
myPCMProcessingNode.onaudioprocess = function(e) {
var canvas=document.getElementById("wavedisplay");
var ctx = canvas.getContext('2d');
var input = e.inputBuffer.getChannelData(0);
var output = e.outputBuffer.getChannelData(0);
var max=0.0;
var min=0.0;
for (var i = 0; i < bufferSize; i++) {
if input[i]>max{max=input[i]};
else if input[i]<min{min=input[i]};
else{
}
}
if max===0.0 && min===0.0{
}
else{
ctx.beginPath();
ctx.fillStyle="green";
ctx.fillrect(0,150-(max-min),300,(max-min)-150);
ctx.clearrect(0,150-(max-min),300,(max-min)-150);
}
}
*/
ctx.clearRect(0,0,300,100);
function draw(){
requestAnimationFrame(draw);
analyser.getByteTimeDomainData(dataArray);
ctx.fillStyle='rgb(0,0,0)';
ctx.fillRect(0,0,300,100);
ctx.lineWidth=1;
ctx.strokeStyle='rgb(0,256,0)';
ctx.beginPath();
var sliceWidth=300*1.0/bufferLength;
var x=0;
for (var i=0; i<bufferLength; i++){
var v= dataArray[i]/128.0;
var y = v*100/2;
if(i===0){
ctx.moveTo(x,y);
} else{
ctx.lineTo(x,y);
}
x+=sliceWidth;
}
ctx.lineTo(300, 100/2)
ctx.stroke();
};
draw();
</script>
</html>