Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinelliott/962ab6a7a5b8f43bfc0c979df4ffa609 to your computer and use it in GitHub Desktop.
Save kevinelliott/962ab6a7a5b8f43bfc0c979df4ffa609 to your computer and use it in GitHub Desktop.
Effort to Reverse Engineer WebSDR @ Twente

Trying to figure out how to capture the audio from the WebSDR @ Twente.

http://websdr.ewi.utwente.nl:8901

Mirror the websdr site

wget --mirror http://websdr.ewi.utwente.nl:8901

Current Efforts

The ruby script will successfully pull down the audio IQ, however the IQ cannot be played in Audacity. I believe this is because the audio is encoded or otherwise slightly mangled to deter us.

To figure this out, I am deobfuscating the websdr-sound.js that handles the data coming in from the WebSocket from the server to see what they are doing to be able to play it with HTML5's AudioContext.

I have also decompiled the Java Applet version of the sound player websdrsound.class that is optionally used if the user's browser cannot do HTML5 Audio.

require 'faye/websocket'
require 'eventmachine'
frequency = "1010"
band = "0"
EM.run {
output = nil
ws = Faye::WebSocket::Client.new('ws://websdr.ewi.utwente.nl:8901/~~stream?v=11', [], headers: {
'Connection' => 'Upgrade',
'Host' => 'websdr.ewi.utwente.nl:8901',
'Origin' => 'http://websdr.ewi.utwente.nl:8901',
'Cookie' => 'view=2; ID=5d83b2fd9c13',
'Pragma' => 'no-cache',
'Cache-Control' => 'no-cache',
'Sec-WebSocket-Key' => 'K+3pZ6WnO+JMDVF5CX4J+w==',
'Sec-WebSocket-Version' => '13',
'Sec-WebSocket-Extensions' => 'x-webkit-deflate-frame',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15'
})
ws.on :open do |event|
puts "WebSocket connected, sending params to set the tuner..."
pcm_output = File.open('pcm', 'wb')
ws.send("GET /~~param?f=#{frequency}&band=#{band}&lo=-4dd.5&hi=4.5&mode=1&name=")
end
ws.on :message do |event|
puts "Received #{event.data.size} bytes"
event.data.each do |byte|
pcm_output.print byte.chr
end
# p [:message, event.data]
end
ws.on :close do |event|
pcm_output.close
puts "Closed."
ws = nil
end
}
// Originally from http://websdr.ewi.utwente.nl:8901/websdr-sound.js
// Effort made to de-obfuscate
//WebSDR HTML5 client side - Copyright 2013-2020, [email protected] - all rights reserved
//Since the intended use of this code involves sending a copy to the client computer, I (PA3FWM) hereby allow making it available unmodified, via my original WebSDR server software, to original WebSDR clients. Other use, including distribution in part or entirety or as part of other software, or reverse engineering, is not allowed without my explicit prior permission.
(function () {
var h = null,
AudioContext = window.AudioContext || window.webkitAudioContext;
if (AudioContext) {
document.audioContext || (document.audioContext = new AudioContext());
var convolver;
try {
convolver = document.audioContext.createConvolver;
} catch (wa) {}
convolver || ((document.audioContext = h), (sup_webaudio = !1));
}
var F = 32768;
function za() {
function processEvent(audioProcessEvent) {
var channelData = audioProcessEvent.outputBuffer.getChannelData(0),
bufferIndex;
var timeDifference;
var bufferLength = audioProcessEvent.outputBuffer.length;
processStartTime = new Date().getTime();
if (ha || 2 <= P)
(ha = 0),
3 < P && (P = 0),
(channelData = p),
(timeDifference = processStartTime - wsMessageReceiveTime),
0 <= R && ((R = -1), (actualRemoteSampleRate *= remoteSampleRate / v), (v = remoteSampleRate)),
(p = qa + (timeDifference / 1e3) * remoteSampleRate - H * remoteSampleRate - (bufferLength * v) / audioSampleRate),
(p = Math.round(p)),
(p = (2 * F + p) % F);
200 < processStartTime - lastProcessTime && 0 < lastProcessTime && (ha = 1);
lastProcessTime = processStartTime;
for (bufferIndex = 0; bufferIndex < bufferLength; bufferIndex++) {
var d = 0,
f = (x * v) / audioSampleRate;
q += f;
1 <= q
? ((q -= 1),
(y[p] = 0),
p++,
p >= F && (p -= F),
p == R && ((R = -1), (actualRemoteSampleRate *= remoteSampleRate / v), (v = remoteSampleRate)),
p == g && (P = 1),
(d = q / f),
(d *= y[p]),
(d /= f))
: q < 2 * f && ((d = (2 * f - q) / f), (d *= y[p]), (d /= f));
muted && (d = 0);
channelData[bufferIndex] = 2e-5 * d * volume;
}
M += (1e3 * bufferLength) / actualAudioSampleRate;
processStartTime < M && (M = processStartTime);
V += bufferLength;
V >= audioSampleRate &&
((channelData = 1e3 * (V / (M - sa))),
channelData < 1.01 * audioSampleRate && channelData > 0.99 * audioSampleRate && (actualAudioSampleRate += (channelData - actualAudioSampleRate) / W),
(sa = M),
(V = 0),
(M = processStartTime));
}
document.getElementById("soundappletdiv").innerHTML =
'<div onclick="var e=document.getElementById(\'soundappletdebug\'); e.style.display=(e.style.display==\'none\')?\'block\':\'none\';" style="max-width:400px; min-height:50px; border-style:solid; border-color:black; background-color:white; color:black; border-width:1px; margin:2px; padding:2px; font-family:sans-serif; font-size:x-small;">WebSDR HTML5 sound - Copyright 2007-2020, P.T. de Boer, [email protected]<br><span id="soundappletdebug" style="display:none"></span></div><span id="debug2"></span>';
var y = new Int16Array(F),
g = 0,
p = 6144,
q = 0,
remoteSampleRate = 8e3,
v = 8e3,
R = -1,
actualRemoteSampleRate = 8e3,
audioSampleRate = 48e3,
actualAudioSampleRate = 48e3,
x = 1,
volume = 1,
ja = -1,
S,
A = 0,
B = [],
ka,
X,
Y = 0,
soundApplet = this,
webSocket = h,
ya = [
-5504,
-5248,
-6016,
-5760,
-4480,
-4224,
-4992,
-4736,
-7552,
-7296,
-8064,
-7808,
-6528,
-6272,
-7040,
-6784,
-2752,
-2624,
-3008,
-2880,
-2240,
-2112,
-2496,
-2368,
-3776,
-3648,
-4032,
-3904,
-3264,
-3136,
-3520,
-3392,
-22016,
-20992,
-24064,
-23040,
-17920,
-16896,
-19968,
-18944,
-30208,
-29184,
-32256,
-31232,
-26112,
-25088,
-28160,
-27136,
-11008,
-10496,
-12032,
-11520,
-8960,
-8448,
-9984,
-9472,
-15104,
-14592,
-16128,
-15616,
-13056,
-12544,
-14080,
-13568,
-344,
-328,
-376,
-360,
-280,
-264,
-312,
-296,
-472,
-456,
-504,
-488,
-408,
-392,
-440,
-424,
-88,
-72,
-120,
-104,
-24,
-8,
-56,
-40,
-216,
-200,
-248,
-232,
-152,
-136,
-184,
-168,
-1376,
-1312,
-1504,
-1440,
-1120,
-1056,
-1248,
-1184,
-1888,
-1824,
-2016,
-1952,
-1632,
-1568,
-1760,
-1696,
-688,
-656,
-752,
-720,
-560,
-528,
-624,
-592,
-944,
-912,
-1008,
-976,
-816,
-784,
-880,
-848,
5504,
5248,
6016,
5760,
4480,
4224,
4992,
4736,
7552,
7296,
8064,
7808,
6528,
6272,
7040,
6784,
2752,
2624,
3008,
2880,
2240,
2112,
2496,
2368,
3776,
3648,
4032,
3904,
3264,
3136,
3520,
3392,
22016,
20992,
24064,
23040,
17920,
16896,
19968,
18944,
30208,
29184,
32256,
31232,
26112,
25088,
28160,
27136,
11008,
10496,
12032,
11520,
8960,
8448,
9984,
9472,
15104,
14592,
16128,
15616,
13056,
12544,
14080,
13568,
344,
328,
376,
360,
280,
264,
312,
296,
472,
456,
504,
488,
408,
392,
440,
424,
88,
72,
120,
104,
24,
8,
56,
40,
216,
200,
248,
232,
152,
136,
184,
168,
1376,
1312,
1504,
1440,
1120,
1056,
1248,
1184,
1888,
1824,
2016,
1952,
1632,
1568,
1760,
1696,
688,
656,
752,
720,
560,
528,
624,
592,
944,
912,
1008,
976,
816,
784,
880,
848,
],
playbackBuffer = [
4.846206e-4,
3.218322e-4,
3.870879e-4,
4.263937e-4,
4.294803e-4,
3.876866e-4,
2.978334e-4,
1.628906e-4,
-6.746e-6,
-1.976636e-4,
-3.887846e-4,
-5.583476e-4,
-6.843798e-4,
-7.475333e-4,
-7.360876e-4,
-6.458231e-4,
-4.834126e-4,
-2.654101e-4,
-1.72358e-5,
2.297496e-4,
4.414505e-4,
5.867386e-4,
6.40364e-4,
5.889058e-4,
4.320051e-4,
1.84623e-4,
-1.245772e-4,
-4.557272e-4,
-7.630407e-4,
-0.0010001924,
-0.0011278035,
-0.0011186013,
-9.630688e-4,
-6.715766e-4,
-2.747173e-4,
1.796051e-4,
6.316952e-4,
0.0010178421,
0.0012788905,
0.0013693135,
0.0012644532,
9.656565e-4,
5.020083e-4,
-7.20758e-5,
-6.82586e-4,
-0.0012452921,
-0.001676923,
-0.0019071107,
-0.0018892901,
-0.0016090151,
-0.0010880322,
-3.838639e-4,
4.162385e-4,
0.0012055137,
0.0018717189,
0.0023126901,
0.0024515221,
0.0022491337,
0.001712324,
8.956676e-4,
-1.030426e-4,
-0.0011539845,
-0.0021116455,
-0.0028343942,
-0.0032049046,
-0.0031482203,
-0.0026451434,
-0.0017384393,
-5.307213e-4,
8.263157e-4,
0.0021501888,
0.0032516099,
0.0039606691,
0.0041522226,
0.0037662639,
0.0028206105,
0.0014132717,
-2.862273e-4,
-0.0020562471,
-0.0036508477,
-0.0048329708,
-0.0054082689,
-0.0052553028,
-0.0043473176,
-0.0027622291,
-6.785974e-4,
0.0016427351,
0.0038897014,
0.0057392293,
0.0069017337,
0.0071638948,
0.0064237642,
0.0047128748,
0.0022013269,
-8.158008e-4,
-0.0039503266,
-0.0067678548,
-0.0088444407,
-0.0098259631,
-0.0094824393,
-0.0077495259,
-0.004750882,
-7.96851e-4,
0.003641892,
0.0079842451,
0.0116072743,
0.0139260255,
0.0144751543,
0.0129821211,
0.0094221367,
0.0040467651,
-0.002619195,
-0.0098143027,
-0.0166082859,
-0.0219950434,
-0.0250012628,
-0.0247990241,
-0.0208094743,
-0.0127853572,
-8.61941e-4,
0.0144307224,
0.0321972603,
0.0512463819,
0.0701941201,
0.08759059,
0.1020573346,
0.1124206916,
0.1178269679,
0.1178269679,
0.1124206916,
0.1020573346,
0.08759059,
0.0701941201,
0.0512463819,
0.0321972603,
0.0144307224,
-8.61941e-4,
-0.0127853572,
-0.0208094743,
-0.0247990241,
-0.0250012628,
-0.0219950434,
-0.0166082859,
-0.0098143027,
-0.002619195,
0.0040467651,
0.0094221367,
0.0129821211,
0.0144751543,
0.0139260255,
0.0116072743,
0.0079842451,
0.003641892,
-7.96851e-4,
-0.004750882,
-0.0077495259,
-0.0094824393,
-0.0098259631,
-0.0088444407,
-0.0067678548,
-0.0039503266,
-8.158008e-4,
0.0022013269,
0.0047128748,
0.0064237642,
0.0071638948,
0.0069017337,
0.0057392293,
0.0038897014,
0.0016427351,
-6.785974e-4,
-0.0027622291,
-0.0043473176,
-0.0052553028,
-0.0054082689,
-0.0048329708,
-0.0036508477,
-0.0020562471,
-2.862273e-4,
0.0014132717,
0.0028206105,
0.0037662639,
0.0041522226,
0.0039606691,
0.0032516099,
0.0021501888,
8.263157e-4,
-5.307213e-4,
-0.0017384393,
-0.0026451434,
-0.0031482203,
-0.0032049046,
-0.0028343942,
-0.0021116455,
-0.0011539845,
-1.030426e-4,
8.956676e-4,
0.001712324,
0.0022491337,
0.0024515221,
0.0023126901,
0.0018717189,
0.0012055137,
4.162385e-4,
-3.838639e-4,
-0.0010880322,
-0.0016090151,
-0.0018892901,
-0.0019071107,
-0.001676923,
-0.0012452921,
-6.82586e-4,
-7.20758e-5,
5.020083e-4,
9.656565e-4,
0.0012644532,
0.0013693135,
0.0012788905,
0.0010178421,
6.316952e-4,
1.796051e-4,
-2.747173e-4,
-6.715766e-4,
-9.630688e-4,
-0.0011186013,
-0.0011278035,
-0.0010001924,
-7.630407e-4,
-4.557272e-4,
-1.245772e-4,
1.84623e-4,
4.320051e-4,
5.889058e-4,
6.40364e-4,
5.867386e-4,
4.414505e-4,
2.297496e-4,
-1.72358e-5,
-2.654101e-4,
-4.834126e-4,
-6.458231e-4,
-7.360876e-4,
-7.475333e-4,
-6.843798e-4,
-5.583476e-4,
-3.887846e-4,
-1.976636e-4,
-6.746e-6,
1.628906e-4,
2.978334e-4,
3.876866e-4,
4.294803e-4,
4.263937e-4,
3.870879e-4,
3.218322e-4,
4.846206e-4,
],
T = [
-1.47942e-4,
-4.63086e-4,
-5.43866e-4,
-8.37905e-4,
-0.001014311,
-0.00116118,
-0.001180796,
-0.001076634,
-8.36391e-4,
-4.92451e-4,
-9.4469e-5,
2.87595e-4,
5.82401e-4,
7.30717e-4,
7.01055e-4,
4.9903e-4,
1.69525e-4,
-2.11135e-4,
-5.51117e-4,
-7.64022e-4,
-7.90178e-4,
-6.13389e-4,
-2.67748e-4,
1.67964e-4,
5.87153e-4,
8.80407e-4,
9.63624e-4,
8.01554e-4,
4.19872e-4,
-9.7144e-5,
-6.23995e-4,
-0.001024122,
-0.001184736,
-0.001047445,
-6.27522e-4,
-1.5309e-5,
6.42685e-4,
0.001177774,
0.001441643,
0.001347024,
8.94359e-4,
1.77665e-4,
-6.33187e-4,
-0.001332504,
-0.001730079,
-0.001701687,
-0.001226744,
-4.00227e-4,
5.84703e-4,
0.001480338,
0.002046494,
0.002113569,
0.001631749,
6.92239e-4,
-4.88223e-4,
-0.001615646,
-0.002391073,
-0.002589193,
-0.002121436,
-0.001068587,
3.30072e-4,
0.001729551,
0.002762744,
0.003135904,
0.002709835,
0.001546543,
-9.4626e-5,
-0.001812887,
-0.003161817,
-0.00376451,
-0.003416048,
-0.002148579,
-2.37525e-4,
0.001855519,
0.003592039,
0.004493442,
0.004269849,
0.002908814,
6.95458e-4,
-0.001842797,
-0.004059329,
-0.005350342,
-0.005315623,
-0.003877314,
-0.001320828,
0.001755334,
0.004576368,
0.006381587,
0.006625592,
0.005135045,
0.002180561,
-0.001563598,
-0.005167068,
-0.00766869,
-0.008325453,
-0.006823363,
-0.003391342,
0.001216581,
0.005877394,
0.00936274,
0.010650623,
0.009208796,
0.005175064,
-6.20228e-4,
-0.006807588,
-0.011783774,
-0.014104442,
-0.012872482,
-0.008024648,
-4.34977e-4,
0.008206407,
0.015731357,
0.019986001,
0.019373693,
0.013324602,
0.002574305,
-0.010829893,
-0.023820926,
-0.032862179,
-0.034655123,
-0.026862623,
-0.008693659,
0.018783377,
0.052680302,
0.088692158,
0.121798708,
0.147134469,
0.160859545,
0.160859545,
0.147134469,
0.121798708,
0.088692158,
0.052680302,
0.018783377,
-0.008693659,
-0.026862623,
-0.034655123,
-0.032862179,
-0.023820926,
-0.010829893,
0.002574305,
0.013324602,
0.019373693,
0.019986001,
0.015731357,
0.008206407,
-4.34977e-4,
-0.008024648,
-0.012872482,
-0.014104442,
-0.011783774,
-0.006807588,
-6.20228e-4,
0.005175064,
0.009208796,
0.010650623,
0.00936274,
0.005877394,
0.001216581,
-0.003391342,
-0.006823363,
-0.008325453,
-0.00766869,
-0.005167068,
-0.001563598,
0.002180561,
0.005135045,
0.006625592,
0.006381587,
0.004576368,
0.001755334,
-0.001320828,
-0.003877314,
-0.005315623,
-0.005350342,
-0.004059329,
-0.001842797,
6.95458e-4,
0.002908814,
0.004269849,
0.004493442,
0.003592039,
0.001855519,
-2.37525e-4,
-0.002148579,
-0.003416048,
-0.00376451,
-0.003161817,
-0.001812887,
-9.4626e-5,
0.001546543,
0.002709835,
0.003135904,
0.002762744,
0.001729551,
3.30072e-4,
-0.001068587,
-0.002121436,
-0.002589193,
-0.002391073,
-0.001615646,
-4.88223e-4,
6.92239e-4,
0.001631749,
0.002113569,
0.002046494,
0.001480338,
5.84703e-4,
-4.00227e-4,
-0.001226744,
-0.001701687,
-0.001730079,
-0.001332504,
-6.33187e-4,
1.77665e-4,
8.94359e-4,
0.001347024,
0.001441643,
0.001177774,
6.42685e-4,
-1.5309e-5,
-6.27522e-4,
-0.001047445,
-0.001184736,
-0.001024122,
-6.23995e-4,
-9.7144e-5,
4.19872e-4,
8.01554e-4,
9.63624e-4,
8.80407e-4,
5.87153e-4,
1.67964e-4,
-2.67748e-4,
-6.13389e-4,
-7.90178e-4,
-7.64022e-4,
-5.51117e-4,
-2.11135e-4,
1.69525e-4,
4.9903e-4,
7.01055e-4,
7.30717e-4,
5.82401e-4,
2.87595e-4,
-9.4469e-5,
-4.92451e-4,
-8.36391e-4,
-0.001076634,
-0.001180796,
-0.00116118,
-0.001014311,
-8.37905e-4,
-5.43866e-4,
-4.63086e-4,
-1.47942e-4,
],
da = [
-1.559505e-4,
-7.98112e-5,
-9.80814e-5,
-1.173125e-4,
-1.369746e-4,
-1.565189e-4,
-1.753732e-4,
-1.929362e-4,
-2.083552e-4,
-2.206804e-4,
-2.291911e-4,
-2.333843e-4,
-2.318305e-4,
-2.244133e-4,
-2.102e-4,
-1.887765e-4,
-1.597355e-4,
-1.22856e-4,
-7.82038e-5,
-2.59739e-5,
3.34012e-5,
9.91605e-5,
1.702513e-4,
2.45599e-4,
3.235647e-4,
4.025475e-4,
4.805722e-4,
5.555847e-4,
6.253709e-4,
6.875873e-4,
7.399121e-4,
7.800625e-4,
8.058147e-4,
8.15116e-4,
8.062358e-4,
7.776257e-4,
7.282308e-4,
6.573325e-4,
5.647707e-4,
4.50904e-4,
3.166371e-4,
1.635138e-4,
-6.3141e-6,
-1.901069e-4,
-3.845389e-4,
-5.857031e-4,
-7.892655e-4,
-9.904092e-4,
-0.001184062,
-0.0013648737,
-0.0015274109,
-0.0016662822,
-0.0017762342,
-0.0018523274,
-0.0018900859,
-0.0018856324,
-0.0018358173,
-0.0017383931,
-0.0015920662,
-0.0013966904,
-0.0011532549,
-8.640083e-4,
-5.324827e-4,
-1.6347e-4,
2.369773e-4,
6.616157e-4,
0.0011021011,
0.0015491213,
0.0019925324,
0.0024215833,
0.0028250632,
0.0031916142,
0.0035099281,
0.0037690342,
0.0039585921,
0.0040691533,
0.0040924552,
0.0040216824,
0.0038517234,
0.0035793947,
0.003203659,
0.0027257456,
0.0021493323,
0.0014805737,
7.281494e-4,
-9.67559e-5,
-9.805496e-4,
-0.0019073471,
-0.002859177,
-0.0038162186,
-0.0047570964,
-0.0056592108,
-0.0064991489,
-0.0072530544,
-0.0078971131,
-0.0084079899,
-0.0087633047,
-0.0089421178,
-0.008925372,
-0.0086963572,
-0.0082411169,
-0.0075488253,
-0.0066121147,
-0.0054273698,
-0.0039949083,
-0.0023191615,
-4.087211e-4,
0.0017236549,
0.0040611162,
0.0065829025,
0.0092645575,
0.0120782551,
0.0149931771,
0.0179759604,
0.0209911855,
0.0240019478,
0.0269704134,
0.0298584578,
0.0326282789,
0.035243024,
0.0376674322,
0.0398684103,
0.0418156203,
0.0434819958,
0.0448442166,
0.0458831097,
0.046584001,
0.0469369495,
0.0469369495,
0.046584001,
0.0458831097,
0.0448442166,
0.0434819958,
0.0418156203,
0.0398684103,
0.0376674322,
0.035243024,
0.0326282789,
0.0298584578,
0.0269704134,
0.0240019478,
0.0209911855,
0.0179759604,
0.0149931771,
0.0120782551,
0.0092645575,
0.0065829025,
0.0040611162,
0.0017236549,
-4.087211e-4,
-0.0023191615,
-0.0039949083,
-0.0054273698,
-0.0066121147,
-0.0075488253,
-0.0082411169,
-0.0086963572,
-0.008925372,
-0.0089421178,
-0.0087633047,
-0.0084079899,
-0.0078971131,
-0.0072530544,
-0.0064991489,
-0.0056592108,
-0.0047570964,
-0.0038162186,
-0.002859177,
-0.0019073471,
-9.805496e-4,
-9.67559e-5,
7.281494e-4,
0.0014805737,
0.0021493323,
0.0027257456,
0.003203659,
0.0035793947,
0.0038517234,
0.0040216824,
0.0040924552,
0.0040691533,
0.0039585921,
0.0037690342,
0.0035099281,
0.0031916142,
0.0028250632,
0.0024215833,
0.0019925324,
0.0015491213,
0.0011021011,
6.616157e-4,
2.369773e-4,
-1.6347e-4,
-5.324827e-4,
-8.640083e-4,
-0.0011532549,
-0.0013966904,
-0.0015920662,
-0.0017383931,
-0.0018358173,
-0.0018856324,
-0.0018900859,
-0.0018523274,
-0.0017762342,
-0.0016662822,
-0.0015274109,
-0.0013648737,
-0.001184062,
-9.904092e-4,
-7.892655e-4,
-5.857031e-4,
-3.845389e-4,
-1.901069e-4,
-6.3141e-6,
1.635138e-4,
3.166371e-4,
4.50904e-4,
5.647707e-4,
6.573325e-4,
7.282308e-4,
7.776257e-4,
8.062358e-4,
8.15116e-4,
8.058147e-4,
7.800625e-4,
7.399121e-4,
6.875873e-4,
6.253709e-4,
5.555847e-4,
4.805722e-4,
4.025475e-4,
3.235647e-4,
2.45599e-4,
1.702513e-4,
9.91605e-5,
3.34012e-5,
-2.59739e-5,
-7.82038e-5,
-1.22856e-4,
-1.597355e-4,
-1.887765e-4,
-2.102e-4,
-2.244133e-4,
-2.318305e-4,
-2.333843e-4,
-2.291911e-4,
-2.206804e-4,
-2.083552e-4,
-1.929362e-4,
-1.753732e-4,
-1.565189e-4,
-1.369746e-4,
-1.173125e-4,
-9.80814e-5,
-7.98112e-5,
-1.559505e-4,
],
Z = [
7.0433e-5,
-1.0611e-5,
-8.6755e-5,
-1.81287e-4,
-2.40082e-4,
-2.16126e-4,
-1.04338e-4,
4.4967e-5,
1.48777e-4,
1.41957e-4,
2.4902e-5,
-1.26821e-4,
-2.06025e-4,
-1.44934e-4,
3.0288e-5,
2.06761e-4,
2.55662e-4,
1.2428e-4,
-1.1508e-4,
-3.01598e-4,
-2.92187e-4,
-6.8791e-5,
2.32511e-4,
4.01522e-4,
2.98948e-4,
-3.3133e-5,
-3.8003e-4,
-4.90923e-4,
-2.57989e-4,
1.88334e-4,
5.47393e-4,
5.48608e-4,
1.52152e-4,
-3.96707e-4,
-7.15685e-4,
-5.49251e-4,
3.1938e-5,
6.48678e-4,
8.57479e-4,
4.66461e-4,
-3.00057e-4,
-9.23468e-4,
-9.38715e-4,
-2.77012e-4,
6.4652e-4,
0.001188228,
9.213e-4,
-3.4936e-5,
-0.001051564,
-0.001399457,
-7.68199e-4,
4.72146e-4,
0.001478988,
0.00150551,
4.48904e-4,
-0.001020195,
-0.001876749,
-0.001451986,
5.3805e-5,
0.001643867,
0.002179009,
0.001188116,
-7.3768e-4,
-0.002285796,
-0.002311045,
-6.74762e-4,
0.001575511,
0.002867565,
0.002196431,
-1.07222e-4,
-0.002511465,
-0.003293514,
-0.001765763,
0.001149421,
0.003460246,
0.003457538,
9.66687e-4,
-0.002409513,
-0.004308854,
-0.003251791,
2.2654e-4,
0.003807624,
0.004921598,
0.002577091,
-0.001804315,
-0.005225193,
-0.005147223,
-0.001353262,
0.003715307,
0.006506739,
0.004827221,
-4.72053e-4,
-0.005863008,
-0.007463412,
-0.003802999,
0.002917889,
0.008104906,
0.007875542,
0.001918029,
-0.005970371,
-0.010253403,
-0.007489417,
9.91323e-4,
0.009592392,
0.012074666,
0.005996842,
-0.005130313,
-0.013749242,
-0.013274935,
-0.002967159,
0.010844556,
0.018471983,
0.013448699,
-0.002354894,
-0.018901844,
-0.024024383,
-0.011880584,
0.011749681,
0.03149634,
0.031517411,
0.006673294,
-0.031328123,
-0.057596682,
-0.046701295,
0.012224635,
0.106626251,
0.203735462,
0.265089227,
0.265089227,
0.203735462,
0.106626251,
0.012224635,
-0.046701295,
-0.057596682,
-0.031328123,
0.006673294,
0.031517411,
0.03149634,
0.011749681,
-0.011880584,
-0.024024383,
-0.018901844,
-0.002354894,
0.013448699,
0.018471983,
0.010844556,
-0.002967159,
-0.013274935,
-0.013749242,
-0.005130313,
0.005996842,
0.012074666,
0.009592392,
9.91323e-4,
-0.007489417,
-0.010253403,
-0.005970371,
0.001918029,
0.007875542,
0.008104906,
0.002917889,
-0.003802999,
-0.007463412,
-0.005863008,
-4.72053e-4,
0.004827221,
0.006506739,
0.003715307,
-0.001353262,
-0.005147223,
-0.005225193,
-0.001804315,
0.002577091,
0.004921598,
0.003807624,
2.2654e-4,
-0.003251791,
-0.004308854,
-0.002409513,
9.66687e-4,
0.003457538,
0.003460246,
0.001149421,
-0.001765763,
-0.003293514,
-0.002511465,
-1.07222e-4,
0.002196431,
0.002867565,
0.001575511,
-6.74762e-4,
-0.002311045,
-0.002285796,
-7.3768e-4,
0.001188116,
0.002179009,
0.001643867,
5.3805e-5,
-0.001451986,
-0.001876749,
-0.001020195,
4.48904e-4,
0.00150551,
0.001478988,
4.72146e-4,
-7.68199e-4,
-0.001399457,
-0.001051564,
-3.4936e-5,
9.213e-4,
0.001188228,
6.4652e-4,
-2.77012e-4,
-9.38715e-4,
-9.23468e-4,
-3.00057e-4,
4.66461e-4,
8.57479e-4,
6.48678e-4,
3.1938e-5,
-5.49251e-4,
-7.15685e-4,
-3.96707e-4,
1.52152e-4,
5.48608e-4,
5.47393e-4,
1.88334e-4,
-2.57989e-4,
-4.90923e-4,
-3.8003e-4,
-3.3133e-5,
2.98948e-4,
4.01522e-4,
2.32511e-4,
-6.8791e-5,
-2.92187e-4,
-3.01598e-4,
-1.1508e-4,
1.2428e-4,
2.55662e-4,
2.06761e-4,
3.0288e-5,
-1.44934e-4,
-2.06025e-4,
-1.26821e-4,
2.4902e-5,
1.41957e-4,
1.48777e-4,
4.4967e-5,
-1.04338e-4,
-2.16126e-4,
-2.40082e-4,
-1.81287e-4,
-8.6755e-5,
-1.0611e-5,
7.0433e-5,
],
J = [
0.0065862,
-0.0022838,
-0.0059202,
-0.0112239,
-0.0169697,
-0.0214685,
-0.022742,
-0.0189184,
-0.0086407,
0.0084932,
0.0316914,
0.0588926,
0.0870663,
0.1126093,
0.1320398,
0.1425063,
0.1425063,
0.1320398,
0.1126093,
0.0870663,
0.0588926,
0.0316914,
0.0084932,
-0.0086407,
-0.0189184,
-0.022742,
-0.0214685,
-0.0169697,
-0.0112239,
-0.0059202,
-0.0022838,
0.0065862,
],
la = [
-0.0086492,
-0.0044524,
-0.0043664,
-0.0030946,
-3.094e-4,
0.0042348,
0.010627,
0.018809,
0.028525,
0.039333,
0.050605,
0.061655,
0.071697,
0.079997,
0.085925,
0.089013,
0.089013,
0.085925,
0.079997,
0.071697,
0.061655,
0.050605,
0.039333,
0.028525,
0.018809,
0.010627,
0.0042348,
-3.094e-4,
-0.0030946,
-0.0043664,
-0.0044524,
-0.0086492,
],
ea = [
0.0080236,
0.001488,
-0.0074204,
-0.0175495,
-0.0195816,
-0.0075536,
0.0136434,
0.0283156,
0.020311,
-0.0121801,
-0.0489419,
-0.0561146,
-0.0078976,
0.0922184,
0.2069483,
0.2833355,
0.2833355,
0.2069483,
0.0922184,
-0.0078976,
-0.0561146,
-0.0489419,
-0.0121801,
0.020311,
0.0283156,
0.0136434,
-0.0075536,
-0.0195816,
-0.0175495,
-0.0074204,
0.001488,
0.0080236,
],
ta = 1e3,
N = 0.125,
muted = !1,
processStartTime = 0,
M = 0,
V = 0,
sa = 0,
P = 1,
lastProcessTime = 0,
ha = 0,
currentAudioContext,
scriptProcessor,
currentConvolver,
$,
K = [],
ma = 1;
if ((currentAudioContext = document.audioContext)) {
currentAudioContext.sampleRate = audioSampleRate;
var actualAudioSampleRate = (audioSampleRate = currentAudioContext.sampleRate),
na;
na = 4096;
try {
scriptProcessor = currentAudioContext.createScriptProcessor(na, 0, 1);
} catch (Aa) {
scriptProcessor = currentAudioContext.createJavaScriptNode(na, 1, 1);
}
scriptProcessor.onaudioprocess = processEvent;
this.currentScriptProcessor = scriptProcessor;
currentConvolver = currentAudioContext.createConvolver();
scriptProcessor.connect(currentConvolver);
currentConvolver.connect(currentAudioContext.destination);
var channelDataChunk;
if (window.sup_android)
(playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate)),
(channelDataChunk = playbackBuffer.getChannelData(0)),
channelDataChunk.set(J),
(K[0] = playbackBuffer),
(playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate)),
(channelDataChunk = playbackBuffer.getChannelData(0)),
channelDataChunk.set(J),
(K[1] = playbackBuffer),
(playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate)),
(channelDataChunk = playbackBuffer.getChannelData(0)),
channelDataChunk.set(la),
(K[2] = playbackBuffer),
(playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate)),
(channelDataChunk = playbackBuffer.getChannelData(0)),
channelDataChunk.set(ea),
(K[3] = playbackBuffer);
else {
J = Math.round(audioSampleRate / 48e3);
1 > J && (J = 1);
la = 512 * J;
da = [T, playbackBuffer, da, Z];
for (T = 0; T < da.length; T++) {
for (var ea = da[T], D = [], playbackBuffer = 0; playbackBuffer < ea.length; playbackBuffer++)
for (Z = 0; Z < J; Z++) D[playbackBuffer * J + Z] = ea[playbackBuffer];
playbackBuffer = currentAudioContext.createBuffer(1, la, audioSampleRate);
channelDataChunk = playbackBuffer.getChannelData(0);
channelDataChunk.set(D);
K[T] = playbackBuffer;
}
}
currentConvolver.normalize = !1;
currentConvolver.buffer = K[0];
} else window.browsersupporterror && window.browsersupporterror();
var fa,
ua,
z,
oa,
D = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
E = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
aa = 0,
webSocket = new WebSocket("ws://" + window.location.host + "/~~stream");
webSocket.binaryType = "arraybuffer";
var H = 0.0625,
L = 0,
va = 0,
ba = 0,
O = 1,
W = 2,
wsMessageReceiveTime,
qa = 0;
webSocket.onmessage = function (c) {
P && P++;
wsMessageReceiveTime = new Date().getTime();
qa = g;
var a = (2 * F + g - p - ((wsMessageReceiveTime - processStartTime) * v) / 1e3) % F,
b = a;
a > F / 2 && (a = 0);
b > F / 2 && (b -= F);
b /= v;
H += 0.01 * (a / v - H);
1e9 > L && (H = N);
var d = H - N;
if (!(0 <= R))
if (O && 0.05 > Math.abs(d) / N) (O = 0), (x = actualRemoteSampleRate / actualAudioSampleRate / (v / audioSampleRate));
else {
if (d < 0.25 * -N || d > 0.5 * N) O = 1;
0.01 < Math.abs(d) && 20 > W && (O = 1);
a = O ? 1 + 0.1 * d : 1 + 0.01 * d;
a *= actualRemoteSampleRate / actualAudioSampleRate / (v / audioSampleRate);
x = O ? a : x + 0.003 * (a - x);
}
1.005 < x && (x = 1.005);
0.995 > x && (x = 0.995);
var soundAppletDebugHtml =
Math.round(1e3 * b) +
" " +
Math.round(1e3 * N) +
" " +
Math.round(1e3 * H) +
" " +
Math.round(1e6 * (x - 1)) +
" " +
O +
"<br>";
soundAppletDebugHtml += Math.round(audioSampleRate) + " " + Math.round(remoteSampleRate) + " " + fa;
soundAppletDebugHtml += currentAudioContext ? " WebAudio " : " none ";
soundAppletDebugHtml += actualAudioSampleRate.toFixed(2) + " " + actualRemoteSampleRate.toFixed(2);
document.getElementById("soundappletdebug").innerHTML = soundAppletDebugHtml;
b = new Uint8Array(c.data);
c = g;
lastlen = b.length;
for (a = 0; a < b.length; a++) {
var f = 0,
l = 0;
if (240 == (b[a] & 240))
(smeter = 256 * (b[a] & 15) + b[a + 1]),
soundApplet.smetercallback && soundApplet.smetercallback(10 * smeter),
a++;
else if (128 == b[a]) {
var e;
for (e = Y = 0; 128 > e; e++) y[g + e] = ya[b[a + 1 + e]];
g += 128;
g >= F && (g -= F);
var a = a + 128,
j;
for (j = 0; 20 > j; j++) D[j] = E[j] = 0;
aa = 0;
} else if (144 <= b[a] && 223 >= b[a])
(l = 4), (f = 2), (z = 14 - (b[a] >> 4));
else if (128 != (b[a] & 128)) (l = 1), (f = 2);
else if (129 == b[a])
(j = 256 * b[a + 1] + b[a + 2]),
j != remoteSampleRate && ((remoteSampleRate = j), (R = g)),
webSocket && webSocket.postMessage({ type: "samplerate", samplerate: remoteSampleRate }, "*"),
0 < remoteSampleRate ? (ja = 1) : ((ja = 0), stopall()),
(a += 2);
else if (130 == b[a]) (ua = 256 * b[a + 1] + b[a + 2]), (a += 2);
else if (131 == b[a])
(oa = b[a + 1]),
(j = b[a + 1] & 15),
j != fa && ((fa = j), currentConvolver && (currentConvolver.buffer = K[fa])),
a++;
else if (132 == b[a]) {
Y += 128;
for (e = 0; 128 > e; e++) y[g + e] = 0;
g += 128;
g >= F && (g -= F);
for (j = 0; 20 > j; j++) D[j] = E[j] = 0;
aa = 0;
} else
133 == b[a] &&
((d =
16777216 *
(((b[a + 1] & 15) << 16) + (b[a + 2] << 8) + b[a + 3]) +
(b[a + 4] << 16) +
(b[a + 5] << 8) +
b[a + 6]),
(e = b[a + 1] >> 4),
soundApplet.truefreqcallback && soundApplet.truefreqcallback(d, e),
(a += 6));
if (2 == f) {
f = Y = 0;
for (j = 16 == (oa & 16) ? 12 : 14; 128 > f; ) {
d =
(b[a + 3] & 255) |
((b[a + 2] & 255) << 8) |
((b[a + 1] & 255) << 16) |
((b[a + 0] & 255) << 24);
d <<= l;
e = 0;
var n;
n = 15 - z;
var s = ua,
u = [999, 999, 8, 4, 2, 1, 99, 99];
if (0 != d) for (; 0 == (d & 2147483648) && e < n; ) (d <<= 1), e++;
e < n
? ((n = e), e++, (d <<= 1))
: ((n = (d >> 24) & 255), (e += 8), (d <<= 8));
var q = 0;
n >= u[z] && q++;
n >= u[z - 1] && q++;
q > z - 1 && (q = z - 1);
u = (((d >> 16) & 65535) >> (17 - z)) & (-1 << q);
u += n << (z - 1);
0 != (d & (1 << (32 - z + q))) && ((u |= (1 << q) - 1), (u = ~u));
for (l += e + z - q; 8 <= l; ) a++, (l -= 8);
for (e = d = 0; 20 > e; e++) d += D[e] * E[e];
d |= 0;
d = 0 <= d ? d >> 12 : (d + 4095) >> 12;
s = u * s + s / 2;
u = s >> 4;
for (e = 19; 0 <= e; e--) {
D[e] += -(D[e] >> 7) + ((E[e] * u) >> j);
if (0 == e) break;
E[e] = E[e - 1];
}
E[0] = d + s;
d = E[0] + (aa >> 4);
aa = 16 == (oa & 16) ? 0 : aa + ((E[0] << 4) >> 3);
y[g++] = d;
g >= F && (g -= F);
f++;
}
0 == l && a--;
}
}
e = g - c;
0 > e && (e += F);
ba += e;
L += (1e3 * e) / remoteSampleRate;
wsMessageReceiveTime < L && (L = wsMessageReceiveTime);
ba >= remoteSampleRate &&
((j = 1e3 * (ba / (L - va))),
j < 1.01 * remoteSampleRate && j > 0.99 * remoteSampleRate && (actualRemoteSampleRate += (j - actualRemoteSampleRate) / W),
(ba = 0),
100 > W && W++,
(va = L),
(L = wsMessageReceiveTime));
webSocket &&
((b = c),
c > g && (webSocket.postMessage(y.subarray(c), "*"), (b = 0)),
g > b && webSocket.postMessage(y.subarray(b, g), "*"));
if (S && !(Y > 2 * remoteSampleRate))
for (; c != g; ) {
for (X += ka / remoteSampleRate; 1 <= X; )
S.setInt16(A, y[c], !0),
(A += 2),
65536 <= A &&
((b = new ArrayBuffer(65536)),
(A = 0),
(S = new DataView(b)),
B.push(b)),
X--;
c++;
c >= F && (c -= F);
}
if (ma) {
if ((c = document.getElementById("audiostartbutton")))
c.style.display = "suspended" === currentAudioContext.state ? "block" : "none";
"running" === currentAudioContext.state && (ma = 0);
}
};
webSocket.onopen = function () {
soundappletstarted();
};
webSocket.onclose = function () {
for (var c = 0; c < F; c++) y[c] = 0;
webSocket.onclose = h;
webSocket = webSocket.onmessage = h;
};
this.setparam = function (c) {
try {
webSocket.send("GET /~~param?" + c);
} catch (a) {}
};
this.smeter = function () {
return 10 * smeter;
};
this.getid = function () {
return ja;
};
this.mute = function (newValue) {
muted = newValue;
!S && !webSocket && this.setparam("mute=" + newValue);
};
this.setvolume = function (newVolume) {
volume = newVolume;
};
this.setdelay1 = function (c) {
ta = c;
H = N = c / 8e3;
p = (F + g - ta) % F;
};
stopall = function () {
currentAudioContext
? (webSocket.close(),
(scriptProcessor.onaudioprocess = h),
scriptProcessor.disconnect(),
(channelDataChunk = K = this.p = currentAudioContext = $ = currentConvolver = scriptProcessor = scriptProcessor.destination = h))
: webSocket.close();
};
this.restartaudio = function () {
stopall();
document.audioContext = new AudioContext();
window.prep_html5sound();
};
this.destroy = function () {
stopall();
window.soundapplet = h;
};
this.rec_start = function () {
A = 0;
ka = remoteSampleRate;
X = 0;
var c = new ArrayBuffer(65536);
S = new DataView(c);
B = [c];
muted && this.setparam("mute=0");
};
this.rec_finish = function () {
B[B.length - 1] = B[B.length - 1].slice(0, A);
S = h;
var c = {};
c.wavdata = B;
c.len = 65536 * (B.length - 1) + A;
c.sr = ka;
!webSocket && muted && this.setparam("mute=1");
return c;
};
this.rec_length_kB = function () {
return (65536 * (B.length - 1) + A) / 1024;
};
this.setbcaudio = function (c) {
webSocket = c;
muted &&
(c && this.setparam("mute=0"),
!c && !recaudio && this.setparam("mute=1"));
c && webSocket.postMessage({ type: "samplerate", samplerate: remoteSampleRate }, "*");
};
this.setstereo = function (c) {
0 > c
? (currentConvolver.disconnect(), currentConvolver.connect(currentAudioContext.destination))
: ($ || (($ = currentAudioContext.createChannelMerger()), $.connect(currentAudioContext.destination)),
currentConvolver.disconnect(),
currentConvolver.connect($, 0, c));
};
this.audioresume = function () {
currentAudioContext.resume();
var audioStartButton = document.getElementById("audiostartbutton");
audioStartButton && (audioStartButton.style.display = "none");
ma = 0;
};
}
window.prep_html5sound = function () {
window.soundapplet = new za();
};
prep_html5sound();
})();
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import netscape.javascript.JSObject;
public class websdrsound extends Applet implements LineListener, Runnable, MouseListener {
private SourceDataLine I;
private Socket I1;
private InputStream II;
OutputStream Il;
static final long serialVersionUID = 1L;
int I11 = -2;
int II1 = -2;
int Il1 = -1;
int I1I = 0;
int III = 0;
final float IlI = 200.0F;
int I1l = 0;
String IIl = "";
int Ill = -1;
Thread I111;
boolean II11 = true;
boolean Il11 = false;
public int smeter = -32767;
public int l = 0;
public int I1I1 = this.l;
double III1 = 1.0D;
float IlI1 = 1.0F;
double I1l1 = 0.0D;
double IIl1 = 0.0D;
final int Ill1 = 23;
final int I11I = 128;
final int II1I = 48;
float Il1I = 1.0F;
final float[] lll1l1l = new float[3];
float lll1ll1;
long I1II = 0L;
long llll11l = 0L;
float llll111 = 0.0F;
final float[] lll1lll = new float[4];
final short[] lll11ll = new short[] {
-5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, -7552, -7296,
-8064, -7808, -6528, -6272, -7040, -6784, -2752, -2624, -3008, -2880,
-2240, -2112, -2496, -2368, -3776, -3648, -4032, -3904, -3264, -3136,
-3520, -3392, -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944,
-30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136, -11008, -10496,
-12032, -11520, -8960, -8448, -9984, -9472, -15104, -14592, -16128, -15616,
-13056, -12544, -14080, -13568, -344, -328, -376, -360, -280, -264,
-312, -296, -472, -456, -504, -488, -408, -392, -440, -424,
-88, -72, -120, -104, -24, -8, -56, -40, -216, -200,
-248, -232, -152, -136, -184, -168, -1376, -1312, -1504, -1440,
-1120, -1056, -1248, -1184, -1888, -1824, -2016, -1952, -1632, -1568,
-1760, -1696, -688, -656, -752, -720, -560, -528, -624, -592,
-944, -912, -1008, -976, -816, -784, -880, -848, 5504, 5248,
6016, 5760, 4480, 4224, 4992, 4736, 7552, 7296, 8064, 7808,
6528, 6272, 7040, 6784, 2752, 2624, 3008, 2880, 2240, 2112,
2496, 2368, 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944, 30208, 29184,
32256, 31232, 26112, 25088, 28160, 27136, 11008, 10496, 12032, 11520,
8960, 8448, 9984, 9472, 15104, 14592, 16128, 15616, 13056, 12544,
14080, 13568, 344, 328, 376, 360, 280, 264, 312, 296,
472, 456, 504, 488, 408, 392, 440, 424, 88, 72,
120, 104, 24, 8, 56, 40, 216, 200, 248, 232,
152, 136, 184, 168, 1376, 1312, 1504, 1440, 1120, 1056,
1248, 1184, 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
688, 656, 752, 720, 560, 528, 624, 592, 944, 912,
1008, 976, 816, 784, 880, 848 };
boolean IIII = false;
int IlII = 5;
float I1lI = 0.0F;
int IIlI = 0;
float IllI = 0.0F;
float[] lll1111 = new float[272];
float[] lll111l = new float[1552];
byte[] lll11l1 = new byte[3120];
int I11l = 1;
float[] lll1l11 = new float[20];
int II1l = 1;
int Il1l = 0;
static Class I1Il;
public static void main(String[] paramArrayOfString) {
System.out.println("Copyright 2007-2016, Pieter-Tjerk de Boer, PA3FWM, [email protected] - All rights reserved.");
System.out.println("Since the intended use of this (or any) applet involves sending a copy to the client computer, I (PA3FWM) hereby allow making it available unmodified, as part of the original .jar file, via my original WebSDR server software, to original WebSDR clients.");
System.out.println("Other use, including distribution in part or entirety in other forms or as part of other software, or reverse engineering is not allowed without my explicit prior permission.");
}
public void stop() {
this.I111 = null;
this.IIl = "stop()";
I();
}
public void destroy() {
stop();
}
public void paint(Graphics paramGraphics) {
paramGraphics.drawString("WebSDR sound applet", 10, 10);
paramGraphics.drawString("Copyright 2007-2016, P.T. de Boer, [email protected]", 10, 24);
paramGraphics.drawString("Java version: " + System.getProperty("java.version"), 10, 88);
if (this.II11)
return;
paramGraphics.drawString(this.I11 + " " + this.IIl + " " + this.Ill + this.l, 10, 40);
paramGraphics.drawString(this.III + " " + this.I1I, 10, 52);
paramGraphics.drawString(this.I1l + " " + 200.0F, 10, 64);
paramGraphics.drawString((int)(0.5D + (this.IlI1 * 8000.0F)) + " " + (int)(0.5D + (this.III1 - 1.0D) * 1000000.0D) + " " + (int)(0.5D + (1.0D - this.IIl1 / 6.0D / this.I1l1 * this.IlI1) * 1000000.0D), 10, 76);
}
void I() {
if (this.II11)
return;
repaint();
}
public void mouseEntered(MouseEvent paramMouseEvent) {}
public void mouseExited(MouseEvent paramMouseEvent) {}
public void mouseReleased(MouseEvent paramMouseEvent) {}
public void mousePressed(MouseEvent paramMouseEvent) {}
public void I(MouseEvent paramMouseEvent) {}
public void mouseClicked(MouseEvent paramMouseEvent) {
this.II11 = !this.II11;
repaint();
}
public int getid() {
return this.Ill;
}
public int I1() {
return this.smeter;
}
public String javaversion() {
return System.getProperty("java.version");
}
public void setparam(String paramString) {
paramString = "GET /~~param?ppm=" + (int)(0.5D + (this.III1 - 1.0D) * 1000000.0D) + "&ppml=" + (int)(0.5D + (1.0D - this.IIl1 / 6.0D / this.I1l1 * this.IlI1) * 1000000.0D) + "&" + paramString + "\r\n\r\n";
try {
this.Il.write(paramString.getBytes(), 0, paramString.length());
} catch (Exception exception) {}
this.IIl1 = this.I1l1 = 0.0D;
}
public void setvolume(float paramFloat) {
this.Il1I = paramFloat;
}
public void start() {
AudioFormat audioFormat = new AudioFormat(48000.0F, 16, 1, true, false);
DataLine.Info info = new DataLine.Info((I1Il == null) ? (I1Il = I("javax.sound.sampled.SourceDataLine")) : I1Il, audioFormat, 96000);
try {
this.I = (SourceDataLine)AudioSystem.getLine(info);
this.I.open(audioFormat, 96000);
} catch (LineUnavailableException lineUnavailableException) {}
this.I.addLineListener(this);
this.I.start();
try {
int i = getCodeBase().getPort();
if (i < 0)
i = 80;
this.I1 = new Socket(getCodeBase().getHost(), i);
this.II = this.I1.getInputStream();
this.Il = this.I1.getOutputStream();
this.Il.write("GET /~~stream?java=1&23\r\n\r\n".getBytes(), 0, 27);
this.I11 = 1;
I();
} catch (Exception exception) {
this.I11 = -3;
I();
}
this.I11 = 4;
this.IIl = "start()";
this.I111 = new Thread(this);
this.I111.start();
JSObject.getWindow(this).eval("soundappletstarted()");
addMouseListener(this);
I();
this.I1II = System.currentTimeMillis();
}
void I(int paramInt) {
if (this.Ill == -1) {
this.Ill = paramInt;
} else if ((paramInt & 0x8000) == 0) {
this.smeter = paramInt;
} else {
paramInt &= 0x7FFF;
if ((paramInt & 0x4000) == 0)
this.IlI1 = paramInt / 8000.0F;
}
}
void I1(int paramInt) {
this.I1l1 += paramInt;
this.Il1 = this.I.getBufferSize() - this.I.available();
if (!this.I.isActive()) {
this.I1I++;
this.Il1 = -1;
}
this.I11++;
this.lll1l1l[0] = this.lll1l1l[1];
this.lll1l1l[1] = this.lll1l1l[2];
this.lll1l1l[2] = this.I.getFramePosition() / 48.0F - (float)(System.currentTimeMillis() - this.I1II);
if (this.lll1l1l[1] > this.lll1l1l[0] && this.lll1l1l[1] > this.lll1l1l[2])
this.lll1ll1 = 0.1F * this.lll1l1l[1] + 0.9F * this.lll1ll1;
for (byte b2 = 0; b2 < paramInt; b2++) {
for (byte b = 0; b < 6; b++) {
byte b3;
float[] arrayOfFloat2 = {
-0.0030657F, -0.0027421F, -0.0028342F, -0.0018084F, 5.5067E-4F, 0.0040855F, 0.0081821F, 0.011793F, 0.01366F, 0.01262F,
0.0080115F, 1.7366E-5F, -0.010139F, -0.020236F, -0.027388F, -0.028593F, -0.02145F, -0.0048089F, 0.020752F, 0.052804F,
0.087352F, 0.11948F, 0.14428F, 0.15778F, 0.15778F, 0.14428F, 0.11948F, 0.087352F, 0.052804F, 0.020752F,
-0.0048089F, -0.02145F, -0.028593F, -0.027388F, -0.020236F, -0.010139F, 1.7366E-5F, 0.0080115F, 0.01262F, 0.01366F,
0.011793F, 0.0081821F, 0.0040855F, 5.5067E-4F, -0.0018084F, -0.0028342F, -0.0027421F, -0.0030657F };
float[] arrayOfFloat1 = {
-0.0024615F, -0.0072497F, -0.0080908F, -0.0078587F, -0.0024454F, 0.0045784F, 0.010045F, 0.009404F, 0.0018009F, -0.0092801F,
-0.016675F, -0.013973F, -1.8887E-4F, 0.017873F, 0.028294F, 0.020954F, -0.0048033F, -0.036754F, -0.053709F, -0.035879F,
0.023444F, 0.11149F, 0.19934F, 0.25408F, 0.25408F, 0.19934F, 0.11149F, 0.023444F, -0.035879F, -0.053709F,
-0.036754F, -0.0048033F, 0.020954F, 0.028294F, 0.017873F, -1.8887E-4F, -0.013973F, -0.016675F, -0.0092801F, 0.0018009F,
0.009404F, 0.010045F, 0.0045784F, -0.0024454F, -0.0078587F, -0.0080908F, -0.0072497F, -0.0024615F };
this.lll111l[16 + 6 * b2 + b] = 0.0F;
if (this.Il11) {
for (b3 = 0; b3 < 8; b3++)
this.lll111l[16 + 6 * b2 + b] = this.lll111l[16 + 6 * b2 + b] + this.lll1111[b2 + 7 + b3] * arrayOfFloat1[6 * b3 + 5 - b];
} else {
for (byte b4 = 0; b4 < 8; b4++)
this.lll111l[16 + 6 * b2 + b] = this.lll111l[16 + 6 * b2 + b] + this.lll1111[b2 + 7 + b4] * b3[6 * b4 + 5 - b];
}
this.lll111l[16 + 6 * b2 + b] = this.lll111l[16 + 6 * b2 + b] * 6.0F;
}
}
int i = paramInt * 6;
byte b1;
for (b1 = 0; this.I1lI < i; b1++) {
int j = (int)this.I1lI + 16;
float f1 = this.I1lI - (j - 16);
f1 = (1.0F - f1) * this.lll111l[j - 1] + f1 * this.lll111l[j];
if (2 * b1 > 3100)
break;
this.lll11l1[2 * b1] = (byte)((int)f1 & 0xFF);
this.lll11l1[2 * b1 + 1] = (byte)((int)f1 >> 8);
this.I1lI = (float)(this.I1lI + this.III1 * this.IlI1);
}
this.I1lI -= i;
if (this.IIlI == 0) {
this.I.write(this.lll11l1, 0, b1 * 2);
this.IIl1 += b1;
} else if (b1 < this.IIlI) {
this.IIlI -= b1;
} else {
this.I.write(this.lll11l1, this.IIlI * 2, (b1 - this.IIlI) * 2);
this.IIlI = 0;
this.IIl1 += (b1 - this.IIlI);
}
if (this.llll11l == 0L)
this.llll111 = (float)this.llll11l;
this.llll11l += b1;
this.lll1lll[0] = this.lll1lll[1];
this.lll1lll[1] = this.lll1lll[2];
this.lll1lll[2] = this.lll1lll[3];
this.lll1lll[3] = (float)this.llll11l / 48.0F - (float)(System.currentTimeMillis() - this.I1II);
if (this.IIlI == 0 && this.lll1lll[3] < this.lll1ll1 && this.llll111 > this.lll1ll1 + 150.0F) {
this.IIlI = (int)(this.lll1ll1 - this.lll1lll[3]);
this.III++;
this.llll111 -= this.IIlI;
this.lll1lll[0] = this.lll1lll[0] - this.IIlI;
this.lll1lll[1] = this.lll1lll[1] - this.IIlI;
this.lll1lll[2] = this.lll1lll[2] - this.IIlI;
this.lll1lll[3] = this.lll1lll[3] - this.IIlI;
this.lll1ll1 -= this.IIlI;
this.IIlI *= 48;
this.llll11l -= this.IIlI;
}
if (this.lll1lll[1] > this.lll1lll[0] && this.lll1lll[1] > this.lll1lll[2] && this.lll1lll[1] > this.lll1lll[3])
this.llll111 = this.lll1lll[1];
for (paramInt = 0; paramInt < 16; paramInt++) {
this.lll111l[paramInt] = this.lll111l[i + paramInt];
this.lll1111[paramInt] = this.lll1111[i / 6 + paramInt];
}
float f = this.llll111 - this.lll1ll1;
this.I1l = (int)f;
f -= 200.0F;
f /= 3.0F;
this.IllI = 0.999F * this.IllI + 0.001F * f;
if (this.IllI < -40.0F)
this.IllI = -40.0F;
if (this.IllI > 40.0F)
this.IllI = 40.0F;
this.III1 = (1.0F + this.IllI * 5.0E-5F);
if (f > 200.0F) {
this.IIlI = (int)f;
this.III++;
this.llll111 -= this.IIlI;
this.lll1lll[0] = this.lll1lll[0] - this.IIlI;
this.lll1lll[1] = this.lll1lll[1] - this.IIlI;
this.lll1lll[2] = this.lll1lll[2] - this.IIlI;
this.lll1lll[3] = this.lll1lll[3] - this.IIlI;
this.IIlI *= 48;
this.llll11l -= this.IIlI;
}
}
void I(float paramFloat, int paramInt) {
for (byte b = 19; b > 0; b--)
this.lll1l11[b] = this.lll1l11[b - 1];
this.lll1l11[0] = paramFloat;
float f = this.lll1l11[10];
if (this.II1l >= 0) {
f = 0.0F;
float[][] arrayOfFloat = { { 0.0416798F, -0.0010372F, -0.0316519F, 0.0592284F, -0.0496101F, -0.0066906F, 0.0774353F, -0.0963F, -0.0179755F, 0.5594503F }, { 0.030725F, 0.062421F, -0.028814F, -0.027426F, -0.056624F, -0.034655F, 0.021408F, 0.110595F, 0.199341F, 0.255473F } };
for (byte b1 = 0; b1 < 10; b1++)
f += arrayOfFloat[this.II1l][b1] * (this.lll1l11[b1] + this.lll1l11[19 - b1]);
}
this.lll1111[paramInt + 16] = f * this.Il1I;
if (paramInt == 127)
I1(128);
}
public void run() {
byte[] arrayOfByte = new byte[264];
int[] arrayOfInt3 = new int[20];
int[] arrayOfInt2 = new int[20];
int[] arrayOfInt1 = new int[20];
int m = 0;
byte b1 = 0;
byte b = -1;
char c = Character.MIN_VALUE;
int k = 0;
int j = 256;
int i = 0;
this.Ill = -1;
try {
while (Thread.currentThread() == this.I111) {
this.I11++;
I();
this.I1I1 = this.l;
int i1 = 0;
int n = 0;
while (c < ') {
i1 = this.II.read(arrayOfByte, m, 260 - m);
if (i1 < 0)
break;
m += i1;
boolean bool = true;
while (bool && m > 0) {
int i2 = 0;
if (b == -1) {
if (m < 2) {
bool = false;
} else {
b = 0;
int i3 = (arrayOfByte[0] & 0xFF) + ((arrayOfByte[1] & 0xFF) << 8);
I(i3);
i2 = 2;
}
} else if (b == 0) {
if ((arrayOfByte[0] & 0x80) != 128) {
n = 1;
b = 2;
c = Character.MIN_VALUE;
} else if (arrayOfByte[0] >= -112 && arrayOfByte[0] <= -33) {
n = 4;
b = 2;
c = Character.MIN_VALUE;
i = 6 - (0xF & arrayOfByte[0] - 128 >> 4);
} else if (arrayOfByte[0] == Byte.MIN_VALUE) {
b = 1;
i2 = 1;
} else if ((arrayOfByte[0] & 0xF0) == 240) {
if (m < 2) {
bool = false;
} else {
this.smeter = 10 * (((arrayOfByte[0] & 0xF) << 8) + (arrayOfByte[1] & 0xFF));
i2 = 2;
}
} else if (arrayOfByte[0] == -127) {
if (m < 3) {
bool = false;
} else {
int i3 = (arrayOfByte[1] << 8) + (arrayOfByte[2] & 0xFF);
this.IlI1 = i3 / 8000.0F;
i2 = 3;
}
} else if (arrayOfByte[0] == -126) {
if (m < 3) {
bool = false;
} else {
int i3 = (arrayOfByte[1] << 8) + (arrayOfByte[2] & 0xFF);
j = i3;
i2 = 3;
}
} else if (arrayOfByte[0] == -125) {
if (m < 2) {
bool = false;
} else {
this.Il1l = arrayOfByte[1];
this.II1l = (arrayOfByte[1] & 0xF) - 1;
if (this.II1l == 2) {
this.II1l = 0;
this.Il11 = true;
} else {
this.Il11 = false;
}
i2 = 2;
}
} else if (arrayOfByte[0] == -124) {
i2 = 1;
c = ';
for (byte b2 = 0; b2 < '; b2++)
this.lll1111[b2 + 16] = 0.0F;
I1(128);
for (i1 = 0; i1 < 20; i1++) {
arrayOfInt2[i1] = 0;
arrayOfInt3[i1] = 0;
}
k = 0;
} else if (arrayOfByte[0] == -123) {
if (m < 7) {
bool = false;
} else {
i2 = 7;
}
} else {
i2 = 1;
this.IIII = true;
bool = false;
}
} else if (b == 1) {
if (m < 128 || c == ') {
bool = false;
} else {
for (byte b2 = 0; b2 < 20; b2++) {
arrayOfInt2[b2] = 0;
arrayOfInt3[b2] = 0;
}
k = 0;
i1 = 0;
while (i1 < m && c < ') {
this.lll1111[c + 16] = this.lll11ll[(short)arrayOfByte[i1] & 0xFF];
I(this.lll11ll[(short)arrayOfByte[i1] & 0xFF], c);
i1++;
c++;
}
i2 = 128;
b = 0;
bool = false;
}
}
if (b == 2) {
i1 = 0;
byte b2 = ((this.Il1l & 0x10) == 16) ? 12 : 14;
while (i1 < m && c < ') {
int i4 = (arrayOfByte[i1 + 3] & 0xFF) + ((arrayOfByte[i1 + 2] & 0xFF) << 8) + ((arrayOfByte[i1 + 1] & 0xFF) << 16) + ((arrayOfByte[i1 + 0] & 0xFF) << 24);
int i5 = i4 << n;
int i10 = n;
int i9 = i5;
byte b3 = 0;
int i6 = 15 - i;
int i8 = j;
int[] arrayOfInt = { 999, 999, 8, 4, 2, 1, 99, 99 };
if (i5 != 0)
while ((i5 & Integer.MIN_VALUE) == 0 && b3 < i6) {
i5 <<= 1;
b3++;
}
if (b3 < i6) {
i7 = b3;
b3++;
i6 = i5 << 1;
} else {
i7 = i5 >> 24 & 0xFF;
b3 += 8;
i6 = i5 << 8;
}
i5 = 0;
if (i7 >= arrayOfInt[i])
i5++;
if (i7 >= arrayOfInt[i - 1])
i5++;
if (i5 > i - 1)
i5 = i - 1;
int i3 = (i6 >> 16 & 0xFFFF) >> 17 - i & -1 << i5;
i3 += i7 << i - 1;
if ((i6 & 1 << 32 - i + i5) != 0) {
i3 |= (1 << i5) - 1;
i3 ^= 0xFFFFFFFF;
}
for (n += b3 + i - i5; n >= 8; n -= 8)
i1++;
if (i9 == 0 || i1 + (7 + n) / 8 > m) {
bool = false;
n = i10;
break;
}
i2 = i1;
i6 = 0;
for (i5 = 0; i5 < 20; i5++)
i6 += arrayOfInt3[i5] * arrayOfInt2[i5];
i5 = i6 / 4096;
int i7 = i3 * i8 + i8 / 2;
i6 = i7 >> 4;
for (i3 = 0; i3 < 20; i3++)
arrayOfInt3[i3] = arrayOfInt3[i3] + -(arrayOfInt3[i3] >> 7) + (arrayOfInt2[i3] * i6 >> b2);
for (i3 = 19; i3 > 0; i3--) {
arrayOfInt2[i3] = arrayOfInt2[i3 - 1];
arrayOfInt1[i3] = arrayOfInt1[i3 - 1];
}
arrayOfInt2[0] = i5 + i7;
i3 = i5 + i7 * this.I1I1 + (k >> 4);
if ((this.Il1l & 0x10) == 16) {
k = 0;
} else {
k += arrayOfInt2[0] << 4 >> 3;
}
I(i3, c);
c++;
}
if (c == ') {
b = 0;
if (n > 0) {
i2++;
n = 0;
}
}
b1++;
}
if (i2 > 0)
for (i1 = i2; i1 < m; i1++)
arrayOfByte[i1 - i2] = arrayOfByte[i1];
m -= i2;
}
if (this.IIII || m < 0)
break;
}
if (c == ')
c = Character.MIN_VALUE;
this.II1 = i1;
this.I11++;
if (this.IIII || i1 == -1)
break;
}
} catch (IOException iOException) {
this.IIl = "!" + iOException.getMessage();
}
this.IIl = "^" + this.IIl;
this.I.flush();
this.I.stop();
this.I.close();
try {
this.I1.close();
} catch (Exception exception) {}
this.I11 = -5;
I();
}
public void update(LineEvent paramLineEvent) {}
static Class I(String paramString) {
try {
return Class.forName(paramString);
} catch (ClassNotFoundException classNotFoundException) {
throw (new NoClassDefFoundError()).initCause(classNotFoundException);
}
}
}
@endiny
Copy link

endiny commented Aug 23, 2022

I suspect there might be a raw radio signal on the websocket that needs to be demodulated

@kevinelliott
Copy link
Author

I suspect there might be a raw radio signal on the websocket that needs to be demodulated

Any interest in fixing this to work?

@natsuru-san
Copy link

natsuru-san commented Sep 10, 2022

Any interest in fixing this to work?
I do not know if I can help you, but I can give you some direction of thought :)
The audio from websocket encoded to G911-format (aLaw). Audiacity plays it well. You need a decoder of this format. I have one in my project, but it is written in java...

@endiny
Copy link

endiny commented Sep 13, 2022

Any interest in fixing this to work?
Actually, I believe this helped me to get an applet with no syntax errors. That helped me to make it run at least and change frequencies

@natsuru-san gonna check this out. There is also a golang lib for that

@mrzachhigginsofficial
Copy link

I suspect there might be a raw radio signal on the websocket that needs to be demodulated

Tackling this in python and I think this is where I'm stuck. I think the keys to the kingdom are locked away here processEvent(audioProcessEvent). Gonna start picking it apart tomorrow or friday.

@einball
Copy link

einball commented Jun 11, 2023

@natsuru-san I'm not able to get anything usable out of Audacity using RAW audio import, aLaw, little-Endian, FS 8kHz. I made sure to modify the frequency into one I should be able to listen to. Am I missing something? Can you confirm the above code works on your machine ™️?

@natsuru-san
Copy link

@einball Seems that audio stream codec been changed or modified by the server owner which (I suppose) knew about our research his facility. I think too because my app's playing with a some issues at last time. Your problem (as is my) might be into it. And I have no idea how to solve it. May be you have any idea?

@realies
Copy link

realies commented Aug 10, 2023

@natsuru-san, do you know the diff on the frontend so we can narrow down the change?

@realies
Copy link

realies commented Aug 10, 2023

I've been trying to capture the WebSocket stream on websdr.info:8902, which uses an older version of the websdr frontend using this node script:

const WebSocket = require('ws');
const fs = require('fs');

// GET /~~param?f=145625&band=0&lo=-6.2&hi=6.2&mode=4&name=
const frequency = "145625";
const band = "0";
const lo = "-6.2";
const hi = "6.2";
const mode = "4";
const ws = new WebSocket('ws://websdr.info:8902/~~stream?v=11', { headers: {
  'Connection': 'Upgrade',
  'Host': 'websdr.info:8902',
  'Origin': 'http://websdr.info:8902',
  'Cookie': 'view=2; ID=5d83b2fd9c13',
  'Pragma': 'no-cache',
  'Cache-Control': 'no-cache',
  'Sec-WebSocket-Key': 'K+3pZ6WnO+JMDVF5CX4J+w==',
  'Sec-WebSocket-Version': '13',
  'Sec-WebSocket-Extensions': 'x-webkit-deflate-frame',
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15'
}, binaryType: 'arraybuffer' });

const dataBuffer = [];

ws.on('open', function open() {
  console.log('Connection opened...');
  ws.send(`GET /~~param?f=${frequency}&band=${band}&lo=${lo}&hi=${hi}&mode=${mode}&name=`, () => {
    ws.send(`GET /~~param?mute=0`, () => {
      ws.send(`GET /~~param?squelch=0`, () => {
        ws.send(`GET /~~param?autonotch=0`, () => {
          ws.on('message', function incoming(data) {
            console.log(`Received ${data.length} bytes`);
            dataBuffer.push(data);
          });
          setTimeout(() => {
            ws.close();
            console.log('Connection closed.');
          }, 1000 * 60);
        });
      });
    });
  });
});

ws.on('error', function error(err) {
  console.error('Error:', err);
});

ws.on('close', function close() {
  console.log('Connection closed by server.');
  fs.writeFile('capturedAudio.raw', Buffer.concat(dataBuffer), (err) => {
    if (err) throw err;
    console.log('Data saved to file.');
  });
});

Unfortunately, reading the file in Audacity, or converting it with sox (sox -t raw -r 8000 -e a-law input.raw output.wav) produces only white noise-like output. A strange thing I noticed is that while I 'record' for 60 seconds, the resulting file is around ~42 seconds long.

Any ideas or suggestions on how to capture and decode this? Here's a captured file: https://github.com/realies/websdr-capture/raw/master/capturedAudio.raw

PS: websdr.info:8902 works fine when intialised with this, much older websdr-sound.js: https://github.com/FarnhamSDR/websdr-webpages/blob/master/websdr-sound.js

@mrzachhigginsofficial
Copy link

@realies - you need to demodulate the stream. You can check try to reverse engineer the JS or I can provide an example in python if you're interested.

@realies
Copy link

realies commented Aug 11, 2023

@mrzachhigginsofficial, an example would be greatly appreciated.

@einball
Copy link

einball commented Aug 11, 2023

I have reason to believe that there was a kind of packet structure / framing introduced. The first byte in every package is the almost everytime the same. I did not get it to run but did not sink a lot of time into it by now. This leads me to believe that the author started to do asynchronous resampling or injecting data into the stream. In any case, it seems like there's a 'length' field now.

Screenshot from 2023-08-11 09-57-33

Screenshot from 2023-08-11 09-57-21

Screenshot from 2023-08-11 09-57-06

The code is so convoluted it's very hard to read it. It might be better to reimplement the functionality using the webaudio API and/or run our own server.

@mrzachhigginsofficial Did you run this through a codec, deinterleave the obtained samples and IQ demodulate it after?

When I tune to a stationary signal (keyed beacon for example) the data rate drops from 750bytes/message to 420bytes/message so I assume the/a codec is still in play.

@mrzachhigginsofficial
Copy link

I checked the project from my phone. Honestly I don't understand it anymore (or at least enough to read from this screen on github) and need to step through it to find the relevant portions. Will do this tomorrow. It's been a while since I touched it.

@einball
Copy link

einball commented Aug 11, 2023

@mrzachhigginsofficial Your project will probably no longer work. The current implementation of this SDR does some more things than simply decode some fixed-rate samples from the server. This version does asynchronous samplerate conversion to adapt its playback rate to what's sent from the server. After staring at the code for a while I think I'm starting to get the hang of it.

@realies
Copy link

realies commented Aug 11, 2023

@einball, I had a feeling that something like this is happening based on some byte flags: https://github.com/FarnhamSDR/websdr-webpages/blob/951cbfc5433b845bdcf600c42ae2739e32123e9a/websdr-sound.js#L223-L299 Although I'm still lost in the data flow.

@einball
Copy link

einball commented Aug 11, 2023

I already decoded parts of the file and have a basic understanding of what's going on. However, I'd like to respect the authors copyright and will not post my results publicly.

@realies
Copy link

realies commented Aug 11, 2023

@einball, can you share if you decoded parts of the file I posted (capturedAudio.raw)?

@kevinelliott
Copy link
Author

@einball I'd love to see what you've done. Any chance you could contact me privately about it?

@realies
Copy link

realies commented Aug 11, 2023

@einball I'd love to see what you've done. Any chance you could contact me privately about it?

+1

@idramm25
Copy link

idramm25 commented Jan 17, 2024

I made a python script to connect to the server and record the stream to a file. then try to listen to it with the second script. in the speakers there is something similar to white noise with sound artifacts in the form of snatches of speech.
making raw: https://pastebin.com/SPhn5bS8
play raw: https://pastebin.com/m2qxAeFh
wav to raw from web: https://pastebin.com/M0xfJfvs
my goal is something like that:
121212

@kevinelliott
Copy link
Author

Interesting. I would be willing to bet there is some encoding happening to prevent this very thing that we need to figure out.

@degenoah
Copy link

degenoah commented Jul 5, 2024

my attempt to clean up the latest version to the best of my abilities.

many variables end up getting reused and as a result there's likely some control flow errors from trying to split these.

(function() {
  function SoundApplet() {
    function processEvent(audioProcessEvent) {
      var channelData = audioProcessEvent.outputBuffer.getChannelData(0);
      var bufferLength = audioProcessEvent.outputBuffer.length;

      processStartTime = (new Date).getTime();
      var timeDifference = processStartTime - wsMessageReceiveTime;
      
      var d = ta + timeDifference / 1000 * remoteSampleRate - p * 
              remoteSampleRate - bufferLength * x / audioSampleRate;
      d = Math.round(d);
      d = (2 * unk_const_5731 + d) % unk_const_5731;
      
      var unk_1354 = 1000 * ((t - d + 2.5 * unk_const_5731) % 
                     unk_const_5731 - unk_const_5731 / 2) / remoteSampleRate;

      if (L) {
        unk_1354 = Math.abs(unk_1354);
        
        if (unk_1354 < 500 * p) {
          L = 0;
        }
        
        if (1 == F) {
          L = 0;
        }
      }

      if (L || 3 <= F) {
        ua = L ? "r" + unk_1354.toFixed(0) : "u" + Da.toFixed(0);
        var f = 0;
        var g = 0;
        var e = 0;

        for (var chIndex = 0; chIndex < G.length; chIndex++) {
          channelData = G[chIndex];

          if (channelData > f) {
            e = g;
            g = f;
            f = channelData;
          } else if (channelData > g) {
            e = g;
            g = channelData;
          } else if (channelData > e) {
            e = channelData;
          }
        }

        p = 1.5 * (e / 1000);

        if (p <= 0.125) {
          p = 0.125;
        }

        if (p >= 0.7) {
          p = 0.7;
        }

        // `d` was previously used for the last loop, so it was calculated again...
        // d = ta + timeDifference / 1000 * remoteSampleRate - p * 
        //     remoteSampleRate - bufferLength * x / audioSampleRate;
        // d = Math.round(d);
        // d = (2 * unk_const_5731 + d) % unk_const_5731;

        L = 0;

        if (F > 3) {
          F = 0;
        }

        channelData = t;

        if (Z > 0) {
          Z = -1;
          actualRemoteSampleRate *= remoteSampleRate / x;
          x = remoteSampleRate;
        }

        t = d;
        M = p;
        Ea++;
        va++;

        B = actualRemoteSampleRate / actualAudioSampleRate / (x / audioSampleRate);
      }

      var unk_1 = Math.abs(1000 * ((t - d + 2.5 * unk_const_5731) % 
                  unk_const_5731 - unk_const_5731 / 2) / remoteSampleRate);
      if (!(500 > unk_1)) {
        unk_1 = 500;
      }

      la += 0.1 * (unk_1 - la);

      if (unk_1354 < -500 * p) {
        L = 1;
      }

      var unk_2 = Math.floor(processStartTime - lastProcessTime - 1000 * 
                             bufferLength / actualAudioSampleRate);

      if (unk_2 < Ga) {
        if (unk_2 > G[0]) {
          G[0] = unk_2;
        }
      }

      lastProcessTime = processStartTime;

      var unk_const_tbl = [
        -0.00052849, -0.0007085, -0.000497, -0.00096915, -0.00098441, -0.0013791, 
        -0.0015351, -0.0019014, -0.0021403, -0.0024899, -0.0027631, -0.0030833, 
        -0.0033437, -0.0036043, -0.0038008, -0.0039597, -0.0040394, -0.004047, 
        -0.0039537, -0.0037585, -0.0034404, -0.0029934, -0.0024042, -0.0016671, 
        -0.00077343, 0.00027964, 0.0014943, 0.0028693, 0.0044015, 0.0060827, 
        0.0079045, 0.0098529, 0.011913, 0.014065, 0.016289, 0.018561, 0.020857, 
        0.023149, 0.025409, 0.027609, 0.029721, 0.031717, 0.03357, 0.035253, 
        0.036743, 0.03802, 0.039064, 0.039862, 0.0404, 0.040671, 0.040671, 0.0404, 
        0.039862, 0.039064, 0.03802, 0.036743, 0.035253, 0.03357, 0.031717, 
        0.029721, 0.027609, 0.025409, 0.023149, 0.020857, 0.018561, 0.016289, 
        0.014065, 0.011913, 0.0098529, 0.0079045, 0.0060827, 0.0044015, 0.0028693, 
        0.0014943, 0.00027964, -0.00077343, -0.0016671, -0.0024042, -0.0029934, 
        -0.0034404, -0.0037585, -0.0039537, -0.004047, -0.0040394, -0.0039597, 
        -0.0038008, -0.0036043, -0.0033437, -0.0030833, -0.0027631, -0.0024899, 
        -0.0021403, -0.0019014, -0.0015351, -0.0013791, -0.00098441, -0.00096915, 
        -0.000497, -0.0007085, -0.00052849
      ];

      for (var bufferIndex = 0; bufferIndex < bufferLength; bufferIndex++) {
        var unk_4517 = z[t];
        f = B * x / audioSampleRate;
        u += f;

        if (u > 1) {
          u -= 1;
          Ha = z[t];

          if (t == k) {
            if (!F) {
              Ia = processStartTime;
            }

            F = 1;
          } else {
            t++;

            if (t >= unk_const_5731) {
              t -= unk_const_5731;
            }
          }

          g = z[t];

          if (Ta) {
            unk_4517 = (u * g + (f - u) * unk_4517) / f;
          }

          if (t == Z) {
            Z = -1;
            actualRemoteSampleRate *= remoteSampleRate / x;
            x = remoteSampleRate;
          }
        }

        f = 0;
        f += 50 * z[t] * unk_const_tbl[Math.floor(50 * u)];
        f += 50 * Ha * unk_const_tbl[Math.floor(50 + 50 * u)];

        if (Ba && Ra <= 50) {
          ca_debug2_related += "d " + unk_4517 + " " + t + " " + u + " " + z[t] + " " + f + "<br>";
        }

        if ($ & 1) {
          unk_4517 = f;
        }

        if (muted) {
          unk_4517 = 0;
        }

        channelData[bufferIndex] = 0.00002 * unk_4517 * volume;
      }

      Ra++;

      if (Ba) {
        if (Ra > 50 && ca_debug2_related != "") {
          document.getElementById("soundappletdebug2").innerHTML = ca_debug2_related;
          ca_debug2_related = "";
          alert(1);
        }
      }

      X += 1000 * bufferLength / actualAudioSampleRate;

      if (processStartTime < X) {
        X = processStartTime;
      }

      ea += bufferLength;

      if (ea >= audioSampleRate) {
        channelData = 1000 * (ea / (X - Ka));

        if (channelData < 1.01 * audioSampleRate) {
          if (channelData > 0.99 * audioSampleRate) {
            actualAudioSampleRate += (channelData - actualAudioSampleRate) / fa;
          }
        }

        Ka = X;
        ea = 0;
        X = processStartTime;
        G.unshift(0);
        G.splice(30, 1);
      }
    }

    function Ua(audioProcessEvent) {
      var inputBuffer = audioProcessEvent.inputBuffer.getChannelData(0);
      var outputBuffer = audioProcessEvent.outputBuffer.getChannelData(0);
      
      var bufferLength = audioProcessEvent.outputBuffer.length;
      
      for (var l = 0; l < bufferLength; l++) {
        outputBuffer[l] = inputBuffer[l];

        if (Ca) {
          if (N_recording_related) {
            N_recording_related.setInt16(w, 0x3FFF * inputBuffer[l], true);
            
            w += 2;
            if (w >= Y) {
              var b = new ArrayBuffer(Y);
              w = 0;
              N_recording_related = new DataView(b);
              recordedBufferData.push(b);
            }
          }
        }
      }
    }

    document.getElementById("soundappletdiv").innerHTML = /*html*/`
      <div 
        onclick="var e = document.getElementById('soundappletdebug'); e.style.display = (e.style.display == 'none') ? 'block' : 'none';" 
        style="max-width:400px; min-height:50px; border-style:solid; border-color:black; background-color:white; color:black; 
               border-width:1px; margin:2px; padding:2px; font-family:sans-serif; font-size:x-small;"
      >
        WebSDR HTML5 sound FJ9 - Copyright 2007-2020, P.T. de Boer, [email protected]<br>
        <span id="soundappletdebug" style="display:none"></span>
      </div>
      <span id="soundappletdebug2"></span>
    `;

    var z = new Int16Array(unk_const_5731);
    var k = 0;
    var t = 6144;
    var u = 0;
    var remoteSampleRate = 8000;
    var x = 8000;
    var Z = -1;
    var actualRemoteSampleRate = 8000;
    var audioSampleRate = 48000;
    var actualAudioSampleRate = 48000;
    var B = 1;
    var volume = 1;
    var unk__ret_by_getid = -1;
    var N_recording_related;
    var w = 0;
    var Y = 65536;
    var recordedBufferData = []; // name is assumed.
    var unk_smplrate;
    var ga;
    var ha = 0;
    var soundApplet = this;
    var audioBroadcastChannel = null;
    var $ = 3;

    var const_tbl__Va = [-5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736, -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784, -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368, -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392, -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944, -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136, -11008, -10496, -12032, -11520, -8960, -8448, -9984, -9472, -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568, -344, -328, 
    -376, -360, -280, -264, -312, -296, -472, -456, -504, -488, -408, -392, -440, -424, -88, -72, -120, -104, -24, -8, -56, -40, -216, -200, -248, -232, -152, -136, -184, -168, -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184, -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696, -688, -656, -752, -720, -560, -528, -624, -592, -944, -912, -1008, -976, -816, -784, -880, -848, 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736, 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784, 2752, 2624, 3008, 2880, 
    2240, 2112, 2496, 2368, 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392, 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944, 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136, 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472, 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568, 344, 328, 376, 360, 280, 264, 312, 296, 472, 456, 504, 488, 408, 392, 440, 424, 88, 72, 120, 104, 24, 8, 56, 40, 216, 200, 248, 232, 152, 136, 184, 168, 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184, 1888, 
    1824, 2016, 1952, 1632, 1568, 1760, 1696, 688, 656, 752, 720, 560, 528, 624, 592, 944, 912, 1008, 976, 816, 784, 880, 848];

    var const_tbl__un = [0.0084619, 3.6183E-4, 2.0264E-4, -4.8621E-5, -3.6771E-4, -7.0991E-4, -0.0010355, -0.0012935, -0.0014506, -0.0014733, -0.0013571, -0.0011019, -7.4253E-4, -3.0836E-4, 1.358E-4, 5.6517E-4, 8.8996E-4, 0.0010664, 0.0010912, 9.2941E-4, 6.0906E-4, 1.5494E-4, -3.7203E-4, -9.1186E-4, -0.001389, -0.0017416, -0.0019133, -0.0018764, -0.0016225, -0.0011768, -5.8255E-4, 9.2361E-5, 7.5528E-4, 0.0013306, 0.0017366, 0.0019135, 0.0018299, 0.0014834, 9.0902E-4, 1.6944E-4, -6.4513E-4, -0.0014333, -0.0020901, 
    -0.002526, -0.0026728, -0.0024998, -0.0020096, -0.0012556, -3.2129E-4, 6.8312E-4, 0.0016291, 0.0023941, 0.0028705, 0.0029846, 0.002705, 0.0020504, 0.0010884, -7.0093E-5, -0.0012848, -0.0024011, -0.0032709, -0.0037692, -0.0038134, -0.0033791, -0.0024966, -0.0012601, 1.8871E-4, 0.0016733, 0.0030042, 0.0040027, 0.0045239, 0.0044775, 0.0038421, 0.0026705, 0.0010869, -7.2511E-4, -0.0025439, -0.0041336, -0.0052788, -0.0058077, -0.0056185, -0.0046979, -0.0031235, -0.0010625, 0.0012472, 0.0035218, 0.005466, 
    0.0068099, 0.0073449, 0.0069525, 0.0056265, 0.0034784, 7.3321E-4, -0.0022942, -0.005233, -0.007697, -0.0093357, -0.0098779, -0.0091724, -0.0072151, -0.0041599, -3.1209E-4, 0.0038988, 0.007962, 0.011341, 0.013538, 0.014156, 0.012956, 0.0099028, 0.0051811, -7.971E-4, -0.0074221, -0.013934, -0.019491, -0.023251, -0.024456, -0.02252, -0.017099, -0.0081382, 0.0040987, 0.019038, 0.035829, 0.053411, 0.070595, 0.086169, 0.098999, 0.10813, 0.11288, 0.11288, 0.10813, 0.098999, 0.086169, 0.070595, 0.053411, 
    0.035829, 0.019038, 0.0040987, -0.0081382, -0.017099, -0.02252, -0.024456, -0.023251, -0.019491, -0.013934, -0.0074221, -7.971E-4, 0.0051811, 0.0099028, 0.012956, 0.014156, 0.013538, 0.011341, 0.007962, 0.0038988, -3.1209E-4, -0.0041599, -0.0072151, -0.0091724, -0.0098779, -0.0093357, -0.007697, -0.005233, -0.0022942, 7.3321E-4, 0.0034784, 0.0056265, 0.0069525, 0.0073449, 0.0068099, 0.005466, 0.0035218, 0.0012472, -0.0010625, -0.0031235, -0.0046979, -0.0056185, -0.0058077, -0.0052788, -0.0041336, 
    -0.0025439, -7.2511E-4, 0.0010869, 0.0026705, 0.0038421, 0.0044775, 0.0045239, 0.0040027, 0.0030042, 0.0016733, 1.8871E-4, -0.0012601, -0.0024966, -0.0033791, -0.0038134, -0.0037692, -0.0032709, -0.0024011, -0.0012848, -7.0093E-5, 0.0010884, 0.0020504, 0.002705, 0.0029846, 0.0028705, 0.0023941, 0.0016291, 6.8312E-4, -3.2129E-4, -0.0012556, -0.0020096, -0.0024998, -0.0026728, -0.002526, 0.0035218, 0.0012472, -0.0010625, -0.0031235, -0.0046979, -0.0056185, -0.0058077, -0.0052788, -0.0041336, -0.0025439, 
    -7.2511E-4, 0.0010869, 0.0026705, 0.0038421, 0.0044775, 0.0045239, 0.0040027, 0.0030042, 0.0016733, 1.8871E-4, -0.0012601, -0.0024966, -0.0033791, -0.0038134, -0.0037692, -0.0032709, -0.0024011, -0.0012848, -7.0093E-5, 0.0010884, 0.0020504, 0.002705, 0.0029846, 0.0028705, 0.0023941, 0.0016291, 6.8312E-4, -3.2129E-4, -0.0012556, -0.0020096, -0.0024998, -0.0026728, -0.002526, -0.0020901, -0.0014333, -6.4513E-4, 1.6944E-4, 9.0902E-4, 0.0014834, 0.0018299, 0.0019135, 0.0017366, 0.0013306, 7.5528E-4, 
    9.2361E-5, -5.8255E-4, -0.0011768, -0.0016225, -0.0018764, -0.0019133, -0.0017416, -0.001389, -9.1186E-4, -3.7203E-4, 1.5494E-4, 6.0906E-4, 9.2941E-4, 0.0010912, 0.0010664, 8.8996E-4, 5.6517E-4, 1.358E-4, -3.0836E-4, -7.4253E-4, -0.0011019, -0.0013571, -0.0014733, -0.0014506, -0.0012935, -0.0010355, -7.0991E-4, -3.6771E-4, -4.8621E-5, 2.0264E-4, 3.6183E-4, 0.0084619];
    var const_tbl__aa = [-6.0729E-4, 0.005547, 0.0012025, 5.5133E-4, 1.6992E-4, -2.3195E-4, -5.9426E-4, -8.2206E-4, -8.4752E-4, -6.5061E-4, -2.6977E-4, 2.0642E-4, 6.5721E-4, 9.6247E-4, 0.001032, 8.3416E-4, 4.0395E-4, -1.5769E-4, -7.1117E-4, -0.0011087, -0.0012377, -0.0010475, -5.7139E-4, 8.2522E-5, 7.5058E-4, 0.001259, 0.001464, 0.0012963, 7.7829E-4, 2.8808E-5, -7.6962E-4, -0.0014083, -0.001713, -0.0015833, -0.001033, -1.8129E-4, 7.6089E-4, 0.0015551, 0.0019797, 0.0019098, 0.0013313, 3.7702E-4, -7.2555E-4, 
    -0.0016986, -0.0022625, -0.0022768, -0.0016922, -6.3215E-4, 6.491E-4, 0.0018212, 0.002576, 0.0026933, 0.0021119, 9.4722E-4, -5.2351E-4, -0.0019315, -0.0029037, -0.0031646, -0.002609, -0.0013427, 3.3954E-4, 0.0020171, 0.0032517, 0.0036965, 0.003196, 0.0018324, -8.0558E-5, -0.0020711, -0.0036212, -0.004303, -0.0038921, -0.0024398, -2.7089E-4, 0.0020837, 0.0040178, 0.0050015, 0.0047273, 0.003197, 7.4395E-4, -0.0020419, -0.0044463, -0.0058212, -0.0057441, -0.0041549, -0.0013781, 0.0019266, 0.004923, 
    0.0068105, 0.0070197, 0.0053925, 0.0022394, -0.00171, -0.0054734, -0.0080484, -0.0086754, -0.0070524, -0.0034446, 0.001345, 0.0061452, 0.0096921, 0.010951, 0.009402, 0.0052149, -7.3621E-4, -0.0070399, -0.012063, -0.014353, -0.013025, -0.0080465, -3.2853E-4, 0.0084029, 0.015957, 0.020176, 0.019477, 0.013318, 0.0024682, -0.010997, -0.023996, -0.032993, -0.034705, -0.026822, -0.0085825, 0.018925, 0.052806, 0.088761, 0.12179, 0.14705, 0.16074, 0.16074, 0.14705, 0.12179, 0.088761, 0.052806, 0.018925, 
    -0.0085825, -0.026822, -0.034705, -0.032993, -0.023996, -0.010997, 0.0024682, 0.013318, 0.019477, 0.020176, 0.015957, 0.0084029, -3.2853E-4, -0.0080465, -0.013025, -0.014353, -0.012063, -0.0070399, -7.3621E-4, 0.0052149, 0.009402, 0.010951, 0.0096921, 0.0061452, 0.001345, -0.0034446, -0.0070524, -0.0086754, -0.0080484, -0.0054734, -0.00171, 0.0022394, 0.0053925, 0.0070197, 0.0068105, 0.004923, 0.0019266, -0.0013781, -0.0041549, -0.0057441, -0.0058212, -0.0044463, -0.0020419, 7.4395E-4, 0.003197, 
    0.0047273, 0.0050015, 0.0040178, 0.0020837, -2.7089E-4, -0.0024398, -0.0038921, -0.004303, -0.0036212, -0.0020711, -8.0558E-5, 0.0018324, 0.003196, 0.0036965, 0.0032517, 0.0020171, 3.3954E-4, -0.0013427, -0.002609, -0.0031646, -0.0029037, -0.0019315, -5.2351E-4, 9.4722E-4, 0.0021119, 0.0026933, 0.002576, 0.0018212, 6.491E-4, -6.3215E-4, -0.0016922, -0.0022768, -0.0022625, -0.0016986, -7.2555E-4, 3.7702E-4, 0.0013313, 0.0019098, 0.0019797, 0.0015551, 7.6089E-4, -1.8129E-4, -0.001033, -0.0015833, 
    -0.001713, -0.0014083, -7.6962E-4, 2.8808E-5, 7.7829E-4, 0.0012963, 0.001464, 0.001259, 7.5058E-4, 8.2522E-5, -5.7139E-4, -0.0010475, -0.0012377, -0.0011087, -7.1117E-4, -1.5769E-4, 4.0395E-4, 8.3416E-4, 0.001032, 9.6247E-4, 6.5721E-4, 2.0642E-4, -2.6977E-4, -6.5061E-4, -8.4752E-4, -8.2206E-4, -5.9426E-4, -2.3195E-4, 1.6992E-4, 5.5133E-4, 0.0012025, 0.005547, -6.0729E-4];
    var const_tbl__oa = [-0.0057279, -3.55E-4, -3.4657E-4, -3.2265E-4, -2.8568E-4, -2.3281E-4, -1.673E-4, -8.6773E-5, 4.4005E-6, 1.0817E-4, 2.1895E-4, 3.3872E-4, 4.6081E-4, 5.89E-4, 7.1566E-4, 8.5449E-4, 9.6872E-4, 0.0010826, 0.0011887, 0.0012785, 0.0013539, 0.0014097, 0.0014451, 0.0014572, 0.0014449, 0.0014071, 0.0013429, 0.001253, 0.0011363, 9.944E-4, 8.2476E-4, 6.3679E-4, 4.284E-4, 2.0073E-4, -3.878E-5, -2.8944E-4, -5.4502E-4, -8.0225E-4, -0.0010553, -0.0012998, -0.0015302, -0.001742, -0.00193, -0.0020897, 
    -0.0022163, -0.0023046, -0.0023534, -0.0023594, -0.0023179, -0.0022306, -0.0020944, -0.0019112, -0.0016809, -0.0014065, -0.0010903, -7.3703E-4, -3.507E-4, 6.2545E-5, 4.9677E-4, 9.4413E-4, 0.0013968, 0.001847, 0.0022869, 0.0027056, 0.0030964, 0.003449, 0.0037558, 0.0040081, 0.0041989, 0.0043211, 0.0043693, 0.0043381, 0.0042245, 0.0040256, 0.0037411, 0.0033716, 0.0029193, 0.002387, 0.0017819, 0.0011093, 3.7879E-4, -4.0024E-4, -0.0012159, -0.002056, -0.0029064, -0.0037527, -0.0045791, -0.0053699, 
    -0.0061082, -0.006778, -0.007363, -0.0078475, -0.0082153, -0.0084535, -0.0085479, -0.0084873, -0.0082614, -0.007862, -0.0072826, -0.0065194, -0.00557, -0.0044354, -0.0031181, -0.0016241, 3.9188E-5, 0.0018614, 0.00383, 0.0059296, 0.008144, 0.010454, 0.012839, 0.015277, 0.017745, 0.020218, 0.022673, 0.025085, 0.027427, 0.029676, 0.031808, 0.0338, 0.035631, 0.037279, 0.038728, 0.039961, 0.040964, 0.041727, 0.04224, 0.042498, 0.042498, 0.04224, 0.041727, 0.040964, 0.039961, 0.038728, 0.037279, 0.035631, 
    0.0338, 0.031808, 0.029676, 0.027427, 0.025085, 0.022673, 0.020218, 0.017745, 0.015277, 0.012839, 0.010454, 0.008144, 0.0059296, 0.00383, 0.0018614, 3.9188E-5, -0.0016241, -0.0031181, -0.0044354, -0.00557, -0.0065194, -0.0072826, -0.007862, -0.0082614, -0.0084873, -0.0085479, -0.0084535, -0.0082153, -0.0078475, -0.007363, -0.006778, -0.0061082, -0.0053699, -0.0045791, -0.0037527, -0.0029064, -0.002056, -0.0012159, -4.0024E-4, 3.7879E-4, 0.0011093, 0.0017819, 0.002387, 0.0029193, 0.0033716, 0.0037411, 
    0.0040256, 0.0042245, 0.0043381, 0.0043693, 0.0043211, 0.0041989, 0.0040081, 0.0037558, 0.003449, 0.0030964, 0.0027056, 0.0022869, 0.001847, 0.0013968, 9.4413E-4, 4.9677E-4, 6.2545E-5, -3.507E-4, -7.3703E-4, -0.0010903, -0.0014065, -0.0016809, -0.0019112, -0.0020944, -0.0022306, -0.0023179, -0.0023594, -0.0023534, -0.0023046, -0.0022163, -0.0020897, -0.00193, -0.001742, -0.0015302, -0.0012998, -0.0010553, -8.0225E-4, -5.4502E-4, -2.8944E-4, -3.878E-5, 2.0073E-4, 4.284E-4, 6.3679E-4, 8.2476E-4, 
    9.944E-4, 0.0011363, 0.001253, 0.0013429, 0.0014071, 0.0014449, 0.0014572, 0.0014451, 0.0014097, 0.0013539, 0.0012785, 0.0011887, 0.0010826, 9.6872E-4, 8.5449E-4, 7.1566E-4, 5.89E-4, 4.6081E-4, 3.3872E-4, 2.1895E-4, 1.0817E-4, 4.4005E-6, -8.6773E-5, -1.673E-4, -2.3281E-4, -2.8568E-4, -3.2265E-4, -3.4657E-4, -3.55E-4, -0.0057279];
    var const_tbl__pa = [1.4796E-5, 5.4604E-4, 1.0129E-4, -1.1334E-6, -1.3189E-4, -1.9395E-4, -1.3571E-4, 2.1337E-5, 1.8632E-4, 2.5029E-4, 1.5699E-4, -5.2509E-5, -2.543E-4, -3.138E-4, -1.739E-4, 9.7403E-5, 3.3704E-4, 3.8346E-4, 1.8391E-4, -1.5855E-4, -4.3525E-4, -4.5776E-4, -1.8388E-4, 2.3889E-4, 5.5005E-4, 5.3497E-4, 1.7021E-4, -3.4174E-4, -6.8209E-4, -6.1268E-4, -1.3912E-4, 4.6928E-4, 8.3027E-4, 6.8693E-4, 8.6099E-5, -6.2455E-4, -9.9487E-4, -7.5513E-4, -6.7519E-6, 8.1051E-4, 0.0011744, 8.1167E-4, -1.0417E-4, 
    -0.0010287, -0.001367, -8.5273E-4, 2.5207E-4, 0.0012819, 0.0015701, 8.7113E-4, -4.4169E-4, -0.0015723, -0.0017801, -8.6101E-4, 6.801E-4, 0.0019007, 0.0019933, 8.1468E-4, -9.7311E-4, -0.0022683, -0.0022045, -7.237E-4, 0.0013276, 0.0026763, 0.002408, 5.7881E-4, -0.0017511, -0.0031255, -0.0025968, -3.6912E-4, 0.0022518, 0.0036165, 0.0027634, 8.2343E-5, -0.0028398, -0.0041506, -0.0028982, 2.9666E-4, 0.0035272, 0.0047294, 0.0029905, -7.8603E-4, -0.0043296, -0.0053562, -0.0030274, 0.0014094, 0.0052683, 
    0.0060364, 0.0029929, -0.0021982, -0.0063734, -0.0067797, -0.0028658, 0.003197, 0.0076896, 0.0076028, 0.0026174, -0.0044718, -0.0092868, -0.008534, -0.0022054, 0.0061279, 0.01128, 0.0096244, 0.0015614, -0.0083444, -0.013874, -0.010969, -5.6468E-4, 0.011455, 0.017461, 0.01276, -0.0010262, -0.016164, -0.022908, -0.015444, 0.0037854, 0.024249, 0.03255, 0.020318, -0.0095077, -0.041874, -0.055528, -0.033308, 0.02819, 0.11468, 0.19857, 0.25007, 0.25007, 0.19857, 0.11468, 0.02819, -0.033308, -0.055528, 
    -0.041874, -0.0095077, 0.020318, 0.03255, 0.024249, 0.0037854, -0.015444, -0.022908, -0.016164, -0.0010262, 0.01276, 0.017461, 0.011455, -5.6468E-4, -0.010969, -0.013874, -0.0083444, 0.0015614, 0.0096244, 0.01128, 0.0061279, -0.0022054, -0.008534, -0.0092868, -0.0044718, 0.0026174, 0.0076028, 0.0076896, 0.003197, -0.0028658, -0.0067797, -0.0063734, -0.0021982, 0.0029929, 0.0060364, 0.0052683, 0.0014094, -0.0030274, -0.0053562, -0.0043296, -7.8603E-4, 0.0029905, 0.0047294, 0.0035272, 2.9666E-4, 
    -0.0028982, -0.0041506, -0.0028398, 8.2343E-5, 0.0027634, 0.0036165, 0.0022518, -3.6912E-4, -0.0025968, -0.0031255, -0.0017511, 5.7881E-4, 0.002408, 0.0026763, 0.0013276, -7.237E-4, -0.0022045, -0.0022683, -9.7311E-4, 8.1468E-4, 0.0019933, 0.0019007, 6.801E-4, -8.6101E-4, -0.0017801, -0.0015723, -4.4169E-4, 8.7113E-4, 0.0015701, 0.0012819, 2.5207E-4, -8.5273E-4, -0.001367, -0.0010287, -1.0417E-4, 8.1167E-4, 0.0011744, 8.1051E-4, -6.7519E-6, -7.5513E-4, -9.9487E-4, -6.2455E-4, 8.6099E-5, 6.8693E-4, 
    8.3027E-4, 4.6928E-4, -1.3912E-4, -6.1268E-4, -6.8209E-4, -3.4174E-4, 1.7021E-4, 5.3497E-4, 5.5005E-4, 2.3889E-4, -1.8388E-4, -4.5776E-4, -4.3525E-4, -1.5855E-4, 1.8391E-4, 3.8346E-4, 3.3704E-4, 9.7403E-5, -1.739E-4, -3.138E-4, -2.543E-4, -5.2509E-5, 1.5699E-4, 2.5029E-4, 1.8632E-4, 2.1337E-5, -1.3571E-4, -1.9395E-4, -1.3189E-4, -1.1334E-6, 1.0129E-4, 5.4604E-4, 1.4796E-5];
    var const_tbl__La = [4.846206E-4, 3.218322E-4, 3.870879E-4, 4.263937E-4, 4.294803E-4, 3.876866E-4, 2.978334E-4, 1.628906E-4, -6.746E-6, -1.976636E-4, -3.887846E-4, -5.583476E-4, -6.843798E-4, -7.475333E-4, -7.360876E-4, -6.458231E-4, -4.834126E-4, -2.654101E-4, -1.72358E-5, 2.297496E-4, 4.414505E-4, 5.867386E-4, 6.40364E-4, 5.889058E-4, 4.320051E-4, 1.84623E-4, -1.245772E-4, -4.557272E-4, -7.630407E-4, -0.0010001924, -0.0011278035, -0.0011186013, -9.630688E-4, -6.715766E-4, -2.747173E-4, 1.796051E-4, 6.316952E-4, 
    0.0010178421, 0.0012788905, 0.0013693135, 0.0012644532, 9.656565E-4, 5.020083E-4, -7.20758E-5, -6.82586E-4, -0.0012452921, -0.001676923, -0.0019071107, -0.0018892901, -0.0016090151, -0.0010880322, -3.838639E-4, 4.162385E-4, 0.0012055137, 0.0018717189, 0.0023126901, 0.0024515221, 0.0022491337, 0.001712324, 8.956676E-4, -1.030426E-4, -0.0011539845, -0.0021116455, -0.0028343942, -0.0032049046, -0.0031482203, -0.0026451434, -0.0017384393, -5.307213E-4, 8.263157E-4, 0.0021501888, 0.0032516099, 0.0039606691, 
    0.0041522226, 0.0037662639, 0.0028206105, 0.0014132717, -2.862273E-4, -0.0020562471, -0.0036508477, -0.0048329708, -0.0054082689, -0.0052553028, -0.0043473176, -0.0027622291, -6.785974E-4, 0.0016427351, 0.0038897014, 0.0057392293, 0.0069017337, 0.0071638948, 0.0064237642, 0.0047128748, 0.0022013269, -8.158008E-4, -0.0039503266, -0.0067678548, -0.0088444407, -0.0098259631, -0.0094824393, -0.0077495259, -0.004750882, -7.96851E-4, 0.003641892, 0.0079842451, 0.0116072743, 0.0139260255, 0.0144751543, 
    0.0129821211, 0.0094221367, 0.0040467651, -0.002619195, -0.0098143027, -0.0166082859, -0.0219950434, -0.0250012628, -0.0247990241, -0.0208094743, -0.0127853572, -8.61941E-4, 0.0144307224, 0.0321972603, 0.0512463819, 0.0701941201, 0.08759059, 0.1020573346, 0.1124206916, 0.1178269679, 0.1178269679, 0.1124206916, 0.1020573346, 0.08759059, 0.0701941201, 0.0512463819, 0.0321972603, 0.0144307224, -8.61941E-4, -0.0127853572, -0.0208094743, -0.0247990241, -0.0250012628, -0.0219950434, -0.0166082859, 
    -0.0098143027, -0.002619195, 0.0040467651, 0.0094221367, 0.0129821211, 0.0144751543, 0.0139260255, 0.0116072743, 0.0079842451, 0.003641892, -7.96851E-4, -0.004750882, -0.0077495259, -0.0094824393, -0.0098259631, -0.0088444407, -0.0067678548, -0.0039503266, -8.158008E-4, 0.0022013269, 0.0047128748, 0.0064237642, 0.0071638948, 0.0069017337, 0.0057392293, 0.0038897014, 0.0016427351, -6.785974E-4, -0.0027622291, -0.0043473176, -0.0052553028, -0.0054082689, -0.0048329708, -0.0036508477, -0.0020562471, 
    -2.862273E-4, 0.0014132717, 0.0028206105, 0.0037662639, 0.0041522226, 0.0039606691, 0.0032516099, 0.0021501888, 8.263157E-4, -5.307213E-4, -0.0017384393, -0.0026451434, -0.0031482203, -0.0032049046, -0.0028343942, -0.0021116455, -0.0011539845, -1.030426E-4, 8.956676E-4, 0.001712324, 0.0022491337, 0.0024515221, 0.0023126901, 0.0018717189, 0.0012055137, 4.162385E-4, -3.838639E-4, -0.0010880322, -0.0016090151, -0.0018892901, -0.0019071107, -0.001676923, -0.0012452921, -6.82586E-4, -7.20758E-5, 5.020083E-4, 
    9.656565E-4, 0.0012644532, 0.0013693135, 0.0012788905, 0.0010178421, 6.316952E-4, 1.796051E-4, -2.747173E-4, -6.715766E-4, -9.630688E-4, -0.0011186013, -0.0011278035, -0.0010001924, -7.630407E-4, -4.557272E-4, -1.245772E-4, 1.84623E-4, 4.320051E-4, 5.889058E-4, 6.40364E-4, 5.867386E-4, 4.414505E-4, 2.297496E-4, -1.72358E-5, -2.654101E-4, -4.834126E-4, -6.458231E-4, -7.360876E-4, -7.475333E-4, -6.843798E-4, -5.583476E-4, -3.887846E-4, -1.976636E-4, -6.746E-6, 1.628906E-4, 2.978334E-4, 3.876866E-4, 
    4.294803E-4, 4.263937E-4, 3.870879E-4, 3.218322E-4, 4.846206E-4];
    var const_tbl__Ma = [-1.47942E-4, -4.63086E-4, -5.43866E-4, -8.37905E-4, -0.001014311, -0.00116118, -0.001180796, -0.001076634, -8.36391E-4, -4.92451E-4, -9.4469E-5, 2.87595E-4, 5.82401E-4, 7.30717E-4, 7.01055E-4, 4.9903E-4, 1.69525E-4, -2.11135E-4, -5.51117E-4, -7.64022E-4, -7.90178E-4, -6.13389E-4, -2.67748E-4, 1.67964E-4, 5.87153E-4, 8.80407E-4, 9.63624E-4, 8.01554E-4, 4.19872E-4, -9.7144E-5, -6.23995E-4, -0.001024122, -0.001184736, -0.001047445, -6.27522E-4, -1.5309E-5, 6.42685E-4, 0.001177774, 0.001441643, 
    0.001347024, 8.94359E-4, 1.77665E-4, -6.33187E-4, -0.001332504, -0.001730079, -0.001701687, -0.001226744, -4.00227E-4, 5.84703E-4, 0.001480338, 0.002046494, 0.002113569, 0.001631749, 6.92239E-4, -4.88223E-4, -0.001615646, -0.002391073, -0.002589193, -0.002121436, -0.001068587, 3.30072E-4, 0.001729551, 0.002762744, 0.003135904, 0.002709835, 0.001546543, -9.4626E-5, -0.001812887, -0.003161817, -0.00376451, -0.003416048, -0.002148579, -2.37525E-4, 0.001855519, 0.003592039, 0.004493442, 0.004269849, 
    0.002908814, 6.95458E-4, -0.001842797, -0.004059329, -0.005350342, -0.005315623, -0.003877314, -0.001320828, 0.001755334, 0.004576368, 0.006381587, 0.006625592, 0.005135045, 0.002180561, -0.001563598, -0.005167068, -0.00766869, -0.008325453, -0.006823363, -0.003391342, 0.001216581, 0.005877394, 0.00936274, 0.010650623, 0.009208796, 0.005175064, -6.20228E-4, -0.006807588, -0.011783774, -0.014104442, -0.012872482, -0.008024648, -4.34977E-4, 0.008206407, 0.015731357, 0.019986001, 0.019373693, 0.013324602, 
    0.002574305, -0.010829893, -0.023820926, -0.032862179, -0.034655123, -0.026862623, -0.008693659, 0.018783377, 0.052680302, 0.088692158, 0.121798708, 0.147134469, 0.160859545, 0.160859545, 0.147134469, 0.121798708, 0.088692158, 0.052680302, 0.018783377, -0.008693659, -0.026862623, -0.034655123, -0.032862179, -0.023820926, -0.010829893, 0.002574305, 0.013324602, 0.019373693, 0.019986001, 0.015731357, 0.008206407, -4.34977E-4, -0.008024648, -0.012872482, -0.014104442, -0.011783774, -0.006807588, 
    -6.20228E-4, 0.005175064, 0.009208796, 0.010650623, 0.00936274, 0.005877394, 0.001216581, -0.003391342, -0.006823363, -0.008325453, -0.00766869, -0.005167068, -0.001563598, 0.002180561, 0.005135045, 0.006625592, 0.006381587, 0.004576368, 0.001755334, -0.001320828, -0.003877314, -0.005315623, -0.005350342, -0.004059329, -0.001842797, 6.95458E-4, 0.002908814, 0.004269849, 0.004493442, 0.003592039, 0.001855519, -2.37525E-4, -0.002148579, -0.003416048, -0.00376451, -0.003161817, -0.001812887, -9.4626E-5, 
    0.001546543, 0.002709835, 0.003135904, 0.002762744, 0.001729551, 3.30072E-4, -0.001068587, -0.002121436, -0.002589193, -0.002391073, -0.001615646, -4.88223E-4, 6.92239E-4, 0.001631749, 0.002113569, 0.002046494, 0.001480338, 5.84703E-4, -4.00227E-4, -0.001226744, -0.001701687, -0.001730079, -0.001332504, -6.33187E-4, 1.77665E-4, 8.94359E-4, 0.001347024, 0.001441643, 0.001177774, 6.42685E-4, -1.5309E-5, -6.27522E-4, -0.001047445, -0.001184736, -0.001024122, -6.23995E-4, -9.7144E-5, 4.19872E-4, 
    8.01554E-4, 9.63624E-4, 8.80407E-4, 5.87153E-4, 1.67964E-4, -2.67748E-4, -6.13389E-4, -7.90178E-4, -7.64022E-4, -5.51117E-4, -2.11135E-4, 1.69525E-4, 4.9903E-4, 7.01055E-4, 7.30717E-4, 5.82401E-4, 2.87595E-4, -9.4469E-5, -4.92451E-4, -8.36391E-4, -0.001076634, -0.001180796, -0.00116118, -0.001014311, -8.37905E-4, -5.43866E-4, -4.63086E-4, -1.47942E-4];
    var const_tbl__Na = [-1.559505E-4, -7.98112E-5, -9.80814E-5, -1.173125E-4, -1.369746E-4, -1.565189E-4, -1.753732E-4, -1.929362E-4, -2.083552E-4, -2.206804E-4, -2.291911E-4, -2.333843E-4, -2.318305E-4, -2.244133E-4, -2.102E-4, -1.887765E-4, -1.597355E-4, -1.22856E-4, -7.82038E-5, -2.59739E-5, 3.34012E-5, 9.91605E-5, 1.702513E-4, 2.45599E-4, 3.235647E-4, 4.025475E-4, 4.805722E-4, 5.555847E-4, 6.253709E-4, 6.875873E-4, 7.399121E-4, 7.800625E-4, 8.058147E-4, 8.15116E-4, 8.062358E-4, 7.776257E-4, 7.282308E-4, 
    6.573325E-4, 5.647707E-4, 4.50904E-4, 3.166371E-4, 1.635138E-4, -6.3141E-6, -1.901069E-4, -3.845389E-4, -5.857031E-4, -7.892655E-4, -9.904092E-4, -0.001184062, -0.0013648737, -0.0015274109, -0.0016662822, -0.0017762342, -0.0018523274, -0.0018900859, -0.0018856324, -0.0018358173, -0.0017383931, -0.0015920662, -0.0013966904, -0.0011532549, -8.640083E-4, -5.324827E-4, -1.6347E-4, 2.369773E-4, 6.616157E-4, 0.0011021011, 0.0015491213, 0.0019925324, 0.0024215833, 0.0028250632, 0.0031916142, 0.0035099281, 
    0.0037690342, 0.0039585921, 0.0040691533, 0.0040924552, 0.0040216824, 0.0038517234, 0.0035793947, 0.003203659, 0.0027257456, 0.0021493323, 0.0014805737, 7.281494E-4, -9.67559E-5, -9.805496E-4, -0.0019073471, -0.002859177, -0.0038162186, -0.0047570964, -0.0056592108, -0.0064991489, -0.0072530544, -0.0078971131, -0.0084079899, -0.0087633047, -0.0089421178, -0.008925372, -0.0086963572, -0.0082411169, -0.0075488253, -0.0066121147, -0.0054273698, -0.0039949083, -0.0023191615, -4.087211E-4, 0.0017236549, 
    0.0040611162, 0.0065829025, 0.0092645575, 0.0120782551, 0.0149931771, 0.0179759604, 0.0209911855, 0.0240019478, 0.0269704134, 0.0298584578, 0.0326282789, 0.035243024, 0.0376674322, 0.0398684103, 0.0418156203, 0.0434819958, 0.0448442166, 0.0458831097, 0.046584001, 0.0469369495, 0.0469369495, 0.046584001, 0.0458831097, 0.0448442166, 0.0434819958, 0.0418156203, 0.0398684103, 0.0376674322, 0.035243024, 0.0326282789, 0.0298584578, 0.0269704134, 0.0240019478, 0.0209911855, 0.0179759604, 0.0149931771, 
    0.0120782551, 0.0092645575, 0.0065829025, 0.0040611162, 0.0017236549, -4.087211E-4, -0.0023191615, -0.0039949083, -0.0054273698, -0.0066121147, -0.0075488253, -0.0082411169, -0.0086963572, -0.008925372, -0.0089421178, -0.0087633047, -0.0084079899, -0.0078971131, -0.0072530544, -0.0064991489, -0.0056592108, -0.0047570964, -0.0038162186, -0.002859177, -0.0019073471, -9.805496E-4, -9.67559E-5, 7.281494E-4, 0.0014805737, 0.0021493323, 0.0027257456, 0.003203659, 0.0035793947, 0.0038517234, 0.0040216824, 
    0.0040924552, 0.0040691533, 0.0039585921, 0.0037690342, 0.0035099281, 0.0031916142, 0.0028250632, 0.0024215833, 0.0019925324, 0.0015491213, 0.0011021011, 6.616157E-4, 2.369773E-4, -1.6347E-4, -5.324827E-4, -8.640083E-4, -0.0011532549, -0.0013966904, -0.0015920662, -0.0017383931, -0.0018358173, -0.0018856324, -0.0018900859, -0.0018523274, -0.0017762342, -0.0016662822, -0.0015274109, -0.0013648737, -0.001184062, -9.904092E-4, -7.892655E-4, -5.857031E-4, -3.845389E-4, -1.901069E-4, -6.3141E-6, 1.635138E-4, 
    3.166371E-4, 4.50904E-4, 5.647707E-4, 6.573325E-4, 7.282308E-4, 7.776257E-4, 8.062358E-4, 8.15116E-4, 8.058147E-4, 7.800625E-4, 7.399121E-4, 6.875873E-4, 6.253709E-4, 5.555847E-4, 4.805722E-4, 4.025475E-4, 3.235647E-4, 2.45599E-4, 1.702513E-4, 9.91605E-5, 3.34012E-5, -2.59739E-5, -7.82038E-5, -1.22856E-4, -1.597355E-4, -1.887765E-4, -2.102E-4, -2.244133E-4, -2.318305E-4, -2.333843E-4, -2.291911E-4, -2.206804E-4, -2.083552E-4, -1.929362E-4, -1.753732E-4, -1.565189E-4, -1.369746E-4, -1.173125E-4, 
    -9.80814E-5, -7.98112E-5, -1.559505E-4];
    var const_tbl__Wa = [7.0433E-5, -1.0611E-5, -8.6755E-5, -1.81287E-4, -2.40082E-4, -2.16126E-4, -1.04338E-4, 4.4967E-5, 1.48777E-4, 1.41957E-4, 2.4902E-5, -1.26821E-4, -2.06025E-4, -1.44934E-4, 3.0288E-5, 2.06761E-4, 2.55662E-4, 1.2428E-4, -1.1508E-4, -3.01598E-4, -2.92187E-4, -6.8791E-5, 2.32511E-4, 4.01522E-4, 2.98948E-4, -3.3133E-5, -3.8003E-4, -4.90923E-4, -2.57989E-4, 1.88334E-4, 5.47393E-4, 5.48608E-4, 1.52152E-4, -3.96707E-4, -7.15685E-4, -5.49251E-4, 3.1938E-5, 6.48678E-4, 8.57479E-4, 4.66461E-4, 
    -3.00057E-4, -9.23468E-4, -9.38715E-4, -2.77012E-4, 6.4652E-4, 0.001188228, 9.213E-4, -3.4936E-5, -0.001051564, -0.001399457, -7.68199E-4, 4.72146E-4, 0.001478988, 0.00150551, 4.48904E-4, -0.001020195, -0.001876749, -0.001451986, 5.3805E-5, 0.001643867, 0.002179009, 0.001188116, -7.3768E-4, -0.002285796, -0.002311045, -6.74762E-4, 0.001575511, 0.002867565, 0.002196431, -1.07222E-4, -0.002511465, -0.003293514, -0.001765763, 0.001149421, 0.003460246, 0.003457538, 9.66687E-4, -0.002409513, -0.004308854, 
    -0.003251791, 2.2654E-4, 0.003807624, 0.004921598, 0.002577091, -0.001804315, -0.005225193, -0.005147223, -0.001353262, 0.003715307, 0.006506739, 0.004827221, -4.72053E-4, -0.005863008, -0.007463412, -0.003802999, 0.002917889, 0.008104906, 0.007875542, 0.001918029, -0.005970371, -0.010253403, -0.007489417, 9.91323E-4, 0.009592392, 0.012074666, 0.005996842, -0.005130313, -0.013749242, -0.013274935, -0.002967159, 0.010844556, 0.018471983, 0.013448699, -0.002354894, -0.018901844, -0.024024383, -0.011880584, 
    0.011749681, 0.03149634, 0.031517411, 0.006673294, -0.031328123, -0.057596682, -0.046701295, 0.012224635, 0.106626251, 0.203735462, 0.265089227, 0.265089227, 0.203735462, 0.106626251, 0.012224635, -0.046701295, -0.057596682, -0.031328123, 0.006673294, 0.031517411, 0.03149634, 0.011749681, -0.011880584, -0.024024383, -0.018901844, -0.002354894, 0.013448699, 0.018471983, 0.010844556, -0.002967159, -0.013274935, -0.013749242, -0.005130313, 0.005996842, 0.012074666, 0.009592392, 9.91323E-4, -0.007489417, 
    -0.010253403, -0.005970371, 0.001918029, 0.007875542, 0.008104906, 0.002917889, -0.003802999, -0.007463412, -0.005863008, -4.72053E-4, 0.004827221, 0.006506739, 0.003715307, -0.001353262, -0.005147223, -0.005225193, -0.001804315, 0.002577091, 0.004921598, 0.003807624, 2.2654E-4, -0.003251791, -0.004308854, -0.002409513, 9.66687E-4, 0.003457538, 0.003460246, 0.001149421, -0.001765763, -0.003293514, -0.002511465, -1.07222E-4, 0.002196431, 0.002867565, 0.001575511, -6.74762E-4, -0.002311045, -0.002285796, 
    -7.3768E-4, 0.001188116, 0.002179009, 0.001643867, 5.3805E-5, -0.001451986, -0.001876749, -0.001020195, 4.48904E-4, 0.00150551, 0.001478988, 4.72146E-4, -7.68199E-4, -0.001399457, -0.001051564, -3.4936E-5, 9.213E-4, 0.001188228, 6.4652E-4, -2.77012E-4, -9.38715E-4, -9.23468E-4, -3.00057E-4, 4.66461E-4, 8.57479E-4, 6.48678E-4, 3.1938E-5, -5.49251E-4, -7.15685E-4, -3.96707E-4, 1.52152E-4, 5.48608E-4, 5.47393E-4, 1.88334E-4, -2.57989E-4, -4.90923E-4, -3.8003E-4, -3.3133E-5, 2.98948E-4, 4.01522E-4, 
    2.32511E-4, -6.8791E-5, -2.92187E-4, -3.01598E-4, -1.1508E-4, 1.2428E-4, 2.55662E-4, 2.06761E-4, 3.0288E-5, -1.44934E-4, -2.06025E-4, -1.26821E-4, 2.4902E-5, 1.41957E-4, 1.48777E-4, 4.4967E-5, -1.04338E-4, -2.16126E-4, -2.40082E-4, -1.81287E-4, -8.6755E-5, -1.0611E-5, 7.0433E-5];
    var const_tbl__Xa = [-0, 1.983921580729042E-9, 2.075025014186962E-8, 3.7927907418138206E-8, -4.887230166144236E-8, -3.0134222374163864E-7, -5.164096309937236E-7, -2.427802968390461E-7, 7.578872729147132E-7, 1.936347430688365E-6, 1.9928593432900643E-6, -8.833327890479072E-8, -3.633685361514617E-6, -5.926187360916015E-6, -3.888518012581186E-6, 2.9394480591017127E-6, 1.0588006304239223E-5, 1.237826214562279E-5, 4.031116390349734E-6, -1.1335088291765613E-5, -2.3061493034081963E-5, -1.961540997059002E-5, 1.5431926802190891E-6, 
    2.8621954294876678E-5, 4.088648566767064E-5, 2.3477265415246905E-5, -1.825132435020537E-5, -5.725105950936853E-5, -6.105907613427537E-5, -1.7053594043356197E-5, 5.195062551563851E-5, 9.714386172375794E-5, 7.670648103584976E-5, -8.862781061563497E-6, -1.071900971490809E-4, -1.438814388965832E-4, -7.663514640042618E-5, 6.436023256906108E-5, 1.8483229047002838E-4, 1.8712644066413056E-4, 4.5880116008676896E-5, -1.5792930682603264E-4, -2.7937668887359577E-4, -2.098213726073394E-4, 3.2395551495906435E-5, 
    2.930589455766727E-4, 3.7654638964494447E-4, 1.8874570968166178E-4, -1.7350270831694483E-4, -4.643470536990024E-4, -4.518715625944161E-4, -9.69116897109054E-5, 3.864978130696432E-4, 6.538627129366464E-4, 4.7104717629236064E-4, -9.198398143389356E-5, -6.686777487330067E-4, -8.28712043395985E-4, -3.9270823310783866E-4, 3.9723623183352837E-4, 0.0010002233336305977, 9.408119990978091E-4, 1.7393840394085787E-4, -8.235942900930931E-4, -0.0013401798613667298, -9.297114887987371E-4, 2.2166011636270375E-4, 
    0.0013536203297926054, 0.001625025680809726, 7.289057261284617E-4, -8.140758051722581E-4, -0.0019413654191519833, -0.0017708819217589435, -2.7551082980417803E-4, 0.0015964459263299764, 0.0025088515660724045, 0.0016799475403552245, -4.775008778155763E-4, -0.0025256883298749597, -0.0029465993674170333, -0.0012510538277719042, 0.0015479183818790214, 0.0035158825953273166, 0.0031188536220775353, 3.934288998865438E-4, -0.002911574509003463, -0.004435720882383458, -0.0028732671993217467, 9.580060501031196E-4, 
    0.004492124341360815, 0.0051105150595499565, 0.0020536721864262875, -0.0028280591617187907, -0.0061546254603737065, -0.00532785326789502, -5.132327916508329E-4, 0.00518989395341977, 0.007702946112721694, 0.004843818321375578, -0.0018764094264846294, -0.00795915258040955, -0.00887853204366306, -0.0033829208723135, 0.005227159534473934, 0.010995240773062263, 0.009352948365577077, 6.168426802902624E-4, -0.00966135215649298, -0.014110446042209703, -0.008693943602339856, 0.003915133476790796, 0.015397374190484566, 
    0.017086355411157897, 0.006244593993185483, -0.011058960077660544, -0.02300534238884552, -0.019695824886880115, -6.866992974749606E-4, 0.022944702670610186, 0.034335180646351667, 0.021727748934421462, -0.01197169067339667, -0.04751214999276027, -0.057834991721873716, -0.023011276005042925, 0.05665114965901404, 0.15731258350755897, 0.24099996414442773, 0.2734204843167779, 0.24088000924476755, 0.15715600775834096, 0.05656657963472933, -0.022965475738754015, -0.0576911005215651, -0.04737028960461404, 
    -0.011929983013683818, 0.021641222352470783, 0.03418131747512627, 0.022830423052507886, -6.829356867897236E-4, -0.01957801398670588, -0.022856196117738148, -0.010981706488440811, 0.006197827633338942, 0.016949772891467887, 0.015266505785835134, 0.0038798722166704593, -0.008611222788126505, -0.013968994738359393, -0.009559560641714957, 6.100272064271946E-4, 0.009244793393562002, 0.010862414507424608, 0.0051613030636138155, -0.0033385385931099312, -0.008757408589602715, -0.007846392743178783, -0.0018488361106382115, 
    0.004770073070042823, 0.007581570047721741, 0.005105338678589917, -5.04594919508779E-4, -0.005235301544957861, -0.0060443631989364095, -0.0027758458330998117, 0.002014625337202301, 0.005010516416744247, 0.004401720855068482, 9.381884679538007E-4, -0.0028122057691922155, -0.004338929485727358, -0.0028463714895122817, 3.843909322671774E-4, 0.00304538992484389, 0.0034310027900693687, 0.001509632464837753, -0.001219363552568798, -0.002870184664293718, -0.002458654110841795, -4.6453461006792837E-4, 
    0.0016332889986342878, 0.002437601891857792, 0.0015500991660471824, -2.6733649268880465E-4, -0.0017171972803443588, -0.0018812454938858976, -7.88328200468433E-4, 7.053649796246619E-4, 0.0015714450556098374, 0.0013080617120597112, 2.140459851980433E-4, -8.971219193501259E-4, -0.0012922468074570053, -7.935420864160041E-4, 1.6746393274834053E-4, 9.050914761745759E-4, 9.614900857340691E-4, 3.815478122958882E-4, -3.768913505765538E-4, -7.946745133791186E-4, -6.406709346307471E-4, -8.805530189081738E-5, 
    4.505314039847276E-4, 6.248220026463029E-4, 3.6899209418686036E-4, -9.243513793733619E-5, -4.305829732147994E-4, -4.4203308104864386E-4, -1.6499741787650413E-4, 1.793058836278036E-4, 3.573298913174901E-4, 2.7779542909195837E-4, 3.067322823691018E-5, -1.9843183519417632E-4, -2.6388911401853014E-4, -1.489856314871752E-4, 4.322504984248852E-5, 1.7605672395419093E-4, 1.7365080868827324E-4, 6.037689612816951E-5, -7.178033355968087E-5, -1.3454690089842827E-4, -1.0006422984553232E-4, -8.258659148088651E-6, 
    7.1341577759407E-5, 9.016709825391204E-5, 4.811616488886463E-5, -1.575878420452323E-5, -5.628534800592927E-5, -5.2636904285414835E-5, -1.6733101376361367E-5, 2.1458876053844004E-5, 3.724821114596087E-5, 2.598149170172758E-5, 1.3953345414609446E-6, -1.765959612435935E-5, -2.066334928992409E-5, -1.0102757314176758E-5, 3.5716869597612703E-6, 1.089486313183067E-5, 9.249282892585478E-6, 2.5458239847764294E-6, -3.334629820145936E-6, -5.02381657863727E-6, -3.038841994292752E-6, -7.268377549370801E-8, 
    1.6077764054795699E-6, 1.5244467116818205E-6, 5.784008030122593E-7, -1.7787130511403513E-7, -3.577659459539192E-7, -1.9248240664251762E-7, -2.7448753331369325E-8, 1.6838434320997926E-8, 5.184155599280385E-9, -5.037646234529052E-22];
    var const_tbl__S = [0.0065862, -0.0022838, -0.0059202, -0.0112239, -0.0169697, -0.0214685, -0.022742, -0.0189184, -0.0086407, 0.0084932, 0.0316914, 0.0588926, 0.0870663, 0.1126093, 0.1320398, 0.1425063, 0.1425063, 0.1320398, 0.1126093, 0.0870663, 0.0588926, 0.0316914, 0.0084932, -0.0086407, -0.0189184, -0.022742, -0.0214685, -0.0169697, -0.0112239, -0.0059202, -0.0022838, 0.0065862];
    var const_tbl__xa = [-0.0086492, -0.0044524, -0.0043664, -0.0030946, -3.094E-4, 0.0042348, 0.010627, 0.018809, 0.028525, 0.039333, 0.050605, 0.061655, 0.071697, 0.079997, 0.085925, 0.089013, 0.089013, 0.085925, 0.079997, 0.071697, 0.061655, 0.050605, 0.039333, 0.028525, 0.018809, 0.010627, 0.0042348, -3.094E-4, -0.0030946, -0.0043664, -0.0044524, -0.0086492];
    var const_tbl__Ya = [0.0080236, 0.001488, -0.0074204, -0.0175495, -0.0195816, -0.0075536, 0.0136434, 0.0283156, 0.020311, -0.0121801, -0.0489419, -0.0561146, -0.0078976, 0.0922184, 0.2069483, 0.2833355, 0.2833355, 0.2069483, 0.0922184, -0.0078976, -0.0561146, -0.0489419, -0.0121801, 0.020311, 0.0283156, 0.0136434, -0.0075536, -0.0195816, -0.0175495, -0.0074204, 0.001488, 0.0080236];
    
    var Ta = true;
    var Oa = 1000;
    var p = 0.125;
    var muted = false;
    var processStartTime = 0;
    var X = 0;
    var ea = 0;
    var Ka = 0;
    var F = 1;
    var Ia = 0;
    var Da = 0;
    var Ha = 0;
    var lastProcessTime = 0;
    var L = 0;
    var la = 100;
    var qa = 100;
    var Ea = 0;
    var va = 0;
    var ua = "";
    var G = [];
    var Ga = 700;
    var ca_debug2_related = "";
    var currentAudioContext;
    var scriptProcessor;
    var T;
    var currentConvolver;
    var ia;

    var D = []; // playback buffers are stored in here
    
    var ya = 1;
    
    if (currentAudioContext = document.ct) {
      currentAudioContext.sampleRate = audioSampleRate;
      actualAudioSampleRate = audioSampleRate = currentAudioContext.sampleRate;

      try {
        scriptProcessor = currentAudioContext.createScriptProcessor(4096, 0, 1);
      } catch (ex) {
        scriptProcessor = currentAudioContext.createJavaScriptNode(4096, 1, 1);
      }

      scriptProcessor.onaudioprocess = processEvent;
      this._scriptProcessor = scriptProcessor;

      currentConvolver = currentAudioContext.createConvolver();
      scriptProcessor.connect(currentConvolver);

      if (Ca) {
        T = currentAudioContext.createScriptProcessor(4096, 1, 1);
        T.onaudioprocess = Ua;
        currentConvolver.connect(T);
        T.connect(currentAudioContext.destination);
      } else {
        currentConvolver.connect(currentAudioContext.destination);
      }
      
      var channelDataChunk;
      
      if (window.sup_android) {
        playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate);
        channelDataChunk = playbackBuffer.getChannelData(0);
        channelDataChunk.set(const_tbl__S);
        D[0] = playbackBuffer;

        playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate);
        channelDataChunk = playbackBuffer.getChannelData(0);
        channelDataChunk.set(const_tbl__S);
        D[1] = playbackBuffer;

        playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate);
        channelDataChunk = playbackBuffer.getChannelData(0);
        channelDataChunk.set(const_tbl__xa);
        D[2] = playbackBuffer;

        playbackBuffer = currentAudioContext.createBuffer(1, 32, audioSampleRate);
        channelDataChunk = playbackBuffer.getChannelData(0);
        channelDataChunk.set(const_tbl__Ya);
        D[3] = playbackBuffer;

        for (var l = 4; l <= 16; l++) {
          D[l] = D[l - 4];
        }
      } else {
        var S = Math.round(audioSampleRate / 48000);
        
        if (1 > S) {
          S = 1;
        }

        var bufferLength = 512 * S;
        var lots_of_large_tbls = [
          const_tbl__Ma, const_tbl__La, const_tbl__Na, const_tbl__Wa, const_tbl__aa, const_tbl__un, 
          const_tbl__oa, const_tbl__pa, const_tbl__Ma, const_tbl__La, const_tbl__Na, const_tbl__Xa
        ];

        for (aa = 0; aa < lots_of_large_tbls.length; aa++) {
          pa = lots_of_large_tbls[aa];
          var Q = [];
          
          for (var l = 0; l < pa.length; l++) {
            for (playbackBuffer = 0; playbackBuffer < S; playbackBuffer++) {
              Q[l * S + playbackBuffer] = pa[l];
            }
          }

          playbackBuffer = currentAudioContext.createBuffer(1, bufferLength, audioSampleRate);
          channelDataChunk = playbackBuffer.getChannelData(0);
          channelDataChunk.set(Q);
          D[aa] = playbackBuffer;
        }
      }

      currentConvolver.normalize = false;
      currentConvolver.buffer = D[0];
    } else {
      if (window.browsersupporterror) {
        window.browsersupporterror();
      }
    }

