|
|
|
function bool(t){return 1===t||"1"===t||t===!0||"true"===t}function numfmt(t,e){var n=Math.pow(10,e);return Math.round(t*n)/n}function estimateLoadTime(t,e){return 1e3/t*e+1500}function msNow(){return+new Date}function msElapsed(t){return msNow()-t}function errorMsg(t,e){notify.show(t,e||3e3)}!function(){"use strict";function t(){var t;for(p=!0,t=0;t<f.length;t+=1)f[t]();f=[]}function e(){var e;for(m=!0,p||t(),e=0;e<d.length;e+=1)d[e]();d=[]}function n(t,e){var n;for(n=e.length-1;n>=0;n-=1)t(e[n])}function r(t){return t.replace(/-\w/g,function(t){return t.charAt(1).toUpperCase()})}function i(t,e){return t.currentStyle?t.currentStyle[r(e)]:g.getComputedStyle?g.getComputedStyle(t,null).getPropertyValue(e):null}function a(t,e){return encodeURIComponent(t).replace(/%20/g,"+")+"="+encodeURIComponent(e).replace(/%20/g,"+")}function o(t,e,n){try{t.style[r(e)]=n}catch(i){}}function s(t){t.style.display="","none"===i(t,"display")&&(t.style.display="block")}function u(t){var e,r,i,o="";if(t.constructor===Object){for(e in t)if(t.hasOwnProperty(e))if(t[e].constructor===Array)for(r=0;r<t[e].length;r+=1)o+="&"+a(e,t[e][r]);else o+="&"+a(e,t[e])}else n(function(t){if("FORM"===t.nodeName)for(r=0;r<t.elements.length;r+=1)if(e=t.elements[r],!e.disabled)switch(e.type){case"button":case"image":case"file":case"submit":case"reset":break;case"select-one":e.length>0&&(o+="&"+a(e.name,e.value));break;case"select-multiple":for(i=0;i<e.length;i+=1)e[i].selected&&(o+="&"+a(e.name,e[i].value));break;case"checkbox":case"radio":e.checked&&(o+="&"+a(e.name,e.value));break;default:o+="&"+a(e.name,e.value)}},t);return o.length>0?o.substring(1):""}function c(t,e,r){var i,a,o,s=!1;return t&&(i=t.split(/\s+/),n(function(t){for(o=0;o<i.length;o+=1)if(a=new RegExp("\\b"+i[o]+"\\b","g"),"remove"===e)t.className=t.className.replace(a,"");else if("toggle"===e)t.className=t.className.match(a)?t.className.replace(a,""):t.className+" "+i[o];else if("has"===e&&t.className.match(a)){s=!0;break}},r)),s}function l(t,e,r){var i,a;t&&n(function(n){for(i=v.createElement("div"),i.innerHTML=t;null!==(a=i.lastChild);)try{"before"===e?n.parentNode.insertBefore(a,n):"after"===e?n.parentNode.insertBefore(a,n.nextSibling):"append"===e?n.appendChild(a):"prepend"===e&&n.insertBefore(a,n.firstChild)}catch(r){break}},r)}function h(t){var e,a,x,y=[],b=!1;if(t)if(t.nodeType&&1===t.nodeType)y=[t];else if("object"==typeof t)b="number"!=typeof t.length,y=t;else if("string"==typeof t)for(v.querySelectorAll||(v.querySelectorAll=function(t){var e,n,r,a=v.getElementsByTagName("head")[0],o=[];if(e=v.createElement("STYLE"),e.type="text/css",e.styleSheet){for(e.styleSheet.cssText=t+" {a:b}",a.appendChild(e),n=v.getElementsByTagName("*"),r=0;r<n.length;r+=1)"b"===i(n[r],"a")&&o.push(n[r]);a.removeChild(e)}return o}),a=v.querySelectorAll(t),x=0;x<a.length;x+=1)y[x]=a[x];return e=b?{}:y,e.ready=function(t){if(t){if(p)return t(),e;f.push(t)}},e.loaded=function(t){if(t){if(m)return t(),e;d.push(t)}},e.each=function(t){return"function"==typeof t&&n(function(e){return t.apply(e,arguments)},y),e},e.first=function(){return h(y.shift())},e.last=function(){return h(y.pop())},e.odd=function(){var t,e=[];for(t=0;t<y.length;t+=2)e.push(y[t]);return h(e)},e.even=function(){var t,e=[];for(t=1;t<y.length;t+=2)e.push(y[t]);return h(e)},e.hide=function(){return n(function(t){t.style.display="none"},y),e},e.show=function(){return n(function(t){s(t)},y),e},e.toggle=function(t){return"undefined"!=typeof t?t?e.show():e.hide():n(function(t){"none"===i(t,"display")?s(t):t.style.display="none"},y),e},e.remove=function(){return n(function(t){try{t.parentNode.removeChild(t)}catch(e){}},y),h()},e.css=function(t,a){if(t){if(a||""===a)return n(function(e){o(e,t,a)},y),e;if(y[0]){if(y[0].style[r(t)])return y[0].style[r(t)];if(i(y[0],t))return i(y[0],t)}}},e.getClass=function(){return y[0]&&y[0].className.length>0?y[0].className.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"").replace(/\s+/," "):void 0},e.setClass=function(t){return(t||""===t)&&n(function(e){e.className=t},y),e},e.addClass=function(t){return t&&n(function(e){
|
|
|
|
};this.svg=n.createSvg(this.container,t.width,t.height,t.classNames.chart);var r,i,o=this.svg.elem("g").addClass(t.classNames.gridGroup),s=this.svg.elem("g"),u=this.svg.elem("g").addClass(t.classNames.labelGroup),c=n.createChartRect(this.svg,t,a.padding);r=void 0===t.axisX.type?new n.StepAxis(n.Axis.units.x,e,c,n.extend({},t.axisX,{ticks:e.raw.labels,stretch:t.fullWidth})):t.axisX.type.call(n,n.Axis.units.x,e,c,t.axisX),i=void 0===t.axisY.type?new n.AutoScaleAxis(n.Axis.units.y,e,c,n.extend({},t.axisY,{high:n.isNum(t.high)?t.high:t.axisY.high,low:n.isNum(t.low)?t.low:t.axisY.low})):t.axisY.type.call(n,n.Axis.units.y,e,c,t.axisY),r.createGridAndLabels(o,u,this.supportsForeignObject,t,this.eventEmitter),i.createGridAndLabels(o,u,this.supportsForeignObject,t,this.eventEmitter),e.raw.series.forEach(function(a,o){var u=s.elem("g");u.attr({"ct:series-name":a.name,"ct:meta":n.serialize(a.meta)}),u.addClass([t.classNames.series,a.className||t.classNames.series+"-"+n.alphaNumerate(o)].join(" "));var l=[],h=[];e.normalized[o].forEach(function(t,s){var u={x:c.x1+r.projectValue(t,s,e.normalized[o]),y:c.y1-i.projectValue(t,s,e.normalized[o])};l.push(u.x,u.y),h.push({value:t,valueIndex:s,meta:n.getMetaData(a,s)})}.bind(this));var f={lineSmooth:n.getSeriesOption(a,t,"lineSmooth"),showPoint:n.getSeriesOption(a,t,"showPoint"),showLine:n.getSeriesOption(a,t,"showLine"),showArea:n.getSeriesOption(a,t,"showArea"),areaBase:n.getSeriesOption(a,t,"areaBase")},d="function"==typeof f.lineSmooth?f.lineSmooth:f.lineSmooth?n.Interpolation.cardinal():n.Interpolation.none(),p=d(l,h);if(f.showPoint&&p.pathElements.forEach(function(e){var s=u.elem("line",{x1:e.x,y1:e.y,x2:e.x+.01,y2:e.y},t.classNames.point).attr({"ct:value":[e.data.value.x,e.data.value.y].filter(n.isNum).join(","),"ct:meta":e.data.meta});this.eventEmitter.emit("draw",{type:"point",value:e.data.value,index:e.data.valueIndex,meta:e.data.meta,series:a,seriesIndex:o,axisX:r,axisY:i,group:u,element:s,x:e.x,y:e.y})}.bind(this)),f.showLine){var m=u.elem("path",{d:p.stringify()},t.classNames.line,!0);this.eventEmitter.emit("draw",{type:"line",values:e.normalized[o],path:p.clone(),chartRect:c,index:o,series:a,seriesIndex:o,axisX:r,axisY:i,group:u,element:m})}if(f.showArea&&i.range){var v=Math.max(Math.min(f.areaBase,i.range.max),i.range.min),g=c.y1-i.projectValue(v);p.splitByCommand("M").filter(function(t){return t.pathElements.length>1}).map(function(t){var e=t.pathElements[0],n=t.pathElements[t.pathElements.length-1];return t.clone(!0).position(0).remove(1).move(e.x,g).line(e.x,e.y).position(t.pathElements.length+1).line(n.x,g)}).forEach(function(n){var s=u.elem("path",{d:n.stringify()},t.classNames.area,!0);this.eventEmitter.emit("draw",{type:"area",values:e.normalized[o],path:n.clone(),series:a,seriesIndex:o,axisX:r,axisY:i,chartRect:c,index:o,group:u,element:s})}.bind(this))}}.bind(this)),this.eventEmitter.emit("created",{bounds:i.bounds,chartRect:c,axisX:r,axisY:i,svg:this.svg,options:t})}function i(t,e,r,i){n.Line["super"].constructor.call(this,t,e,a,n.extend({},a,r),i)}var a={axisX:{offset:30,position:"end",labelOffset:{x:0,y:0},showLabel:!0,showGrid:!0,labelInterpolationFnc:n.noop,type:void 0},axisY:{offset:40,position:"start",labelOffset:{x:0,y:0},showLabel:!0,showGrid:!0,labelInterpolationFnc:n.noop,type:void 0,scaleMinSpace:20,onlyInteger:!1},width:void 0,height:void 0,showLine:!0,showPoint:!0,showArea:!1,areaBase:0,lineSmooth:!0,low:void 0,high:void 0,chartPadding:{top:15,right:15,bottom:5,left:10},fullWidth:!1,reverseData:!1,classNames:{chart:"ct-chart-line",label:"ct-label",labelGroup:"ct-labels",series:"ct-series",line:"ct-line",point:"ct-point",area:"ct-area",grid:"ct-grid",gridGroup:"ct-grids",vertical:"ct-vertical",horizontal:"ct-horizontal",start:"ct-start",end:"ct-end"}};n.Line=n.Base.extend({constructor:i,createChart:r})}(window,document,t),function(t,e,n){"use strict";function r(t){this.data=n.normalizeData(this.data);var e,r={raw:this.data,normalized:t.distributeSeries?n.getDataArray(this.data,t.reverseData,t.horizontalBars?"x":"y").map(function(t){return[t]}):n.getData
|
|
|
|
$("#stat-i-rms").html(numfmt(t.stats.rms,2)),$(".stats").removeClass("invis");var h=o?t.stats.freq/t.stats.count:1e3/t.stats.freq,f=_.map(t.samples,function(t,e){return{x:e*h,y:t}}),d=[Chartist.plugins.zoom({resetOnRightMouseBtn:!0,onZoom:function(t,e){a=e,u=t.options.axisX.highLow,c=t.options.axisY.highLow}})];i||d.push(Chartist.plugins.ctAxisTitle({axisX:{axisTitle:e,offset:{x:0,y:55}},axisY:{axisTitle:n,flipText:!0,offset:{x:0,y:15}}}));var p,m,v,g;u?(p=u.high,m=u.low,v=c.high,g=c.low):(v=o?void 0:l,g=o?0:-l),new Chartist.Line("#chart",{series:[{name:"a",data:f}]},{showPoint:!1,showArea:o,fullWidth:!0,chartPadding:i?{right:20,bottom:5,left:0}:{right:25,bottom:30,left:25},series:{a:{lineSmooth:Chartist.Interpolation.monotoneCubic()}},axisX:{type:Chartist.AutoScaleAxis,high:p,low:m},axisY:{type:Chartist.AutoScaleAxis,high:v,low:g},explicitBounds:{xLow:0,yLow:o?0:void 0,xHigh:f[f.length-1].x},plugins:d})}function e(e,n){if(h=!1,200!=n)errorMsg("Request failed.",1e3),f&&i();else{var a=JSON.parse(e);if(!a.success)return errorMsg("Sampling failed.",1e3),void(f&&i());t(a),f&&(p=setTimeout(r,Math.max(0,d-msElapsed(s))))}}function n(){m.count=$("#count").val(),m.freq=$("#freq").val()*("fft"==o?2:1)}function r(){if(h)return!1;h=!0,s=msNow();var t=m.count,n=m.freq,r=_root+"/measure/"+o+"?n="+t+"&fs="+n;return $().get(r,e,estimateLoadTime(n,t)),!0}function i(){d=+$("#ar-time").val(),n(),f=!f,f?r():clearTimeout(p),$("#ar-btn").toggleClass("btn-blue").toggleClass("btn-red").val(f?"Stop":"Auto")}var a,o,s,u,c,l={},h=!1,f=!1,d=1,p=-1,m={count:0,freq:0};return l.init=function(t){function e(){n(),r()}o=t,$("#load").on("click",e),$("#count,#freq").on("keyup",function(t){13==t.which&&e()}),$("#chart").on("contextmenu",function(t){return a&&a(),a=null,u=null,c=null,t.preventDefault(),!1}),$("#ar-btn").on("click",i)},l}(),page_spectrogram=function(){function t(t){var e,n,r,i;t=Math.log10(1+t),t>2&&(t=2),0>t&&(t=0);for(var a=0;a<b.length;a++){var o=b[a],s=o[0];if(t>=s&&(e=s,r=o),s>=t){n=s,i=o;break}}var u=(t-e)/(n-e);e==n&&(u=0);var c=Math.round(r[1]+(i[1]-r[1])*u),l=Math.round(r[2]+(i[2]-r[2])*u),h=Math.round(r[3]+(i[3]-r[3])*u);return"rgb("+c+","+l+","+h+")"}function e(){var t=c.getImageData(g.x+g.dx,g.y,g.w-g.dx,g.h+6);c.fillStyle="black",c.fillRect(g.x,g.y,g.w,g.h),c.putImageData(t,g.x,g.y)}function n(n){e();for(var r=x.sampCount/2,i=0;r>i;i++){var a;if(i*g.dy>g.h)break;a=i>n.length?"#000":t(n[i]),c.fillStyle=a;var o=g.x+g.w-g.dx,s=g.y+g.h-(i+1)*g.dy,u=g.dx,l=g.dy;s<g.y&&(l-=g.y-s,s=g.y),c.fillRect(o,s,u,l)}if(console.log("remain",msElapsed(p)),msElapsed(p)>=950){p=msNow();var h=!1;msElapsed(m)>9500&&(h=!0,m=msNow()),c.strokeStyle="white",c.beginPath(),c.moveTo(g.x+g.w-.5,g.y+g.h+1),c.lineTo(g.x+g.w-.5,g.y+g.h+1+(h?6:2)),c.stroke()}else c.clearRect(g.x+g.w-1,g.y+g.h+1,2,10)}function r(t,e){if(h=!1,200==e)try{var r=JSON.parse(t);r.success?n(r.samples):errorMsg("Sampling failed.",1e3)}catch(a){errorMsg(a)}else errorMsg("Request failed.",1e3);y&&(l=setTimeout(i,Math.max(0,x.interval-msElapsed(d))))}function i(){h&&(errorMsg("Request already pending - aborting."),f.abort()),h=!0,d=msNow();var t=x.freq,e=x.sampCount,n=_root+"/measure/fft?n="+e+"&fs="+t;return f=$().get(n,r,estimateLoadTime(t,e)),!0}function a(){for(var e=8,n=10,r=g.h-12,i=g.y+6,a=g.x-e-n,o=100/r,s=0;r>s;s++){var u=t(s*o),l=t((s+1)*o),h=Math.floor(i+r-(s+1)),f=c.createLinearGradient(0,h+1,0,h);f.addColorStop(0,u),f.addColorStop(1,l),c.fillStyle=f,c.fillRect(a,h,n,1)}c.strokeStyle="#000",c.strokeRect(a-.5,i-.5,n+1,r+1),o=100/r,c.font="12px sans-serif",c.fillStyle="white",c.textAlign="right";for(var s=0;s<=g.h;s+=r/10)c.fillText(Math.round(s*o)+"",g.x-e-n-e,i+r-s+3)}function o(){var t=8,e=g.x+g.w,n=e+t,r=g.y,i=g.h,a=70;c.clearRect(e+.5,r-10,a,i+20);var o=x.freq/2/(x.sampCount/2),s=g.h/g.dy,u=s*o;console.log("perbin=",o,"totalBins=",s,"totalHz=",u);for(var l,h=[[200,10],[1e3,50],[3e3,250],[5e3,500],[1e4,1e3],[25e3,2500],[5e4,5e3],[1e5,1e4],[5e5,5e4],[1e6,1e5],[1/0,25e4]],f=0;f<=h.length;f++)if(u<=h[f][0]){l=h[f][1];break}l/=o,c.font="12px sans-serif",c.fillStyle="white",c.strok
|