-
Notifications
You must be signed in to change notification settings - Fork 6
/
eq.html
145 lines (136 loc) · 4.73 KB
/
eq.html
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
142
143
144
145
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/>
<meta name="format-detection" content="telephone=no"/>
<title>均衡器(BiquadFilter)</title>
<style>
.filter label {
width: 50px;
display: inline-block;
height: 25px;
line-height: 25px;
}
.filter input {
width: 150px;
vertical-align: middle;
}
.filter em {
font-style: normal;
color: #ff4500;
}
</style>
</head>
<body>
<h1>均衡器(BiquadFilter)</h1>
<div id="eq">
<section class="filter">
<label for="filter1">32HZ</label>
<input id="filter1" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db1">0</em>db</span>
</section>
<section class="filter">
<label for="filter2">63HZ</label>
<input id="filter2" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db2">0</em>db</span>
</section>
<section class="filter">
<label for="filter3">125HZ</label>
<input id="filter3" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db3">0</em>db</span>
</section>
<section class="filter">
<label for="filter4">250HZ</label>
<input id="filter4" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db4">0</em>db</span>
</section>
<section class="filter">
<label for="filter5">500HZ</label>
<input id="filter5" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db5">0</em>db</span>
</section>
<section class="filter">
<label for="filter6">1kHZ</label>
<input id="filter6" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db6">0</em>db</span>
</section>
<section class="filter">
<label for="filter7">2kHZ</label>
<input id="filter7" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db7">0</em>db</span>
</section>
<section class="filter">
<label for="filter8">4kHZ</label>
<input id="filter8" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db8">0</em>db</span>
</section>
<section class="filter">
<label for="filter9">8kHZ</label>
<input id="filter9" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db9">0</em>db</span>
</section>
<section class="filter">
<label for="filter10">16kHZ</label>
<input id="filter10" type="range" value="0" step="1"
max="30" min="-30">
<span><em id="db10">0</em>db</span>
</section>
</div>
<p>
<input type="button" id="play" disabled value="加载中..."/>
</p>
<script type="text/javascript" src="sound.js"></script>
<script type="text/javascript">
var Ctx = window.webkitAudioContext ? window.webkitAudioContext : window.AudioContext;
var ctx = new Ctx();
(function () {
var freqs = [32, 63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000];
var biquads = [];
var i;
for (i = 0; i < 10; i ++) {
biquads[i] = ctx.createBiquadFilter();
biquads[i].type = 5; // 'peaking';
biquads[i].frequency.value = freqs[i];
biquads[i].Q.value = 1.4;
biquads[i].gain.value = 0;
}
for (i = 1; i < 10; i ++) {
biquads[i-1].connect(biquads[i]);
}
biquads[9].connect(ctx.destination);
for (i = 0; i < 10; i ++) {
document.getElementById('filter' + (i+1)).onchange = (function (k){
return function () {
biquads[k].gain.value = parseInt(this.value);
document.getElementById('db' + (k+1)).innerHTML = this.value;
};
})(i);
}
var loadedCallback = function(){
document.getElementById('play').removeAttribute('disabled');
document.getElementById('play').value = '播放';
};
var gangnam = new Sound(ctx);
gangnam.setOutput(biquads[0]);
//gangnam.load('res/gangnam_style_clip.mp3', loadedCallback);
//gangnam.setLoop(5.106, 12.386);
gangnam.load('res/beir_shuang_chip.mp3', loadedCallback);
gangnam.setLoop(1.755, 12.813);
document.getElementById('play').onclick = function () {
gangnam.play();
document.getElementById('play').setAttribute('disabled', 'disabled');
};
})();
</script>
</body>
</html>