    var U;
    var Pa;
    var I;
    var za;
    Q = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    var R = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    var ja = 0;
    var websockStream = new WebSocket("ws://" + window.location.host + "/~~stream");
    websockStream.binaryType = "arraybuffer";
    var M = 0.0625;
    var V = 0;
    var Qa = 0;
    var ka = 0;
    var W = 1;
    var fa = 2;
    var wsMessageReceiveTime;
    var ta = 0;
    var Aa = 0;

    websockStream.onmessage = function(msgEvt) {
      var wsMessageReceiveStartTime = wsMessageReceiveTime;
      wsMessageReceiveTime = (new Date).getTime();
      ta = k;
      var a = (2 * unk_const_5731 + k - t - (wsMessageReceiveTime - processStartTime) * x / 1000) % unk_const_5731;
      var b = a;

      if (a > unk_const_5731 / 2) {
        a = 0;
      }

      if (b > unk_const_5731 / 2) {
        b -= unk_const_5731;
      }

      b /= x;
      M += (W ? 0.1 : 0.01) * (a / x - M);

      if (1000000000 > V) {
        M = p;
      }

      var d = M - p;
      a = Math.abs(1000 * d);

      if (!(500 > a)) {
        a = 500;
      }

      qa += 0.1 * (a - qa);

      if (!(0 <= Z || (L || F))) {
        if (W && 0.05 > Math.abs(d) / p) {
          W = 0;
          B = actualRemoteSampleRate / actualAudioSampleRate / (x / audioSampleRate);
          M = p;
        } else {
          if (0 > b || b > 4 * p) {
            L = 1;
          }

          if (d < 0.25 * -p || d > 0.5 * p) {
            W = 1;
          }

          if (0.01 < Math.abs(d)) {
            if (20 > fa) {
              W = 1;
            }
          }

          a = W ? 1 + 0.1 * d : 1 + 0.01 * d;
          a *= actualRemoteSampleRate / actualAudioSampleRate / (x / audioSampleRate);
          B = W ? a : B + 0.003 * (a - B);
        }
      }

      if (1.005 < B) {
        B = 1.005;
      }

      if (0.995 > B) {
        B = 0.995;
      }

      var soundAppletDebugHtml = 
        Math.round(1000 * b) + 
        " " + Math.round(1000 * p) + 
        " " + Math.round(1000 * M) + 
        " " + Math.round(1000000 * (B - 1)) + 
        " " + W + "<br>";
      soundAppletDebugHtml += Math.round(audioSampleRate) + " " + Math.round(remoteSampleRate) + " " + U;
      soundAppletDebugHtml += currentAudioContext ? " WebAudio " : " none ";
      soundAppletDebugHtml += "f" + $ + " ";
      soundAppletDebugHtml += actualAudioSampleRate.toFixed(2) + " " + actualRemoteSampleRate.toFixed(2);
      soundAppletDebugHtml += "<br>" + Ea + " " + la.toFixed(2) + " " + qa.toFixed(2) + "<br>" + G;
      document.getElementById("soundappletdebug").innerHTML = soundAppletDebugHtml;

      b = new Uint8Array(msgEvt.data);
      var unk_7165 = k;
      lastlen = b.length;

      for (var a = 0; a < b.length; a++) {
        var g = 0;
        var l = 0;

        if ((b[a] & 240) == 240) {
          smeter = 256 * (b[a] & 15) + b[a + 1];

          if (soundApplet.smetercallback) {
            soundApplet.smetercallback(10 * smeter);
          }

          a++;
        } else if (b[a] == 128) {
          ha = 0;
          
          var e;
          for (var e = 0; e <= 128; e++) {
            z[k + e] = const_tbl__Va[b[a + 1 + e]];
          }
          
          k += 128;
          
          if (k >= unk_const_5731) {
            k -= unk_const_5731;
          }
          
          a = a + 128;
          
          for (var m = 0; m <= 20; m++) {
            Q[m] = 0;
            R[m] = 0;
          }

          ja = 0;
        } else if (b[a] > 144 && b[a] < 223) {
          l = 4;
          g = 2;
          I = 14 - (b[a] >> 4);
        } else if ((b[a] & 128) != 128) {
          l = 1;
          g = 2;
        } else if (b[a] == 129) {
          var m = 256 * b[a + 1] + b[a + 2];

          if (m != remoteSampleRate) {
            remoteSampleRate = m;
            Z = k;
          }

          if (audioBroadcastChannel) {
            audioBroadcastChannel.postMessage({ 
              type: "samplerate", 
              samplerate: remoteSampleRate 
            }, "*");
          }

          if (remoteSampleRate >= 0) {
            unk__ret_by_getid = 1;
          } else {
            unk__ret_by_getid = 0;
            stopall();
          }

          a += 2;
        } else if (b[a] == 130) {
          Pa = 256 * b[a + 1] + b[a + 2];

          a += 2;
        } else if (b[a] == 131) {
          za = b[a + 1];
          var m = b[a + 1] & 15;

          if ($ & 2) {
            m += 4;
          }

          if ($ & 4) {
            m += 8;
          }

          if (m != U) {
            U = m;

            if (currentConvolver) {
              currentConvolver.buffer = D[U];
            }
          }

          a++;
        } else if (b[a] == 132) {
          ha += 128;

          for (e = 0; e <= 128; e++) {
            z[k + e] = 0;
          }

          k += 128;

          if (k >= unk_const_5731) {
            k -= unk_const_5731;
          }

          for (var m = 0; m <= 20; m++) {
            Q[m] = 0;
            R[m] = 0;
          }

          ja = 0;
        } else if (b[a] == 133) {
          d = 0x1000000 * (((b[a + 1] & 15) << 16) + (b[a + 2] << 8) + b[a + 3]) + 
                          (b[a + 4] << 16) + (b[a + 5] << 8) + b[a + 6];
          
          var e = b[a + 1] >> 4;
          
          if (soundApplet.truefreqcallback) {
            soundApplet.truefreqcallback(d, e);
          }
          
          a += 6;
        }

        if (g == 2) {
          g = 0;
          ha = 0;

          var m = (za & 16) == 16 ? 12 : 14;
          
          while (g <= 128) {
            d =  b[a + 3] & 255        | 
                (b[a + 2] & 255) << 8  | 
                (b[a + 1] & 255) << 16 | 
                (b[a + 0] & 255) << 24;
            d <<= l;
            
            var e = 0;
            
            var q = 15 - I;
            var u = Pa;

            var unk_tbl_A = [999, 999, 8, 4, 2, 1, 99, 99];

            if (d != 0) {
              while ((d & 0x80000000) == 0 && e < q) {
                d <<= 1;
                e++;
              }
            }

            if (e < q) {
              q = e;
              e++;
              d <<= 1;
            } else {
              q = d >> 24 & 255;
              e += 8;
              d <<= 8;
            }
            
            var s = 0;
            
            if (q >= unk_tbl_A[I]) {
              s++;
            }
            
            if (q >= unk_tbl_A[I - 1]) {
              s++;
            }
            
            if (s > I - 1) {
              s = I - 1;
            }
            
            var A = (d >> 16 & 0xFFFF) >> 17 - I & -1 << s;
            A += q << I - 1;
            if ((d & 1 << 32 - I + s) != 0) {
              A |= (1 << s) - 1;
              A = ~A;
            }
            
            l += e + I - s;
            while (l > 8) {
              a++;
              l -= 8;
            }

            d = 0;
            for (var e = 0; e <= 20; e++) {
              d += Q[e] * R[e];
            }

            d |= 0;
            d = d > 0 ? d >> 12 : d + 0xFFF >> 12;

            u = A * u + u / 2;
            A = u >> 4;

            for (var e = 19; e > 0; e--) {
              Q[e] += -(Q[e] >> 7) + (R[e] * A >> m);

              if (0 == e) {
                break;
              }

              R[e] = R[e - 1];
            }

            R[0] = d + u;
            d = R[0] + (ja >> 4);
            ja = (za & 16) == 16 ? 0 : ja + (R[0] << 4 >> 3);
            z[k++] = d;

            if (k >= unk_const_5731) {
              k -= unk_const_5731;
            }

            g++;
          }

          if (l == 0) {
            a--;
          }
        }
      }

      var unk_1937 = k - unk_7165;

      if (unk_1937 <= 0) {
        unk_1937 += unk_const_5731;
      }

      var unk_1870 = Math.floor(wsMessageReceiveTime - wsMessageReceiveStartTime - 
                                1000 * unk_1937 / actualRemoteSampleRate);

      if (unk_1870 < Ga) {
        if (unk_1870 > G[0]) {
          G[0] = unk_1870;
        }
      }

      if (F > 1) {
        if (wsMessageReceiveTime - wsMessageReceiveStartTime > 1000 * unk_1937 / remoteSampleRate) {
          F++;

          if (F == 2) {
            Da = wsMessageReceiveTime - Ia;
          }
        }
      }

      ka += unk_1937;
      V += 1000 * unk_1937 / remoteSampleRate;

      if (wsMessageReceiveTime < V) {
        V = wsMessageReceiveTime;
      }

      if (ka >= remoteSampleRate) {
        var m = 1000 * (ka / (V - Qa));

        if (m < 1.01 * remoteSampleRate) {
          if (m > 0.99 * remoteSampleRate) {
            actualRemoteSampleRate += (m - actualRemoteSampleRate) / fa;
          }
        }

        ka = 0;
        if (100 > fa) {
          fa++;
        }

        Qa = V;
        V = wsMessageReceiveTime;
        Aa++; // time since last telemetry message?

        if (Aa == 60) {
          Aa = 0;
          var telemetryRequest = newXMLHttpRequest();
          var endpoint = "/~~telem?sdr=" + actualRemoteSampleRate.toFixed(2) + 
                         "&play=" + actualAudioSampleRate.toFixed(2) + 
                         "&resync=" + va + "&tl=" + G + "&s=" + ua + 
                         "&t=" + p.toFixed(3) + "<br>";
          va = 0;
          ua = "";
          telemetryRequest.open("GET", endpoint, true);
          telemetryRequest.send(null);
        }
      }

      if (audioBroadcastChannel) {
        var unk_6517 = unk_7165;

        if (unk_7165 > k) {
          audioBroadcastChannel.postMessage(z.subarray(unk_7165), "*");
          unk_6517 = 0;
        }

        if (k > unk_6517) {
          audioBroadcastChannel.postMessage(z.subarray(unk_6517, k), "*");
        }
      }

      if (N_recording_related && (!Ca && !(ha > 2 * remoteSampleRate))) {
        while (unk_7165 != k) {
          ga += unk_smplrate / remoteSampleRate;

          while (1 <= ga) {
            N_recording_related.setInt16(w, z[unk_7165], true);
            w += 2;
            
            if (w >= Y) {
              var unk_8751 = new ArrayBuffer(Y);
              w = 0;
              N_recording_related = new DataView(unk_8751);
              recordedBufferData.push(unk_8751);
            }

            ga--;
          }

          unk_7165++;
          
          if (unk_7165 >= unk_const_5731) {
            unk_7165 -= unk_const_5731;
          }
        }
      }

      if (ya) {
        var audioStartButton = document.getElementById("audiostartbutton");

        if (audioStartButton) {
          audioStartButton.style.display = "suspended" === currentAudioContext.state ? "block" : "none";
        }

        if (currentAudioContext.state === "running") {
          ya = 0;
        }
      }
    };

