{"size": 5795, "ext": "js", "max_stars_repo_path": "js/crunker.js", "max_stars_repo_name": "antgiant/No-Dumb-Commercial", "max_stars_repo_stars_event_min_datetime": "2020-06-01T20:15:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T16:06:41.000Z", "max_issues_repo_path": "js/crunker.js", "max_issues_repo_name": "antgiant/No-Dumb-Commercial", "max_issues_repo_issues_event_min_datetime": "2020-09-13T04:34:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-27T20:42:52.000Z", "max_forks_repo_path": "js/crunker.js", "max_forks_repo_name": "antgiant/No-Dumb-Commercial", "max_forks_repo_forks_event_min_datetime": "2021-09-08T07:55:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-13T01:08:08.000Z"}
{"max_stars_count": 12, "max_issues_count": 10, "max_forks_count": 2, "avg_line_length": 5795.0, "max_line_length": 5795, "alphanum_fraction": 0.7233822261}
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Crunker",[],t):"object"==typeof exports?exports.Crunker=t():e.Crunker=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.sampleRate,r=void 0===n?44100:n;a(this,e),this._sampleRate=r,this._context=this._createContext()}return r(e,[{key:"_createContext",value:function(){return window.AudioContext=window.AudioContext||window.webkitAudioContext||window.mozAudioContext,new AudioContext}},{key:"fetchAudio",value:async function(){for(var e=this,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];var a=n.map((async function(t){var n=await fetch(t).then((function(e){return e.arrayBuffer()}));return await e._context.decodeAudioData(n)}));return await Promise.all(a)}},{key:"mergeAudio",value:function(e){var t=this._context.createBuffer(this._maxNumberOfChannels(e),this._sampleRate*this._maxDuration(e),this._sampleRate);return e.forEach((function(e){for(var n=0;n<e.numberOfChannels;n+=1){for(var r=t.getChannelData(n),a=e.getChannelData(n),o=e.getChannelData(n).length-1;o>=0;o-=1)r[o]+=a[o];t.getChannelData(n).set(r)}})),t}},{key:"concatAudio",value:function(e){var t=this._context.createBuffer(this._maxNumberOfChannels(e),this._totalLength(e),this._sampleRate),n=0;return e.forEach((function(e){for(var r=0;r<e.numberOfChannels;r+=1)t.getChannelData(r).set(e.getChannelData(r),n);n+=e.length})),t}},{key:"padAudio",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(0===n)return e;if(t<0)throw new Error('Crunker: Parameter "padStart" in padAudio must be positive');if(n<0)throw new Error('Crunker: Parameter "seconds" in padAudio must be positive');for(var r=this._context.createBuffer(e.numberOfChannels,e.length+n*e.sampleRate,e.sampleRate),a=0;a<e.numberOfChannels;a+=1){var o=e.getChannelData(a);r.getChannelData(a).set(o.subarray(0,t*e.sampleRate+1),0),r.getChannelData(a).set(o.subarray(t*e.sampleRate+2,r.length+1),(t+n)*e.sampleRate)}return r}},{key:"play",value:function(e){var t=this._context.createBufferSource();return t.buffer=e,t.connect(this._context.destination),t.start(),t}},{key:"export",value:function(e,t){var n=t||"audio/mp3",r=this._interleave(e),a=this._writeHeaders(r),o=new Blob([a],{type:n});return{blob:o,url:this._renderURL(o),element:this._renderAudioElement(o,n)}}},{key:"download",value:function(e,t){var n=t||"crunker",r=document.createElement("a");return r.style="display: none",r.href=this._renderURL(e),r.download=n+"."+e.type.split("/")[1],r.click(),r}},{key:"notSupported",value:function(e){return!this._isSupported()&&e()}},{key:"close",value:function(){return this._context.close(),this}},{key:"_maxDuration",value:function(e){return Math.max.apply(Math,e.map((function(e){return e.duration})))}},{key:"_maxNumberOfChannels",value:function(e){return Math.max.apply(Math,e.map((function(e){return e.numberOfChannels})))}},{key:"_totalLength",value:function(e){return e.map((function(e){return e.length})).reduce((function(e,t){return e+t}),0)}},{key:"_isSupported",value:function(){return"AudioContext"in window}},{key:"_writeHeaders",value:function(e){var t=new ArrayBuffer(44+2*e.length),n=new DataView(t);return this._writeString(n,0,"RIFF"),n.setUint32(4,32+2*e.length,!0),this._writeString(n,8,"WAVE"),this._writeString(n,12,"fmt "),n.setUint32(16,16,!0),n.setUint16(20,1,!0),n.setUint16(22,2,!0),n.setUint32(24,this._sampleRate,!0),n.setUint32(28,4*this._sampleRate,!0),n.setUint16(32,4,!0),n.setUint16(34,16,!0),this._writeString(n,36,"data"),n.setUint32(40,2*e.length,!0),this._floatTo16BitPCM(n,e,44)}},{key:"_floatTo16BitPCM",value:function(e,t,n){for(var r=0;r<t.length;r++,n+=2){var a=Math.max(-1,Math.min(1,t[r]));e.setInt16(n,a<0?32768*a:32767*a,!0)}return e}},{key:"_writeString",value:function(e,t,n){for(var r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}},{key:"_interleave",value:function(e){for(var t=e.getChannelData(0),n=2*t.length,r=new Float32Array(n),a=0,o=0;a<n;)r[a++]=t[o],r[a++]=t[o],o++;return r}},{key:"_renderAudioElement",value:function(e,t){var n=document.createElement("audio");return n.controls="controls",n.type=t,n.src=this._renderURL(e),n}},{key:"_renderURL",value:function(e){return(window.URL||window.webkitURL).createObjectURL(e)}}]),e}();t.default=o}])}));