1268 lines
562 KiB
JavaScript
1268 lines
562 KiB
JavaScript
|
//Mobile detection///////////////////////////////////////////////////////////////////////////
|
||
|
/* eslint-disable */
|
||
|
const IS_MOBILE = (function (a) {
|
||
|
return (
|
||
|
/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i
|
||
|
.test(
|
||
|
a.substr(0,4)
|
||
|
)
|
||
|
)
|
||
|
// @ts-ignore
|
||
|
})(navigator.userAgent || navigator.vendor || window.opera)
|
||
|
/* eslint-enable */
|
||
|
|
||
|
//Extra Generals///////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
function bodyload(){
|
||
|
disableSFFC();
|
||
|
checkCookie();
|
||
|
if(IS_MOBILE)initformobile();
|
||
|
}
|
||
|
|
||
|
function disableSFFC() {
|
||
|
// Get the current page scroll position
|
||
|
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||
|
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
|
||
|
|
||
|
// if any scroll is attempted, set this to the previous value
|
||
|
window.onscroll = function() {
|
||
|
window.scrollTo(scrollLeft, scrollTop);
|
||
|
};
|
||
|
|
||
|
document.addEventListener('contextmenu', event => event.preventDefault());
|
||
|
document.body.style.overflow = "hidden";
|
||
|
|
||
|
}
|
||
|
|
||
|
//Mobiles routines///////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
function initformobile(){
|
||
|
x = document.getElementById('TX-record');
|
||
|
preventLongPressMenu(x);
|
||
|
x.addEventListener("touchstart", x.onmousedown);
|
||
|
x.addEventListener("touchend", x.onmouseup);
|
||
|
|
||
|
x = document.getElementById('canBFFFT_scale_floor');
|
||
|
x.addEventListener("touchstart", disableScrolling);
|
||
|
x.addEventListener("touchend", enableScrolling);
|
||
|
x = document.getElementById('canBFFFT_scale_multhz');
|
||
|
x.addEventListener("touchstart", disableScrolling);
|
||
|
x.addEventListener("touchend", enableScrolling);
|
||
|
x = document.getElementById('canBFFFT_scale_multdb');
|
||
|
x.addEventListener("touchstart", disableScrolling);
|
||
|
x.addEventListener("touchend", enableScrolling);
|
||
|
x = document.getElementById('canBFFFT_scale_start');
|
||
|
x.addEventListener("touchstart", disableScrolling);
|
||
|
x.addEventListener("touchend", enableScrolling);
|
||
|
}
|
||
|
|
||
|
function absorbEvent_(event) {
|
||
|
var e = event || window.event;
|
||
|
e.preventDefault && e.preventDefault();
|
||
|
e.stopPropagation && e.stopPropagation();
|
||
|
e.cancelBubble = true;
|
||
|
e.returnValue = false;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
function preventLongPressMenu(node) {
|
||
|
node.ontouchstart = absorbEvent_;
|
||
|
node.ontouchmove = absorbEvent_;
|
||
|
node.ontouchend = absorbEvent_;
|
||
|
node.ontouchcancel = absorbEvent_;
|
||
|
}
|
||
|
|
||
|
function disableScrolling(){
|
||
|
var x=window.scrollX;
|
||
|
var y=window.scrollY;
|
||
|
window.onscroll=function(){window.scrollTo(x, y);};
|
||
|
}
|
||
|
|
||
|
function enableScrolling(){
|
||
|
window.onscroll=function(){};
|
||
|
}
|
||
|
|
||
|
//Generals routines///////////////////////////////////////////////////////////////////////////
|
||
|
var poweron = false;
|
||
|
var canvasRXsmeter = "";
|
||
|
var ctxRXsmeter = "";
|
||
|
function powertogle()
|
||
|
{
|
||
|
if(event.srcElement.src.replace(/^.*[\\\/]/, '')=="poweroff.png"){
|
||
|
event.srcElement.src="img/poweron.png";
|
||
|
document.getElementById("ombre-body").style.display = "block";
|
||
|
document.getElementById("pop-upspinner").style.display = "block";
|
||
|
check_connected();
|
||
|
AudioRX_start();
|
||
|
AudioTX_start();
|
||
|
ControlTRX_start();
|
||
|
checklatency();
|
||
|
poweron = true;
|
||
|
|
||
|
canvasRXsmeter = document.getElementById("canRXsmeter");
|
||
|
ctxRXsmeter = canvasRXsmeter.getContext("2d");
|
||
|
initRXSmeter();
|
||
|
|
||
|
button_light_all("div-filtershortcut");
|
||
|
}
|
||
|
else{
|
||
|
event.srcElement.src="img/poweroff.png";
|
||
|
AudioRX_stop();
|
||
|
AudioTX_stop();
|
||
|
ControlTRX_stop();
|
||
|
poweron = false;
|
||
|
button_unlight_all("div-filtershortcut");
|
||
|
button_unlight_all("div-mode_menu");
|
||
|
document.getElementById("div-panfft").style.display = "none";
|
||
|
if (typeof panfft !== 'undefined') {panfft.close();}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
window.addEventListener('beforeunload', function (e) {
|
||
|
if(poweron)e.preventDefault();
|
||
|
if (typeof panfft !== 'undefined') {
|
||
|
panfft.close();
|
||
|
e.returnValue = '';
|
||
|
}
|
||
|
});
|
||
|
|
||
|
function check_connected() {
|
||
|
setTimeout(function () {
|
||
|
if (wsAudioRX.readyState === WebSocket.OPEN && wsAudioTX.readyState === WebSocket.OPEN && wsControlTRX.readyState === WebSocket.OPEN){document.getElementById("ombre-body").style.display = "none";document.getElementById("pop-upspinner").style.display = "none";}
|
||
|
else{check_connected();}
|
||
|
}, 1000);
|
||
|
}
|
||
|
|
||
|
//RX Audio routines///////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
const RXinstantMeter = document.querySelector('#RXinstant meter');
|
||
|
|
||
|
var wsAudioRX = "";
|
||
|
var AudioRX_context = "";
|
||
|
var AudioRX_source_node = "";
|
||
|
var AudioRX_gain_node = "";
|
||
|
var AudioRX_biquadFilter_node = "";
|
||
|
var AudioRX_analyser = "";
|
||
|
var audiobufferready = false;
|
||
|
var AudioRX_audiobuffer = [];
|
||
|
var AudioRX_sampleRate=8000;
|
||
|
|
||
|
function AudioRX_start(){
|
||
|
document.getElementById("indwsAudioRX").innerHTML='<img src="img/critsgrey.png">wsRX';
|
||
|
AudioRX_audiobuffer = [];var lenglitchbuf = 2;
|
||
|
|
||
|
wsAudioRX = new WebSocket( 'wss://' + window.location.href.split( '/' )[2] + '/WSaudioRX' );
|
||
|
wsAudioRX.binaryType = 'arraybuffer';
|
||
|
wsAudioRX.onmessage = appendwsAudioRX;
|
||
|
wsAudioRX.onopen = wsAudioRXopen;
|
||
|
wsAudioRX.onclose = wsAudioRXclose;
|
||
|
wsAudioRX.onerror = wsAudioRXerror;
|
||
|
|
||
|
function appendwsAudioRX( msg ){
|
||
|
AudioRX_audiobuffer.push(new Float32Array(msg.data));
|
||
|
}
|
||
|
|
||
|
const BUFF_SIZE = 256; // spec allows, yet do not go below 1024
|
||
|
AudioRX_context = new AudioContext({latencyHint: "interactive",sampleRate: AudioRX_sampleRate});
|
||
|
AudioRX_gain_node = AudioRX_context.createGain();
|
||
|
AudioRX_biquadFilter_node = AudioRX_context.createBiquadFilter();
|
||
|
AudioRX_analyser = AudioRX_context.createAnalyser();
|
||
|
|
||
|
AudioRX_source_node = AudioRX_context.createScriptProcessor(BUFF_SIZE, 1, 1);
|
||
|
|
||
|
AudioRX_source_node.onaudioprocess = (function() {
|
||
|
return function(event) {
|
||
|
var synth_buff = event.outputBuffer.getChannelData(0); // mono for now
|
||
|
let le = Boolean(AudioRX_audiobuffer.length);
|
||
|
if(le){
|
||
|
for (var i = 0, buff_size = synth_buff.length; i < buff_size; i++) {
|
||
|
synth_buff[i] = AudioRX_audiobuffer[0][i];
|
||
|
}
|
||
|
if(le){AudioRX_audiobuffer.shift();}
|
||
|
}
|
||
|
};
|
||
|
}());
|
||
|
|
||
|
AudioRX_source_node.connect(AudioRX_biquadFilter_node);
|
||
|
AudioRX_biquadFilter_node.connect(AudioRX_gain_node);
|
||
|
AudioRX_gain_node.connect(AudioRX_analyser);
|
||
|
AudioRX_gain_node.connect( AudioRX_context.destination );
|
||
|
drawBF();
|
||
|
drawRXvol();
|
||
|
|
||
|
AudioRX_biquadFilter_node.type = "lowshelf";
|
||
|
AudioRX_biquadFilter_node.frequency.setValueAtTime(22000, AudioRX_context.currentTime);
|
||
|
AudioRX_biquadFilter_node.gain.setValueAtTime(0, AudioRX_context.currentTime);
|
||
|
|
||
|
AudioRX_SetGAIN();
|
||
|
|
||
|
}
|
||
|
|
||
|
function setaudiofilter(){
|
||
|
if(poweron){
|
||
|
AudioRX_biquadFilter_node.type = event.srcElement.getAttribute('ft');
|
||
|
AudioRX_biquadFilter_node.frequency.setValueAtTime(parseInt(event.srcElement.getAttribute('frq')), AudioRX_context.currentTime);
|
||
|
AudioRX_biquadFilter_node.gain.setValueAtTime(parseInt(event.srcElement.getAttribute('fg')), AudioRX_context.currentTime);
|
||
|
AudioRX_biquadFilter_node.Q.setValueAtTime(parseInt(event.srcElement.getAttribute('fq')), AudioRX_context.currentTime);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function setcustomaudiofilter(){
|
||
|
if(poweron){
|
||
|
AudioRX_biquadFilter_node.type = document.getElementById("customfilter_T").value;
|
||
|
AudioRX_biquadFilter_node.frequency.setValueAtTime(parseInt(document.getElementById("customfilter_F").value), AudioRX_context.currentTime);
|
||
|
AudioRX_biquadFilter_node.gain.setValueAtTime(parseInt(document.getElementById("customfilter_G").value), AudioRX_context.currentTime);
|
||
|
AudioRX_biquadFilter_node.Q.setValueAtTime(parseInt(document.getElementById("customfilter_Q").value), AudioRX_context.currentTime);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function AudioRX_SetGAIN( vol="None" ){
|
||
|
if(vol == "None"){volumeRX=document.getElementById("C_af").value/100;vol=volumeRX;}
|
||
|
if(poweron){AudioRX_gain_node.gain.setValueAtTime(vol, AudioRX_context.currentTime);}
|
||
|
}
|
||
|
|
||
|
function wsAudioRXopen(){
|
||
|
document.getElementById("indwsAudioRX").innerHTML='<img src="img/critsgreen.png">wsRX';
|
||
|
}
|
||
|
|
||
|
function wsAudioRXclose(){
|
||
|
document.getElementById("indwsAudioRX").innerHTML='<img src="img/critsred.png">wsRX';
|
||
|
AudioRX_stop();
|
||
|
}
|
||
|
|
||
|
function wsAudioRXerror(err){
|
||
|
document.getElementById("indwsAudioRX").innerHTML='<img src="img/critsred.png">wsRX';
|
||
|
AudioRX_stop();
|
||
|
}
|
||
|
|
||
|
function AudioRX_stop()
|
||
|
{
|
||
|
audiobufferready = false;
|
||
|
wsAudioRX.close();
|
||
|
AudioRX_source_node.onaudioprocess = null
|
||
|
AudioRX_context.close();
|
||
|
}
|
||
|
|
||
|
var muteRX=false;
|
||
|
function toggleaudioRX(stat="None"){
|
||
|
muteRX=!muteRX;
|
||
|
if(stat != "None"){muteRX=stat;}
|
||
|
if(muteRX){AudioRX_SetGAIN(0);}
|
||
|
else{AudioRX_SetGAIN();}
|
||
|
}
|
||
|
|
||
|
|
||
|
canvasBFFFT = document.getElementById("canBFFFT");
|
||
|
ctxFFFT = canvasBFFFT.getContext("2d");
|
||
|
var Audio_analyser="";
|
||
|
function drawRXFFT(Audio_analyser){
|
||
|
Audio_analyser.fftSize = canvasBFFFT.width;
|
||
|
var arrayFFT = new Float32Array(Audio_analyser.frequencyBinCount);
|
||
|
Audio_analyser.getFloatFrequencyData(arrayFFT);
|
||
|
ctxFFFT.clearRect(0, 0, canvasBFFFT.width, canvasBFFFT.height);
|
||
|
ctxFFFT.fillStyle = 'rgb(0, 0, 0)';
|
||
|
ctxFFFT.fillRect(0, 0, canvasBFFFT.width, canvasBFFFT.height);
|
||
|
var scale_mult = Math.exp(parseInt(document.getElementById("canBFFFT_scale_multdb").value)/100);
|
||
|
var scale_floor = parseInt(document.getElementById("canBFFFT_scale_floor").value)*scale_mult;
|
||
|
var scale_hz = Math.exp(parseInt(document.getElementById("canBFFFT_scale_multhz").value)/100);
|
||
|
var start = (parseInt(document.getElementById("canBFFFT_scale_start").value)*Audio_analyser.frequencyBinCount/100)*scale_hz;
|
||
|
var largeurBarre = (canvasBFFFT.width / Audio_analyser.frequencyBinCount)*scale_hz;
|
||
|
var hauteurBarre;
|
||
|
var x = start;
|
||
|
for(var i = 0; i < Audio_analyser.frequencyBinCount; i++) {
|
||
|
hauteurBarre = (arrayFFT[i]*scale_mult + canvasBFFFT.height + scale_floor);
|
||
|
ctxFFFT.fillStyle = 'rgb(' + Math.floor(hauteurBarre*2+100) + ',50,50)';
|
||
|
ctxFFFT.fillRect(x*scale_hz, canvasBFFFT.height-hauteurBarre, largeurBarre*scale_hz, hauteurBarre);
|
||
|
x += largeurBarre;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
canvasBFFFT.addEventListener('dblclick', function(evt) {
|
||
|
document.getElementById("canBFFFT_scale_multdb").value=0;
|
||
|
document.getElementById("canBFFFT_scale_floor").value=0;
|
||
|
document.getElementById("canBFFFT_scale_multhz").value=0;
|
||
|
document.getElementById("canBFFFT_scale_start").value=0;
|
||
|
}, false);
|
||
|
|
||
|
canvasBFFFT_coord = document.getElementById("canvasBFFFT_coord");
|
||
|
canvasBFFFT.addEventListener('mousemove', function(evt) {
|
||
|
if(Audio_analyser){
|
||
|
var rect = canvasBFFFT.getBoundingClientRect()
|
||
|
scaleX = canvasBFFFT.width / rect.width; // relationship bitmap vs. element for X
|
||
|
hzperpixel=(AudioRX_sampleRate/2)/rect.width;
|
||
|
|
||
|
var scale_hz = Math.exp(parseInt(document.getElementById("canBFFFT_scale_multhz").value)/100);
|
||
|
var start = (parseInt(document.getElementById("canBFFFT_scale_start").value)*Audio_analyser.frequencyBinCount/100)*scale_hz;
|
||
|
|
||
|
scaleY = canvasBFFFT.height / rect.height; // relationship bitmap vs. element for Y
|
||
|
var scale_mult = Math.exp(parseInt(document.getElementById("canBFFFT_scale_multdb").value)/100);
|
||
|
var scale_floor = parseInt(document.getElementById("canBFFFT_scale_floor").value);
|
||
|
|
||
|
canvasBFFFT_coord.innerHTML = parseInt(((((evt.clientX - rect.left)/(scale_hz*scale_hz) * scaleX ) - (start/scale_hz))* (AudioRX_sampleRate/2))/canvasBFFFT.width) + 'hz ,-' + parseInt(((evt.clientY - rect.top) * scaleY)/(scale_mult) + (scale_floor))+'dB';
|
||
|
}
|
||
|
}, false);
|
||
|
|
||
|
canvasBFFFT.addEventListener('mouseenter', function(evt) {
|
||
|
canvasBFFFT_coord.style.display="block";
|
||
|
}, false);
|
||
|
|
||
|
canvasBFFFT.addEventListener('mouseout', function(evt) {
|
||
|
canvasBFFFT_coord.style.display="none";
|
||
|
}, false);
|
||
|
|
||
|
canvasBFFFT.addEventListener('click', function(evt) {
|
||
|
var rect = canvasBFFFT.getBoundingClientRect()
|
||
|
scaleX = canvasBFFFT.width / rect.width;
|
||
|
if(document.getElementById("custom_filter_click").hasAttribute('lichecked')){
|
||
|
AudioRX_biquadFilter_node.type = "bandpass";
|
||
|
AudioRX_biquadFilter_node.frequency.setValueAtTime(parseInt((((evt.clientX - rect.left) * scaleX) * (AudioRX_sampleRate/2))/canvasBFFFT.width), AudioRX_context.currentTime);
|
||
|
AudioRX_biquadFilter_node.gain.setValueAtTime(-100, AudioRX_context.currentTime);
|
||
|
AudioRX_biquadFilter_node.Q.setValueAtTime(50, AudioRX_context.currentTime);
|
||
|
}
|
||
|
else{document.getElementById("customfilter_F").value=parseInt((((evt.clientX - rect.left) * scaleX) * (AudioRX_sampleRate/2))/canvasBFFFT.width);}
|
||
|
}, false);
|
||
|
|
||
|
|
||
|
function drawRXSPC(Audio_analyser){
|
||
|
var arraySPC = new Float32Array(Audio_analyser.fftSize);
|
||
|
Audio_analyser.getFloatTimeDomainData(arraySPC);
|
||
|
canvasBFspc = document.getElementById("canBFSPC");
|
||
|
ctxFwf = canvasBFspc.getContext("2d");
|
||
|
ctxFwf.clearRect(0, 0, canvasBFspc.width, canvasBFspc.height);
|
||
|
ctxFwf.fillStyle = 'rgb(0, 0, 0)';
|
||
|
ctxFwf.fillRect(0, 0, canvasBFspc.width, canvasBFspc.height);
|
||
|
ctxFwf.lineWidth = 2;
|
||
|
ctxFwf.strokeStyle = 'rgb(255, 255, 0)';
|
||
|
ctxFwf.beginPath();
|
||
|
var largeurTranche = canvasBFspc.width * 1.0 / Audio_analyser.fftSize;
|
||
|
var x = 0;
|
||
|
|
||
|
for(var i = 0; i < Audio_analyser.fftSize; i++) {
|
||
|
var y = canvasBFspc.height/2 + arraySPC[i] * canvasBFspc.height;
|
||
|
|
||
|
if(i === 0) {
|
||
|
ctxFwf.moveTo(x, y);
|
||
|
} else {
|
||
|
ctxFwf.lineTo(x, y);
|
||
|
}
|
||
|
x += largeurTranche;
|
||
|
}
|
||
|
ctxFwf.lineTo(canvasBFspc.width, canvasBFspc.height/2);
|
||
|
ctxFwf.stroke();
|
||
|
}
|
||
|
|
||
|
|
||
|
function drawBF(){
|
||
|
if(muteRX){Audio_analyser=AudioTX_analyser}else{Audio_analyser=AudioRX_analyser}
|
||
|
drawRXSPC(Audio_analyser);
|
||
|
drawRXFFT(Audio_analyser);
|
||
|
setTimeout(function(){ drawBF(); }, 200);
|
||
|
}
|
||
|
|
||
|
function drawRXvol(){
|
||
|
var arraySPC = new Float32Array(AudioRX_analyser.fftSize);
|
||
|
AudioRX_analyser.getFloatTimeDomainData(arraySPC);
|
||
|
RXinstantMeter.value = Math.max.apply(null, arraySPC)*100;
|
||
|
if(RXinstantMeter.value > RXinstantMeter.high){blikcritik("RX-GAIN_control")};
|
||
|
setTimeout(function(){ drawRXvol(); }, 300);
|
||
|
}
|
||
|
|
||
|
function showRXvol(){
|
||
|
|
||
|
}
|
||
|
|
||
|
//ControlTRX routines///////////////////////////////////////////////////////////////////////////
|
||
|
var wsControlTRX = "";
|
||
|
|
||
|
function ControlTRX_start(){
|
||
|
document.getElementById("indwsControlTRX").innerHTML='<img src="img/critsgrey.png">wsCtrl';
|
||
|
wsControlTRX = new WebSocket( 'wss://' + window.location.href.split( '/' )[2] + '/WSCTRX' );
|
||
|
wsControlTRX.onopen = wsControlTRXopen;
|
||
|
wsControlTRX.onclose = wsControlTRXclose;
|
||
|
wsControlTRX.onerror = wsControlTRXerror;
|
||
|
wsControlTRX.onmessage = wsControlTRXcrtol;
|
||
|
}
|
||
|
|
||
|
var SignalLevel=0;
|
||
|
function wsControlTRXcrtol( msg ){
|
||
|
words = String(msg.data).split(':');
|
||
|
if(words[0] == "PONG"){showlatency();}
|
||
|
else if(words[0] == "getFreq"){showTRXfreq(words[1]);TRXfrequency=parseInt(words[1]);if (typeof panfft !== 'undefined') {panfft.setcenterfrequency(words[1]);}}
|
||
|
else if(words[0] == "getMode"){showTRXmode(words[1]);}
|
||
|
else if(words[0] == "getSignalLevel"){SignalLevel=words[1];drawRXSmeter();}
|
||
|
else if(words[0] == "panfft"){document.getElementById("div-panfft").style.display = "block";}
|
||
|
}
|
||
|
|
||
|
function ControlTRX_stop()
|
||
|
{
|
||
|
wsControlTRX.close();
|
||
|
}
|
||
|
|
||
|
function ControlTRX_getFreq(){
|
||
|
if (wsControlTRX.readyState === WebSocket.OPEN) {wsControlTRX.send("getFreq");}
|
||
|
}
|
||
|
|
||
|
function wsControlTRXopen(){
|
||
|
document.getElementById("indwsControlTRX").innerHTML='<img src="img/critsgreen.png">wsCtrl';
|
||
|
wsControlTRX.send("getFreq:");
|
||
|
wsControlTRX.send("getMode:");
|
||
|
}
|
||
|
|
||
|
function wsControlTRXclose(){
|
||
|
document.getElementById("indwsControlTRX").innerHTML='<img src="img/critsred.png">wsCtrl';
|
||
|
}
|
||
|
|
||
|
function wsControlTRXerror(err){
|
||
|
wsControlTRX.close();
|
||
|
document.getElementById("indwsControlTRX").innerHTML='<img src="img/critsred.png">wsCtrl';
|
||
|
ControlTRX_start();
|
||
|
}
|
||
|
|
||
|
var startTime;
|
||
|
function checklatency() {
|
||
|
setTimeout(function () {
|
||
|
startTime = Date.now();
|
||
|
if (wsControlTRX.readyState === WebSocket.OPEN) {wsControlTRX.send("PING");}
|
||
|
if(poweron == true){checklatency();}
|
||
|
}, 5000);
|
||
|
}
|
||
|
|
||
|
function showlatency(){
|
||
|
latency = Date.now() - startTime;
|
||
|
document.getElementById("div-latencymeter").innerHTML="latency:"+latency+"ms";
|
||
|
}
|
||
|
|
||
|
function get_digit_freq(){
|
||
|
return parseInt(
|
||
|
document.getElementById("cmhz").innerHTML+
|
||
|
document.getElementById("dmhz").innerHTML+
|
||
|
document.getElementById("umhz").innerHTML+
|
||
|
document.getElementById("ckhz").innerHTML+
|
||
|
document.getElementById("dkhz").innerHTML+
|
||
|
document.getElementById("ukhz").innerHTML+
|
||
|
document.getElementById("chz").innerHTML+
|
||
|
document.getElementById("dhz").innerHTML+
|
||
|
document.getElementById("uhz").innerHTML
|
||
|
);
|
||
|
}
|
||
|
|
||
|
freq_digit_selected="";
|
||
|
function freq_digit_scroll() {
|
||
|
if (poweron) {
|
||
|
if(event.deltaY>0){toadd=-1;}else{toadd=1;}
|
||
|
freq=get_digit_freq()+(freq_digit_selected.getAttribute('v')*toadd);
|
||
|
if(freq>0){showTRXfreq(freq);sendTRXfreq();}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function select_digit() {
|
||
|
freq_digit_selected=event.srcElement;
|
||
|
}
|
||
|
|
||
|
function clear_select_digit() {
|
||
|
freq_digit_selected="";
|
||
|
}
|
||
|
|
||
|
function rotatefreq(){
|
||
|
if (poweron) {
|
||
|
freq=get_digit_freq()+parseInt(event.srcElement.getAttribute('v'));
|
||
|
if(freq>0){showTRXfreq(freq);sendTRXfreq();}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function showTRXfreq(freq){
|
||
|
freq=freq.toString();
|
||
|
while (freq.length < 9){freq="0"+freq;}
|
||
|
document.getElementById("cmhz").innerHTML=freq.substring(0, 1);
|
||
|
document.getElementById("dmhz").innerHTML=freq.substring(1, 2);
|
||
|
document.getElementById("umhz").innerHTML=freq.substring(2, 3);
|
||
|
document.getElementById("ckhz").innerHTML=freq.substring(3, 4);
|
||
|
document.getElementById("dkhz").innerHTML=freq.substring(4, 5);
|
||
|
document.getElementById("ukhz").innerHTML=freq.substring(5, 6);
|
||
|
document.getElementById("chz").innerHTML=freq.substring(6, 7);
|
||
|
document.getElementById("dhz").innerHTML=freq.substring(7, 8);
|
||
|
document.getElementById("uhz").innerHTML=freq.substring(8, 9);
|
||
|
}
|
||
|
|
||
|
function sendTRXfreq(freq=0){
|
||
|
if(!freq){freq=get_digit_freq();}
|
||
|
if (wsControlTRX.readyState === WebSocket.OPEN) {wsControlTRX.send("setFreq:"+freq);}
|
||
|
}
|
||
|
|
||
|
function sendTRXptt(stat){
|
||
|
if (wsControlTRX.readyState === WebSocket.OPEN) {wsControlTRX.send("setPTT:"+stat);}
|
||
|
}
|
||
|
|
||
|
function showTRXmode(mode){
|
||
|
setAttr("div-mode_menu",mode);
|
||
|
}
|
||
|
|
||
|
function sendTRXmode(){
|
||
|
if (wsControlTRX.readyState === WebSocket.OPEN) {wsControlTRX.send("setMode:"+event.srcElement.innerHTML);}
|
||
|
}
|
||
|
|
||
|
function recall_hambands(){
|
||
|
if (wsControlTRX.readyState === WebSocket.OPEN) {wsControlTRX.send("setFreq:"+event.srcElement.getAttribute('v'));}
|
||
|
}
|
||
|
|
||
|
function initRXSmeter(){
|
||
|
ctxRXsmeter.beginPath();
|
||
|
ctxRXsmeter.lineWidth = 2;
|
||
|
ctxRXsmeter.strokeStyle = '#fffb16';
|
||
|
ctxRXsmeter.moveTo(SP[0], 0);
|
||
|
ctxRXsmeter.lineTo(SP[0], 50);
|
||
|
ctxRXsmeter.stroke();
|
||
|
document.getElementById("div-smeterdigitRX").innerHTML="S0";
|
||
|
}
|
||
|
|
||
|
var SP = {0:0,1:25,2:37,3:50,4:62,5:73,6:84,7:98,8:110,9:123,10:144,20:164,30:180,40:202,50:221,60:240};
|
||
|
var RIG_LEVEL_STRENGTH = {0:-54,1:-48,2:-42,3:-36,4:-30,5:-24,6:-18,7:-12,8:-6,9:0,10:10,20:20,30:30,40:40,50:50,60:60};
|
||
|
function drawRXSmeter() {
|
||
|
if(typeof(RIG_LEVEL_STRENGTH[SignalLevel])!="undefined"){
|
||
|
ctxRXsmeter.beginPath();
|
||
|
ctxRXsmeter.lineWidth = 2;
|
||
|
ctxRXsmeter.moveTo(SP[SignalLevel], 0);
|
||
|
ctxRXsmeter.lineTo(SP[SignalLevel], 50);
|
||
|
ctxRXsmeter.clearRect(0, 0, 250, 50);
|
||
|
ctxRXsmeter.strokeStyle = '#fffb16';
|
||
|
ctxRXsmeter.stroke();
|
||
|
|
||
|
sq=document.getElementById("SQUELCH").value*2.5;
|
||
|
ctxRXsmeter.beginPath();
|
||
|
ctxRXsmeter.lineWidth = 2;
|
||
|
ctxRXsmeter.strokeStyle = '#deded5';
|
||
|
ctxRXsmeter.moveTo(sq, 0);
|
||
|
ctxRXsmeter.lineTo(sq, 50);
|
||
|
ctxRXsmeter.stroke();
|
||
|
|
||
|
var res = "S9";
|
||
|
if(SignalLevel > 9){
|
||
|
res = "S9+" + SignalLevel;
|
||
|
}
|
||
|
else{res = "S" + SignalLevel;}
|
||
|
document.getElementById("div-smeterdigitRX").innerHTML=res+" ("+RIG_LEVEL_STRENGTH[SignalLevel]+"dB)";
|
||
|
|
||
|
if(SP[SignalLevel]>=sq && !muteRX){AudioRX_SetGAIN();}
|
||
|
else{AudioRX_SetGAIN(0);}
|
||
|
}
|
||
|
else{
|
||
|
document.getElementById("div-smeterdigitRX").innerHTML="";
|
||
|
ctxRXsmeter.clearRect(0, 0, 250, 50);
|
||
|
ctxRXsmeter.stroke();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function TXtogle(state="None")
|
||
|
{
|
||
|
if(poweron && ((event.srcElement.className=="button_unpressed") || state=="True"))
|
||
|
{
|
||
|
button_pressed();
|
||
|
toggleRecord(true);
|
||
|
toggleaudioRX();
|
||
|
sendTRXptt(true);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
button_unpressed();
|
||
|
if(poweron)
|
||
|
{
|
||
|
toggleRecord();
|
||
|
toggleaudioRX();
|
||
|
sendTRXptt(false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//Cookie routines///////////////////////////////////////////////////////////////////////////
|
||
|
function setCookie(cname,cvalue,exdays) {
|
||
|
var d = new Date();
|
||
|
d.setTime(d.getTime() + (exdays*24*60*60*1000));
|
||
|
var expires = "expires=" + d.toGMTString();
|
||
|
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||
|
}
|
||
|
|
||
|
function getCookie(cname) {
|
||
|
var name = cname + "=";
|
||
|
var decodedCookie = decodeURIComponent(document.cookie);
|
||
|
var ca = decodedCookie.split(';');
|
||
|
for(var i = 0; i < ca.length; i++) {
|
||
|
var c = ca[i];
|
||
|
while (c.charAt(0) == ' ') {
|
||
|
c = c.substring(1);
|
||
|
}
|
||
|
if (c.indexOf(name) == 0) {
|
||
|
return c.substring(name.length, c.length);
|
||
|
}
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
function checkCookie() {
|
||
|
var callsign=getCookie("callsign");
|
||
|
if (callsign != "") {
|
||
|
alert("Welcome " + callsign);
|
||
|
labelcalls = document.getElementById("callsign");
|
||
|
labelcalls.innerHTML=callsign;
|
||
|
if(getCookie("autha"))labelcalls.innerHTML+=' <a href="/logout" id="logout"><img src="img/logout.png"></a>';
|
||
|
} else {
|
||
|
callsign = prompt("Please enter your Call Sign:","");
|
||
|
if (callsign != "" && callsign != null) {
|
||
|
setCookie("callsign", callsign, 180);
|
||
|
}
|
||
|
}
|
||
|
var vol=getCookie("C_af");
|
||
|
if(vol != ""){document.getElementById("C_af").value=vol;}
|
||
|
var sql=getCookie("SQUELCH");
|
||
|
if(sql != ""){document.getElementById("SQUELCH").value=sql;}
|
||
|
var mg=getCookie("C_mg");
|
||
|
if(mg != ""){document.getElementById("C_mg").value=mg;}
|
||
|
get_freqfromcokkies();
|
||
|
}
|
||
|
|
||
|
function get_freqfromcokkies(itemselected=""){
|
||
|
var freqs=getCookie("freqs").replace("//", '/').split("/").sort();
|
||
|
var x = document.getElementById("selectpersonalfrequency");
|
||
|
var length = x.options.length;
|
||
|
for (i = length-1; i >= 0; i--) {
|
||
|
x.options[i] = null;
|
||
|
}
|
||
|
|
||
|
for (i in freqs) {
|
||
|
var option = document.createElement("option");
|
||
|
if(freqs[i]!=""){
|
||
|
freq=freqs[i].split(",")[0]
|
||
|
mode=freqs[i].split(",")[1]
|
||
|
option.text = parseInt(freq)+" in "+mode;
|
||
|
option.value = freqs[i];
|
||
|
if(option.value == itemselected){option.selected = true;}
|
||
|
x.add(option);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
function save_freqtocokkies(){
|
||
|
var freq=(
|
||
|
document.getElementById("cmhz").innerHTML+
|
||
|
document.getElementById("dmhz").innerHTML+
|
||
|
document.getElementById("umhz").innerHTML+
|
||
|
document.getElementById("ckhz").innerHTML+
|
||
|
document.getElementById("dkhz").innerHTML+
|
||
|
document.getElementById("ukhz").innerHTML+
|
||
|
document.getElementById("chz").innerHTML+
|
||
|
document.getElementById("dhz").innerHTML+
|
||
|
document.getElementById("uhz").innerHTML
|
||
|
);
|
||
|
var mode=get_actualmode();
|
||
|
var freqs=getCookie("freqs").replace("//", '/');
|
||
|
var val=freq.toString()+","+mode;
|
||
|
if(!freqs.includes(val)){
|
||
|
freqs = freqs +val+"/";
|
||
|
setCookie("freqs", freqs, 180);
|
||
|
get_freqfromcokkies(val);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function delete_freqfromcokkies(){
|
||
|
var e = document.getElementById("selectpersonalfrequency");
|
||
|
var freq = e.options[e.selectedIndex].value;
|
||
|
var freqs=getCookie("freqs").replace(freq+"/", '').replace("//", '/');
|
||
|
setCookie("freqs", freqs, 180);
|
||
|
get_freqfromcokkies();
|
||
|
}
|
||
|
|
||
|
function recall_freqfromcokkies(){
|
||
|
var e = document.getElementById("selectpersonalfrequency");
|
||
|
var freq = e.options[e.selectedIndex].value.split(",")[0];
|
||
|
var mode = e.options[e.selectedIndex].value.split(",")[1];
|
||
|
if (wsControlTRX.readyState === WebSocket.OPEN) {wsControlTRX.send("setFreq:"+freq);wsControlTRX.send("setMode:"+mode);}
|
||
|
}
|
||
|
|
||
|
//Cosmetics
|
||
|
function changeinputfreqstyle(e){
|
||
|
var item=document.getElementById("freq_disp_input_text");
|
||
|
var digit_elements = document.getElementsByClassName('freq_digit');
|
||
|
ids="inline-block";
|
||
|
desd="none";
|
||
|
|
||
|
if (e.keyCode == 13) {
|
||
|
freq=item.value.toString();
|
||
|
showTRXfreq(freq);
|
||
|
sendTRXfreq();
|
||
|
ids="none";
|
||
|
desd="inline-block";
|
||
|
}
|
||
|
item.style.display = ids;
|
||
|
for (var i in digit_elements) {
|
||
|
if (digit_elements.hasOwnProperty(i)) {
|
||
|
digit_elements[i].style.display = desd;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function validateNumber(evt) {
|
||
|
var e = evt || window.event;
|
||
|
var key = e.keyCode || e.which;
|
||
|
var item=document.getElementById("freq_disp_input_text");
|
||
|
|
||
|
if(key == 77){item.value*=1000000;}
|
||
|
if(key == 75){item.value*=1000;}
|
||
|
|
||
|
if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
|
||
|
// numbers
|
||
|
key >= 48 && key <= 57 ||
|
||
|
// Numeric keypad
|
||
|
key >= 96 && key <= 105 ||
|
||
|
// Backspace and Tab and Enter
|
||
|
key == 8 || key == 9 || key == 13 ||
|
||
|
// Home and End
|
||
|
key == 35 || key == 36 ||
|
||
|
// left and right arrows
|
||
|
key == 37 || key == 39 ||
|
||
|
// Del and Ins
|
||
|
key == 46 || key == 45) {
|
||
|
// input is VALID
|
||
|
}
|
||
|
else {
|
||
|
// input is INVALID
|
||
|
e.returnValue = false;
|
||
|
if (e.preventDefault) e.preventDefault();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function get_actualmode()
|
||
|
{
|
||
|
var items = document.getElementById("div-mode_menu").getElementsByTagName("li");
|
||
|
var mode = ""
|
||
|
for (var i = 0; i < items.length; ++i) {
|
||
|
if(items[i].hasAttribute('lichecked') ){
|
||
|
mode = items[i].innerHTML;
|
||
|
}
|
||
|
}
|
||
|
return mode
|
||
|
}
|
||
|
|
||
|
function button_pressed(item)
|
||
|
{
|
||
|
if(!item){item=event.srcElement;}
|
||
|
item.classList.remove('button_unpressed');
|
||
|
item.classList.add('button_pressed');
|
||
|
button_light(item);
|
||
|
}
|
||
|
|
||
|
function button_unpressed(item)
|
||
|
{
|
||
|
if(!item){item=event.srcElement;}
|
||
|
item.classList.remove('button_green');
|
||
|
item.classList.remove('button_pressed');
|
||
|
item.classList.add('button_unpressed');
|
||
|
}
|
||
|
|
||
|
function button_unlight_all(iddiv){
|
||
|
var items = document.getElementById(iddiv).getElementsByTagName("li");
|
||
|
for (var i = 0; i < items.length; ++i) {
|
||
|
items[i].classList.remove('button_green');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function button_light_all(iddiv)
|
||
|
{
|
||
|
var items = document.getElementById(iddiv).getElementsByTagName("li");
|
||
|
for (var i = 0; i < items.length; ++i) {
|
||
|
if(items[i].hasAttribute('lichecked')){
|
||
|
items[i].classList.add('button_green');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function button_light(item,color="G")
|
||
|
{
|
||
|
if(!item){item=event.srcElement;}
|
||
|
if(color=="G"){
|
||
|
if(poweron){item.classList.add('button_green');}
|
||
|
else{item.classList.remove('button_green');}
|
||
|
}
|
||
|
else if(color=="R"){
|
||
|
if(poweron){item.classList.add('button_red');}
|
||
|
else{item.classList.remove('button_red');}
|
||
|
}
|
||
|
else if(color=="Z"){
|
||
|
item.classList.remove('button_red');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function set_css_li_in_ul(items, tag=true)
|
||
|
{
|
||
|
for (var i = 0; i < items.length; ++i) {
|
||
|
if(items[i].hasAttribute('lichecked') && tag){
|
||
|
button_pressed(items[i]);
|
||
|
}else{
|
||
|
button_unpressed(items[i]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function togle_li()
|
||
|
{
|
||
|
var items = event.srcElement.parentNode.getElementsByTagName("li");
|
||
|
for (var i = 0; i < items.length; ++i) {
|
||
|
items[i].removeAttribute('lichecked');
|
||
|
}
|
||
|
event.srcElement.setAttribute('lichecked',"");
|
||
|
set_css_li_in_ul(items);
|
||
|
}
|
||
|
|
||
|
function setAttr(div,mode){
|
||
|
var items = document.getElementById(div).getElementsByTagName("li");
|
||
|
for (var i = 0; i < items.length; ++i) {
|
||
|
items[i].removeAttribute('lichecked');
|
||
|
if(items[i].innerHTML==mode){items[i].setAttribute('lichecked',"")}
|
||
|
if(items[i].getAttribute('v')==mode){items[i].setAttribute('lichecked',"")}
|
||
|
}
|
||
|
set_css_li_in_ul(items);
|
||
|
}
|
||
|
|
||
|
function blikcritik(elemtID){
|
||
|
document.getElementById(elemtID).classList.add("blink");
|
||
|
document.getElementById(elemtID).style.color="red";
|
||
|
setTimeout(function(){
|
||
|
document.getElementById(elemtID).classList.remove("blink");
|
||
|
document.getElementById(elemtID).style.color="white";
|
||
|
}, 3000);
|
||
|
}
|
||
|
|
||
|
//TX Audio routines///////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
|
var Module;if(!Module)Module=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function";var ENVIRONMENT_IS_WEB=typeof window==="object";var ENVIRONMENT_IS_WORKER=typeof importScripts==="function";var ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=function print(x){process["stdout"].write(x+"\n")};if(!Module["printErr"])Module["printErr"]=function printErr(x){process["stderr"].write(x+"\n")};var nodeFS=require("fs");var nodePath=require("path");Module["read"]=function read(filename,binary){filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"](filename);if(!ret&&filename!=nodePath["resolve"](filename)){filename=path.join(__dirname,"..","src",filename);ret=nodeFS["readFileSync"](filename)}if(ret&&!binary)ret=ret.toString();return ret};Module["readBinary"]=function readBinary(filename){return Module["read"](filename,true)};Module["load"]=function load(f){globalEval(read(f))};Module["thisProgram"]=process["argv"][1].replace(/\\/g,"/");Module["arguments"]=process["argv"].slice(2);if(typeof module!=="undefined"){module["exports"]=Module}process["on"]("uncaughtException",(function(ex){if(!(ex instanceof ExitStatus)){throw ex}}))}else if(ENVIRONMENT_IS_SHELL){if(!Module["print"])Module["print"]=print;if(typeof printErr!="undefined")Module["printErr"]=printErr;if(typeof read!="undefined"){Module["read"]=read}else{Module["read"]=function read(){throw"no read() available (jsc?)"}}Module["readBinary"]=function readBinary(f){if(typeof readbuffer==="function"){return new Uint8Array(readbuffer(f))}var data=read(f,"binary");assert(typeof data==="object");return data};if(typeof scriptArgs!="undefined"){Module["arguments"]=scriptArgs}else if(typeof arguments!="undefined"){Module["arguments"]=arguments}this["Module"]=Module}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){Module["read"]=function read(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(typeof arguments!="undefined"){Module["arguments"]=arguments}if(typeof console!=="undefined"){if(!Module["print"])Module["print"]=function print(x){console.log(x)};if(!Module["printErr"])Module["printErr"]=function printErr(x){console.log(x)}}else{var TRY_USE_DUMP=false;if(!Module["print"])Module["print"]=TRY_USE_DUMP&&typeof dump!=="undefined"?(function(x){dump(x)}):(function(x){})}if(ENVIRONMENT_IS_WEB){window["Module"]=Module}else{Module["load"]=importScripts}}else{throw"Unknown runtime environment. Where are we?"}function globalEval(x){eval.call(null,x)}if(!Module["load"]&&Module["read"]){Module["load"]=function load(f){globalEval(Module["read"](f))}}if(!Module["print"]){Module["print"]=(function(){})}if(!Module["printErr"]){Module["printErr"]=Module["print"]}if(!Module["arguments"]){Module["arguments"]=[]}if(!Module["thisProgram"]){Module["thisProgram"]="./this.program"}Module.print=Module["print"];Module.printErr=Module["printErr"];Module["preRun"]=[];Module["postRun"]=[];for(var key in moduleOverrides){if(moduleOverrides.hasOwnProperty(key)){Module[key]=moduleOverrides[key]}}var Runtime={setTempRet0:(function(value){tempRet0=value}),getTempRet0:(function(){return tempRet0}),stackSave:(function(){return STACKTOP}),stackRestore:(function(stackTop){STACKTOP=stackTop}),getNativeTypeSize:(function(type){switch(type){case"i1":case"i8":return 1;case"i16":return 2;case"i32":return 4;case"i64":return 8;case"float":return 4;case"double":return 8;default:{if(type[type.length-1]==="*"){return Runtime.QUANTUM_SIZE}else if(type[0]==="i"){var bits=parseInt(type.substr(1));assert(bits%8===0);return bits/8}else{return 0}}}}),getNativeFieldSize:(function(type){return Math.max(Runtime.getNativeTypeSize(type),Runtime.QUANTUM_SIZE)}),STACK_ALIGN:16,getAlignSize:(function(type,size,vararg){if(!vararg&&(type=="i64"||type=="double"))return 8;if(!type)return Math.min(siz
|
||
|
var asm=(function(global,env,buffer) {
|
||
|
"use asm";var a=new global.Int8Array(buffer);var b=new global.Int16Array(buffer);var c=new global.Int32Array(buffer);var d=new global.Uint8Array(buffer);var e=new global.Uint16Array(buffer);var f=new global.Uint32Array(buffer);var g=new global.Float32Array(buffer);var h=new global.Float64Array(buffer);var i=env.STACKTOP|0;var j=env.STACK_MAX|0;var k=env.tempDoublePtr|0;var l=env.ABORT|0;var m=env.cttz_i8|0;var n=env.ctlz_i8|0;var o=0;var p=0;var q=0;var r=0;var s=+env.NaN,t=+env.Infinity;var u=0,v=0,w=0,x=0,y=0.0,z=0,A=0,B=0,C=0.0;var D=0;var E=0;var F=0;var G=0;var H=0;var I=0;var J=0;var K=0;var L=0;var M=0;var N=global.Math.floor;var O=global.Math.abs;var P=global.Math.sqrt;var Q=global.Math.pow;var R=global.Math.cos;var S=global.Math.sin;var T=global.Math.tan;var U=global.Math.acos;var V=global.Math.asin;var W=global.Math.atan;var X=global.Math.atan2;var Y=global.Math.exp;var Z=global.Math.log;var _=global.Math.ceil;var $=global.Math.imul;var aa=env.abort;var ba=env.assert;var ca=env.min;var da=env.invoke_viiiiiii;var ea=env._exp;var fa=env._llvm_pow_f64;var ga=env._sqrtf;var ha=env._atan2;var ia=env.___setErrNo;var ja=env._llvm_stackrestore;var ka=env._floor;var la=env._log10;var ma=env._fabsf;var na=env._sbrk;var oa=env._emscripten_memcpy_big;var pa=env._exp2;var qa=env._sysconf;var ra=env._cos;var sa=env._lrintf;var ta=env._llvm_stacksave;var ua=env._floorf;var va=env._log;var wa=env.___errno_location;var xa=env._abort;var ya=env._time;var za=env._rint;var Aa=env._sqrt;var Ba=0.0;
|
||
|
// EMSCRIPTEN_START_FUNCS
|
||
|
function Da(a){a=a|0;var b=0;b=i;i=i+a|0;i=i+15&-16;return b|0}function Ea(){return i|0}function Fa(a){a=a|0;i=a}function Ga(a,b){a=a|0;b=b|0;if(!o){o=a;p=b}}function Ha(b){b=b|0;a[k>>0]=a[b>>0];a[k+1>>0]=a[b+1>>0];a[k+2>>0]=a[b+2>>0];a[k+3>>0]=a[b+3>>0]}function Ia(b){b=b|0;a[k>>0]=a[b>>0];a[k+1>>0]=a[b+1>>0];a[k+2>>0]=a[b+2>>0];a[k+3>>0]=a[b+3>>0];a[k+4>>0]=a[b+4>>0];a[k+5>>0]=a[b+5>>0];a[k+6>>0]=a[b+6>>0];a[k+7>>0]=a[b+7>>0]}function Ja(a){a=a|0;D=a}function Ka(){return D|0}function La(a,b){a=+a;b=b|0;var c=0,d=0,e=0;c=i;d=0;while(1){if((d|0)>=21)break;if(+g[320+(d<<2)>>2]>a)break;d=d+1|0}if((d|0)>(b|0)?+g[320+(b<<2)>>2]+ +g[408+(b<<2)>>2]>a:0){d=b;i=c;return d|0}if((d|0)>=(b|0)){i=c;return d|0}e=b+ -1|0;if(!(+g[320+(e<<2)>>2]- +g[408+(e<<2)>>2]<a)){e=d;i=c;return e|0}e=b;i=c;return e|0}function Ma(a){a=a|0;a=($(a,1664525)|0)+1013904223|0;return a|0}function Na(a,d,e,f,h,j){a=a|0;d=d|0;e=e|0;f=f|0;h=h|0;j=j|0;var k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0.0,s=0,t=0;m=i;k=c[a+32>>2]|0;l=c[a+44>>2]<<j;n=a+8|0;a=0;do{o=$(a,l)|0;p=0;while(1){if((p|0)>=(f|0))break;s=b[k+(p<<1)>>1]|0;t=d+(o+(s<<j)<<2)|0;q=p+1|0;r=+P(+(+Oa(t,t,(b[k+(q<<1)>>1]|0)-s<<j)+1.0000000272452012e-27));g[e+(p+($(a,c[n>>2]|0)|0)<<2)>>2]=r;p=q}a=a+1|0}while((a|0)<(h|0));i=m;return}function Oa(a,b,c){a=a|0;b=b|0;c=c|0;var d=0,e=0.0,f=0,h=0.0;d=i;f=0;e=0.0;while(1){if((f|0)>=(c|0))break;h=e+ +g[a+(f<<2)>>2]*+g[b+(f<<2)>>2];f=f+1|0;e=h}i=d;return+e}function Pa(a,d,e,f,h,j,k){a=a|0;d=d|0;e=e|0;f=f|0;h=h|0;j=j|0;k=k|0;var l=0,m=0,n=0,o=0,p=0,q=0.0,r=0,s=0,t=0,u=0;n=i;l=c[a+32>>2]|0;m=$(c[a+44>>2]|0,k)|0;o=a+8|0;a=0;while(1){p=$(a,m)|0;r=0;a:while(1){if((r|0)>=(h|0))break;q=1.0/(+g[f+(r+($(a,c[o>>2]|0)|0)<<2)>>2]+1.0000000272452012e-27);t=$(b[l+(r<<1)>>1]|0,k)|0;r=r+1|0;s=$(b[l+(r<<1)>>1]|0,k)|0;while(1){if((t|0)>=(s|0))continue a;u=t+p|0;g[e+(u<<2)>>2]=+g[d+(u<<2)>>2]*q;t=t+1|0}}a=a+1|0;if((a|0)>=(j|0))break}i=n;return}function Qa(a,d,e,f,h,j,k,l,m){a=a|0;d=d|0;e=e|0;f=f|0;h=h|0;j=j|0;k=k|0;l=l|0;m=m|0;var n=0,o=0,p=0.0,q=0,r=0,s=0,t=0;o=i;n=c[a+32>>2]|0;a=$(c[a+44>>2]|0,k)|0;q=$(b[n+(j<<1)>>1]|0,k)|0;if((l|0)!=1){t=(a|0)/(l|0)|0;q=(q|0)<(t|0)?q:t}r=(m|0)==0;m=r?q:0;j=r?j:0;h=r?h:0;r=n+(h<<1)|0;s=b[r>>1]|0;l=d+(($(s<<16>>16,k)|0)<<2)|0;q=e;d=0;while(1){if((d|0)>=($(s<<16>>16,k)|0)){r=h;break}g[q>>2]=0.0;s=b[r>>1]|0;q=q+4|0;d=d+1|0}a:while(1){if((r|0)>=(j|0))break;s=$(b[n+(r<<1)>>1]|0,k)|0;d=r+1|0;h=$(b[n+(d<<1)>>1]|0,k)|0;p=+Y(+((+g[f+(r<<2)>>2]+ +g[20656+(r<<2)>>2])*.6931471805599453));t=l;while(1){l=t+4|0;r=q+4|0;g[q>>2]=+g[t>>2]*p;s=s+1|0;if((s|0)<(h|0)){q=r;t=l}else{q=r;r=d;continue a}}}wj(e+(m<<2)|0,0,a-m<<2|0)|0;i=o;return}function Ra(a,e,f,h,j,k,l,m,n,o,p,q,r,s){a=a|0;e=e|0;f=f|0;h=h|0;j=j|0;k=k|0;l=l|0;m=m|0;n=n|0;o=o|0;p=p|0;q=q|0;r=r|0;s=s|0;var t=0,u=0,v=0,w=0,x=0,y=0,z=0.0,A=0.0,B=0,C=0,D=0,E=0,F=0,G=0.0,H=0.0,I=0,J=0,K=0,L=0,M=0.0,N=0;u=i;t=a+32|0;w=a+8|0;v=(j|0)==1;x=(h|0)==3;a=1<<h;a:while(1){if((l|0)>=(m|0))break;C=l+1|0;B=c[t>>2]|0;B=(b[B+(C<<1)>>1]|0)-(b[B+(l<<1)>>1]|0)|0;A=+Y(+(+((Sa((c[q+(l<<2)>>2]|0)+1|0,B)|0)>>>h|0)*-.125*.6931471805599453))*.5;D=B<<h;z=1.0/+P(+(+(D|0)));y=$(l,j)|0;E=0;while(1){I=c[w>>2]|0;F=($(E,I)|0)+l|0;M=+g[o+(F<<2)>>2];G=+g[p+(F<<2)>>2];if(v){L=I+l|0;H=+g[o+(L<<2)>>2];M=M>H?M:H;H=+g[p+(L<<2)>>2];if(!(G>H))G=H}G=+g[n+(F<<2)>>2]-(M<G?M:G);G=+Y(+(-(G<0.0?0.0:G)*.6931471805599453))*2.0;if(x)G=G*1.4142135381698608;G=(A<G?A:G)*z;F=$(E,k)|0;F=F+(b[(c[t>>2]|0)+(l<<1)>>1]<<h)|0;J=e+(F<<2)|0;I=f+(y+E)|0;H=-G;L=0;K=0;while(1){if((K|0)>=(a|0))break;b:do if(!(d[I>>0]&1<<K)){L=0;while(1){if((L|0)>=(B|0)){L=1;break b}N=Ma(r)|0;g[e+(F+((L<<h)+K)<<2)>>2]=(N&32768|0)==0?H:G;r=N;L=L+1|0}}while(0);K=K+1|0}if(L)Ad(J,D,1.0,s);E=E+1|0;if((E|0)>=(j|0)){l=C;continue a}}}i=u;return}function Sa(a,b){a=a|0;b=b|0;return(a>>>0)/(b>>>0)|0|0}function Ta(a,d,e,f,h,j,k,l,m,n){a=a|0;d=d|0;e=e|0;f=f|0;h=h|0;j=j|0;k=k|0;l=l|0;m=m|0;n=n|0;var o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0.0,D=0,E=0.0;o=i;q=c[a+32>>2]|0;r=$(c[a+44>>2]|0,n)|0;if(($((b[q+(l<<1)>>1]|0)-(b[q+(l+ -1<<1)>>1]|0)|0,n)|0)<9){D=0;i=o;return D|0}s=a+8|0;z=0;x=0;p=0;y=0;a=0;a:wh
|
||
|
|
||
|
|
||
|
|
||
|
function Sd(a,c,d,e,f,g){a=a|0;c=c|0;d=d|0;e=e|0;f=f|0;g=g|0;var h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;l=i;g=d+2|0;m=d+4|0;k=d+6|0;h=d+8|0;n=d+10|0;j=f;while(1){if((j|0)>=(e|0))break;p=j+ -1|0;o=$(b[c+(p<<1)>>1]|0,b[d>>1]|0)|0;o=o+($(b[c+(j+ -2<<1)>>1]|0,b[g>>1]|0)|0)|0;o=o+($(b[c+(j+ -3<<1)>>1]|0,b[m>>1]|0)|0)|0;o=o+($(b[c+(j+ -4<<1)>>1]|0,b[k>>1]|0)|0)|0;o=o+($(b[c+(j+ -5<<1)>>1]|0,b[h>>1]|0)|0)|0;o=o+($(b[c+(j+ -6<<1)>>1]|0,b[n>>1]|0)|0)|0;q=6;while(1){if((q|0)>=(f|0))break;r=o+($(b[c+(p-q<<1)>>1]|0,b[d+(q<<1)>>1]|0)|0)|0;o=r+($(b[c+(p+~q<<1)>>1]|0,b[d+((q|1)<<1)>>1]|0)|0)|0;q=q+2|0}o=((b[c+(j<<1)>>1]<<12)-o>>11)+1>>1;if((o|0)>32767)o=32767;else o=(o|0)<-32768?-32768:o&65535;b[a+(j<<1)>>1]=o;j=j+1|0}wj(a|0,0,f<<1|0)|0;i=l;return}function Td(a,d){a=a|0;d=d|0;var e=0,f=0,g=0,h=0,j=0,k=0;e=i;i=i+128|0;f=e;h=d&1;g=0;j=0;while(1){if((j|0)>=(d|0))break;k=b[a+(j<<1)>>1]|0;c[f+(h<<6)+(j<<2)>>2]=k<<12;g=g+k|0;j=j+1|0}if((g|0)>4095){k=0;i=e;return k|0}k=Ud(f,d)|0;i=e;return k|0}function Ud(a,b){a=a|0;b=b|0;var d=0,e=0,f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;d=i;f=b&1;l=1073741824;k=0;while(1){b=b+ -1|0;if((b|0)<=0)break;g=c[a+(f<<6)+(b<<2)>>2]|0;if((g|0)>16773022|(g|0)<-16773022){a=0;e=13;break}j=0-(g<<7)|0;h=((j|0)<0)<<31>>31;Gj(j|0,h|0,j|0,h|0)|0;o=1073741824-D|0;m=32-(Vd((o|0)>0?o:0-o|0)|0)|0;g=Wd(o,m+30|0)|0;k=Gj(l|0,k|0,o|0,((o|0)<0)<<31>>31|0)|0;k=uj(k|0,D|0,30)|0;k=k&-4;l=b&1;o=(m|0)==1;n=((g|0)<0)<<31>>31;m=m+ -1|0;p=0;while(1){if((p|0)>=(b|0))break;q=c[a+(f<<6)+(p<<2)>>2]|0;r=c[a+(f<<6)+(b-p+ -1<<2)>>2]|0;r=Gj(r|0,((r|0)<0)<<31>>31|0,j|0,h|0)|0;r=uj(r|0,D|0,30)|0;r=xj(r|0,D|0,1,0)|0;r=uj(r|0,D|0,1)|0;r=q-r|0;r=Gj(r|0,((r|0)<0)<<31>>31|0,g|0,n|0)|0;q=D;if(o){q=uj(r|0,q|0,1)|0;q=xj(q|0,D|0,r&1|0,0)|0}else{q=tj(r|0,q|0,m|0)|0;q=xj(q|0,D|0,1,0)|0;q=uj(q|0,D|0,1)|0}c[a+(l<<6)+(p<<2)>>2]=q;p=p+1|0}f=l;l=k;k=((k|0)<0)<<31>>31}if((e|0)==13){i=d;return a|0}e=c[a+(f<<6)>>2]|0;if((e|0)>16773022|(e|0)<-16773022){r=0;i=d;return r|0}q=0-(e<<7)|0;r=((q|0)<0)<<31>>31;Gj(q|0,r|0,q|0,r|0)|0;r=1073741824-D|0;r=Gj(l|0,k|0,r|0,((r|0)<0)<<31>>31|0)|0;r=uj(r|0,D|0,30)|0;r=r&-4;i=d;return r|0}function Vd(a){a=a|0;var b=0;b=i;if(!a)a=32;else a=vj(a|0)|0;i=b;return a|0}function Wd(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0,g=0,h=0;c=i;e=Vd((a|0)>0?a:0-a|0)|0;d=a<<e+ -1;h=d>>16;a=536870911/(h|0)|0;g=a<<16;f=g>>16;d=536870912-(($(h,f)|0)+(($(d&65535,f)|0)>>16))<<3;a=g+(($(d>>16,f)|0)+(($(d&65528,f)|0)>>16))+($(d,(a>>15)+1>>1)|0)|0;b=62-e-b|0;if((b|0)>=1){i=c;return((b|0)<32?a>>b:0)|0}b=0-b|0;d=-2147483648>>b;e=2147483647>>>b;if((d|0)>(e|0)){if((a|0)>(d|0)){h=d;h=h<<b;i=c;return h|0}h=(a|0)<(e|0)?e:a;h=h<<b;i=c;return h|0}else{if((a|0)>(e|0)){h=e;h=h<<b;i=c;return h|0}h=(a|0)<(d|0)?d:a;h=h<<b;i=c;return h|0}return 0}function Xd(a,b,d){a=a|0;b=b|0;d=d|0;var e=0,f=0,g=0,h=0,j=0,k=0,l=0;e=i;i=i+32|0;f=e+8|0;g=e;j=a+12|0;if(!(c[j>>2]|0)){i=e;return}h=a+8|0;l=256-(c[h>>2]|0)<<10;k=l>>16;Yd(f,g,k,l-(k<<16)|0);j=(c[h>>2]|0)+(c[j>>2]|0)|0;if((j|0)>256)j=256;else j=(j|0)<0?0:j;c[h>>2]=j;gf(b,f,g,a,b,d);i=e;return}function Yd(a,b,d,e){a=a|0;b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,j=0,k=0;h=i;if((d|0)>=4){c[a+0>>2]=c[6270];c[a+4>>2]=c[6271];c[a+8>>2]=c[6272];e=b;c[e>>2]=35497197;c[e+4>>2]=57401098;i=h;return}if((e|0)<=0){g=25032+(d*12|0)|0;c[a+0>>2]=c[g+0>>2];c[a+4>>2]=c[g+4>>2];c[a+8>>2]=c[g+8>>2];g=25096+(d<<3)|0;a=c[g+4>>2]|0;e=b;c[e>>2]=c[g>>2];c[e+4>>2]=a;i=h;return}f=d+1|0;g=e<<16>>16;if((e|0)<32768){e=0;while(1){if((e|0)>=3){a=0;break}k=c[25032+(d*12|0)+(e<<2)>>2]|0;j=(c[25032+(f*12|0)+(e<<2)>>2]|0)-k|0;c[a+(e<<2)>>2]=k+(($(j>>16,g)|0)+(($(j&65535,g)|0)>>16));e=e+1|0}while(1){if((a|0)>=2)break;j=c[25096+(d<<3)+(a<<2)>>2]|0;k=(c[25096+(f<<3)+(a<<2)>>2]|0)-j|0;c[b+(a<<2)>>2]=j+(($(k>>16,g)|0)+(($(k&65535,g)|0)>>16));a=a+1|0}i=h;return}else{e=0;while(1){if((e|0)>=3){a=0;break}j=c[25032+(f*12|0)+(e<<2)>>2]|0;k=j-(c[25032+(d*12|0)+(e<<2)>>2]|0)|0;c[a+(e<<2)>>2]=j+(($(k>>16,g)|0)+(($(k&65535,g)|0)>>16));e=e+1|0}while(1){if((a|0)>=2)break;j=c[25096+(f<<3)+(a<<2)>>2]|0;k=j-(c[25096+(d<<3)+(a<<2)>>2]|0)|0;c[b+(a<<2)>>2]=j+(($(k>>16,g)|0)+(($(k&65535,g)|0)>>16))
|
||
|
|
||
|
|
||
|
|
||
|
function xg(b,d,e,f){b=b|0;d=d|0;e=e|0;f=f|0;var h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0.0,r=0.0,s=0.0,t=0,u=0,v=0,w=0,x=0,y=0.0,z=0,A=0,B=0,C=0.0;h=i;i=i+1040|0;n=h+72|0;m=h;o=f+(0-(c[b+4624>>2]|0)<<2)|0;p=b+4748|0;s=+(c[p>>2]|0)*.0078125;l=b+4728|0;q=+((c[l>>2]|0)+(c[b+4732>>2]|0)|0)*.5*30517578125.0e-15;j=d+856|0;g[j>>2]=q;r=+yg((s+-20.0)*.25);k=d+860|0;g[k>>2]=r;if(!(c[b+4708>>2]|0)){C=1.0- +(c[b+4556>>2]|0)*.00390625;r=s-r*2.0*(q*.5+.5)*C*C}else r=s;f=b+4797|0;if((a[f>>0]|0)==2){q=r+ +g[b+12236>>2]*2.0;a[b+4798>>0]=0;g[d+864>>2]=0.0}else{q=r+(+(c[p>>2]|0)*-.4000000059604645*.0078125+6.0)*(1.0-q);t=c[b+4600>>2]<<1;p=b+4604|0;r=+(t|0);s=0.0;C=0.0;u=0;while(1){if((u|0)>=(((c[p>>2]<<16>>16)*5|0)/2|0|0))break;y=+zg(r+ +og(e,t));if((u|0)>0)s=s+ +O(+(y-C));C=y;e=e+(t<<2)|0;u=u+1|0}C=+yg((s+-5.0)*.4000000059604645);e=d+864|0;g[e>>2]=C;p=b+4798|0;if(C>.75)a[p>>0]=0;else a[p>>0]=1;q=q+(+g[e>>2]+-.5)*2.0}C=+g[d+868>>2]*.0010000000474974513;C=.949999988079071/(C*C+1.0);y=+g[k>>2];r=(1.0-y*.75)*.009999999776482582;s=C+r;r=(C-r)/s;t=b+4704|0;e=c[t>>2]|0;if((e|0)>0)y=+(e|0)*152587890625.0e-16+y*.009999999776482582;else y=0.0;e=b+4604|0;p=b+4600|0;x=b+4628|0;w=b+4612|0;u=b+4660|0;v=0;while(1){z=c[e>>2]|0;if((v|0)>=(z|0))break;B=c[p>>2]|0;z=B*3|0;A=((c[x>>2]|0)-z|0)/2|0;ag(n,o,1,A);yj(n+(A<<2)|0,o+(A<<2)|0,B*12|0)|0;z=A+z|0;ag(n+(z<<2)|0,o+(z<<2)|0,2,A);o=o+(c[w>>2]<<2)|0;A=c[x>>2]|0;z=c[u>>2]|0;if((c[t>>2]|0)>0)_g(m,n,y,A,z);else bg(m,n,A,z+1|0);C=+g[m>>2];g[m>>2]=C+C*4999999873689376.0e-20;A=v<<4;B=d+(A<<2)+500|0;C=+P(+(+wg(B,m,c[u>>2]|0)));z=d+(v<<2)|0;g[z>>2]=C;if((c[t>>2]|0)>0)g[z>>2]=C*+Ag(B,y,c[u>>2]|0);dg(B,c[u>>2]|0,s);A=d+(A<<2)+244|0;yj(A|0,B|0,c[u>>2]<<2|0)|0;dg(A,c[u>>2]|0,r);C=+Zf(B,c[u>>2]|0);g[d+(v<<2)+788>>2]=1.0-(1.0-C/+Zf(A,c[u>>2]|0))*.699999988079071;Bg(B,A,y,c[u>>2]|0);v=v+1|0}q=+pa(+(q*-.1599999964237213));m=0;while(1){if((m|0)>=(z|0))break;z=d+(m<<2)|0;g[z>>2]=+g[z>>2]*q+1.2483305931091309;z=c[e>>2]|0;m=m+1|0}q=+g[k>>2]*.10000000149011612+1.0499999523162842;m=0;while(1){if((m|0)>=(z|0))break;z=d+(m<<2)+788|0;g[z>>2]=+g[z>>2]*q;z=c[e>>2]|0;m=m+1|0}m=b+4556|0;q=((+(c[l>>2]|0)*30517578125.0e-15+-1.0)*.5+1.0)*4.0*+(c[m>>2]|0)*.00390625;a:do if((a[f>>0]|0)==2){l=0;while(1){if((l|0)>=(z|0))break;C=.20000000298023224/+(c[p>>2]|0)+3.0/+(c[d+(l<<2)+228>>2]|0);g[d+(l<<2)+756>>2]=C+-1.0;g[d+(l<<2)+772>>2]=1.0-C-C*q;z=c[e>>2]|0;l=l+1|0}q=-.25- +(c[m>>2]|0)*.26249998807907104*.00390625}else{C=1.2999999523162842/+(c[p>>2]|0);l=d+756|0;g[l>>2]=C+-1.0;m=d+772|0;g[m>>2]=1.0-C-C*q*.6000000238418579;n=1;while(1){z=c[e>>2]|0;if((n|0)>=(z|0)){q=-.25;break a}g[d+(n<<2)+756>>2]=+g[l>>2];g[d+(n<<2)+772>>2]=+g[m>>2];n=n+1|0}}while(0);s=1.0- +g[k>>2];y=+g[b+12236>>2];C=+g[j>>2];r=s*.10000000149011612*y+(1.0-C)*.10000000149011612;if((a[f>>0]|0)==2)s=((1.0-s*C)*.20000000298023224+.30000001192092896)*+P(+y);else s=0.0;j=b+7204|0;f=b+7208|0;b=b+7212|0;k=0;while(1){if((k|0)>=(z|0))break;C=+g[j>>2];C=C+(r-C)*.4000000059604645;g[j>>2]=C;g[d+(k<<2)+804>>2]=C;C=+g[f>>2];C=C+(s-C)*.4000000059604645;g[f>>2]=C;g[d+(k<<2)+836>>2]=C;C=+g[b>>2];C=C+(q-C)*.4000000059604645;g[b>>2]=C;g[d+(k<<2)+820>>2]=C;z=c[e>>2]|0;k=k+1|0}i=h;return}function yg(a){a=+a;a=1.0/(+Y(+-a)+1.0);return+a}function zg(a){a=+a;var b=0;b=i;a=+la(+a)*3.32192809488736;i=b;return+a}function Ag(a,b,c){a=a|0;b=+b;c=c|0;var d=0,e=0.0;d=i;b=-b;e=+g[a+(c+ -1<<2)>>2];c=c+ -2|0;while(1){e=e*b;if((c|0)<=-1)break;e=e+ +g[a+(c<<2)>>2];c=c+ -1|0}i=d;return+(1.0/(1.0-e))}function Bg(a,b,c,d){a=a|0;b=b|0;c=+c;d=d|0;var e=0,f=0.0,h=0,j=0,k=0.0,l=0.0,m=0.0,n=0,o=0,p=0.0,q=0.0,r=0,s=0;e=i;j=d;while(1){h=j+ -1|0;if((h|0)<=0)break;o=j+ -2|0;n=a+(o<<2)|0;g[n>>2]=+g[n>>2]- +g[a+(h<<2)>>2]*c;o=b+(o<<2)|0;g[o>>2]=+g[o>>2]- +g[b+(h<<2)>>2]*c;j=h}f=1.0-c*c;m=f/(+g[a>>2]*c+1.0);k=f/(+g[b>>2]*c+1.0);h=0;while(1){if((h|0)>=(d|0)){j=0;h=0;break}o=a+(h<<2)|0;g[o>>2]=+g[o>>2]*m;o=b+(h<<2)|0;g[o>>2]=+g[o>>2]*k;h=h+1|0}while(1){if((h|0)<10){l=-1.0;n=0}else{a=23;break}while(1){if((n|0)>=(d|0))break;q=+O(+(+g[a+(n<<2)>>2]));p=+O(+(+g[b+(n<<2)>>2]));p=q>p?q:p;o=p>l;j=o?n:j;l=o?p:l;n=n+1|0}if(!(l<=3.999000072479248))n
|
||
|
|
||
|
|
||
|
|
||
|
function qj(a){a=a|0;var b=0,d=0,e=0,f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0;b=i;do if(a>>>0<245){if(a>>>0<11)a=16;else a=a+11&-8;v=a>>>3;p=c[7654]|0;w=p>>>v;if(w&3){h=(w&1^1)+v|0;g=h<<1;e=30656+(g<<2)|0;g=30656+(g+2<<2)|0;j=c[g>>2]|0;d=j+8|0;f=c[d>>2]|0;do if((e|0)!=(f|0)){if(f>>>0<(c[7658]|0)>>>0)xa();k=f+12|0;if((c[k>>2]|0)==(j|0)){c[k>>2]=e;c[g>>2]=f;break}else xa()}else c[7654]=p&~(1<<h);while(0);H=h<<3;c[j+4>>2]=H|3;H=j+(H|4)|0;c[H>>2]=c[H>>2]|1;H=d;i=b;return H|0}if(a>>>0>(c[7656]|0)>>>0){if(w){h=2<<v;h=w<<v&(h|0-h);h=(h&0-h)+ -1|0;d=h>>>12&16;h=h>>>d;f=h>>>5&8;h=h>>>f;g=h>>>2&4;h=h>>>g;e=h>>>1&2;h=h>>>e;j=h>>>1&1;j=(f|d|g|e|j)+(h>>>j)|0;h=j<<1;e=30656+(h<<2)|0;h=30656+(h+2<<2)|0;g=c[h>>2]|0;d=g+8|0;f=c[d>>2]|0;do if((e|0)!=(f|0)){if(f>>>0<(c[7658]|0)>>>0)xa();k=f+12|0;if((c[k>>2]|0)==(g|0)){c[k>>2]=e;c[h>>2]=f;break}else xa()}else c[7654]=p&~(1<<j);while(0);h=j<<3;f=h-a|0;c[g+4>>2]=a|3;e=g+a|0;c[g+(a|4)>>2]=f|1;c[g+h>>2]=f;h=c[7656]|0;if(h){g=c[7659]|0;k=h>>>3;j=k<<1;h=30656+(j<<2)|0;l=c[7654]|0;k=1<<k;if(l&k){j=30656+(j+2<<2)|0;k=c[j>>2]|0;if(k>>>0<(c[7658]|0)>>>0)xa();else{D=j;C=k}}else{c[7654]=l|k;D=30656+(j+2<<2)|0;C=h}c[D>>2]=g;c[C+12>>2]=g;c[g+8>>2]=C;c[g+12>>2]=h}c[7656]=f;c[7659]=e;H=d;i=b;return H|0}p=c[7655]|0;if(p){e=(p&0-p)+ -1|0;G=e>>>12&16;e=e>>>G;F=e>>>5&8;e=e>>>F;H=e>>>2&4;e=e>>>H;f=e>>>1&2;e=e>>>f;d=e>>>1&1;d=c[30920+((F|G|H|f|d)+(e>>>d)<<2)>>2]|0;e=(c[d+4>>2]&-8)-a|0;f=d;while(1){g=c[f+16>>2]|0;if(!g){g=c[f+20>>2]|0;if(!g)break}f=(c[g+4>>2]&-8)-a|0;H=f>>>0<e>>>0;e=H?f:e;f=g;d=H?g:d}h=c[7658]|0;if(d>>>0<h>>>0)xa();f=d+a|0;if(d>>>0>=f>>>0)xa();g=c[d+24>>2]|0;k=c[d+12>>2]|0;do if((k|0)==(d|0)){k=d+20|0;j=c[k>>2]|0;if(!j){k=d+16|0;j=c[k>>2]|0;if(!j){B=0;break}}while(1){l=j+20|0;m=c[l>>2]|0;if(m){j=m;k=l;continue}m=j+16|0;l=c[m>>2]|0;if(!l)break;else{j=l;k=m}}if(k>>>0<h>>>0)xa();else{c[k>>2]=0;B=j;break}}else{j=c[d+8>>2]|0;if(j>>>0<h>>>0)xa();h=j+12|0;if((c[h>>2]|0)!=(d|0))xa();l=k+8|0;if((c[l>>2]|0)==(d|0)){c[h>>2]=k;c[l>>2]=j;B=k;break}else xa()}while(0);do if(g){h=c[d+28>>2]|0;j=30920+(h<<2)|0;if((d|0)==(c[j>>2]|0)){c[j>>2]=B;if(!B){c[7655]=c[7655]&~(1<<h);break}}else{if(g>>>0<(c[7658]|0)>>>0)xa();h=g+16|0;if((c[h>>2]|0)==(d|0))c[h>>2]=B;else c[g+20>>2]=B;if(!B)break}if(B>>>0<(c[7658]|0)>>>0)xa();c[B+24>>2]=g;g=c[d+16>>2]|0;do if(g)if(g>>>0<(c[7658]|0)>>>0)xa();else{c[B+16>>2]=g;c[g+24>>2]=B;break}while(0);g=c[d+20>>2]|0;if(g)if(g>>>0<(c[7658]|0)>>>0)xa();else{c[B+20>>2]=g;c[g+24>>2]=B;break}}while(0);if(e>>>0<16){H=e+a|0;c[d+4>>2]=H|3;H=d+(H+4)|0;c[H>>2]=c[H>>2]|1}else{c[d+4>>2]=a|3;c[d+(a|4)>>2]=e|1;c[d+(e+a)>>2]=e;h=c[7656]|0;if(h){g=c[7659]|0;l=h>>>3;j=l<<1;h=30656+(j<<2)|0;k=c[7654]|0;l=1<<l;if(k&l){j=30656+(j+2<<2)|0;k=c[j>>2]|0;if(k>>>0<(c[7658]|0)>>>0)xa();else{A=j;z=k}}else{c[7654]=k|l;A=30656+(j+2<<2)|0;z=h}c[A>>2]=g;c[z+12>>2]=g;c[g+8>>2]=z;c[g+12>>2]=h}c[7656]=e;c[7659]=f}H=d+8|0;i=b;return H|0}}}else if(a>>>0<=4294967231){z=a+11|0;a=z&-8;B=c[7655]|0;if(B){A=0-a|0;z=z>>>8;if(z)if(a>>>0>16777215)C=31;else{G=(z+1048320|0)>>>16&8;H=z<<G;F=(H+520192|0)>>>16&4;H=H<<F;C=(H+245760|0)>>>16&2;C=14-(F|G|C)+(H<<C>>>15)|0;C=a>>>(C+7|0)&1|C<<1}else C=0;D=c[30920+(C<<2)>>2]|0;a:do if(!D){F=0;z=0}else{if((C|0)==31)z=0;else z=25-(C>>>1)|0;F=0;E=a<<z;z=0;while(1){H=c[D+4>>2]&-8;G=H-a|0;if(G>>>0<A>>>0)if((H|0)==(a|0)){A=G;F=D;z=D;break a}else{A=G;z=D}H=c[D+20>>2]|0;D=c[D+(E>>>31<<2)+16>>2]|0;F=(H|0)==0|(H|0)==(D|0)?F:H;if(!D)break;else E=E<<1}}while(0);if((F|0)==0&(z|0)==0){H=2<<C;B=B&(H|0-H);if(!B)break;H=(B&0-B)+ -1|0;D=H>>>12&16;H=H>>>D;C=H>>>5&8;H=H>>>C;E=H>>>2&4;H=H>>>E;G=H>>>1&2;H=H>>>G;F=H>>>1&1;F=c[30920+((C|D|E|G|F)+(H>>>F)<<2)>>2]|0}if(F)while(1){H=(c[F+4>>2]&-8)-a|0;B=H>>>0<A>>>0;A=B?H:A;z=B?F:z;B=c[F+16>>2]|0;if(B){F=B;continue}F=c[F+20>>2]|0;if(!F)break}if((z|0)!=0?A>>>0<((c[7656]|0)-a|0)>>>0:0){f=c[7658]|0;if(z>>>0<f>>>0)xa();d=z+a|0;if(z>>>0>=d>>>0)xa();e=c[z+24>>2]|0;h=c[z+12>>2]|0;do if((h|0)==(z|0)){h=z+20|0;g=c[h>>2]|0;if(!g){h=z+16|0;g=c[h>>2]|0;if(!g){x=0;break}}while(1){j=g+20|0;k=c[j>>2]|0;if(k){g=k;h=j;conti
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// EMSCRIPTEN_END_FUNCS
|
||
|
var Ca=[Lj,Ri,Qi,Lj];return{_opus_get_version_string:qb,_free:rj,_opus_encode_float:fj,_opus_decoder_create:si,_i64Add:xj,_memmove:zj,_opus_decode_float:Di,_bitshift64Ashr:tj,_opus_encoder_destroy:hj,_memset:wj,_malloc:qj,_opus_decoder_destroy:Fi,_opus_encoder_create:Ni,_opus_encode:ej,_llvm_ctlz_i32:vj,_bitshift64Lshr:uj,_opus_decode:Ai,_opus_decoder_ctl:Ei,_memcpy:yj,_opus_encoder_ctl:gj,runPostSets:sj,stackAlloc:Da,stackSave:Ea,stackRestore:Fa,setThrew:Ga,setTempRet0:Ja,getTempRet0:Ka,dynCall_viiiiiii:Kj}})
|
||
|
|
||
|
|
||
|
// EMSCRIPTEN_END_ASM
|
||
|
(Module.asmGlobalArg,Module.asmLibraryArg,buffer);var _opus_get_version_string=Module["_opus_get_version_string"]=asm["_opus_get_version_string"];var _free=Module["_free"]=asm["_free"];var _opus_encode_float=Module["_opus_encode_float"]=asm["_opus_encode_float"];var _opus_decoder_create=Module["_opus_decoder_create"]=asm["_opus_decoder_create"];var _i64Add=Module["_i64Add"]=asm["_i64Add"];var _memmove=Module["_memmove"]=asm["_memmove"];var _opus_decode_float=Module["_opus_decode_float"]=asm["_opus_decode_float"];var _bitshift64Ashr=Module["_bitshift64Ashr"]=asm["_bitshift64Ashr"];var _opus_encoder_destroy=Module["_opus_encoder_destroy"]=asm["_opus_encoder_destroy"];var _memset=Module["_memset"]=asm["_memset"];var _malloc=Module["_malloc"]=asm["_malloc"];var _opus_decoder_destroy=Module["_opus_decoder_destroy"]=asm["_opus_decoder_destroy"];var _opus_encoder_create=Module["_opus_encoder_create"]=asm["_opus_encoder_create"];var _opus_encode=Module["_opus_encode"]=asm["_opus_encode"];var _llvm_ctlz_i32=Module["_llvm_ctlz_i32"]=asm["_llvm_ctlz_i32"];var _bitshift64Lshr=Module["_bitshift64Lshr"]=asm["_bitshift64Lshr"];var _opus_decode=Module["_opus_decode"]=asm["_opus_decode"];var _opus_decoder_ctl=Module["_opus_decoder_ctl"]=asm["_opus_decoder_ctl"];var _memcpy=Module["_memcpy"]=asm["_memcpy"];var _opus_encoder_ctl=Module["_opus_encoder_ctl"]=asm["_opus_encoder_ctl"];var runPostSets=Module["runPostSets"]=asm["runPostSets"];var dynCall_viiiiiii=Module["dynCall_viiiiiii"]=asm["dynCall_viiiiiii"];Runtime.stackAlloc=asm["stackAlloc"];Runtime.stackSave=asm["stackSave"];Runtime.stackRestore=asm["stackRestore"];Runtime.setTempRet0=asm["setTempRet0"];Runtime.getTempRet0=asm["getTempRet0"];var i64Math=(function(){var goog={math:{}};goog.math.Long=(function(low,high){this.low_=low|0;this.high_=high|0});goog.math.Long.IntCache_={};goog.math.Long.fromInt=(function(value){if(-128<=value&&value<128){var cachedObj=goog.math.Long.IntCache_[value];if(cachedObj){return cachedObj}}var obj=new goog.math.Long(value|0,value<0?-1:0);if(-128<=value&&value<128){goog.math.Long.IntCache_[value]=obj}return obj});goog.math.Long.fromNumber=(function(value){if(isNaN(value)||!isFinite(value)){return goog.math.Long.ZERO}else if(value<=-goog.math.Long.TWO_PWR_63_DBL_){return goog.math.Long.MIN_VALUE}else if(value+1>=goog.math.Long.TWO_PWR_63_DBL_){return goog.math.Long.MAX_VALUE}else if(value<0){return goog.math.Long.fromNumber(-value).negate()}else{return new goog.math.Long(value%goog.math.Long.TWO_PWR_32_DBL_|0,value/goog.math.Long.TWO_PWR_32_DBL_|0)}});goog.math.Long.fromBits=(function(lowBits,highBits){return new goog.math.Long(lowBits,highBits)});goog.math.Long.fromString=(function(str,opt_radix){if(str.length==0){throw Error("number format error: empty string")}var radix=opt_radix||10;if(radix<2||36<radix){throw Error("radix out of range: "+radix)}if(str.charAt(0)=="-"){return goog.math.Long.fromString(str.substring(1),radix).negate()}else if(str.indexOf("-")>=0){throw Error('number format error: interior "-" character: '+str)}var radixToPower=goog.math.Long.fromNumber(Math.pow(radix,8));var result=goog.math.Long.ZERO;for(var i=0;i<str.length;i+=8){var size=Math.min(8,str.length-i);var value=parseInt(str.substring(i,i+size),radix);if(size<8){var power=goog.math.Long.fromNumber(Math.pow(radix,size));result=result.multiply(power).add(goog.math.Long.fromNumber(value))}else{result=result.multiply(radixToPower);result=result.add(goog.math.Long.fromNumber(value))}}return result});goog.math.Long.TWO_PWR_16_DBL_=1<<16;goog.math.Long.TWO_PWR_24_DBL_=1<<24;goog.math.Long.TWO_PWR_32_DBL_=goog.math.Long.TWO_PWR_16_DBL_*goog.math.Long.TWO_PWR_16_DBL_;goog.math.Long.TWO_PWR_31_DBL_=goog.math.Long.TWO_PWR_32_DBL_/2;goog.math.Long.TWO_PWR_48_DBL_=goog.math.Long.TWO_PWR_32_DBL_*goog.math.Long.TWO_PWR_16_DBL_;goog.math.Long.TWO_PWR_64_DBL_=goog.math.Long.TWO_PWR_32_DBL_*goog.math.Long.TWO_PWR_32_DBL_;goog.math.Long.TWO_PWR_63_DBL_=goog.math.Long.TWO_PWR_64_DBL_/2;goog.math.Long.ZERO=goog.math.Long.fromInt(0);goog.math.Long.ONE=goog.math.Long.fromInt(1);goog.math.Long.NE
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
var OpusApplication;
|
||
|
(function (OpusApplication) {
|
||
|
OpusApplication[OpusApplication["VoIP"] = 2048] = "VoIP";
|
||
|
OpusApplication[OpusApplication["Audio"] = 2049] = "Audio";
|
||
|
OpusApplication[OpusApplication["RestrictedLowDelay"] = 2051] = "RestrictedLowDelay";
|
||
|
})(OpusApplication || (OpusApplication = {}));
|
||
|
var OpusError;
|
||
|
(function (OpusError) {
|
||
|
OpusError[OpusError["OK"] = 0] = "OK";
|
||
|
OpusError[OpusError["BadArgument"] = -1] = "BadArgument";
|
||
|
OpusError[OpusError["BufferTooSmall"] = -2] = "BufferTooSmall";
|
||
|
OpusError[OpusError["InternalError"] = -3] = "InternalError";
|
||
|
OpusError[OpusError["InvalidPacket"] = -4] = "InvalidPacket";
|
||
|
OpusError[OpusError["Unimplemented"] = -5] = "Unimplemented";
|
||
|
OpusError[OpusError["InvalidState"] = -6] = "InvalidState";
|
||
|
OpusError[OpusError["AllocFail"] = -7] = "AllocFail";
|
||
|
})(OpusError || (OpusError = {}));
|
||
|
var Opus = (function () {
|
||
|
function Opus() {
|
||
|
}
|
||
|
Opus.getVersion = function () {
|
||
|
var ptr = _opus_get_version_string();
|
||
|
return Pointer_stringify(ptr);
|
||
|
};
|
||
|
Opus.getMaxFrameSize = function (numberOfStreams) {
|
||
|
if (numberOfStreams === void 0) { numberOfStreams = 1; }
|
||
|
return (1275 * 3 + 7) * numberOfStreams;
|
||
|
};
|
||
|
Opus.getMinFrameDuration = function () {
|
||
|
return 2.5;
|
||
|
};
|
||
|
Opus.getMaxFrameDuration = function () {
|
||
|
return 60;
|
||
|
};
|
||
|
Opus.validFrameDuration = function (x) {
|
||
|
return [2.5, 5, 10, 20, 40, 60].some(function (element) {
|
||
|
return element == x;
|
||
|
});
|
||
|
};
|
||
|
Opus.getMaxSamplesPerChannel = function (sampling_rate) {
|
||
|
return sampling_rate / 1000 * Opus.getMaxFrameDuration();
|
||
|
};
|
||
|
return Opus;
|
||
|
})();
|
||
|
|
||
|
var OpusEncoder = (function () {
|
||
|
function OpusEncoder(sampling_rate, channels, app, frame_duration) {
|
||
|
if (frame_duration === void 0) { frame_duration = 20; }
|
||
|
this.handle = 0;
|
||
|
this.frame_size = 0;
|
||
|
this.in_ptr = 0;
|
||
|
this.in_off = 0;
|
||
|
this.out_ptr = 0;
|
||
|
if (!Opus.validFrameDuration(frame_duration))
|
||
|
throw 'invalid frame duration';
|
||
|
this.frame_size = sampling_rate * frame_duration / 1000;
|
||
|
var err_ptr = allocate(4, 'i32', ALLOC_STACK);
|
||
|
this.handle = _opus_encoder_create(sampling_rate, channels, app, err_ptr);
|
||
|
if (getValue(err_ptr, 'i32') != 0 /* OK */)
|
||
|
throw 'opus_encoder_create failed: ' + getValue(err_ptr, 'i32');
|
||
|
this.in_ptr = _malloc(this.frame_size * channels * 4);
|
||
|
this.in_len = this.frame_size * channels;
|
||
|
this.in_i16 = HEAP16.subarray(this.in_ptr >> 1, (this.in_ptr >> 1) + this.in_len);
|
||
|
this.in_f32 = HEAPF32.subarray(this.in_ptr >> 2, (this.in_ptr >> 2) + this.in_len);
|
||
|
this.out_bytes = Opus.getMaxFrameSize();
|
||
|
this.out_ptr = _malloc(this.out_bytes);
|
||
|
this.out_buf = HEAPU8.subarray(this.out_ptr, this.out_ptr + this.out_bytes);
|
||
|
}
|
||
|
OpusEncoder.prototype.encode = function (pcm) {
|
||
|
var output = [];
|
||
|
var pcm_off = 0;
|
||
|
while (pcm.length - pcm_off >= this.in_len - this.in_off) {
|
||
|
if (this.in_off > 0) {
|
||
|
this.in_i16.set(pcm.subarray(pcm_off, pcm_off + this.in_len - this.in_off), this.in_off);
|
||
|
pcm_off += this.in_len - this.in_off;
|
||
|
this.in_off = 0;
|
||
|
}
|
||
|
else {
|
||
|
this.in_i16.set(pcm.subarray(pcm_off, pcm_off + this.in_len));
|
||
|
pcm_off += this.in_len;
|
||
|
}
|
||
|
var ret = _opus_encode(this.handle, this.in_ptr, this.frame_size, this.out_ptr, this.out_bytes);
|
||
|
if (ret <= 0)
|
||
|
throw 'opus_encode failed: ' + ret;
|
||
|
var packet = new ArrayBuffer(ret);
|
||
|
new Uint8Array(packet).set(this.out_buf.subarray(0, ret));
|
||
|
output.push(packet);
|
||
|
}
|
||
|
if (pcm_off < pcm.length) {
|
||
|
this.in_i16.set(pcm.subarray(pcm_off));
|
||
|
this.in_off = pcm.length - pcm_off;
|
||
|
}
|
||
|
return output;
|
||
|
};
|
||
|
OpusEncoder.prototype.encode_float = function (pcm) {
|
||
|
var output = [];
|
||
|
var pcm_off = 0;
|
||
|
while (pcm.length - pcm_off >= this.in_len - this.in_off) {
|
||
|
if (this.in_off > 0) {
|
||
|
this.in_f32.set(pcm.subarray(pcm_off, pcm_off + this.in_len - this.in_off), this.in_off);
|
||
|
pcm_off += this.in_len - this.in_off;
|
||
|
this.in_off = 0;
|
||
|
}
|
||
|
else {
|
||
|
this.in_f32.set(pcm.subarray(pcm_off, pcm_off + this.in_len));
|
||
|
pcm_off += this.in_len;
|
||
|
}
|
||
|
var ret = _opus_encode_float(this.handle, this.in_ptr, this.frame_size, this.out_ptr, this.out_bytes);
|
||
|
if (ret <= 0)
|
||
|
throw 'opus_encode failed: ' + ret;
|
||
|
var packet = new ArrayBuffer(ret);
|
||
|
new Uint8Array(packet).set(this.out_buf.subarray(0, ret));
|
||
|
output.push(packet);
|
||
|
}
|
||
|
if (pcm_off < pcm.length) {
|
||
|
this.in_f32.set(pcm.subarray(pcm_off));
|
||
|
this.in_off = pcm.length - pcm_off;
|
||
|
}
|
||
|
return output;
|
||
|
};
|
||
|
OpusEncoder.prototype.encode_final = function () {
|
||
|
if (this.in_off == 0)
|
||
|
return new ArrayBuffer(0);
|
||
|
for (var i = this.in_off; i < this.in_len; ++i)
|
||
|
this.in_i16[i] = 0;
|
||
|
var ret = _opus_encode(this.handle, this.in_ptr, this.frame_size, this.out_ptr, this.out_bytes);
|
||
|
if (ret <= 0)
|
||
|
throw 'opus_encode failed: ' + ret;
|
||
|
var packet = new ArrayBuffer(ret);
|
||
|
new Uint8Array(packet).set(this.out_buf.subarray(0, ret));
|
||
|
return packet;
|
||
|
};
|
||
|
OpusEncoder.prototype.encode_float_final = function () {
|
||
|
if (this.in_off == 0)
|
||
|
return new ArrayBuffer(0);
|
||
|
for (var i = this.in_off; i < this.in_len; ++i)
|
||
|
this.in_f32[i] = 0;
|
||
|
var ret = _opus_encode_float(this.handle, this.in_ptr, this.frame_size, this.out_ptr, this.out_bytes);
|
||
|
if (ret <= 0)
|
||
|
throw 'opus_encode failed: ' + ret;
|
||
|
var packet = new ArrayBuffer(ret);
|
||
|
new Uint8Array(packet).set(this.out_buf.subarray(0, ret));
|
||
|
return packet;
|
||
|
};
|
||
|
OpusEncoder.prototype.destroy = function () {
|
||
|
if (!this.handle)
|
||
|
return;
|
||
|
_opus_encoder_destroy(this.handle);
|
||
|
_free(this.in_ptr);
|
||
|
this.handle = this.in_ptr = 0;
|
||
|
};
|
||
|
return OpusEncoder;
|
||
|
})();
|
||
|
var OpusDecoder = (function () {
|
||
|
function OpusDecoder(sampling_rate, channels) {
|
||
|
this.handle = 0;
|
||
|
this.in_ptr = 0;
|
||
|
this.out_ptr = 0;
|
||
|
this.channels = channels;
|
||
|
var err_ptr = allocate(4, 'i32', ALLOC_STACK);
|
||
|
this.handle = _opus_decoder_create(sampling_rate, channels, err_ptr);
|
||
|
if (getValue(err_ptr, 'i32') != 0 /* OK */)
|
||
|
throw 'opus_decoder_create failed: ' + getValue(err_ptr, 'i32');
|
||
|
this.in_ptr = _malloc(Opus.getMaxFrameSize(channels));
|
||
|
this.in_buf = HEAPU8.subarray(this.in_ptr, this.in_ptr + Opus.getMaxFrameSize(channels));
|
||
|
this.out_len = Opus.getMaxSamplesPerChannel(sampling_rate);
|
||
|
var out_bytes = this.out_len * channels * 4;
|
||
|
this.out_ptr = _malloc(out_bytes);
|
||
|
this.out_i16 = HEAP16.subarray(this.out_ptr >> 1, (this.out_ptr + out_bytes) >> 1);
|
||
|
this.out_f32 = HEAPF32.subarray(this.out_ptr >> 2, (this.out_ptr + out_bytes) >> 2);
|
||
|
}
|
||
|
OpusDecoder.prototype.decode = function (packet) {
|
||
|
this.in_buf.set(new Uint8Array(packet));
|
||
|
var ret = _opus_decode(this.handle, this.in_ptr, packet.byteLength, this.out_ptr, this.out_len, 0);
|
||
|
if (ret < 0)
|
||
|
throw 'opus_decode failed: ' + ret;
|
||
|
var samples = new Int16Array(ret * this.channels);
|
||
|
samples.set(this.out_i16.subarray(0, samples.length));
|
||
|
return samples;
|
||
|
};
|
||
|
OpusDecoder.prototype.decode_float = function (packet) {
|
||
|
this.in_buf.set(new Uint8Array(packet));
|
||
|
var ret = _opus_decode_float(this.handle, this.in_ptr, packet.byteLength, this.out_ptr, this.out_len, 0);
|
||
|
if (ret < 0)
|
||
|
throw 'opus_decode failed: ' + ret;
|
||
|
var samples = new Float32Array(ret * this.channels);
|
||
|
samples.set(this.out_f32.subarray(0, samples.length));
|
||
|
return samples;
|
||
|
};
|
||
|
OpusDecoder.prototype.destroy = function () {
|
||
|
if (!this.handle)
|
||
|
return;
|
||
|
_opus_decoder_destroy(this.handle);
|
||
|
_free(this.in_ptr);
|
||
|
_free(this.out_ptr);
|
||
|
this.handle = this.in_ptr = this.out_ptr = 0;
|
||
|
};
|
||
|
return OpusDecoder;
|
||
|
})();
|
||
|
|
||
|
var OpusEncoderProcessor = function( wsh )
|
||
|
{
|
||
|
this.wsh = wsh;
|
||
|
this.bufferSize = 4096; // for webaudio script processor
|
||
|
this.downSample = 2;
|
||
|
this.opusFrameDur = 60; // msec
|
||
|
this.opusRate = 24000;
|
||
|
this.i16arr = new Int16Array( this.bufferSize / this.downSample );
|
||
|
this.f32arr = new Float32Array( this.bufferSize / this.downSample );
|
||
|
this.opusEncoder = new OpusEncoder( this.opusRate, 1, 2049, this.opusFrameDur );
|
||
|
}
|
||
|
|
||
|
|
||
|
OpusEncoderProcessor.prototype.onAudioProcess = function( e )
|
||
|
{
|
||
|
this.instant = 0.0;
|
||
|
const that = this;
|
||
|
|
||
|
if( isRecording )
|
||
|
{
|
||
|
var data = e.inputBuffer.getChannelData( 0 )
|
||
|
var i = 0, ds = this.downSample;
|
||
|
|
||
|
if( encode )
|
||
|
{
|
||
|
for( var idx = 0; idx < data.length; idx += ds )
|
||
|
this.f32arr[ i++ ] = data[ idx ]/10;
|
||
|
|
||
|
var res = this.opusEncoder.encode_float( this.f32arr );
|
||
|
|
||
|
for( var idx = 0; idx < res.length; ++idx )
|
||
|
this.wsh.send( res[ idx ] );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
for( var idx = 0; idx < data.length; idx += ds )
|
||
|
this.i16arr[ i++ ] = (data[ idx ] /10) * 0xFFFF; // int16
|
||
|
|
||
|
this.wsh.send( this.i16arr );
|
||
|
}
|
||
|
|
||
|
let u;
|
||
|
let sum = 0.0;
|
||
|
let clipcount = 0;
|
||
|
for (u = 0; u < data.length; ++u) {
|
||
|
sum += data[u] * data[u];
|
||
|
if (Math.abs(data[u]) > 0.99) {
|
||
|
clipcount += 1;
|
||
|
}
|
||
|
}
|
||
|
if(clipcount > 5){
|
||
|
blikcritik("TX-GAIN_control");
|
||
|
}
|
||
|
that.instant = Math.sqrt(sum / data.length);
|
||
|
TXinstantMeter.value = that.instant*100;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
var MediaHandler = function( audioProcessor )
|
||
|
{
|
||
|
var context = new (window.AudioContext||window.webkitAudioContext)();
|
||
|
if( !context.createScriptProcessor )
|
||
|
context.createScriptProcessor = context.createJavaScriptNode;
|
||
|
|
||
|
if( context.sampleRate < 44000 || context.SampleRate > 50000 )
|
||
|
{
|
||
|
alert( "Unsupported sample rate: " + String( context.sampleRate ) );
|
||
|
return;
|
||
|
};
|
||
|
|
||
|
//initialize mic
|
||
|
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
||
|
|
||
|
this.context = context;
|
||
|
this.audioProcessor = audioProcessor;
|
||
|
var userMediaConfig = {
|
||
|
"audio": {
|
||
|
"mandatory": {},
|
||
|
"optional": []
|
||
|
}
|
||
|
}
|
||
|
|
||
|
navigator.getUserMedia( userMediaConfig, this.callback.bind( this ), this.error );
|
||
|
}
|
||
|
|
||
|
var AudioTX_analyser = "";
|
||
|
|
||
|
MediaHandler.prototype.callback = function( stream )
|
||
|
{
|
||
|
console.log( 'starting callback' );
|
||
|
AudioTX_analyser = this.context.createAnalyser();
|
||
|
this.gain_node = this.context.createGain();
|
||
|
this.micSource = this.context.createMediaStreamSource( stream );
|
||
|
this.processor = this.context.createScriptProcessor( this.audioProcessor.bufferSize, 1, 1 );
|
||
|
this.processor.onaudioprocess = this.audioProcessor.onAudioProcess.bind( this.audioProcessor );
|
||
|
this.micSource.connect( this.gain_node );
|
||
|
this.gain_node.connect( this.processor );
|
||
|
this.processor.connect( this.context.destination );
|
||
|
this.gain_node.connect( AudioTX_analyser );
|
||
|
console.log( 'ending callback' );
|
||
|
}
|
||
|
|
||
|
|
||
|
MediaHandler.prototype.error = function( err ) { alert( "Problem" ); }
|
||
|
|
||
|
|
||
|
var isRecording = false, encode = false;
|
||
|
var wsAudioTX = "";
|
||
|
var ap = "";
|
||
|
var mh = "";
|
||
|
|
||
|
const TXinstantMeter = document.querySelector('#Txinstant meter');
|
||
|
|
||
|
function AudioTX_start()
|
||
|
{
|
||
|
isRecording = false;
|
||
|
encode = false;
|
||
|
document.getElementById("indwsAudioTX").innerHTML='<img src="img/critsgrey.png">wsTX';
|
||
|
wsAudioTX = new WebSocket( 'wss://' + window.location.href.split( '/' )[2] + '/WSaudioTX' );
|
||
|
wsAudioTX.onopen = appendwsAudioTXOpen;
|
||
|
wsAudioTX.onerror = appendwsAudioTXError;
|
||
|
wsAudioTX.onclose = appendwsAudioTXclose;
|
||
|
ap = new OpusEncoderProcessor( wsAudioTX );
|
||
|
mh = new MediaHandler( ap );
|
||
|
}
|
||
|
|
||
|
function appendwsAudioTXclose(){
|
||
|
document.getElementById("indwsAudioTX").innerHTML='<img src="img/critsred.png">wsTX';
|
||
|
}
|
||
|
|
||
|
function appendwsAudioTXOpen(){
|
||
|
document.getElementById("indwsAudioTX").innerHTML='<img src="img/critsgreen.png">wsTX';
|
||
|
}
|
||
|
|
||
|
function appendwsAudioTXError(err){
|
||
|
document.getElementById("indwsAudioTX").innerHTML='<img src="img/critsred.png">wsTX';
|
||
|
wsAudioTX.close();
|
||
|
AudioTX_start();
|
||
|
}
|
||
|
|
||
|
function AudioTX_stop()
|
||
|
{
|
||
|
isRecording = false;
|
||
|
encode = false;
|
||
|
wsAudioTX.close();
|
||
|
ap = "";
|
||
|
mh = "";
|
||
|
}
|
||
|
|
||
|
function sendSettings()
|
||
|
{
|
||
|
if( document.getElementById( "encode" ).checked )
|
||
|
encode = 1;
|
||
|
else
|
||
|
encode = 0;
|
||
|
|
||
|
var rate = String( mh.context.sampleRate / ap.downSample );
|
||
|
var opusRate = String( ap.opusRate );
|
||
|
var opusFrameDur = String( ap.opusFrameDur )
|
||
|
|
||
|
var msg = "m:" + [ rate, encode, opusRate, opusFrameDur ].join( "," );
|
||
|
console.log( msg );
|
||
|
wsAudioTX.send( msg );
|
||
|
}
|
||
|
|
||
|
function startRecord()
|
||
|
{
|
||
|
document.getElementById( "encode" ).disabled = true;
|
||
|
mh.context.resume(); // needs an await?
|
||
|
sendSettings();
|
||
|
isRecording = true;
|
||
|
console.log( 'started recording' );
|
||
|
}
|
||
|
|
||
|
function stopRecord()
|
||
|
{
|
||
|
TXinstantMeter.value = 0;
|
||
|
|
||
|
isRecording = false;
|
||
|
document.getElementById( "encode" ).disabled = false;
|
||
|
console.log( 'ended recording' );
|
||
|
|
||
|
var msg = "s:";
|
||
|
console.log( msg );
|
||
|
wsAudioTX.send( msg );
|
||
|
}
|
||
|
|
||
|
function AudioTX_SetGAIN( vol ){
|
||
|
if(poweron)mh.gain_node.gain.setValueAtTime(vol, mh.context.currentTime);
|
||
|
}
|
||
|
|
||
|
function toggleRecord(sendit = false)
|
||
|
{
|
||
|
if( !sendit ){stopRecord();}
|
||
|
else {if (wsAudioTX.readyState !== WebSocket.CLOSED) {startRecord();}}
|
||
|
}
|
||
|
|