    websockStream.onopen = function() {
      soundappletstarted();
    };

    websockStream.onclose = function() {
      for (var c = 0; c < unk_const_5731; c++) {
        z[c] = 0;
      }

      websockStream.onclose = null;
      websockStream.onmessage = null;
      websockStream = null;
    };

    this.setparam = function(c) {
      try {
        websockStream.send("GET /~~param?" + c);
      } catch (f) {}
    };

    this.smeter = function() {
      return 10 * smeter;
    };

    this.getid = function() {
      return unk__ret_by_getid;
    };

    this.mute = function(c) {
      muted = c;

      if (!N_recording_related) {
        if (!audioBroadcastChannel) {
          this.setparam("mute=" + c);
        }
      }
    };

    this.setvolume = function(c) {
      volume = c;
    };

    this.setdelay1 = function(c) {
      Oa = c;
      M = p = c / 8000;
      t = (unk_const_5731 + k - Oa) % unk_const_5731;
    };

    stopall = function() {
      if (currentAudioContext) {
        websockStream.close();
        
        scriptProcessor.onaudioprocess = null;
        scriptProcessor.disconnect();

        channelDataChunk = null;
        D = null;
        this._scriptProcessor = null;
        currentAudioContext = null;
        ia = null;
        currentConvolver = null;
        scriptProcessor = null;
        scriptProcessor.destination = null;
      } else {
        websockStream.close();
      }
    };

