Skip to content

Commit 4a76fe3

Browse files
committed
better example web for the graphic eq
1 parent 20fb188 commit 4a76fe3

File tree

2 files changed

+19
-38
lines changed

2 files changed

+19
-38
lines changed

dsp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ GraphicalEq = function(sampleRate) {
12601260
}
12611261

12621262
if (!this.w) {
1263-
this.w = Float32Array(200);
1263+
this.w = Float32Array(400);
12641264
for (var i=0; i<this.w.length; i++) {
12651265
this.w[i] = Math.PI/this.w.length * i;
12661266
}

examples/grapheq.html

+18-37
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
var writeCount = 0;
7575

7676
var signal = new Float32Array(2048);
77-
var response = [0];
77+
var freqz = [0];
7878

7979
var grapheq;
8080

@@ -112,25 +112,9 @@
112112

113113
var changeBandGain = function(event, ui) {
114114
grapheq.setBandGain(ui.handle.parentNode.id.split("_")[1], ui.value);
115+
plotCoeffs();
115116
}
116117

117-
function getMethods(obj, short) {
118-
var result = [];
119-
for (var id in obj) {
120-
try {
121-
if (short) {
122-
result.push(id + ": " + typeof(obj[id]));
123-
} else {
124-
result.push(id + ": " + obj[id].toString());
125-
}
126-
} catch (err) {
127-
result.push(id + ": inaccessible");
128-
}
129-
}
130-
return result;
131-
}
132-
133-
134118
var plotCoeffs = function() {
135119
freqz = new Float32Array(grapheq.freqzs[0].length);
136120

@@ -155,16 +139,16 @@
155139

156140
<script type="application/processing" target="#signal">
157141
// Draw axes
158-
float yMin = -12;
159-
float yMax = 3;
142+
float yMin = -60;
143+
float yMax = 12;
160144
float yCenter = 0;
161145

162146
float xMin = 0;
163147
float xMax = PI;
164148
float xCenter = 0;
165149

166150
void setup() {
167-
size(300, 200);
151+
size(700, 200);
168152
grapheq = new GraphicalEq(sampleRate);
169153
grapheq.recalculateFilters();
170154
plotCoeffs();
@@ -177,7 +161,11 @@
177161

178162
void draw() {
179163
background(255);
180-
164+
165+
noFill();
166+
stroke(127);
167+
rect(0, 0, width, height);
168+
181169
stroke(0);
182170
line(map(xCenter, xMin, xMax, 0, width), map(yMin, yMin, yMax, height, 0), map(xCenter, xMin, xMax, 0, width), map(yMax, yMin, yMax, height, 0));
183171
line(map(xMin, xMin, xMax, 0, width), map(yCenter, yMin, yMax, height, 0), map(xMax, xMin, xMax, 0, width), map(yCenter, yMin, yMax, height, 0));
@@ -186,32 +174,23 @@
186174
noFill();
187175
stroke(10, 40, 200);
188176
beginShape();
189-
for (int i = 0; i < response.length; i++) {
190-
vertex(map(i, 0, response.length, 0, width), map(response[i], yMin, yMax, height, 0));
177+
for (int i = 0; i < freqz.length; i++) {
178+
vertex(map(i, 0, freqz.length, 0, width), map(freqz[i], yMin, yMax, height, 0));
191179
}
192180
endShape();
193181
}
194182

195-
void mousePressed() {
196-
int ind = (int)map(mouseX, 0, width, 0, grapheq.filters.length-1);
197-
float gain = map(mouseY, 0, height, yMax, yMin);
198-
grapheq.setBandGain(ind, gain);
199-
plotCoeffs();
200-
}
201183
</script>
202184

203185
<h1>Graphical Equalizer</h1>
204186
<h3>by <a href="http://www.ricardmarxer.com/blog">Ricard Marxer</a></h3>
205-
<p>Applies a Graphical Equalizer filter to an audio stream. Remember to <b>Mute</b> the audio to hear the pure filtered sound.</p>
206-
<p>The filter implementation will become part of the <a href="https://wiki.mozilla.org/Audio_Data_API_JS_Library">dsp.js</a> library.</p>
207187
<p>You will need a recent build of Mozilla Firefox with the Audio API to hear the filtered version.</p>
208-
209-
<audio id='input' tabindex="0" src="audio/corban-peddle.ogg" controls="true" onaudiowritten="audioWritten(event);" style="width: 100%;"></audio><br>
210-
188+
<audio id='input' style="float: left; height:70px; width: 100%" tabindex="0" src="audio/corban-peddle.ogg" controls="true" onaudiowritten="audioWritten(event);"></audio></br>
189+
<p></br></br></p>
211190
<div style="width: 100%;">
212191
<div><canvas id="signal" width="50%" height="200px" style="float: left;"></canvas></div>
213192

214-
<div class="control" style="float: right; height: 188px">
193+
<div class="control" style="float: right; height: 200px">
215194
<h3>Graphical Equalizer</h3>
216195
<table>
217196
<tr>
@@ -223,7 +202,9 @@ <h3>Graphical Equalizer</h3>
223202
</div>
224203
</div>
225204

226-
<div class="control" style="width: 100%; float: left;">
205+
<p></br></br></br></p>
206+
207+
<div class="control" style="width: 100%; float: left;">
227208
<table>
228209
<tr id="bandSliders">
229210
</tr>

0 commit comments

Comments
 (0)