Skip to content

Commit 34e4050

Browse files
author
jad73994
committed
added gain, swapped gain to up/down axis and frequency to left/right axis
1 parent b3ea061 commit 34e4050

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

script.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var state = 0,
22
ws,
33
context,
4-
oscillator;
4+
oscillator,
5+
gainer;
56

67
// Support both the WebSocket and MozWebSocket objects
78
if ((typeof(WebSocket) == 'undefined') &&
@@ -24,15 +25,24 @@ function init() {
2425
var obj = JSON.parse(event.data);
2526
if(state > 0) {
2627
if(obj.pointables.length > 0) {
27-
var value = obj.pointables[0].tipPosition[1];
28+
var value = obj.pointables[0].tipPosition[0];
2829
var intensity = $('#intensity').val();
29-
var modified = (575 - value) * intensity;
30+
var modified = (350 - value) * intensity;
3031
if( modified <= 0 ) {
3132
modified = 5;
3233
}
3334
modified = modified.toFixed(2);
3435

36+
var gainval = (obj.pointables[0].tipPosition[1] - 25) / 600;
37+
if (gainval < 0){
38+
gainval = 0;
39+
}
40+
if (gainval > 1){
41+
gainval = 1;
42+
}
43+
3544
oscillator.frequency.value = modified;
45+
gainer.gain.value = gainval;
3646
$('#frequency').html(modified + ' Hz');
3747
}
3848
}
@@ -67,8 +77,10 @@ $(function() {
6777
state = 1;
6878
context = new webkitAudioContext(),
6979
oscillator = context.createOscillator()
70-
oscillator.connect(context.destination);
71-
oscillator.frequency.value = 900;
80+
gainer = context.createGain();
81+
gainer.connect(context.destination);
82+
oscillator.connect(gainer);
83+
oscillator.frequency.value = 901;
7284
oscillator.start(0);
7385

7486
$(this).addClass('active');

0 commit comments

Comments
 (0)