    this.restartaudio = function() {
      stopall();
      document.ct = new __AudioContext;
      window.prep_html5sound();
    };

    this.destroy = function() {
      stopall();
      window.soundapplet = null;
    };

    this.rec_start = function(arg1) {
      if (arg1 == undefined) {
        arg1 = 0;
      }

      Ca = arg1;
      w = 0;
      unk_smplrate = remoteSampleRate;
      
      if (arg1) {
        unk_smplrate = audioSampleRate;
      }
      
      ga = 0;
      var c = new ArrayBuffer(Y);
      N_recording_related = new DataView(c);
      recordedBufferData = [c];
      
      if (muted) {
        this.setparam("mute=0");
      }
    };

    this.rec_finish = function() {
      recordedBufferData[recordedBufferData.length - 1] = 
        recordedBufferData[recordedBufferData.length - 1].slice(0, w);
      
      N_recording_related = null;
      
      var recordedDataComplete = {};
      recordedDataComplete.wavdata = recordedBufferData;
      recordedDataComplete.len = (recordedBufferData.length - 1) * Y + w;
      recordedDataComplete.sr = unk_smplrate;

      if (!audioBroadcastChannel) {
        if (muted) {
          this.setparam("mute=1");
        }
      }

      return recordedDataComplete;
    };

