supersonic-scsynth 0.43.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/osc_channel.js +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function d(e,t,s){return(s-1-e+t)%s}function N({uint8View:e,dataView:t,bufferStart:s,bufferSize:r,head:o,payload:n,sequence:_,messageMagic:c,headerSize:i,sourceId:S=0,headerScratch:p=null,headerScratchView:T=null}){let A=n.length,a=i+A+3&-4,u=r-o;if(a>u){let E=p||new Uint8Array(i),l=T||new DataView(E.buffer);l.setUint32(0,c,!0),l.setUint32(4,a,!0),l.setUint32(8,_,!0),l.setUint32(12,S,!0);let h=s+o,I=s;if(u>=i){e.set(E,h);let f=u-i;f>0&&e.set(n.subarray(0,f),h+i),e.set(n.subarray(f),I)}else{e.set(E.subarray(0,u),h),e.set(E.subarray(u),I);let f=i-u;e.set(n,I+f)}}else{let E=s+o;t.setUint32(E,c,!0),t.setUint32(E+4,a,!0),t.setUint32(E+8,_,!0),t.setUint32(E+12,S,!0),e.set(n,E+i)}return(o+a)%r}function b(e,t,s=0,r=!1){for(let o=0;o<=s;o++)if(Atomics.compareExchange(e,t,0,1)===0)return!0;if(r){for(let n=0;n<100;n++)if(Atomics.wait(e,t,1,100),Atomics.compareExchange(e,t,0,1)===0)return!0;return console.error("[RingBuffer] Lock acquisition timeout after 10s - possible deadlock"),!1}return!1}function y(e,t){Atomics.store(e,t,0),Atomics.notify(e,t,1)}function C({atomicView:e,dataView:t,uint8View:s,bufferConstants:r,ringBufferBase:o,controlIndices:n,oscMessage:_,sourceId:c=0,maxSpins:i=0,useWait:S=!1}){let p=_.length,T=r.MESSAGE_HEADER_SIZE+p;if(T>r.IN_BUFFER_SIZE-r.MESSAGE_HEADER_SIZE||!b(e,n.IN_WRITE_LOCK,i,S))return!1;try{let A=Atomics.load(e,n.IN_HEAD),R=Atomics.load(e,n.IN_TAIL),a=T+3&-4;if(d(A,R,r.IN_BUFFER_SIZE)<a)return!1;let E=Atomics.add(e,n.IN_SEQUENCE,1),l=N({uint8View:s,dataView:t,bufferStart:o+r.IN_BUFFER_START,bufferSize:r.IN_BUFFER_SIZE,head:A,payload:_,sequence:E,messageMagic:r.MESSAGE_MAGIC,headerSize:r.MESSAGE_HEADER_SIZE,sourceId:c});return Atomics.load(e,n.IN_HEAD),Atomics.store(e,n.IN_HEAD,l),Atomics.notify(e,n.IN_HEAD,1),!0}finally{y(e,n.IN_WRITE_LOCK)}}function L(e,t){let s=e+t;return{IN_HEAD:(s+0)/4,IN_TAIL:(s+4)/4,IN_SEQUENCE:(s+24)/4,IN_WRITE_LOCK:(s+40)/4,IN_LOG_TAIL:(s+44)/4}}function Y(e){return e.length>=8&&e[0]===35&&e[1]===98&&e[2]===117&&e[3]===110&&e[4]===100&&e[5]===108&&e[6]===101&&e[7]===0}function k(e){if(e.length<16)return null;let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{ntpSeconds:t.getUint32(8,!1),ntpFraction:t.getUint32(12,!1)}}function U(){return(performance.timeOrigin+performance.now())/1e3+2208988800}function D(e,t={}){let{getCurrentNTP:s=U,bypassLookaheadS:r=.5}=t;if(!Y(e))return"nonBundle";let o=k(e);if(!o)return"nonBundle";let{ntpSeconds:n,ntpFraction:_}=o;if(n===0&&_<=1)return"immediate";let c=s();if(c===null||c===0)return"immediate";let S=n+_/4294967296-c;return S<0?"late":S<r?"nearFuture":"farFuture"}function O(e){return e!=="farFuture"}var B=class e{#s;#r;#n;#i;#e;#t;#_;#E;#c;#S;#o={messagesSent:0,bytesSent:0,nonBundle:0,immediate:0,nearFuture:0,late:0,bypassed:0};constructor(t,s){if(this.#s=t,this.#e=s.preschedulerPort||null,this.#_=s.bypassLookaheadS??.5,this.#E=s.sourceId??0,this.#c=s.blocking??this.#E!==0,this.#S=s.getCurrentNTP??U,t==="postMessage")this.#r=s.port;else if(this.#n={sharedBuffer:s.sharedBuffer,ringBufferBase:s.ringBufferBase,bufferConstants:s.bufferConstants,controlIndices:s.controlIndices},this.#f(),s.sharedBuffer&&s.bufferConstants){let r=s.ringBufferBase+s.bufferConstants.METRICS_START;this.#t=new Int32Array(s.sharedBuffer,r,s.bufferConstants.METRICS_SIZE/4)}}#f(){let t=this.#n.sharedBuffer;this.#i={atomicView:new Int32Array(t),dataView:new DataView(t),uint8View:new Uint8Array(t)}}classify(t){return D(t,{getCurrentNTP:this.#S,bypassLookaheadS:this.#_})}#a(t,s=null){if(this.#s==="sab"&&this.#t){if(Atomics.add(this.#t,24,1),Atomics.add(this.#t,25,t),s){let o={nonBundle:38,immediate:39,nearFuture:40,late:41}[s];o!==void 0&&(Atomics.add(this.#t,o,1),Atomics.add(this.#t,22,1))}}else this.#o.messagesSent++,this.#o.bytesSent+=t,s&&s in this.#o&&(this.#o[s]++,this.#o.bypassed++)}getAndResetMetrics(){let t={...this.#o};return this.#o={messagesSent:0,bytesSent:0,nonBundle:0,immediate:0,nearFuture:0,late:0,bypassed:0},t}getMetrics(){return this.#s==="sab"&&this.#t?{messagesSent:Atomics.load(this.#t,24),bytesSent:Atomics.load(this.#t,25),nonBundle:Atomics.load(this.#t,38),immediate:Atomics.load(this.#t,39),nearFuture:Atomics.load(this.#t,40),late:Atomics.load(this.#t,41),bypassed:Atomics.load(this.#t,22)}:{...this.#o}}#u(t,s=null,r=!0){if(this.#s==="postMessage")return this.#r?(this.#r.postMessage({type:"osc",oscData:t,bypassCategory:s,sourceId:this.#E}),!0):!1;{let o=this.#c,n=C({atomicView:this.#i.atomicView,dataView:this.#i.dataView,uint8View:this.#i.uint8View,bufferConstants:this.#n.bufferConstants,ringBufferBase:this.#n.ringBufferBase,controlIndices:this.#n.controlIndices,oscMessage:t,sourceId:this.#E,maxSpins:o?10:0,useWait:o});return!n&&!o&&r&&this.#e?(this.#t&&Atomics.add(this.#t,45,1),this.#e.postMessage({type:"directDispatch",oscData:t,sourceId:this.#E}),!0):n}}#l(t){return this.#e?(this.#e.postMessage({type:"osc",oscData:t,sourceId:this.#E}),!0):(console.error("[OscChannel] No prescheduler port, sending direct"),this.#u(t))}send(t){let s=this.classify(t);if(O(s)){let r=this.#u(t,s);return r&&this.#a(t.length,s),r}else{let r=this.#l(t);return r&&this.#a(t.length,null),r}}sendDirect(t){return this.#u(t)}sendToPrescheduler(t){return this.#l(t)}set getCurrentNTP(t){this.#S=t}get mode(){return this.#s}get transferable(){let t={mode:this.#s,preschedulerPort:this.#e,bypassLookaheadS:this.#_,sourceId:this.#E,blocking:this.#c};return this.#s==="postMessage"?{...t,port:this.#r}:{...t,sharedBuffer:this.#n.sharedBuffer,ringBufferBase:this.#n.ringBufferBase,bufferConstants:this.#n.bufferConstants,controlIndices:this.#n.controlIndices}}get transferList(){let t=[];return this.#s==="postMessage"&&this.#r&&t.push(this.#r),this.#e&&t.push(this.#e),t}close(){this.#s==="postMessage"&&this.#r&&(this.#r.close(),this.#r=null),this.#e&&(this.#e.close(),this.#e=null)}static createPostMessage(t){return t instanceof MessagePort?new e("postMessage",{port:t}):new e("postMessage",t)}static createSAB(t){let s=t.controlIndices;return s||(s=L(t.ringBufferBase,t.bufferConstants.CONTROL_START)),new e("sab",{sharedBuffer:t.sharedBuffer,ringBufferBase:t.ringBufferBase,bufferConstants:t.bufferConstants,controlIndices:s,preschedulerPort:t.preschedulerPort,bypassLookaheadS:t.bypassLookaheadS,sourceId:t.sourceId,blocking:t.blocking})}static fromTransferable(t){return t.mode==="postMessage"?new e("postMessage",{port:t.port,preschedulerPort:t.preschedulerPort,bypassLookaheadS:t.bypassLookaheadS,sourceId:t.sourceId,blocking:t.blocking}):new e("sab",{sharedBuffer:t.sharedBuffer,ringBufferBase:t.ringBufferBase,bufferConstants:t.bufferConstants,controlIndices:t.controlIndices,preschedulerPort:t.preschedulerPort,bypassLookaheadS:t.bypassLookaheadS,sourceId:t.sourceId,blocking:t.blocking})}};export{B as OscChannel};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "supersonic-scsynth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "SuperCollider scsynth WebAssembly port for AudioWorklet - Run SuperCollider synthesis in the browser",
|
|
5
5
|
"main": "dist/supersonic.js",
|
|
6
6
|
"unpkg": "dist/supersonic.js",
|
|
@@ -36,8 +36,13 @@
|
|
|
36
36
|
"url": "https://github.com/samaaron/supersonic/issues"
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/samaaron/supersonic#readme",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": "./dist/supersonic.js",
|
|
41
|
+
"./osc-channel": "./dist/osc_channel.js"
|
|
42
|
+
},
|
|
39
43
|
"files": [
|
|
40
44
|
"dist/supersonic.js",
|
|
45
|
+
"dist/osc_channel.js",
|
|
41
46
|
"README.md",
|
|
42
47
|
"LICENSE"
|
|
43
48
|
],
|