@pixi/sound
Advanced tools
Comparing version 5.0.0 to 5.1.0
/*! | ||
* @pixi/sound - v5.0.0 | ||
* https://github.com/pixijs/pixi-sound | ||
* Compiled Wed, 21 Sep 2022 19:56:41 UTC | ||
* @pixi/sound - v5.1.0 | ||
* Compiled Fri, 03 Mar 2023 14:39:32 UTC | ||
* | ||
* @pixi/sound is licensed under the MIT license. | ||
* @pixi/sound is licensed under the MIT License. | ||
* http://www.opensource.org/licenses/mit-license | ||
*/this.PIXI=this.PIXI||{},this.PIXI.sound=function(d,tt){"use strict";let k;function et(s){return k=s,s}function l(){return k}let st=0;const S=class extends d.utils.EventEmitter{constructor(s){super(),this.id=st++,this.init(s)}set(s,t){if(this[s]===void 0)throw new Error(`Property with name ${s} does not exist.`);switch(s){case"speed":this.speed=t;break;case"volume":this.volume=t;break;case"paused":this.paused=t;break;case"loop":this.loop=t;break;case"muted":this.muted=t;break}return this}get progress(){const{currentTime:s}=this._source;return s/this._duration}get paused(){return this._paused}set paused(s){this._paused=s,this.refreshPaused()}_onPlay(){this._playing=!0}_onPause(){this._playing=!1}init(s){this._playing=!1,this._duration=s.source.duration;const t=this._source=s.source.cloneNode(!1);t.src=s.parent.url,t.onplay=this._onPlay.bind(this),t.onpause=this._onPause.bind(this),s.context.on("refresh",this.refresh,this),s.context.on("refreshPaused",this.refreshPaused,this),this._media=s}_internalStop(){this._source&&this._playing&&(this._source.onended=null,this._source.pause())}stop(){this._internalStop(),this._source&&this.emit("stop")}get speed(){return this._speed}set speed(s){this._speed=s,this.refresh()}get volume(){return this._volume}set volume(s){this._volume=s,this.refresh()}get loop(){return this._loop}set loop(s){this._loop=s,this.refresh()}get muted(){return this._muted}set muted(s){this._muted=s,this.refresh()}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(s){console.warn("HTML Audio does not support filters")}refresh(){const s=this._media.context,t=this._media.parent;this._source.loop=this._loop||t.loop;const e=s.volume*(s.muted?0:1),i=t.volume*(t.muted?0:1),r=this._volume*(this._muted?0:1);this._source.volume=r*e*i,this._source.playbackRate=this._speed*s.speed*t.speed}refreshPaused(){const s=this._media.context,t=this._media.parent,e=this._paused||t.paused||s.paused;e!==this._pausedReal&&(this._pausedReal=e,e?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._source.currentTime,end:this._end,volume:this._volume,speed:this._speed,loop:this._loop})),this.emit("pause",e))}play(s){const{start:t,end:e,speed:i,loop:r,volume:n,muted:o}=s;e&&console.assert(e>t,"End time is before start time"),this._speed=i,this._volume=n,this._loop=!!r,this._muted=o,this.refresh(),this.loop&&e!==null&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=t,this._end=e||this._duration,this._start=Math.max(0,this._start-S.PADDING),this._end=Math.min(this._end+S.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=t,this._source.onloadedmetadata=null,this.emit("progress",t,this._duration),d.Ticker.shared.add(this._onUpdate,this))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onUpdate(){this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete()}_onComplete(){d.Ticker.shared.remove(this._onUpdate,this),this._internalStop(),this.emit("progress",1,this._duration),this.emit("end",this)}destroy(){d.Ticker.shared.remove(this._onUpdate,this),this.removeAllListeners();const s=this._source;s&&(s.onended=null,s.onplay=null,s.onpause=null,this._internalStop()),this._source=null,this._speed=1,this._volume=1,this._loop=!1,this._end=null,this._start=0,this._duration=0,this._playing=!1,this._pausedReal=!1,this._paused=!1,this._muted=!1,this._media&&(this._media.context.off("refresh",this.refresh,this),this._media.context.off("refreshPaused",this.refreshPaused,this),this._media=null)}toString(){return`[HTMLAudioInstance id=${this.id}]`}};let F=S;F.PADDING=.1;class O extends d.utils.EventEmitter{init(t){this.parent=t,this._source=t.options.source||new Audio,t.url&&(this._source.src=t.url)}create(){return new F(this)}get isPlayable(){return!!this._source&&this._source.readyState===4}get duration(){return this._source.duration}get context(){return this.parent.context}get filters(){return null}set filters(t){console.warn("HTML Audio does not support filters")}destroy(){this.removeAllListeners(),this.parent=null,this._source&&(this._source.src="",this._source.load(),this._source=null)}get source(){return this._source}load(t){const e=this._source,i=this.parent;if(e.readyState===4){i.isLoaded=!0;const h=i.autoPlayStart();t&&setTimeout(()=>{t(null,i,h)},0);return}if(!i.url){t(new Error("sound.url or sound.source must be set"));return}e.src=i.url;const r=()=>{a(),i.isLoaded=!0;const h=i.autoPlayStart();t&&t(null,i,h)},n=()=>{a(),t&&t(new Error("Sound loading has been aborted"))},o=()=>{a();const h=`Failed to load audio element (code: ${e.error.code})`;t?t(new Error(h)):console.error(h)},a=()=>{e.removeEventListener("canplaythrough",r),e.removeEventListener("load",r),e.removeEventListener("abort",n),e.removeEventListener("error",o)};e.addEventListener("canplaythrough",r,!1),e.addEventListener("load",r,!1),e.addEventListener("abort",n,!1),e.addEventListener("error",o,!1),e.load()}}class M{constructor(t,e){this.parent=t,Object.assign(this,e),this.duration=this.end-this.start,console.assert(this.duration>0,"End time must be after start time")}play(t){return this.parent.play({complete:t,speed:this.speed||this.parent.speed,end:this.end,start:this.start,loop:this.loop})}destroy(){this.parent=null}}class m{static setParamValue(t,e){if(t.setValueAtTime){const i=l().context;t.setValueAtTime(e,i.audioContext.currentTime)}else t.value=e;return e}}let it=0;class I extends d.utils.EventEmitter{constructor(t){super(),this.id=it++,this._media=null,this._paused=!1,this._muted=!1,this._elapsed=0,this.init(t)}set(t,e){if(this[t]===void 0)throw new Error(`Property with name ${t} does not exist.`);switch(t){case"speed":this.speed=e;break;case"volume":this.volume=e;break;case"muted":this.muted=e;break;case"loop":this.loop=e;break;case"paused":this.paused=e;break}return this}stop(){this._source&&(this._internalStop(),this.emit("stop"))}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh(),this._update(!0)}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}get filters(){return this._filters}set filters(t){var e;this._filters&&((e=this._filters)==null||e.filter(i=>i).forEach(i=>i.disconnect()),this._filters=null,this._source.connect(this._gain)),this._filters=t!=null&&t.length?t.slice(0):null,this.refresh()}refresh(){if(!this._source)return;const t=this._media.context,e=this._media.parent;this._source.loop=this._loop||e.loop;const i=t.volume*(t.muted?0:1),r=e.volume*(e.muted?0:1),n=this._volume*(this._muted?0:1);m.setParamValue(this._gain.gain,n*r*i),m.setParamValue(this._source.playbackRate,this._speed*e.speed*t.speed),this.applyFilters()}applyFilters(){var t;if((t=this._filters)!=null&&t.length){this._source.disconnect();let e=this._source;this._filters.forEach(i=>{e.connect(i.destination),e=i}),e.connect(this._gain)}}refreshPaused(){const t=this._media.context,e=this._media.parent,i=this._paused||e.paused||t.paused;i!==this._pausedReal&&(this._pausedReal=i,i?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._elapsed%this._duration,end:this._end,speed:this._speed,loop:this._loop,volume:this._volume})),this.emit("pause",i))}play(t){const{start:e,end:i,speed:r,loop:n,volume:o,muted:a,filters:h}=t;i&&console.assert(i>e,"End time is before start time"),this._paused=!1;const{source:c,gain:_}=this._media.nodes.cloneBufferSource();this._source=c,this._gain=_,this._speed=r,this._volume=o,this._loop=!!n,this._muted=a,this._filters=h,this.refresh();const g=this._source.buffer.duration;this._duration=g,this._end=i,this._lastUpdate=this._now(),this._elapsed=e,this._source.onended=this._onComplete.bind(this),this._loop?(this._source.loopEnd=i,this._source.loopStart=e,this._source.start(0,e)):i?this._source.start(0,e,i-e):this._source.start(0,e),this.emit("start"),this._update(!0),this.enableTicker(!0)}enableTicker(t){d.Ticker.shared.remove(this._updateListener,this),t&&d.Ticker.shared.add(this._updateListener,this)}get progress(){return this._progress}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}destroy(){var t;this.removeAllListeners(),this._internalStop(),this._gain&&(this._gain.disconnect(),this._gain=null),this._media&&(this._media.context.events.off("refresh",this.refresh,this),this._media.context.events.off("refreshPaused",this.refreshPaused,this),this._media=null),(t=this._filters)==null||t.forEach(e=>e.disconnect()),this._filters=null,this._end=null,this._speed=1,this._volume=1,this._loop=!1,this._elapsed=0,this._duration=0,this._paused=!1,this._muted=!1,this._pausedReal=!1}toString(){return`[WebAudioInstance id=${this.id}]`}_now(){return this._media.context.audioContext.currentTime}_updateListener(){this._update()}_update(t=!1){if(this._source){const e=this._now(),i=e-this._lastUpdate;if(i>0||t){const r=this._source.playbackRate.value;this._elapsed+=i*r,this._lastUpdate=e;const n=this._duration;let o;if(this._source.loopStart){const a=this._source.loopEnd-this._source.loopStart;o=(this._source.loopStart+this._elapsed%a)/n}else o=this._elapsed%n/n;this._progress=o,this.emit("progress",this._progress,n)}}}init(t){this._media=t,t.context.events.on("refresh",this.refresh,this),t.context.events.on("refreshPaused",this.refreshPaused,this)}_internalStop(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.stop(0),this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null}}_onComplete(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}}this._source=null,this._progress=1,this.emit("progress",1,this._duration),this.emit("end",this)}}class E{constructor(t,e){this._output=e,this._input=t}get destination(){return this._input}get filters(){return this._filters}set filters(t){if(this._filters&&(this._filters.forEach(e=>{e&&e.disconnect()}),this._filters=null,this._input.connect(this._output)),t&&t.length){this._filters=t.slice(0),this._input.disconnect();let e=null;t.forEach(i=>{e===null?this._input.connect(i.destination):e.connect(i.destination),e=i}),e.connect(this._output)}}destroy(){this.filters=null,this._input=null,this._output=null}}const T=class extends E{constructor(s){const t=s.audioContext,e=t.createBufferSource(),i=t.createGain(),r=t.createAnalyser();e.connect(r),r.connect(i),i.connect(s.destination),super(r,i),this.context=s,this.bufferSource=e,this.gain=i,this.analyser=r}get script(){return this._script||(this._script=this.context.audioContext.createScriptProcessor(T.BUFFER_SIZE),this._script.connect(this.context.destination)),this._script}destroy(){super.destroy(),this.bufferSource.disconnect(),this._script&&this._script.disconnect(),this.gain.disconnect(),this.analyser.disconnect(),this.bufferSource=null,this._script=null,this.gain=null,this.analyser=null,this.context=null}cloneBufferSource(){const s=this.bufferSource,t=this.context.audioContext.createBufferSource();t.buffer=s.buffer,m.setParamValue(t.playbackRate,s.playbackRate.value),t.loop=s.loop;const e=this.context.audioContext.createGain();return t.connect(e),e.connect(this.destination),{source:t,gain:e}}get bufferSize(){return this.script.bufferSize}};let C=T;C.BUFFER_SIZE=0;class w{init(t){this.parent=t,this._nodes=new C(this.context),this._source=this._nodes.bufferSource,this.source=t.options.source}destroy(){this.parent=null,this._nodes.destroy(),this._nodes=null;try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null,this.source=null}create(){return new I(this)}get context(){return this.parent.context}get isPlayable(){return!!this._source&&!!this._source.buffer}get filters(){return this._nodes.filters}set filters(t){this._nodes.filters=t}get duration(){return console.assert(this.isPlayable,"Sound not yet playable, no duration"),this._source.buffer.duration}get buffer(){return this._source.buffer}set buffer(t){this._source.buffer=t}get nodes(){return this._nodes}load(t){this.source?this._decode(this.source,t):this.parent.url?this._loadUrl(t):t?t(new Error("sound.url or sound.source must be set")):console.error("sound.url or sound.source must be set")}async _loadUrl(t){const e=this.parent.url,i=await d.settings.ADAPTER.fetch(e);this._decode(await i.arrayBuffer(),t)}_decode(t,e){const i=(r,n)=>{if(r)e&&e(r);else{this.parent.isLoaded=!0,this.buffer=n;const o=this.parent.autoPlayStart();e&&e(null,this.parent,o)}};t instanceof AudioBuffer?i(null,t):this.parent.context.decode(t,i)}}var rt=Object.defineProperty,j=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,G=(s,t,e)=>t in s?rt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,B=(s,t)=>{for(var e in t||(t={}))nt.call(t,e)&&G(s,e,t[e]);if(j)for(var e of j(t))ot.call(t,e)&&G(s,e,t[e]);return s};const b=class{static from(s){let t={};typeof s=="string"?t.url=s:s instanceof ArrayBuffer||s instanceof AudioBuffer||s instanceof HTMLAudioElement?t.source=s:t=s,t=B({autoPlay:!1,singleInstance:!1,url:null,source:null,preload:!1,volume:1,speed:1,complete:null,loaded:null,loop:!1},t),Object.freeze(t);const e=l().useLegacy?new O:new w;return new b(e,t)}constructor(s,t){this.media=s,this.options=t,this._instances=[],this._sprites={},this.media.init(this);const e=t.complete;this._autoPlayOptions=e?{complete:e}:null,this.isLoaded=!1,this.isPlaying=!1,this.autoPlay=t.autoPlay,this.singleInstance=t.singleInstance,this.preload=t.preload||this.autoPlay,this.url=t.url,this.speed=t.speed,this.volume=t.volume,this.loop=t.loop,t.sprites&&this.addSprites(t.sprites),this.preload&&this._preload(t.loaded)}get context(){return l().context}pause(){return this.isPlaying=!1,this.paused=!0,this}resume(){return this.isPlaying=this._instances.length>0,this.paused=!1,this}get paused(){return this._paused}set paused(s){this._paused=s,this.refreshPaused()}get speed(){return this._speed}set speed(s){this._speed=s,this.refresh()}get filters(){return this.media.filters}set filters(s){this.media.filters=s}addSprites(s,t){if(typeof s=="object"){const i={};for(const r in s)i[r]=this.addSprites(r,s[r]);return i}console.assert(!this._sprites[s],`Alias ${s} is already taken`);const e=new M(this,t);return this._sprites[s]=e,e}destroy(){this._removeInstances(),this.removeSprites(),this.media.destroy(),this.media=null,this._sprites=null,this._instances=null}removeSprites(s){if(s){const t=this._sprites[s];t!==void 0&&(t.destroy(),delete this._sprites[s])}else for(const t in this._sprites)this.removeSprites(t);return this}get isPlayable(){return this.isLoaded&&this.media&&this.media.isPlayable}stop(){if(!this.isPlayable)return this.autoPlay=!1,this._autoPlayOptions=null,this;this.isPlaying=!1;for(let s=this._instances.length-1;s>=0;s--)this._instances[s].stop();return this}play(s,t){let e;if(typeof s=="string"?e={sprite:s,loop:this.loop,complete:t}:typeof s=="function"?(e={},e.complete=s):e=s,e=B({complete:null,loaded:null,sprite:null,end:null,start:0,volume:1,speed:1,muted:!1,loop:!1},e||{}),e.sprite){const r=e.sprite;console.assert(!!this._sprites[r],`Alias ${r} is not available`);const n=this._sprites[r];e.start=n.start+(e.start||0),e.end=n.end,e.speed=n.speed||1,e.loop=n.loop||e.loop,delete e.sprite}if(e.offset&&(e.start=e.offset),!this.isLoaded)return new Promise((r,n)=>{this.autoPlay=!0,this._autoPlayOptions=e,this._preload((o,a,h)=>{o?n(o):(e.loaded&&e.loaded(o,a,h),r(h))})});(this.singleInstance||e.singleInstance)&&this._removeInstances();const i=this._createInstance();return this._instances.push(i),this.isPlaying=!0,i.once("end",()=>{e.complete&&e.complete(this),this._onComplete(i)}),i.once("stop",()=>{this._onComplete(i)}),i.play(e),i}refresh(){const s=this._instances.length;for(let t=0;t<s;t++)this._instances[t].refresh()}refreshPaused(){const s=this._instances.length;for(let t=0;t<s;t++)this._instances[t].refreshPaused()}get volume(){return this._volume}set volume(s){this._volume=s,this.refresh()}get muted(){return this._muted}set muted(s){this._muted=s,this.refresh()}get loop(){return this._loop}set loop(s){this._loop=s,this.refresh()}_preload(s){this.media.load(s)}get instances(){return this._instances}get sprites(){return this._sprites}get duration(){return this.media.duration}autoPlayStart(){let s;return this.autoPlay&&(s=this.play(this._autoPlayOptions)),s}_removeInstances(){for(let s=this._instances.length-1;s>=0;s--)this._poolInstance(this._instances[s]);this._instances.length=0}_onComplete(s){if(this._instances){const t=this._instances.indexOf(s);t>-1&&this._instances.splice(t,1),this.isPlaying=this._instances.length>0}this._poolInstance(s)}_createInstance(){if(b._pool.length>0){const s=b._pool.pop();return s.init(this.media),s}return this.media.create()}_poolInstance(s){s.destroy(),b._pool.indexOf(s)<0&&b._pool.push(s)}};let x=b;x._pool=[];class K extends d.utils.EventEmitter{constructor(){super(...arguments),this.speed=1,this.muted=!1,this.volume=1,this.paused=!1}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(t){console.warn("HTML Audio does not support filters")}get audioContext(){return console.warn("HTML Audio does not support audioContext"),null}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this.paused}destroy(){this.removeAllListeners()}}class P extends E{constructor(){const t=window,e=new P.AudioContext,i=e.createDynamicsCompressor(),r=e.createAnalyser();r.connect(i),i.connect(e.destination),super(r,i),this._ctx=e,this._offlineCtx=new P.OfflineAudioContext(1,2,t.OfflineAudioContext?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),this._unlocked=!1,this.compressor=i,this.analyser=r,this.events=new d.utils.EventEmitter,this.volume=1,this.speed=1,this.muted=!1,this.paused=!1,e.state!=="running"&&(this._unlock(),this._unlock=this._unlock.bind(this),document.addEventListener("mousedown",this._unlock,!0),document.addEventListener("touchstart",this._unlock,!0),document.addEventListener("touchend",this._unlock,!0))}_unlock(){this._unlocked||(this.playEmptySound(),this._ctx.state==="running"&&(document.removeEventListener("mousedown",this._unlock,!0),document.removeEventListener("touchend",this._unlock,!0),document.removeEventListener("touchstart",this._unlock,!0),this._unlocked=!0))}playEmptySound(){const t=this._ctx.createBufferSource();t.buffer=this._ctx.createBuffer(1,1,22050),t.connect(this._ctx.destination),t.start(0,0,0),t.context.state==="suspended"&&t.context.resume()}static get AudioContext(){const t=window;return t.AudioContext||t.webkitAudioContext||null}static get OfflineAudioContext(){const t=window;return t.OfflineAudioContext||t.webkitOfflineAudioContext||null}destroy(){super.destroy();const t=this._ctx;typeof t.close!="undefined"&&t.close(),this.events.removeAllListeners(),this.analyser.disconnect(),this.compressor.disconnect(),this.analyser=null,this.compressor=null,this.events=null,this._offlineCtx=null,this._ctx=null}get audioContext(){return this._ctx}get offlineContext(){return this._offlineCtx}set paused(t){t&&this._ctx.state==="running"?this._ctx.suspend():!t&&this._ctx.state==="suspended"&&this._ctx.resume(),this._paused=t}get paused(){return this._paused}refresh(){this.events.emit("refresh")}refreshPaused(){this.events.emit("refreshPaused")}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this._paused}decode(t,e){const i=n=>{e(new Error((n==null?void 0:n.message)||"Unable to decode file"))},r=this._offlineCtx.decodeAudioData(t,n=>{e(null,n)},i);r&&r.catch(i)}}var at=Object.defineProperty,R=Object.getOwnPropertySymbols,ut=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable,D=(s,t,e)=>t in s?at(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,q=(s,t)=>{for(var e in t||(t={}))ut.call(t,e)&&D(s,e,t[e]);if(R)for(var e of R(t))ht.call(t,e)&&D(s,e,t[e]);return s};class V{constructor(){this.init()}init(){return this.supported&&(this._webAudioContext=new P),this._htmlAudioContext=new K,this._sounds={},this.useLegacy=!this.supported,this}get context(){return this._context}get filtersAll(){return this.useLegacy?[]:this._context.filters}set filtersAll(t){this.useLegacy||(this._context.filters=t)}get supported(){return P.AudioContext!==null}add(t,e){if(typeof t=="object"){const n={};for(const o in t){const a=this._getOptions(t[o],e);n[o]=this.add(o,a)}return n}if(console.assert(!this._sounds[t],`Sound with alias ${t} already exists.`),e instanceof x)return this._sounds[t]=e,e;const i=this._getOptions(e),r=x.from(i);return this._sounds[t]=r,r}_getOptions(t,e){let i;return typeof t=="string"?i={url:t}:t instanceof ArrayBuffer||t instanceof AudioBuffer||t instanceof HTMLAudioElement?i={source:t}:i=t,i=q(q({},i),e||{}),i}get useLegacy(){return this._useLegacy}set useLegacy(t){this._useLegacy=t,this._context=!t&&this.supported?this._webAudioContext:this._htmlAudioContext}remove(t){return this.exists(t,!0),this._sounds[t].destroy(),delete this._sounds[t],this}get volumeAll(){return this._context.volume}set volumeAll(t){this._context.volume=t,this._context.refresh()}get speedAll(){return this._context.speed}set speedAll(t){this._context.speed=t,this._context.refresh()}togglePauseAll(){return this._context.togglePause()}pauseAll(){return this._context.paused=!0,this._context.refreshPaused(),this}resumeAll(){return this._context.paused=!1,this._context.refreshPaused(),this}toggleMuteAll(){return this._context.toggleMute()}muteAll(){return this._context.muted=!0,this._context.refresh(),this}unmuteAll(){return this._context.muted=!1,this._context.refresh(),this}removeAll(){for(const t in this._sounds)this._sounds[t].destroy(),delete this._sounds[t];return this}stopAll(){for(const t in this._sounds)this._sounds[t].stop();return this}exists(t,e=!1){const i=!!this._sounds[t];return e&&console.assert(i,`No sound matching alias '${t}'.`),i}find(t){return this.exists(t,!0),this._sounds[t]}play(t,e){return this.find(t).play(e)}stop(t){return this.find(t).stop()}pause(t){return this.find(t).pause()}resume(t){return this.find(t).resume()}volume(t,e){const i=this.find(t);return e!==void 0&&(i.volume=e),i.volume}speed(t,e){const i=this.find(t);return e!==void 0&&(i.speed=e),i.speed}duration(t){return this.find(t).duration}close(){return this.removeAll(),this._sounds=null,this._webAudioContext&&(this._webAudioContext.destroy(),this._webAudioContext=null),this._htmlAudioContext&&(this._htmlAudioContext.destroy(),this._htmlAudioContext=null),this._context=null,this}}var lt={__proto__:null,HTMLAudioMedia:O,HTMLAudioInstance:F,HTMLAudioContext:K};class v{constructor(t,e){this.init(t,e)}init(t,e){this.destination=t,this.source=e||t}connect(t){this.source.connect(t)}disconnect(){this.source.disconnect()}destroy(){this.disconnect(),this.destination=null,this.source=null}}const u=class extends v{constructor(s=0,t=0,e=0,i=0,r=0,n=0,o=0,a=0,h=0,c=0){var _=(...p)=>{super(...p)};if(l().useLegacy){_(null);return}const g=[{f:u.F32,type:"lowshelf",gain:s},{f:u.F64,type:"peaking",gain:t},{f:u.F125,type:"peaking",gain:e},{f:u.F250,type:"peaking",gain:i},{f:u.F500,type:"peaking",gain:r},{f:u.F1K,type:"peaking",gain:n},{f:u.F2K,type:"peaking",gain:o},{f:u.F4K,type:"peaking",gain:a},{f:u.F8K,type:"peaking",gain:h},{f:u.F16K,type:"highshelf",gain:c}].map(p=>{const f=l().context.audioContext.createBiquadFilter();return f.type=p.type,m.setParamValue(f.Q,1),f.frequency.value=p.f,m.setParamValue(f.gain,p.gain),f});_(g[0],g[g.length-1]),this.bands=g,this.bandsMap={};for(let p=0;p<this.bands.length;p++){const f=this.bands[p];p>0&&this.bands[p-1].connect(f),this.bandsMap[f.frequency.value]=f}}setGain(s,t=0){if(!this.bandsMap[s])throw new Error(`No band found for frequency ${s}`);m.setParamValue(this.bandsMap[s].gain,t)}getGain(s){if(!this.bandsMap[s])throw new Error(`No band found for frequency ${s}`);return this.bandsMap[s].gain.value}set f32(s){this.setGain(u.F32,s)}get f32(){return this.getGain(u.F32)}set f64(s){this.setGain(u.F64,s)}get f64(){return this.getGain(u.F64)}set f125(s){this.setGain(u.F125,s)}get f125(){return this.getGain(u.F125)}set f250(s){this.setGain(u.F250,s)}get f250(){return this.getGain(u.F250)}set f500(s){this.setGain(u.F500,s)}get f500(){return this.getGain(u.F500)}set f1k(s){this.setGain(u.F1K,s)}get f1k(){return this.getGain(u.F1K)}set f2k(s){this.setGain(u.F2K,s)}get f2k(){return this.getGain(u.F2K)}set f4k(s){this.setGain(u.F4K,s)}get f4k(){return this.getGain(u.F4K)}set f8k(s){this.setGain(u.F8K,s)}get f8k(){return this.getGain(u.F8K)}set f16k(s){this.setGain(u.F16K,s)}get f16k(){return this.getGain(u.F16K)}reset(){this.bands.forEach(s=>{m.setParamValue(s.gain,0)})}destroy(){this.bands.forEach(s=>{s.disconnect()}),this.bands=null,this.bandsMap=null}};let y=u;y.F32=32,y.F64=64,y.F125=125,y.F250=250,y.F500=500,y.F1K=1e3,y.F2K=2e3,y.F4K=4e3,y.F8K=8e3,y.F16K=16e3;class dt extends v{constructor(t=0){var e=(...n)=>{super(...n)};if(l().useLegacy){e(null);return}const{context:i}=l(),r=i.audioContext.createWaveShaper();e(r),this._distortion=r,this.amount=t}set amount(t){this._amount=t;const e=t*1e3,i=44100,r=new Float32Array(i),n=Math.PI/180;let o=0,a;for(;o<i;++o)a=o*2/i-1,r[o]=(3+e)*a*20*n/(Math.PI+e*Math.abs(a));this._distortion.curve=r,this._distortion.oversample="4x"}get amount(){return this._amount}destroy(){this._distortion=null,super.destroy()}}class ct extends v{constructor(t=0){var e=(...a)=>{super(...a)};if(l().useLegacy){e(null);return}let i,r,n;const{audioContext:o}=l().context;o.createStereoPanner?(i=o.createStereoPanner(),n=i):(r=o.createPanner(),r.panningModel="equalpower",n=r),e(n),this._stereo=i,this._panner=r,this.pan=t}set pan(t){this._pan=t,this._stereo?m.setParamValue(this._stereo.pan,t):this._panner.setPosition(t,0,1-Math.abs(t))}get pan(){return this._pan}destroy(){super.destroy(),this._stereo=null,this._panner=null}}class pt extends v{constructor(t=3,e=2,i=!1){var r=(...n)=>{super(...n)};if(l().useLegacy){r(null);return}r(null),this._seconds=this._clamp(t,1,50),this._decay=this._clamp(e,0,100),this._reverse=i,this._rebuild()}_clamp(t,e,i){return Math.min(i,Math.max(e,t))}get seconds(){return this._seconds}set seconds(t){this._seconds=this._clamp(t,1,50),this._rebuild()}get decay(){return this._decay}set decay(t){this._decay=this._clamp(t,0,100),this._rebuild()}get reverse(){return this._reverse}set reverse(t){this._reverse=t,this._rebuild()}_rebuild(){const t=l().context.audioContext,e=t.sampleRate,i=e*this._seconds,r=t.createBuffer(2,i,e),n=r.getChannelData(0),o=r.getChannelData(1);let a;for(let c=0;c<i;c++)a=this._reverse?i-c:c,n[c]=(Math.random()*2-1)*Math.pow(1-a/i,this._decay),o[c]=(Math.random()*2-1)*Math.pow(1-a/i,this._decay);const h=l().context.audioContext.createConvolver();h.buffer=r,this.init(h)}}class _t extends v{constructor(){var t=(...n)=>{super(...n)};if(l().useLegacy){t(null);return}const e=l().context.audioContext,i=e.createChannelSplitter(),r=e.createChannelMerger();r.connect(i),t(r,i),this._merger=r}destroy(){this._merger.disconnect(),this._merger=null,super.destroy()}}class ft extends v{constructor(){var t=(...n)=>{super(...n)};if(l().useLegacy){t(null);return}const e=l().context.audioContext,i=e.createMediaStreamDestination(),r=e.createMediaStreamSource(i.stream);t(i,r),this._stream=i.stream}get stream(){return this._stream}destroy(){this._stream=null,super.destroy()}}class mt extends v{constructor(){if(l().useLegacy){super(null);return}const{audioContext:t}=l().context,e=t.createBiquadFilter(),i=t.createBiquadFilter(),r=t.createBiquadFilter(),n=t.createBiquadFilter();e.type="lowpass",m.setParamValue(e.frequency,2e3),i.type="lowpass",m.setParamValue(i.frequency,2e3),r.type="highpass",m.setParamValue(r.frequency,500),n.type="highpass",m.setParamValue(n.frequency,500),e.connect(i),i.connect(r),r.connect(n),super(e,n)}}var gt={__proto__:null,Filter:v,EqualizerFilter:y,DistortionFilter:dt,StereoFilter:ct,ReverbFilter:pt,MonoFilter:_t,StreamFilter:ft,TelephoneFilter:mt},yt={__proto__:null,WebAudioMedia:w,WebAudioInstance:I,WebAudioNodes:C,WebAudioContext:P,WebAudioUtils:m};let H=0;function vt(s,t){const e=`alias${H++}`;return l().add(e,{url:s,preload:!0,autoPlay:!0,loaded:i=>{i&&(console.error(i),l().remove(e),t&&t(i))},complete:()=>{l().remove(e),t&&t(null)}}),e}var bt=Object.defineProperty,U=Object.getOwnPropertySymbols,xt=Object.prototype.hasOwnProperty,Pt=Object.prototype.propertyIsEnumerable,N=(s,t,e)=>t in s?bt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,wt=(s,t)=>{for(var e in t||(t={}))xt.call(t,e)&&N(s,e,t[e]);if(U)for(var e of U(t))Pt.call(t,e)&&N(s,e,t[e]);return s};function At(s,t){const e=document.createElement("canvas");t=wt({width:512,height:128,fill:"black"},t||{}),e.width=t.width,e.height=t.height;const i=d.BaseTexture.from(e);if(!(s.media instanceof w))return i;const r=s.media;console.assert(!!r.buffer,"No buffer found, load first");const n=e.getContext("2d");n.fillStyle=t.fill;const o=r.buffer.getChannelData(0),a=Math.ceil(o.length/t.width),h=t.height/2;for(let c=0;c<t.width;c++){let _=1,g=-1;for(let p=0;p<a;p++){const f=o[c*a+p];f<_&&(_=f),f>g&&(g=f)}n.fillRect(c,(1+_)*h,1,Math.max(1,(g-_)*h))}return i}function St(s=200,t=1){const e=x.from({singleInstance:!0});if(!(e.media instanceof w))return e;const i=e.media,r=e.context,n=1,o=48e3,a=2,h=r.audioContext.createBuffer(n,t*o,o),c=h.getChannelData(0);for(let _=0;_<c.length;_++){const g=_/h.sampleRate,p=s*g*Math.PI;c[_]=Math.sin(p)*a}return i.buffer=h,e.isLoaded=!0,e}var Ft=Object.defineProperty,W=Object.getOwnPropertySymbols,Et=Object.prototype.hasOwnProperty,Ct=Object.prototype.propertyIsEnumerable,X=(s,t,e)=>t in s?Ft(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Lt=(s,t)=>{for(var e in t||(t={}))Et.call(t,e)&&X(s,e,t[e]);if(W)for(var e of W(t))Ct.call(t,e)&&X(s,e,t[e]);return s};const L=["mp3","ogg","oga","opus","mpeg","wav","m4a","aiff","wma","mid","caf"],A={};function z(s){const t=Lt({m4a:"audio/mp4",oga:"audio/ogg",opus:'audio/ogg; codecs="opus"',caf:'audio/x-caf; codecs="opus"'},s||{}),e=document.createElement("audio"),i={},r=/^no$/;L.forEach(n=>{const o=e.canPlayType(`audio/${n}`).replace(r,""),a=t[n]?e.canPlayType(t[n]).replace(r,""):"";i[n]=!!o||!!a}),Object.assign(A,i)}z();var $t={__proto__:null,playOnce:vt,get PLAY_ID(){return H},render:At,sineTone:St,validateFormats:z,supported:A,extensions:L},kt=Object.defineProperty,Ot=Object.defineProperties,Mt=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,It=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable,Q=(s,t,e)=>t in s?kt(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,jt=(s,t)=>{for(var e in t||(t={}))It.call(t,e)&&Q(s,e,t[e]);if(Z)for(var e of Z(t))Tt.call(t,e)&&Q(s,e,t[e]);return s},Gt=(s,t)=>Ot(s,Mt(t));const Y=s=>{var t,e;const i=s.src;return(e=(t=s==null?void 0:s.alias)==null?void 0:t[0])!=null?e:d.utils.path.basename(i,d.utils.path.extname(i))},J={extension:d.ExtensionType.Asset,detection:{test:async()=>!0,add:async s=>[...s,...L.filter(t=>A[t])],remove:async s=>s.filter(t=>s.includes(t))},loader:{extension:{type:[d.ExtensionType.LoadParser],priority:tt.LoaderParserPriority.High},test(s){const t=d.utils.path.extname(s).slice(1);return!!A[t]},async load(s,t){const e=await new Promise((i,r)=>x.from(Gt(jt({},t.data),{url:s,preload:!0,loaded(n,o){var a,h;n?r(n):i(o),(h=(a=t.data)==null?void 0:a.loaded)==null||h.call(a,n,o)}})));return l().add(Y(t),e),e},async unload(s,t){l().remove(Y(t))}}};d.extensions.add(J);const $=et(new V);return Object.defineProperties($,{Filterable:{get(){return E}},filters:{get(){return gt}},htmlaudio:{get(){return lt}},Sound:{get(){return x}},SoundLibrary:{get(){return V}},SoundSprite:{get(){return M}},utils:{get(){return $t}},webaudio:{get(){return yt}},sound:{get(){return $}},soundAsset:{get(){return J}}}),$}(PIXI,PIXI); | ||
* | ||
* Copyright 2023, Matt Karl @bigtimebuddy, All Rights Reserved | ||
*/this.PIXI=this.PIXI||{},this.PIXI.sound=function(c,et){"use strict";let O;function st(i){return O=i,i}function h(){return O}let it=0;const F=class extends c.utils.EventEmitter{constructor(t){super(),this.id=it++,this.init(t)}set(t,e){if(this[t]===void 0)throw new Error(`Property with name ${t} does not exist.`);switch(t){case"speed":this.speed=e;break;case"volume":this.volume=e;break;case"paused":this.paused=e;break;case"loop":this.loop=e;break;case"muted":this.muted=e;break}return this}get progress(){const{currentTime:t}=this._source;return t/this._duration}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}_onPlay(){this._playing=!0}_onPause(){this._playing=!1}init(t){this._playing=!1,this._duration=t.source.duration;const e=this._source=t.source.cloneNode(!1);e.src=t.parent.url,e.onplay=this._onPlay.bind(this),e.onpause=this._onPause.bind(this),t.context.on("refresh",this.refresh,this),t.context.on("refreshPaused",this.refreshPaused,this),this._media=t}_internalStop(){this._source&&this._playing&&(this._source.onended=null,this._source.pause())}stop(){this._internalStop(),this._source&&this.emit("stop")}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh()}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(t){console.warn("HTML Audio does not support filters")}refresh(){const t=this._media.context,e=this._media.parent;this._source.loop=this._loop||e.loop;const s=t.volume*(t.muted?0:1),r=e.volume*(e.muted?0:1),n=this._volume*(this._muted?0:1);this._source.volume=n*s*r,this._source.playbackRate=this._speed*t.speed*e.speed}refreshPaused(){const t=this._media.context,e=this._media.parent,s=this._paused||e.paused||t.paused;s!==this._pausedReal&&(this._pausedReal=s,s?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._source.currentTime,end:this._end,volume:this._volume,speed:this._speed,loop:this._loop})),this.emit("pause",s))}play(t){const{start:e,end:s,speed:r,loop:n,volume:o,muted:a}=t;s&&console.assert(s>e,"End time is before start time"),this._speed=r,this._volume=o,this._loop=!!n,this._muted=a,this.refresh(),this.loop&&s!==null&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=e,this._end=s||this._duration,this._start=Math.max(0,this._start-F.PADDING),this._end=Math.min(this._end+F.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=e,this._source.onloadedmetadata=null,this.emit("progress",e,this._duration),c.Ticker.shared.add(this._onUpdate,this))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onUpdate(){this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete()}_onComplete(){c.Ticker.shared.remove(this._onUpdate,this),this._internalStop(),this.emit("progress",1,this._duration),this.emit("end",this)}destroy(){c.Ticker.shared.remove(this._onUpdate,this),this.removeAllListeners();const t=this._source;t&&(t.onended=null,t.onplay=null,t.onpause=null,this._internalStop()),this._source=null,this._speed=1,this._volume=1,this._loop=!1,this._end=null,this._start=0,this._duration=0,this._playing=!1,this._pausedReal=!1,this._paused=!1,this._muted=!1,this._media&&(this._media.context.off("refresh",this.refresh,this),this._media.context.off("refreshPaused",this.refreshPaused,this),this._media=null)}toString(){return`[HTMLAudioInstance id=${this.id}]`}};let $=F;$.PADDING=.1;class M extends c.utils.EventEmitter{init(t){this.parent=t,this._source=t.options.source||new Audio,t.url&&(this._source.src=t.url)}create(){return new $(this)}get isPlayable(){return!!this._source&&this._source.readyState===4}get duration(){return this._source.duration}get context(){return this.parent.context}get filters(){return null}set filters(t){console.warn("HTML Audio does not support filters")}destroy(){this.removeAllListeners(),this.parent=null,this._source&&(this._source.src="",this._source.load(),this._source=null)}get source(){return this._source}load(t){const e=this._source,s=this.parent;if(e.readyState===4){s.isLoaded=!0;const l=s.autoPlayStart();t&&setTimeout(()=>{t(null,s,l)},0);return}if(!s.url){t(new Error("sound.url or sound.source must be set"));return}e.src=s.url;const r=()=>{a(),s.isLoaded=!0;const l=s.autoPlayStart();t&&t(null,s,l)},n=()=>{a(),t&&t(new Error("Sound loading has been aborted"))},o=()=>{a();const l=`Failed to load audio element (code: ${e.error.code})`;t?t(new Error(l)):console.error(l)},a=()=>{e.removeEventListener("canplaythrough",r),e.removeEventListener("load",r),e.removeEventListener("abort",n),e.removeEventListener("error",o)};e.addEventListener("canplaythrough",r,!1),e.addEventListener("load",r,!1),e.addEventListener("abort",n,!1),e.addEventListener("error",o,!1),e.load()}}let I=class{constructor(t,e){this.parent=t,Object.assign(this,e),this.duration=this.end-this.start,console.assert(this.duration>0,"End time must be after start time")}play(t){return this.parent.play({complete:t,speed:this.speed||this.parent.speed,end:this.end,start:this.start,loop:this.loop})}destroy(){this.parent=null}};var rt=Object.defineProperty,T=Object.getOwnPropertySymbols,nt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable,j=(i,t,e)=>t in i?rt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,at=(i,t)=>{for(var e in t||(t={}))nt.call(t,e)&&j(i,e,t[e]);if(T)for(var e of T(t))ot.call(t,e)&&j(i,e,t[e]);return i};const w=["ogg","oga","opus","m4a","mp3","mpeg","wav","aiff","wma","mid","caf"],S={};function G(i){const t=at({m4a:"audio/mp4",oga:"audio/ogg",opus:'audio/ogg; codecs="opus"',caf:'audio/x-caf; codecs="opus"'},i||{}),e=document.createElement("audio"),s={},r=/^no$/;w.forEach(n=>{const o=e.canPlayType(`audio/${n}`).replace(r,""),a=t[n]?e.canPlayType(t[n]).replace(r,""):"";s[n]=!!o||!!a}),Object.assign(S,s)}G();let f=class{static setParamValue(t,e){if(t.setValueAtTime){const s=h().context;t.setValueAtTime(e,s.audioContext.currentTime)}else t.value=e;return e}},ut=0,B=class extends c.utils.EventEmitter{constructor(t){super(),this.id=ut++,this._media=null,this._paused=!1,this._muted=!1,this._elapsed=0,this.init(t)}set(t,e){if(this[t]===void 0)throw new Error(`Property with name ${t} does not exist.`);switch(t){case"speed":this.speed=e;break;case"volume":this.volume=e;break;case"muted":this.muted=e;break;case"loop":this.loop=e;break;case"paused":this.paused=e;break}return this}stop(){this._source&&(this._internalStop(),this.emit("stop"))}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh(),this._update(!0)}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}get filters(){return this._filters}set filters(t){var e;this._filters&&((e=this._filters)==null||e.filter(s=>s).forEach(s=>s.disconnect()),this._filters=null,this._source.connect(this._gain)),this._filters=t!=null&&t.length?t.slice(0):null,this.refresh()}refresh(){if(!this._source)return;const t=this._media.context,e=this._media.parent;this._source.loop=this._loop||e.loop;const s=t.volume*(t.muted?0:1),r=e.volume*(e.muted?0:1),n=this._volume*(this._muted?0:1);f.setParamValue(this._gain.gain,n*r*s),f.setParamValue(this._source.playbackRate,this._speed*e.speed*t.speed),this.applyFilters()}applyFilters(){var t;if((t=this._filters)!=null&&t.length){this._source.disconnect();let e=this._source;this._filters.forEach(s=>{e.connect(s.destination),e=s}),e.connect(this._gain)}}refreshPaused(){const t=this._media.context,e=this._media.parent,s=this._paused||e.paused||t.paused;s!==this._pausedReal&&(this._pausedReal=s,s?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._elapsed%this._duration,end:this._end,speed:this._speed,loop:this._loop,volume:this._volume})),this.emit("pause",s))}play(t){const{start:e,end:s,speed:r,loop:n,volume:o,muted:a,filters:l}=t;s&&console.assert(s>e,"End time is before start time"),this._paused=!1;const{source:d,gain:_}=this._media.nodes.cloneBufferSource();this._source=d,this._gain=_,this._speed=r,this._volume=o,this._loop=!!n,this._muted=a,this._filters=l,this.refresh();const g=this._source.buffer.duration;this._duration=g,this._end=s,this._lastUpdate=this._now(),this._elapsed=e,this._source.onended=this._onComplete.bind(this),this._loop?(this._source.loopEnd=s,this._source.loopStart=e,this._source.start(0,e)):s?this._source.start(0,e,s-e):this._source.start(0,e),this.emit("start"),this._update(!0),this.enableTicker(!0)}enableTicker(t){c.Ticker.shared.remove(this._updateListener,this),t&&c.Ticker.shared.add(this._updateListener,this)}get progress(){return this._progress}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}destroy(){var t;this.removeAllListeners(),this._internalStop(),this._gain&&(this._gain.disconnect(),this._gain=null),this._media&&(this._media.context.events.off("refresh",this.refresh,this),this._media.context.events.off("refreshPaused",this.refreshPaused,this),this._media=null),(t=this._filters)==null||t.forEach(e=>e.disconnect()),this._filters=null,this._end=null,this._speed=1,this._volume=1,this._loop=!1,this._elapsed=0,this._duration=0,this._paused=!1,this._muted=!1,this._pausedReal=!1}toString(){return`[WebAudioInstance id=${this.id}]`}_now(){return this._media.context.audioContext.currentTime}_updateListener(){this._update()}_update(t=!1){if(this._source){const e=this._now(),s=e-this._lastUpdate;if(s>0||t){const r=this._source.playbackRate.value;this._elapsed+=s*r,this._lastUpdate=e;const n=this._duration;let o;if(this._source.loopStart){const a=this._source.loopEnd-this._source.loopStart;o=(this._source.loopStart+this._elapsed%a)/n}else o=this._elapsed%n/n;this._progress=o,this.emit("progress",this._progress,n)}}}init(t){this._media=t,t.context.events.on("refresh",this.refresh,this),t.context.events.on("refreshPaused",this.refreshPaused,this)}_internalStop(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.stop(0),this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null}}_onComplete(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}}this._source=null,this._progress=1,this.emit("progress",1,this._duration),this.emit("end",this)}},C=class{constructor(t,e){this._output=e,this._input=t}get destination(){return this._input}get filters(){return this._filters}set filters(t){if(this._filters&&(this._filters.forEach(e=>{e&&e.disconnect()}),this._filters=null,this._input.connect(this._output)),t&&t.length){this._filters=t.slice(0),this._input.disconnect();let e=null;t.forEach(s=>{e===null?this._input.connect(s.destination):e.connect(s.destination),e=s}),e.connect(this._output)}}destroy(){this.filters=null,this._input=null,this._output=null}};const K=class extends C{constructor(t){const e=t.audioContext,s=e.createBufferSource(),r=e.createGain(),n=e.createAnalyser();s.connect(n),n.connect(r),r.connect(t.destination),super(n,r),this.context=t,this.bufferSource=s,this.gain=r,this.analyser=n}get script(){return this._script||(this._script=this.context.audioContext.createScriptProcessor(K.BUFFER_SIZE),this._script.connect(this.context.destination)),this._script}destroy(){super.destroy(),this.bufferSource.disconnect(),this._script&&this._script.disconnect(),this.gain.disconnect(),this.analyser.disconnect(),this.bufferSource=null,this._script=null,this.gain=null,this.analyser=null,this.context=null}cloneBufferSource(){const t=this.bufferSource,e=this.context.audioContext.createBufferSource();e.buffer=t.buffer,f.setParamValue(e.playbackRate,t.playbackRate.value),e.loop=t.loop;const s=this.context.audioContext.createGain();return e.connect(s),s.connect(this.destination),{source:e,gain:s}}get bufferSize(){return this.script.bufferSize}};let L=K;L.BUFFER_SIZE=0;let E=class{init(t){this.parent=t,this._nodes=new L(this.context),this._source=this._nodes.bufferSource,this.source=t.options.source}destroy(){this.parent=null,this._nodes.destroy(),this._nodes=null;try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null,this.source=null}create(){return new B(this)}get context(){return this.parent.context}get isPlayable(){return!!this._source&&!!this._source.buffer}get filters(){return this._nodes.filters}set filters(t){this._nodes.filters=t}get duration(){return console.assert(this.isPlayable,"Sound not yet playable, no duration"),this._source.buffer.duration}get buffer(){return this._source.buffer}set buffer(t){this._source.buffer=t}get nodes(){return this._nodes}load(t){this.source?this._decode(this.source,t):this.parent.url?this._loadUrl(t):t?t(new Error("sound.url or sound.source must be set")):console.error("sound.url or sound.source must be set")}async _loadUrl(t){const e=this.parent.url,s=await c.settings.ADAPTER.fetch(e);this._decode(await s.arrayBuffer(),t)}_decode(t,e){const s=(r,n)=>{if(r)e&&e(r);else{this.parent.isLoaded=!0,this.buffer=n;const o=this.parent.autoPlayStart();e&&e(null,this.parent,o)}};t instanceof AudioBuffer?s(null,t):this.parent.context.decode(t,s)}};var lt=Object.defineProperty,R=Object.getOwnPropertySymbols,ht=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable,D=(i,t,e)=>t in i?lt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,q=(i,t)=>{for(var e in t||(t={}))ht.call(t,e)&&D(i,e,t[e]);if(R)for(var e of R(t))dt.call(t,e)&&D(i,e,t[e]);return i};const x=class{static from(t){let e={};typeof t=="string"?e.url=t:t instanceof ArrayBuffer||t instanceof AudioBuffer||t instanceof HTMLAudioElement?e.source=t:Array.isArray(t)?e.url=t:e=t,e=q({autoPlay:!1,singleInstance:!1,url:null,source:null,preload:!1,volume:1,speed:1,complete:null,loaded:null,loop:!1},e),Object.freeze(e);const s=h().useLegacy?new M:new E;return new x(s,e)}constructor(t,e){this.media=t,this.options=e,this._instances=[],this._sprites={},this.media.init(this);const s=e.complete;this._autoPlayOptions=s?{complete:s}:null,this.isLoaded=!1,this._preloadQueue=null,this.isPlaying=!1,this.autoPlay=e.autoPlay,this.singleInstance=e.singleInstance,this.preload=e.preload||this.autoPlay,this.url=Array.isArray(e.url)?this.preferUrl(e.url):e.url,this.speed=e.speed,this.volume=e.volume,this.loop=e.loop,e.sprites&&this.addSprites(e.sprites),this.preload&&this._preload(e.loaded)}preferUrl(t){const[{url:e}]=t.map(s=>({url:s,ext:c.utils.path.extname(s).slice(1)})).sort((s,r)=>w.indexOf(s.ext)-w.indexOf(r.ext));return e}get context(){return h().context}pause(){return this.isPlaying=!1,this.paused=!0,this}resume(){return this.isPlaying=this._instances.length>0,this.paused=!1,this}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh()}get filters(){return this.media.filters}set filters(t){this.media.filters=t}addSprites(t,e){if(typeof t=="object"){const r={};for(const n in t)r[n]=this.addSprites(n,t[n]);return r}console.assert(!this._sprites[t],`Alias ${t} is already taken`);const s=new I(this,e);return this._sprites[t]=s,s}destroy(){this._removeInstances(),this.removeSprites(),this.media.destroy(),this.media=null,this._sprites=null,this._instances=null}removeSprites(t){if(t){const e=this._sprites[t];e!==void 0&&(e.destroy(),delete this._sprites[t])}else for(const e in this._sprites)this.removeSprites(e);return this}get isPlayable(){return this.isLoaded&&this.media&&this.media.isPlayable}stop(){if(!this.isPlayable)return this.autoPlay=!1,this._autoPlayOptions=null,this;this.isPlaying=!1;for(let t=this._instances.length-1;t>=0;t--)this._instances[t].stop();return this}play(t,e){let s;if(typeof t=="string"?s={sprite:t,loop:this.loop,complete:e}:typeof t=="function"?(s={},s.complete=t):s=t,s=q({complete:null,loaded:null,sprite:null,end:null,start:0,volume:1,speed:1,muted:!1,loop:!1},s||{}),s.sprite){const n=s.sprite;console.assert(!!this._sprites[n],`Alias ${n} is not available`);const o=this._sprites[n];s.start=o.start+(s.start||0),s.end=o.end,s.speed=o.speed||1,s.loop=o.loop||s.loop,delete s.sprite}if(s.offset&&(s.start=s.offset),!this.isLoaded)return this._preloadQueue?new Promise(n=>{this._preloadQueue.push(()=>{n(this.play(s))})}):(this._preloadQueue=[],this.autoPlay=!0,this._autoPlayOptions=s,new Promise((n,o)=>{this._preload((a,l,d)=>{this._preloadQueue.forEach(_=>_()),this._preloadQueue=null,a?o(a):(s.loaded&&s.loaded(a,l,d),n(d))})}));(this.singleInstance||s.singleInstance)&&this._removeInstances();const r=this._createInstance();return this._instances.push(r),this.isPlaying=!0,r.once("end",()=>{s.complete&&s.complete(this),this._onComplete(r)}),r.once("stop",()=>{this._onComplete(r)}),r.play(s),r}refresh(){const t=this._instances.length;for(let e=0;e<t;e++)this._instances[e].refresh()}refreshPaused(){const t=this._instances.length;for(let e=0;e<t;e++)this._instances[e].refreshPaused()}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}_preload(t){this.media.load(t)}get instances(){return this._instances}get sprites(){return this._sprites}get duration(){return this.media.duration}autoPlayStart(){let t;return this.autoPlay&&(t=this.play(this._autoPlayOptions)),t}_removeInstances(){for(let t=this._instances.length-1;t>=0;t--)this._poolInstance(this._instances[t]);this._instances.length=0}_onComplete(t){if(this._instances){const e=this._instances.indexOf(t);e>-1&&this._instances.splice(e,1),this.isPlaying=this._instances.length>0}this._poolInstance(t)}_createInstance(){if(x._pool.length>0){const t=x._pool.pop();return t.init(this.media),t}return this.media.create()}_poolInstance(t){t.destroy(),x._pool.indexOf(t)<0&&x._pool.push(t)}};let P=x;P._pool=[];let U=class extends c.utils.EventEmitter{constructor(){super(...arguments),this.speed=1,this.muted=!1,this.volume=1,this.paused=!1}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(t){console.warn("HTML Audio does not support filters")}get audioContext(){return console.warn("HTML Audio does not support audioContext"),null}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this.paused}destroy(){this.removeAllListeners()}},A=class extends C{constructor(){const t=window,e=new A.AudioContext,s=e.createDynamicsCompressor(),r=e.createAnalyser();r.connect(s),s.connect(e.destination),super(r,s),this._ctx=e,this._offlineCtx=new A.OfflineAudioContext(1,2,t.OfflineAudioContext?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),this._unlocked=!1,this.compressor=s,this.analyser=r,this.events=new c.utils.EventEmitter,this.volume=1,this.speed=1,this.muted=!1,this.paused=!1,e.state!=="running"&&(this._unlock(),this._unlock=this._unlock.bind(this),document.addEventListener("mousedown",this._unlock,!0),document.addEventListener("touchstart",this._unlock,!0),document.addEventListener("touchend",this._unlock,!0))}_unlock(){this._unlocked||(this.playEmptySound(),this._ctx.state==="running"&&(document.removeEventListener("mousedown",this._unlock,!0),document.removeEventListener("touchend",this._unlock,!0),document.removeEventListener("touchstart",this._unlock,!0),this._unlocked=!0))}playEmptySound(){const t=this._ctx.createBufferSource();t.buffer=this._ctx.createBuffer(1,1,22050),t.connect(this._ctx.destination),t.start(0,0,0),t.context.state==="suspended"&&t.context.resume()}static get AudioContext(){const t=window;return t.AudioContext||t.webkitAudioContext||null}static get OfflineAudioContext(){const t=window;return t.OfflineAudioContext||t.webkitOfflineAudioContext||null}destroy(){super.destroy();const t=this._ctx;typeof t.close!="undefined"&&t.close(),this.events.removeAllListeners(),this.analyser.disconnect(),this.compressor.disconnect(),this.analyser=null,this.compressor=null,this.events=null,this._offlineCtx=null,this._ctx=null}get audioContext(){return this._ctx}get offlineContext(){return this._offlineCtx}set paused(t){t&&this._ctx.state==="running"?this._ctx.suspend():!t&&this._ctx.state==="suspended"&&this._ctx.resume(),this._paused=t}get paused(){return this._paused}refresh(){this.events.emit("refresh")}refreshPaused(){this.events.emit("refreshPaused")}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this._paused}decode(t,e){const s=n=>{e(new Error((n==null?void 0:n.message)||"Unable to decode file"))},r=this._offlineCtx.decodeAudioData(t,n=>{e(null,n)},s);r&&r.catch(s)}};var ct=Object.defineProperty,V=Object.getOwnPropertySymbols,pt=Object.prototype.hasOwnProperty,_t=Object.prototype.propertyIsEnumerable,H=(i,t,e)=>t in i?ct(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,N=(i,t)=>{for(var e in t||(t={}))pt.call(t,e)&&H(i,e,t[e]);if(V)for(var e of V(t))_t.call(t,e)&&H(i,e,t[e]);return i};let z=class{constructor(){this.init()}init(){return this.supported&&(this._webAudioContext=new A),this._htmlAudioContext=new U,this._sounds={},this.useLegacy=!this.supported,this}get context(){return this._context}get filtersAll(){return this.useLegacy?[]:this._context.filters}set filtersAll(t){this.useLegacy||(this._context.filters=t)}get supported(){return A.AudioContext!==null}add(t,e){if(typeof t=="object"){const n={};for(const o in t){const a=this._getOptions(t[o],e);n[o]=this.add(o,a)}return n}if(console.assert(!this._sounds[t],`Sound with alias ${t} already exists.`),e instanceof P)return this._sounds[t]=e,e;const s=this._getOptions(e),r=P.from(s);return this._sounds[t]=r,r}_getOptions(t,e){let s;return typeof t=="string"?s={url:t}:Array.isArray(t)?s={url:t}:t instanceof ArrayBuffer||t instanceof AudioBuffer||t instanceof HTMLAudioElement?s={source:t}:s=t,s=N(N({},s),e||{}),s}get useLegacy(){return this._useLegacy}set useLegacy(t){this._useLegacy=t,this._context=!t&&this.supported?this._webAudioContext:this._htmlAudioContext}remove(t){return this.exists(t,!0),this._sounds[t].destroy(),delete this._sounds[t],this}get volumeAll(){return this._context.volume}set volumeAll(t){this._context.volume=t,this._context.refresh()}get speedAll(){return this._context.speed}set speedAll(t){this._context.speed=t,this._context.refresh()}togglePauseAll(){return this._context.togglePause()}pauseAll(){return this._context.paused=!0,this._context.refreshPaused(),this}resumeAll(){return this._context.paused=!1,this._context.refreshPaused(),this}toggleMuteAll(){return this._context.toggleMute()}muteAll(){return this._context.muted=!0,this._context.refresh(),this}unmuteAll(){return this._context.muted=!1,this._context.refresh(),this}removeAll(){for(const t in this._sounds)this._sounds[t].destroy(),delete this._sounds[t];return this}stopAll(){for(const t in this._sounds)this._sounds[t].stop();return this}exists(t,e=!1){const s=!!this._sounds[t];return e&&console.assert(s,`No sound matching alias '${t}'.`),s}isPlaying(){for(const t in this._sounds)if(this._sounds[t].isPlaying)return!0;return!1}find(t){return this.exists(t,!0),this._sounds[t]}play(t,e){return this.find(t).play(e)}stop(t){return this.find(t).stop()}pause(t){return this.find(t).pause()}resume(t){return this.find(t).resume()}volume(t,e){const s=this.find(t);return e!==void 0&&(s.volume=e),s.volume}speed(t,e){const s=this.find(t);return e!==void 0&&(s.speed=e),s.speed}duration(t){return this.find(t).duration}close(){return this.removeAll(),this._sounds=null,this._webAudioContext&&(this._webAudioContext.destroy(),this._webAudioContext=null),this._htmlAudioContext&&(this._htmlAudioContext.destroy(),this._htmlAudioContext=null),this._context=null,this}};var ft=Object.freeze({__proto__:null,HTMLAudioContext:U,HTMLAudioInstance:$,HTMLAudioMedia:M});let b=class{constructor(t,e){this.init(t,e)}init(t,e){this.destination=t,this.source=e||t}connect(t){this.source.connect(t)}disconnect(){this.source.disconnect()}destroy(){this.disconnect(),this.destination=null,this.source=null}};const u=class extends b{constructor(t=0,e=0,s=0,r=0,n=0,o=0,a=0,l=0,d=0,_=0){var g=(...p)=>{super(...p)};if(h().useLegacy){g(null);return}const y=[{f:u.F32,type:"lowshelf",gain:t},{f:u.F64,type:"peaking",gain:e},{f:u.F125,type:"peaking",gain:s},{f:u.F250,type:"peaking",gain:r},{f:u.F500,type:"peaking",gain:n},{f:u.F1K,type:"peaking",gain:o},{f:u.F2K,type:"peaking",gain:a},{f:u.F4K,type:"peaking",gain:l},{f:u.F8K,type:"peaking",gain:d},{f:u.F16K,type:"highshelf",gain:_}].map(p=>{const v=h().context.audioContext.createBiquadFilter();return v.type=p.type,f.setParamValue(v.Q,1),v.frequency.value=p.f,f.setParamValue(v.gain,p.gain),v});g(y[0],y[y.length-1]),this.bands=y,this.bandsMap={};for(let p=0;p<this.bands.length;p++){const v=this.bands[p];p>0&&this.bands[p-1].connect(v),this.bandsMap[v.frequency.value]=v}}setGain(t,e=0){if(!this.bandsMap[t])throw new Error(`No band found for frequency ${t}`);f.setParamValue(this.bandsMap[t].gain,e)}getGain(t){if(!this.bandsMap[t])throw new Error(`No band found for frequency ${t}`);return this.bandsMap[t].gain.value}set f32(t){this.setGain(u.F32,t)}get f32(){return this.getGain(u.F32)}set f64(t){this.setGain(u.F64,t)}get f64(){return this.getGain(u.F64)}set f125(t){this.setGain(u.F125,t)}get f125(){return this.getGain(u.F125)}set f250(t){this.setGain(u.F250,t)}get f250(){return this.getGain(u.F250)}set f500(t){this.setGain(u.F500,t)}get f500(){return this.getGain(u.F500)}set f1k(t){this.setGain(u.F1K,t)}get f1k(){return this.getGain(u.F1K)}set f2k(t){this.setGain(u.F2K,t)}get f2k(){return this.getGain(u.F2K)}set f4k(t){this.setGain(u.F4K,t)}get f4k(){return this.getGain(u.F4K)}set f8k(t){this.setGain(u.F8K,t)}get f8k(){return this.getGain(u.F8K)}set f16k(t){this.setGain(u.F16K,t)}get f16k(){return this.getGain(u.F16K)}reset(){this.bands.forEach(t=>{f.setParamValue(t.gain,0)})}destroy(){this.bands.forEach(t=>{t.disconnect()}),this.bands=null,this.bandsMap=null}};let m=u;m.F32=32,m.F64=64,m.F125=125,m.F250=250,m.F500=500,m.F1K=1e3,m.F2K=2e3,m.F4K=4e3,m.F8K=8e3,m.F16K=16e3;let mt=class extends b{constructor(t=0){var e=(...n)=>{super(...n)};if(h().useLegacy){e(null);return}const{context:s}=h(),r=s.audioContext.createWaveShaper();e(r),this._distortion=r,this.amount=t}set amount(t){this._amount=t;const e=t*1e3,s=44100,r=new Float32Array(s),n=Math.PI/180;let o=0,a;for(;o<s;++o)a=o*2/s-1,r[o]=(3+e)*a*20*n/(Math.PI+e*Math.abs(a));this._distortion.curve=r,this._distortion.oversample="4x"}get amount(){return this._amount}destroy(){this._distortion=null,super.destroy()}},gt=class extends b{constructor(t=0){var e=(...a)=>{super(...a)};if(h().useLegacy){e(null);return}let s,r,n;const{audioContext:o}=h().context;o.createStereoPanner?(s=o.createStereoPanner(),n=s):(r=o.createPanner(),r.panningModel="equalpower",n=r),e(n),this._stereo=s,this._panner=r,this.pan=t}set pan(t){this._pan=t,this._stereo?f.setParamValue(this._stereo.pan,t):this._panner.setPosition(t,0,1-Math.abs(t))}get pan(){return this._pan}destroy(){super.destroy(),this._stereo=null,this._panner=null}},yt=class extends b{constructor(t=3,e=2,s=!1){var r=(...n)=>{super(...n)};if(h().useLegacy){r(null);return}r(null),this._seconds=this._clamp(t,1,50),this._decay=this._clamp(e,0,100),this._reverse=s,this._rebuild()}_clamp(t,e,s){return Math.min(s,Math.max(e,t))}get seconds(){return this._seconds}set seconds(t){this._seconds=this._clamp(t,1,50),this._rebuild()}get decay(){return this._decay}set decay(t){this._decay=this._clamp(t,0,100),this._rebuild()}get reverse(){return this._reverse}set reverse(t){this._reverse=t,this._rebuild()}_rebuild(){const t=h().context.audioContext,e=t.sampleRate,s=e*this._seconds,r=t.createBuffer(2,s,e),n=r.getChannelData(0),o=r.getChannelData(1);let a;for(let d=0;d<s;d++)a=this._reverse?s-d:d,n[d]=(Math.random()*2-1)*Math.pow(1-a/s,this._decay),o[d]=(Math.random()*2-1)*Math.pow(1-a/s,this._decay);const l=h().context.audioContext.createConvolver();l.buffer=r,this.init(l)}};class vt extends b{constructor(){var t=(...n)=>{super(...n)};if(h().useLegacy){t(null);return}const e=h().context.audioContext,s=e.createChannelSplitter(),r=e.createChannelMerger();r.connect(s),t(r,s),this._merger=r}destroy(){this._merger.disconnect(),this._merger=null,super.destroy()}}var bt=Object.freeze({__proto__:null,DistortionFilter:mt,EqualizerFilter:m,Filter:b,MonoFilter:vt,ReverbFilter:yt,StereoFilter:gt,StreamFilter:class extends b{constructor(){var t=(...n)=>{super(...n)};if(h().useLegacy){t(null);return}const e=h().context.audioContext,s=e.createMediaStreamDestination(),r=e.createMediaStreamSource(s.stream);t(s,r),this._stream=s.stream}get stream(){return this._stream}destroy(){this._stream=null,super.destroy()}},TelephoneFilter:class extends b{constructor(){if(h().useLegacy){super(null);return}const{audioContext:t}=h().context,e=t.createBiquadFilter(),s=t.createBiquadFilter(),r=t.createBiquadFilter(),n=t.createBiquadFilter();e.type="lowpass",f.setParamValue(e.frequency,2e3),s.type="lowpass",f.setParamValue(s.frequency,2e3),r.type="highpass",f.setParamValue(r.frequency,500),n.type="highpass",f.setParamValue(n.frequency,500),e.connect(s),s.connect(r),r.connect(n),super(e,n)}}}),xt=Object.freeze({__proto__:null,WebAudioContext:A,WebAudioInstance:B,WebAudioMedia:E,WebAudioNodes:L,WebAudioUtils:f});let Q=0;function Pt(i,t){const e=`alias${Q++}`;return h().add(e,{url:i,preload:!0,autoPlay:!0,loaded:s=>{s&&(console.error(s),h().remove(e),t&&t(s))},complete:()=>{h().remove(e),t&&t(null)}}),e}var wt=Object.defineProperty,W=Object.getOwnPropertySymbols,At=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable,X=(i,t,e)=>t in i?wt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Et=(i,t)=>{for(var e in t||(t={}))At.call(t,e)&&X(i,e,t[e]);if(W)for(var e of W(t))St.call(t,e)&&X(i,e,t[e]);return i};function Ft(i,t){const e=document.createElement("canvas");t=Et({width:512,height:128,fill:"black"},t||{}),e.width=t.width,e.height=t.height;const s=c.BaseTexture.from(e);if(!(i.media instanceof E))return s;const r=i.media;console.assert(!!r.buffer,"No buffer found, load first");const n=e.getContext("2d");n.fillStyle=t.fill;const o=r.buffer.getChannelData(0),a=Math.ceil(o.length/t.width),l=t.height/2;for(let d=0;d<t.width;d++){let _=1,g=-1;for(let y=0;y<a;y++){const p=o[d*a+y];p<_&&(_=p),p>g&&(g=p)}n.fillRect(d,(1+_)*l,1,Math.max(1,(g-_)*l))}return s}function $t(i=200,t=1){const e=P.from({singleInstance:!0});if(!(e.media instanceof E))return e;const s=e.media,r=e.context,n=1,o=48e3,a=2,l=r.audioContext.createBuffer(n,t*o,o),d=l.getChannelData(0);for(let _=0;_<d.length;_++){const g=_/l.sampleRate,y=i*g*Math.PI;d[_]=Math.sin(y)*a}return s.buffer=l,e.isLoaded=!0,e}var Ct=Object.freeze({__proto__:null,get PLAY_ID(){return Q},extensions:w,playOnce:Pt,render:Ft,sineTone:$t,supported:S,validateFormats:G}),Lt=Object.defineProperty,kt=Object.defineProperties,Ot=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,Mt=Object.prototype.hasOwnProperty,It=Object.prototype.propertyIsEnumerable,Y=(i,t,e)=>t in i?Lt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Tt=(i,t)=>{for(var e in t||(t={}))Mt.call(t,e)&&Y(i,e,t[e]);if(Z)for(var e of Z(t))It.call(t,e)&&Y(i,e,t[e]);return i},jt=(i,t)=>kt(i,Ot(t));const J=i=>{var t,e;const s=i.src;return(e=(t=i==null?void 0:i.alias)==null?void 0:t[0])!=null?e:c.utils.path.basename(s,c.utils.path.extname(s))},tt={extension:c.ExtensionType.Asset,detection:{test:async()=>!0,add:async i=>[...i,...w.filter(t=>S[t])],remove:async i=>i.filter(t=>i.includes(t))},loader:{extension:{type:[c.ExtensionType.LoadParser],priority:et.LoaderParserPriority.High},test(i){const t=c.utils.path.extname(i).slice(1);return!!S[t]},async load(i,t){const e=await new Promise((s,r)=>P.from(jt(Tt({},t.data),{url:i,preload:!0,loaded(n,o){var a,l;n?r(n):s(o),(l=(a=t.data)==null?void 0:a.loaded)==null||l.call(a,n,o)}})));return h().add(J(t),e),e},async unload(i,t){h().remove(J(t))}}};c.extensions.add(tt);const k=st(new z);return Object.defineProperties(k,{Filterable:{get(){return C}},filters:{get(){return bt}},htmlaudio:{get(){return ft}},Sound:{get(){return P}},SoundLibrary:{get(){return z}},SoundSprite:{get(){return I}},utils:{get(){return Ct}},webaudio:{get(){return xt}},sound:{get(){return k}},soundAsset:{get(){return tt}}}),k}(PIXI,PIXI); | ||
//# sourceMappingURL=pixi-sound.js.map |
{ | ||
"name": "@pixi/sound", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "WebAudio API playback library with filters", | ||
"main": "dist/pixi-sound.cjs.js", | ||
"module": "dist/pixi-sound.esm.mjs", | ||
"bundle": "dist/pixi-sound.js", | ||
"types": "dist/pixi-sound.d.ts", | ||
"namespace": "PIXI.sound", | ||
"main": "lib/index.js", | ||
"module": "lib/index.mjs", | ||
"types": "lib/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/pixi-sound.esm.mjs", | ||
"require": "./dist/pixi-sound.cjs.js", | ||
"types": "./dist/pixi-sound.d.ts" | ||
"import": "./lib/index.mjs", | ||
"require": "./lib/index.js", | ||
"types": "./lib/index.d.ts" | ||
} | ||
@@ -26,2 +24,3 @@ }, | ||
"dist/", | ||
"lib/", | ||
"global.d.ts" | ||
@@ -41,5 +40,5 @@ ], | ||
"peerDependencies": { | ||
"@pixi/assets": "^7.0.0-X", | ||
"@pixi/core": "^7.0.0-X" | ||
"@pixi/assets": "^7.0.0", | ||
"@pixi/core": "^7.0.0" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1017712
167
7766
0
1