    this.rec_length_kB = function() {
      return ((recordedBufferData.length - 1) * Y + w) / 1024;
    };

    this.setbcaudio = function(newChannel) {
      audioBroadcastChannel = newChannel;

      if (muted) {
        if (newChannel) {
          this.setparam("mute=0");
        }

        if (!newChannel) {
          if (!recaudio) {
            this.setparam("mute=1");
          }
        }
      }

      if (newChannel) {
        audioBroadcastChannel.postMessage({ 
          type: "samplerate", 
          samplerate: remoteSampleRate 
        }, "*");
      }
    };

    this.setstereo = function(c) {
      if (0 > c) {
        currentConvolver.disconnect();
        currentConvolver.connect(currentAudioContext.destination);
      } else {
        if (!ia) {
          ia = currentAudioContext.createChannelMerger();
          ia.connect(currentAudioContext.destination);
        }

        currentConvolver.disconnect();
        currentConvolver.connect(ia, 0, c);
      }
    };

    this.setfj = function(c) {
      $ = c;
      c = U & 3;

      if ($ & 2) {
        c += 4;
      }

      if (c != U) {
        U = c;
        if (currentConvolver) {
          currentConvolver.buffer = D[U];
        }
      }
    };

    this.audioresume = function() {
      currentAudioContext.resume();
      var audioStartButton = document.getElementById("audiostartbutton");

      if (audioStartButton) {
        audioStartButton.style.display = "none";
      }

      ya = 0;
    };
  }

  var __AudioContext = window.AudioContext || window.webkitAudioContext;
  
  if (__AudioContext) {
    if (!document.ct) {
      document.ct = new __AudioContext;
    }
    
    var tmpTestConvolver;
    
    try {
      tmpTestConvolver = document.ct.createConvolver;
    } catch (ex) {}

    if (!tmpTestConvolver) {
      document.ct = null;
      sup_webaudio = false;
    }
  }

  var Ba = 0;
  var Ca = 0;
  var unk_const_5731 = 0x8000;
  var Ra = 0;

  window.prep_html5sound = function() {
    window.soundapplet = new SoundApplet;
  };

  prep_html5sound();
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment