-
Notifications
You must be signed in to change notification settings - Fork 1
/
wickisynth_lowlatency.html
342 lines (298 loc) · 12 KB
/
wickisynth_lowlatency.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- created by Piers Titus van der Torren, 2010 - http://www.toverlamp.org/static/wickisynth/ -->
<meta charset="UTF-8">
<title>Tuning exploration, Wicki keyboard and Karplus-Strong synthesizer</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="raphael-min.js"></script>
<script src="keyboard.js"></script>
<script src="oscsynth.js"></script>
<style type="text/css">
.slider {
margin:10px;
}
#sliders{
width:400px;
background-color:#555;
padding:10px;
}
body{
background-color:#333;
color:#eee;
font:normal 11px verdana;
}
a{
color:#8af;
}
p{
width:700px;
margin-bottom:20px;
}
#generatorSliderBox {
font: normal 11px verdana;
}
#keyboard {
position: absolute;
left: 250px;
top: 5px;
}
#generatorSliderBox .lbl {
position: absolute;
left: 30px;
}
#generatorSlider {
top: 5px;
}
circle.button {
stroke: #006600;
fill: #00cc00;
}
</style>
<script>
var generator = [700, 1200];
// load the synthesizer
var AudioContext = window.AudioContext || window.webkitAudioContext; // cross browser compatible
var context = new AudioContext();
var synthesizer = new OscSynth(context);
// load the keyboard
var keyBoard = new Keyboard(this, function(event){
synthesizer.play(event.keyId, event.loc, event.volume);
lastHz = event.hz; // for display purposes
// Updating the screen causes audio stuttering
//document.getElementById("data").innerHTML = "Keyboard returns a note at: " + event.hz + " Hz";
}, function(event){
synthesizer.stop(event.keyId);
}, function(event){synthesizer.setSustain(event);});
keyBoard.setGenerator(generator);
synthesizer.setGenerator(generator);
</script>
<script>
// script for graphical wicki layout
var paper;
var buttons;
var xo = 200;var yo = 140; // offset of center button
var tunings = {
tet5: (1200+1200/5)/2, // 720
//tet22:
tet17: (1200+3*1200/17)/2, // 705.88
tet53: (1200+9*1200/53)/2, // 701.89
pyth: Math.log(1.5)/Math.log(2)*1200, // 701.95
tet12: (1200+2*1200/12)/2, // 700
//tet43:
tet31: (1200+5*1200/31)/2, // 696.77
quart: Math.log(Math.pow(5,1/4))/Math.log(2)*1200, // 696.58
//tet50:
tet19: (1200+3*1200/19)/2, // 694.74
//tet26:
tet7: (1200+1200/7)/2 // 685.71
};
var genx = [ 20, 0 ];
var genyFact = 0.07;
var geny = [ generator[0] * genyFact, generator[1] * genyFact ];
var button_size = 30;
var button_spacing = 40;
$(function() {
var noteNamesD = ['F', 'C', 'G', 'D', 'A', 'E', 'B'];
var accidentals = ['bb', 'b', '', '#', 'x'];
//var accidentals = ['𝄫','♭','','♯','𝄪'];
//var accidentals = ['♭♭', '♭', '', '♯', 'x'];
var noteNames = new Array(noteNamesD.length*accidentals.length);
for (var i=0; i<accidentals.length; i++) {
for (var j=0; j<noteNamesD.length; j++) {
noteNames[i*noteNamesD.length + j] = noteNamesD[j] + accidentals[i];
}
}
nnOffset = 17; // offset of the central D
paper = Raphael("keyboard", 800, 320);
//var lines = paper.set();
//var notenames = paper.set();
buttons = {};
for (var i=-9; i<=9; i++) {
for (var j=-9; j<=9; j++) {
var x = xo + i*genx[0] + j*genx[1];
var y = yo -(i*geny[0] + j*geny[1]);
if (y > yo-geny[1]*1.2 && y <= yo+geny[1]*1.2) {
var b = paper.set();
if ( (i > -4 && i < 4) || i < -8 || i>8 ) {
//if ( j & 1 ) { // if j is odd
b.push(
paper.path("M0 0L400 0"),
paper.circle(0, 0, button_size/2).attr({fill:'white'}),
paper.text(0, 0, noteNames[i+nnOffset])
);
} else {
b.push(
paper.path("M0 0L400 0"),
paper.circle(0, 0, button_size/2).attr({fill:'black'}),
paper.text(0, 0, noteNames[i+nnOffset]).attr({fill:'white'})
);
}
b.translate(x-b.getBBox().x,y-b.getBBox().y);
buttons[i+'_'+j]={button: b, loc: [i,j]};
}
}
}
$("#generatorSliderLabel").html(generator[0]);
$("#generatorSlider").slider({ min:685.71, max:720.0, step: 0.01, value:generator[0], orientation:'vertical' });
$("#generatorSlider").bind("slidechange", function(event, ui) {
$("#generatorSliderLabel").html(ui.value);
generator[0] = ui.value;
setGenerator(generator);
//geny = [ generator[0] * genyFact, generator[1] * genyFact ];
//changeGenerator();
});
$("#generatorSlider").bind("slide", function(event, ui) {
$("#generatorSliderLabel").html(ui.value);
generator[0] = ui.value;
setGenerator(generator);
//geny = [ generator[0] * genyFact, generator[1] * genyFact ];
//changeGenerator();
});
for (var t in tunings) {
$('#'+t).click(function(){$('#generatorSlider').slider('option','value',tunings[$(this).attr('id')])});
}
});
function cba_b() {
genyFact = 0.14;
geny = [ generator[0] * genyFact, generator[1] * genyFact ];
genx=[-50,-70];
changeGenerator();
keyBoard.setGenerator([200,100]);
synthesizer.setGenerator([200,100]);
}
function cba_c() {
genyFact = 0.14;
geny = [ generator[0] * genyFact, generator[1] * genyFact ];
genx=[50,70];
changeGenerator();
keyBoard.setGenerator([100,-100]);
synthesizer.setGenerator([100,-100]);
}
function wicki() {
genyFact = 0.07;
geny = [ generator[0] * genyFact, generator[1] * genyFact ];
genx = [ 20, 0 ];
changeGenerator();
keyBoard.setGenerator(generator);
synthesizer.setGenerator(generator);
}
function changeGenerator()
// update positions of buttons
{
for (var c in buttons)
{
var b = buttons[c];
var i = b.loc[0];
var j = b.loc[1];
var x = xo + i*genx[0] + j*genx[1];
var y = yo -(i*geny[0] + j*geny[1]);
//c.button.attr({x: x, y: y});
b=b.button;
b.translate(x-b.getBBox().x,y-b.getBBox().y);
}
}
function setGenxYfact(x,yf)
{
genyFact = yf;
geny = [ generator[0] * genyFact, generator[1] * genyFact ];
genx = x;
changeGenerator();
}
function setGenyXfact(y,xf)
{
genyFact = xf;
genx = [ generator[0] * genyFact, generator[1] * genyFact ];
geny = y;
changeGenerator();
}
function getSecondDist()
{
var x = 2*genx[0] + -1*genx[1];
var y = 2*geny[0] + -1*geny[1];
return Math.sqrt(x*x+y*y);
}
// b_fact slides from terpstra to wicki layout [0-1]
var b_fact = 1;
function setGenerator(g)
{
if (g[0] < 685.7143) g[0] = 685.7143;
generator = g;
synthesizer.setGenerator(generator);
keyBoard.setGenerator(generator);
var a = g[0]/g[1];
// maxb for wicki style:
var maxb = Math.sqrt((2/3)*a - a*a);
// minb for terpstra style:
var minb = Math.sqrt(-1*a*a + 26*a/21 - 8/21);
var b = b_fact * maxb + (1-b_fact) * minb;
//var py = button_spacing / Math.sqrt(b*b + a*a - 2*a + 1);
var py = button_spacing / Math.sqrt(4*b*b + 4*a*a - 4*a + 1);
genx = [b*py, 0];
geny = [a*py, py];
//geny = [b*py, 0];
//genx = [a*py, py];
//console.log(a,b,py);
//geny = [ generator[0] * genyFact, generator[1] * genyFact ];
changeGenerator();
}
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20429508-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="content">
<h1>Tuning exploration, Wicki keyboard and sawtooth synthesizer</h1>
<h2>In pure JavaScript using the Web Audio API</h2>
<p>This page presents a synthesizer written in JavaScript, which you can control with your qwerty keyboard using the <a href="http://en.wikipedia.org/wiki/Wicki-Hayden_note_layout">Wicki note layout</a>. You need at least Firefox 28 or a recent WebKit based browser.</p>
<blockquote><p><i>Update Nov. 2014: Ported to the newer Web Audio API.<br/>
Latency was an issue with the <a href="wickisynth.html">Karplus-Strong synthesizer</a>, so this version uses a simple sawtooth wave.<br/><br/>
Currently I'm working on a physical music instrument with the note layout from the figure below, with similar tuning exploration and much more, see <a href="http://www.striso.org/">www.striso.org</a>.</i></p></blockquote>
<p>This project is inspired by the <a href="http://web.archive.org/web/20130531043807/http://blog.igetitmusic.com/2010/02/exploretuning1.html">tuning exploration Flash app by Jim Plamondon</a>, whose site contains more explanation and interesting thoughts about music theory.
Take a look there also for a reference for the note layout.
Another interesting synthesizer with dynamic tuning and using the Wicki layout is <a href="http://dynamictonality.com/2032.htm">2032</a>, featuring dynamic tonality, but besides that also being a good free synthesizer that stimulates exploration.</p>
<p>If you have comments, questions or just like the idea please send a message to [email protected].
Also if you use parts of the code I'd appreciate it if you send me a note. The synthesizer is using the Karplus Strong algorithm, which is a simple physical simulation of a plucked string. The code is open source and is released under GPL.
You can find the source at <a href="https://github.com/pierstitus/tuning-exploration">https://github.com/pierstitus/tuning-exploration</a>.
</p>
<p>Created by Piers Titus van der Torren, 2010, updated to Web Audio API Nov 2014</p>
<p></p>
<div id='generatorSliderBox' style='position:relative; height: 320px'>
<div class="slider" id="generatorSlider" style='height: 280px;margin-top:5px'></div><span id="generatorSliderLabel"></span>
<div class='lbl' style='top: 0px' id='tet5'>5-tet (Indonesian slendro)</div>
<div class='lbl' style='top: 113px' id='tet17'>17-tet</div>
<div class='lbl' style='display:none; top: 128px' id='tet53'>53-tet (Turkish)</div>
<div class='lbl' style='top: 144px' id='pyth'>Pythagorean (pure fifth)</div>
<div class='lbl' style='top: 160px' id='tet12'>12-tet (Western)</div>
<div class='lbl' style='top: 185px' id='tet31'>31-tet</div>
<div class='lbl' style='top: 194px;left: 30px' id='quart'>1/4 comma meantone (pure major third)</div>
<div class='lbl' style='top: 208px' id='tet19'>19-tet</div>
<div class='lbl' style='top: 278px' id='tet7'>7-tet (Thai, Mandinka balafon)</div>
<div id="keyboard"></div>
<div id="data"></div>
</div>
<p>Drag the slider to change the tuning within the <a href="http://en.wikipedia.org/wiki/Syntonic_temperament">syntonic tuning continuum</a>, or click on the presets.
</p><p>
In the visual note layout the pitch is on the vertical axis, so it's easy to see the distribution of the notes within an octave.
The circle of fifths is on the horizontal axis, so moving left or right changes the <a href="http://en.wikipedia.org/wiki/Key_(music)">key</a> in which is played.
The note layout is called DCompose, which has several origins. It refers to the mathematical term decompose, the layout is an orthogonal decomposition of the pitch and the circle of fifths. There is the D, the D is the central note in the circle of fifths, and as such the central note on the layout. And of course there is the musical meaning of compose.</p>
<p>This note layout is similar to Wicki layout, they can tranform in each other by shearing.
</p>
<p>
You can play on your keyboard using the Wicki button layout. You can press multiple keys and hold keys to sustain them. Further keys:<br/> + = octave up<br/> - = octave down<br/> space = toggle sustain pedal</p>
<p>
</div>
</div>
</body>
</html>