{"version":3,"file":"anim_hwave_mic.min.js","sources":["../src/anim_hwave_mic.js"],"sourcesContent":["/* jshint ignore:start */\ndefine(['jquery', 'core/log'], function ($, log) {\n\n    \"use strict\"; // jshint ;_;\n\n    log.debug('anim_horizontal_wave_mic: initialising');\n\n    return {\n\n        analyser: null,\n        cvs: null,\n        cvsctx: null,\n        sounddetected: false,\n        imgone: null,\n        imgoneloaded: false,\n        drawparams: {\n            micColor: '#CCCCCC',\n            wavColor: \"#CCCCCC\",\n            lineWidth: 2\n        },\n\n        //for making multiple instances\n        clone: function () {\n            return $.extend(true, {}, this);\n        },\n\n        setDrawParam: function (paramkey, paramvalue) {\n            this.drawparams[paramkey] = paramvalue;\n        },\n\n\n        //init\n        init: function (analyser, cvs) {\n            this.cvs = cvs;\n            this.cvsctx = cvs.getContext(\"2d\");\n            this.cvsctx.textAlign = \"center\";\n            this.analyser = analyser;\n\n            //init images\n            //listen for load to ensure initial display\n            var that = this;\n            this.imgone = new Image();\n            this.imgone.addEventListener('load', function () {\n                that.imgoneloaded = true;\n            });\n            this.imgone.src = M.cfg.wwwroot + '/filter/poodll/pix/svg/mic.svg';\n        },\n\n        clear: function () {\n            if (!this.imgoneloaded) {\n                var that = this;\n                this.imgone.addEventListener('load', function () {\n                    that.imgoneloaded = true;\n                    that.clear();\n                });\n                return;\n            }\n            this.cvsctx.clearRect(0, 0, this.cvs.width, this.cvs.height);\n\n            this.cvsctx.beginPath();\n            this.cvsctx.lineWidth = this.drawparams.lineWidth;\n            this.cvsctx.strokeStyle = this.drawparams.wavColor;\n            this.cvsctx.moveTo(0, this.cvs.height / 2);\n            this.cvsctx.lineTo(this.cvs.width, this.cvs.height / 2);\n            this.cvsctx.stroke();\n\n            // this.cvsctx.beginPath();\n            //  this.cvsctx.strokeStyle = this.drawparams.micColor;\n            this.drawMic(this.cvsctx, this.cvs.width, this.cvs.height, this.imgone);\n            //  this.cvsctx.stroke();\n        },\n\n        drawMic: function (ctx, cwidth, cheight, mic) {\n            var x = (cwidth - mic.width) / 2;\n            var y = (cheight - mic.height) / 2;\n            ctx.drawImage(mic, x, y);\n        },\n\n        start: function () {\n            this.analyser.core.fftSize = 2048;\n            var bufferLength = this.analyser.core.fftSize;\n            var dataArray = new Uint8Array(bufferLength);\n            var cwidth = this.cvs.width;\n            var cheight = this.cvs.height;\n            var canvasCtx = this.cvsctx;\n            var analyser = this.analyser;\n            var that = this;\n            this.clear();\n\n            var draw = function () {\n\n                var drawVisual = requestAnimationFrame(draw);\n\n                //cancel out if the theinterval is null\n                if (!analyser.theinterval) {\n                    return;\n                }\n\n                analyser.core.getByteTimeDomainData(dataArray);\n\n                //filling is rubbish, we just clear it\n                //canvasCtx.fillStyle = 'rgb(200, 200, 200)';\n                //canvasCtx.fillRect(0, 0, cwidth, cheight);\n                canvasCtx.clearRect(0, 0, cwidth, cheight);\n\n                canvasCtx.lineWidth = that.drawparams.lineWidth;\n                canvasCtx.strokeStyle = that.drawparams.wavColor;\n\n                canvasCtx.beginPath();\n\n                var sliceWidth = cwidth * 2.0 / bufferLength;\n                var x = 0;\n                var oldy = 0;\n\n                //we check if we could capture sound here\n                if (bufferLength > 0) {\n                    var level = dataArray[bufferLength - 1];\n                    if (level != 128) {\n                        that.sounddetected = true;\n                    }\n                }\n\n                for (var i = 0; i < bufferLength; i++) {\n\n                    var v = dataArray[i] / 128.0;\n                    var y = v * cheight / 2;\n\n                    if (i === 0) {\n                        canvasCtx.moveTo(x, y);\n                    } else {\n                        //canvasCtx.lineTo(x, oldy);\n                        canvasCtx.lineTo(x, y);\n\n                    }\n                    oldy = y;\n                    x += sliceWidth;\n                }\n                canvasCtx.lineTo(cwidth, cheight / 2);\n                canvasCtx.stroke();\n\n                //draw a microphone\n                that.drawMic(canvasCtx, cwidth, cheight, that.imgone);\n\n\n            };\n\n            draw();\n        }//END OF START\n    };//end of returned object\n});//total end\n"],"names":["define","$","log","debug","analyser","cvs","cvsctx","sounddetected","imgone","imgoneloaded","drawparams","micColor","wavColor","lineWidth","clone","extend","this","setDrawParam","paramkey","paramvalue","init","getContext","textAlign","that","Image","addEventListener","src","M","cfg","wwwroot","clear","clearRect","width","height","beginPath","strokeStyle","moveTo","lineTo","stroke","drawMic","ctx","cwidth","cheight","mic","x","y","drawImage","start","core","fftSize","bufferLength","dataArray","Uint8Array","canvasCtx","draw","requestAnimationFrame","theinterval","getByteTimeDomainData","sliceWidth","i"],"mappings":"AACAA,sCAAO,CAAC,SAAU,aAAa,SAAUC,EAAGC,YAIxCA,IAAIC,MAAM,0CAEH,CAEHC,SAAU,KACVC,IAAK,KACLC,OAAQ,KACRC,eAAe,EACfC,OAAQ,KACRC,cAAc,EACdC,WAAY,CACRC,SAAU,UACVC,SAAU,UACVC,UAAW,GAIfC,MAAO,kBACIb,EAAEc,QAAO,EAAM,GAAIC,OAG9BC,aAAc,SAAUC,SAAUC,iBACzBT,WAAWQ,UAAYC,YAKhCC,KAAM,SAAUhB,SAAUC,UACjBA,IAAMA,SACNC,OAASD,IAAIgB,WAAW,WACxBf,OAAOgB,UAAY,cACnBlB,SAAWA,aAIZmB,KAAOP,UACNR,OAAS,IAAIgB,WACbhB,OAAOiB,iBAAiB,QAAQ,WACjCF,KAAKd,cAAe,UAEnBD,OAAOkB,IAAMC,EAAEC,IAAIC,QAAU,kCAGtCC,MAAO,cACEd,KAAKP,kBAQLH,OAAOyB,UAAU,EAAG,EAAGf,KAAKX,IAAI2B,MAAOhB,KAAKX,IAAI4B,aAEhD3B,OAAO4B,iBACP5B,OAAOO,UAAYG,KAAKN,WAAWG,eACnCP,OAAO6B,YAAcnB,KAAKN,WAAWE,cACrCN,OAAO8B,OAAO,EAAGpB,KAAKX,IAAI4B,OAAS,QACnC3B,OAAO+B,OAAOrB,KAAKX,IAAI2B,MAAOhB,KAAKX,IAAI4B,OAAS,QAChD3B,OAAOgC,cAIPC,QAAQvB,KAAKV,OAAQU,KAAKX,IAAI2B,MAAOhB,KAAKX,IAAI4B,OAAQjB,KAAKR,iBAlBxDe,KAAOP,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