forked from MAVProxyUser/SilverPushUnmasked
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aud.js
210 lines (183 loc) · 5.08 KB
/
aud.js
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
// declare global variables
var SPP = cc('_SPP'),
SPS = cc('_SPS'),
SRID = cc('srid'),
e = encodeURIComponent,
url = window.location.href,
tld = window.location.origin,
ref = window.document.referrer,
sys = window.navigator.platform;
// initalize the functions
function init() {
if (SPP == "NP") {
initCookie("_SPP", "SPP", 365);
send('u');
} else if (SPS == "NP") {
initCookie("_SPS", "SPS");
send('u');
} else {
send('v');
}
}
window.onload = init;
// send request regarding the user type
function send(u) {
// var s = "http://54.243.149.109:8085/receiver?acc=" + _spp + "&f=" + _f + "&u=" + u + "&SPP=" + cc('_SPP') + "&SPS=" + cc('_SPS') + "&SRID=" + cc('srid') + "&url=" + e(url) + "&ref=" + e(ref) + "&sys=" + e(sys) + "&tld=" + e(tld);
var s = "http://pix.silverpush.co/receiver?acc=" + _spp + "&f=" + _f+ "&u=" + u + "&SPP=" + cc('_SPP') + "&SPS=" + cc('_SPS') + "&SRID=" + cc('srid') + "&url=" + e(url) + "&ref=" + e(ref) + "&sys=" + e(sys) + "&tld=" + e(tld);
var xhr = initReq(s);
if (!xhr) return;
xhr.onload = function() {
var text = xhr.responseText
};
xhr.onerror = function() {};
xhr.send()
}
// checks for cookie by the 'name'
function cc(name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(name + "=");
if (c_start != -1) {
c_start = c_start + name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end))
} else {
return "NP"
}
} else {
return "NP"
}
}
// initializes a cookie with 'name' and its 'value' and 'days' to expire
function initCookie(name, value, days) {
var time = new Date;
if (value) value = value + "." + Math.random() * time;
if (days) {
time.setTime(time.getTime() + days * 24 * 60 * 60 * 1E3);
var expires = "; expires=" + time.toGMTString()
} else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
// initaliezes a CORS request
function initReq(url) {
var xhr = new XMLHttpRequest;
if ("withCredentials" in xhr) xhr.open('POST', url, true);
else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest;
xhr.open(method, url)
} else xhr = null;
return xhr
}
// initializes a freq playback
var _F = [18051, 18151, 18251, 18351, 18451, 18551, 18651, 18751, 18851, 19051, 19151, 19251, 19351, 19451, 19551, 19651, 19751, 19851];
var _f = [19951];
for (i = 1; i <= 2; i++) {
var f = _F[Math.floor(Math.random() * _F.length)];
if (_f.indexOf(f) != -1) {
i--;
} else {
_f[i] = f;
}
}
// console.log(_f);
// globals
var aud, o;
// hello audio world
(function init(g) {
try {
aud = new(g.AudioContext || g.webkitAudioContext);
// o = aud.createOscillator();
} catch (e) {
alert('No web audio support in this browser');
}
}(window));
/*
// all good except a little tch
function play() {
console.log(freq)
o = aud.createOscillator();
o.frequency.value = freq;
o.connect(aud.destination);
o.noteOn(0);
}
*/
function play() {
// console.log(freq)
o = aud.createOscillator();
o.frequency.value = freq;
o.connect(aud.destination);
var gainNode = aud.createGain();
o.connect(gainNode)
gainNode.connect(aud.destination)
gainNode.gain.value = 0.0001;
// gainNode.gain.linearRampToValueAtTime(0.00001, aud.currentTime + 0.000000000011);
// console.log(aud.currentTime)
o.noteOn(0);
}
function stop() {
o.noteOff(0);
o.stop();
}
var i = 0;
function myLoop() {
setTimeout(function() {
kplay();
k = 0
i++;
if (i < 3) {
myLoop();
}
}, 500)
}
var k = 0;
function kplay() {
setTimeout(function() {
freq = _f[k];
play();
kstop();
k++;
if (k < 3) {
kplay();
}
}, 100)
}
var t = 0
function kstop() {
setTimeout(function() {
stop();
t++;
if (t < 3) {
kstop();
}
}, 100)
}
myLoop();
/*
// play singular freq
function freq() {
if (t >= 0) {
var o = aud.createOscillator();
var g = aud.createGain();
o.connect(g);
g.connect(aud.destination);
g.gain.value = 0;
o.type = 'sawtooth';
setInterval(ch, 140);
var i = 0;
function ch() {
o.frequency.value = _f[i];
i += 1;
}
console.log(t)
t -= 1;
console.log(t)
o.frequency.value = _f;
fade();
o.start();
console.log('k')
function fade() {
g.gain.linearRampToValueAtTime(0.1, aud.currentTime + 0.01);
}
}
}
*/