@hussmartinez/audio-sdk 0.4.0 → 0.6.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.
@@ -0,0 +1,30 @@
1
+ // src/workers/audio.worker.ts?worker&inline
2
+ var jsContent = "var e=/* @__PURE__ */ Symbol.for(`@hussmartinez/sdk-core/SdkError`),t=class extends Error{name=`SdkError`;code;constructor(t,n,r={}){super(n,`cause`in r?{cause:r.cause}:void 0),this.code=t,Object.defineProperty(this,e,{value:!0}),r.details!==void 0&&(this.details=r.details)}};function n(n,r){if(typeof n!=`object`||!n)return!1;let i=n;return(n instanceof t||i[e]===!0)&&typeof i.code==`string`&&typeof i.message==`string`&&(r===void 0||i.code===r)}var r=1<<20;function i(e,t,n){if(!Number.isSafeInteger(t)||t<n)throw RangeError(`The ${e} must be an integer of at least ${n}, not ${String(t)}.`)}function a(e,t={}){let n=t.windowSize??r;i(`window size`,n,1);let a=e.size,o=0,s=/* @__PURE__ */ new Uint8Array;return{size:a,async bytes(t,r){i(`offset`,t,0),i(`length`,r,0);let c=Math.min(t,a),l=Math.min(a,c+r);if(c<o||l>o+s.length){let t=Math.min(a,c+Math.max(r,n));s=new Uint8Array(await e.slice(c,t).arrayBuffer()),o=c}return s.subarray(c-o,l-o)}}}var o=8,s=16,c=`UNKNOWN`;function l(e,t={}){let n=t.includeStack??!1,r=h(t.maxDepth),i=/* @__PURE__ */ new Set,a=(e,t)=>{i.add(e);let o=u(e),s=n&&p(e)?e.stack:void 0;return typeof s==`string`&&(o.stack=s),p(e)&&`cause`in e&&t<r&&!i.has(e.cause)&&(o.cause=a(e.cause,t+1)),o};return a(e,0)}function u(e){if(n(e)){let t={name:e.name,code:e.code,message:e.message},n=d(e.details);return n!==void 0&&(t.details=n),t}if(p(e)&&typeof e.message==`string`){let t=typeof e.name==`string`?e.name:`Error`;return{name:`SdkError`,code:c,message:e.message,details:{originalName:t}}}return typeof e==`string`?{name:`SdkError`,code:c,message:e,details:{thrownType:`string`}}:{name:`SdkError`,code:c,message:`A value that isn't an Error was thrown.`,details:{thrownType:e===null?`null`:typeof e}}}function d(e){if(!m(e))return;let t=f(e,0);return m(t)?t:void 0}function f(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(!(t>=s)){if(Array.isArray(e))return e.flatMap(e=>{let n=f(e,t+1);return n===void 0?[]:[n]});if(m(e)){let n={};for(let[r,i]of Object.entries(e)){let e=f(i,t+1);e!==void 0&&(n[r]=e)}return n}}}function p(e){return typeof e==`object`&&!!e}function m(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function h(e){if(e===void 0)return o;if(!Number.isInteger(e)||e<0)throw RangeError(`maxDepth must be a non-negative integer, received ${e}.`);return e}[...Array.from({length:12},(e,t)=>`F${t+1}`)];var g=`hm-rpc`;function _(e){return{protocol:g,version:1,...e}}function v(e){if(typeof e!=`object`||!e)return;let t=e;if(t.protocol!==`hm-rpc`||typeof t.version!=`number`)return;let n=Number.isSafeInteger(t.id);switch(t.type){case`ready`:return t;case`call`:return n&&typeof t.method==`string`?t:void 0;case`cancel`:case`progress`:case`result`:return n?t:void 0;case`error`:return n?t:void 0;case`crash`:return t;default:return}}function y(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e=>{if(typeof e!=`object`||!e)return e;if(r.has(e))return r.get(e);if(ArrayBuffer.isView(e)){let i=x(e)?e:S(e);return t&&i===e&&n.add(e.buffer),r.set(e,i),i}return w(e)?(t&&n.add(e),r.set(e,e),e):Array.isArray(e)?a(e,()=>[],(e,t)=>{t.forEach((t,n)=>{e[n]=i(t)})}):e instanceof Map?a(e,()=>/* @__PURE__ */ new Map,(e,t)=>{for(let[n,r]of t)e.set(i(n),i(r))}):e instanceof Set?a(e,()=>/* @__PURE__ */ new Set,(e,t)=>{for(let n of t)e.add(i(n))}):T(e)?a(e,()=>({}),(e,t)=>{for(let[n,r]of Object.entries(t))e[n]=i(r)}):(r.set(e,e),e)},a=(e,t,n)=>{let i=t();return r.set(e,i),n(i,e),E(e,i)?(r.set(e,e),e):i};return{value:i(e),transferables:[...n]}}function b(e,t,n){if(n.length===0)e(t,[]);else try{e(t,n)}catch{e(t,[])}}function x(e){return e.buffer instanceof ArrayBuffer&&e.byteOffset===0&&e.byteLength===e.buffer.byteLength}function S(e){let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();if(e instanceof DataView)return new DataView(t.buffer);let n=e.constructor;return new n(t.buffer)}var C=[`ArrayBuffer`,`MessagePort`,`ImageBitmap`,`OffscreenCanvas`,`ReadableStream`,`WritableStream`,`TransformStream`,`VideoFrame`,`AudioData`];function w(e){let t=globalThis;return C.some(n=>{let r=t[n];return typeof r==`function`&&e instanceof r})}function T(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function E(e,t){if(Array.isArray(e)){let n=t;return e.length===n.length&&e.every((e,t)=>e===n[t])}if(e instanceof Map){let n=[...t];return[...e].every(([e,t],r)=>n[r]?.[0]===e&&n[r]?.[1]===t)}if(e instanceof Set){let n=[...t];return[...e].every((e,t)=>n[t]===e)}let n=t;return Object.entries(e).every(([e,t])=>n[e]===t)}function D(e,n={}){let r=n.scope??globalThis,i=n.includeStack??!1,a=/* @__PURE__ */ new Map,o=(e,t=[])=>{r.postMessage(e,t)},s=(e,t)=>{o(_({type:`error`,id:e,error:l(t,{includeStack:i})}))},c=(e,n,i)=>{let a=y(i,!0);try{b((e,t)=>r.postMessage(e,t),_({type:`result`,id:e,output:a.value}),a.transferables)}catch(r){s(e,new t(`WORKER_DATA_NOT_CLONEABLE`,`The result of \"${n}\" can't be sent to the page.`,{cause:r,details:{method:n}}))}},u=n=>{let{id:r,method:i}=n,l=Object.hasOwn(e,i)?e[i]:void 0;if(typeof l!=`function`){s(r,new t(`WORKER_METHOD_NOT_FOUND`,`The worker has no method \"${i}\".`,{details:{method:i}}));return}let u=new AbortController;a.set(r,u);let d={signal:u.signal,progress:e=>{a.get(r)===u&&o(_({type:`progress`,id:r,value:e}))}};Promise.resolve().then(()=>l.call(e,n.input,d)).then(e=>{a.delete(r),c(r,i,e)},e=>{a.delete(r),s(r,e)})},d=e=>{o(_({type:`crash`,error:l(e,{includeStack:i})}))};r.addEventListener(`message`,e=>{let t=v(e.data);t!==void 0&&t.version===1&&(t.type===`call`?u(t):t.type===`cancel`&&a.get(t.id)?.abort())}),r.addEventListener(`error`,e=>{let t=e;d(t.error??Error(t.message))}),r.addEventListener(`unhandledrejection`,e=>{d(e.reason)}),o(_({type:`ready`,...n.packageVersion===void 0?{}:{packageVersion:n.packageVersion}}))}var O=class extends t{name=`AudioError`};function k(e,t){return new O(`INVALID_AUDIO`,`Invalid ${e} file: ${t}.`,{details:{container:e,reason:t}})}function A(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported sample format in ${e}: ${t}.`,{details:{container:e,codec:t}})}async function j(e,t,n){let r=await e.slice(t,t+n).arrayBuffer();return new DataView(r)}function M(e,t=0){return e.byteLength<t+4?``:String.fromCharCode(e.getUint8(t),e.getUint8(t+1),e.getUint8(t+2),e.getUint8(t+3))}function ee(e){let{container:t,channels:n,sampleRate:r,bytesPerSample:i,blockAlign:a,frames:o,dataOffset:s}=e;if(!Number.isInteger(n)||n<1||n>1024)throw k(t,`channel count out of range`);if(!Number.isInteger(r)||r<1)throw k(t,`sample rate out of range`);if(![1,2,3,4,8].includes(i))throw k(t,`sample size out of range`);if(a!==n*i)throw k(t,`frame size doesn't match the channels and sample size`);if(!Number.isSafeInteger(o)||o<0||!Number.isSafeInteger(s))throw k(t,`length out of range`);return e}const te={NONE:{encoding:`int`,littleEndian:!1},twos:{encoding:`int`,littleEndian:!1},sowt:{encoding:`int`,littleEndian:!0},in24:{encoding:`int`,littleEndian:!1,bits:24},\"42ni\":{encoding:`int`,littleEndian:!0,bits:24},in32:{encoding:`int`,littleEndian:!1,bits:32},\"23ni\":{encoding:`int`,littleEndian:!0,bits:32},fl32:{encoding:`float`,littleEndian:!1,bits:32},FL32:{encoding:`float`,littleEndian:!1,bits:32},fl64:{encoding:`float`,littleEndian:!1,bits:64},FL64:{encoding:`float`,littleEndian:!1,bits:64}};function ne(e,t){let n=e.getUint16(t,!1),r=n&32767;return n&32768||r===0||r===32767?NaN:(e.getUint32(t+2,!1)*2**32+e.getUint32(t+6,!1))*2**(r-16383-63)}function re(e,t){if(e.byteLength<(t?22:18))throw k(`aiff`,`truncated COMM chunk`);let n=ne(e,8);if(!Number.isInteger(n)||n<1||n>2**31)throw k(`aiff`,`sample rate out of range`);return{channels:e.getInt16(0,!1),frames:e.getUint32(2,!1),bits:e.getInt16(6,!1),sampleRate:n,type:t?M(e,18):`NONE`}}async function ie(e){let t=await j(e,0,12),n=M(t,8);if(M(t)!==`FORM`||n!==`AIFF`&&n!==`AIFC`)throw k(`aiff`,`missing FORM header`);let r=n===`AIFC`,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw k(`aiff`,`too many chunks`);let n=await j(e,o,8),s=M(n),c=n.getUint32(4,!1),l=o+8,u=e.size-l;if(s===`COMM`){if(c>u)throw k(`aiff`,`truncated COMM chunk`);i=re(await j(e,l,Math.min(c,64)),r)}else if(s===`SSND`){let t=await j(e,l,8);if(c<8||t.byteLength<8)throw k(`aiff`,`truncated SSND chunk`);let n=l+8+t.getUint32(0,!1),r=Math.min(l+c,e.size);if(n>r)throw k(`aiff`,`sound data offset past the chunk`);a={offset:n,size:r-n}}if(i&&a)break;o=l+c+c%2}if(!i)throw k(`aiff`,`missing COMM chunk`);if(!a)throw k(`aiff`,`missing SSND chunk`);let s=te[i.type];if(!s)throw A(`aiff`,i.type||`unknown`);let c=s.bits??i.bits;if(c<1||c>64)throw k(`aiff`,`sample size out of range`);if(s.encoding===`float`&&c!==32&&c!==64)throw A(`aiff`,`${c}-bit float`);if(s.encoding===`int`&&c>32)throw A(`aiff`,`${c}-bit integer`);let l=Math.ceil(c/8),u=ee({container:`aiff`,sampleRate:i.sampleRate,channels:i.channels,encoding:s.encoding,bytesPerSample:l,littleEndian:s.littleEndian,dataOffset:a.offset,blockAlign:i.channels*l,frames:i.frames});return u.frames*u.blockAlign>a.size?{...u,frames:Math.floor(a.size/u.blockAlign),declaredFrames:u.frames}:u}function ae(e,t,n){let{channels:r,bytesPerSample:i,blockAlign:a,encoding:o,littleEndian:s}=t;if(e.byteLength<n*a)throw RangeError(`Expected ${n*a} bytes, got ${e.byteLength}.`);let c=Array.from({length:r},()=>new Float32Array(n)),l=oe(o,i,s);for(let t=0;t<r;t+=1){let r=c[t],o=t*i;for(let t=0;t<n;t+=1)r[t]=l(e,o),o+=a}return c}function oe(e,t,n){if(e===`float`)return t===8?(e,t)=>se(Math.fround(e.getFloat64(t,n))):(e,t)=>se(e.getFloat32(t,n));if(e===`uint`)return(e,t)=>(e.getUint8(t)-128)/128;switch(t){case 1:return(e,t)=>e.getInt8(t)/128;case 2:return(e,t)=>e.getInt16(t,n)/32768;case 3:return(e,t)=>{let r=e.getUint8(t),i=e.getUint8(t+1),a=e.getUint8(t+2);return((n?r|i<<8|a<<16:r<<16|i<<8|a)<<8>>8)/8388608};default:return(e,t)=>e.getInt32(t,n)/2147483648}}function se(e){return Number.isFinite(e)?e:0}const ce=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],le=4294967295;async function ue(e,t){let n=await j(e,t,8);if(n.byteLength<8)return!1;for(let e=0;e<4;e+=1){let t=n.getUint8(e);if(t<32||t>126)return!1}return n.getUint32(4,!0)<=e.size-t-8}function de(e){if(e.byteLength<16)throw k(`wav`,`truncated fmt chunk`);let t=e.getUint16(0,!0),n={channels:e.getUint16(2,!0),sampleRate:e.getUint32(4,!0),blockAlign:e.getUint16(12,!0),bitsPerSample:e.getUint16(14,!0)};if(t===65534){if(e.byteLength<40)throw k(`wav`,`truncated extensible fmt chunk`);t=e.getUint16(24,!0);for(let[t,n]of ce.entries())if(e.getUint8(26+t)!==n)throw A(`wav`,`extensible subformat`)}return{tag:t,...n}}function fe(e,t,n,r){let{tag:i,channels:a,sampleRate:o,blockAlign:s,bitsPerSample:c}=e;if(c%8!=0)throw k(`wav`,`sample size isn't whole bytes`);let l=c/8,u;if(i===1&&[1,2,3,4].includes(l))u=l===1?`uint`:`int`;else if(i===3&&[4,8].includes(l))u=`float`;else throw A(`wav`,`format ${i} at ${c} bits`);if(s<1)throw k(`wav`,`frame size is zero`);return ee({container:`wav`,sampleRate:o,channels:a,encoding:u,bytesPerSample:l,littleEndian:!0,dataOffset:t,blockAlign:s,frames:Math.floor(n/s),...r===void 0?{}:{declaredFrames:Math.floor(r/s)}})}async function pe(e){let t=await j(e,0,12),n=M(t);if(n!==`RIFF`&&n!==`RF64`||M(t,8)!==`WAVE`)throw k(`wav`,`missing RIFF header`);let r,i,a,o=12;for(let t=0;o+8<=e.size;t+=1){if(t>=1024)throw k(`wav`,`too many chunks`);let s=await j(e,o,8),c=M(s),l=s.getUint32(4,!0),u=o+8,d=e.size-u;if(c===`ds64`&&n===`RF64`){let t=await j(e,u,16);if(t.byteLength<16)throw k(`wav`,`truncated ds64 chunk`);let n=t.getUint32(12,!0);if(n>=2**21)throw k(`wav`,`data size out of range`);a=n*2**32+t.getUint32(8,!0)}else if(c===`fmt `){if(l>d)throw k(`wav`,`truncated fmt chunk`);r=de(await j(e,u,Math.min(l,64)))}else if(c===`data`){let t=l;if(n===`RF64`&&l===le){if(a===void 0)throw k(`wav`,`RF64 file without ds64 chunk`);t=a}else(l===le||l===0&&!await ue(e,u))&&(t=d);if(i={offset:u,size:Math.min(t,d),declared:t>d?t:void 0},r)break;o=u+t+t%2;continue}if(r&&i)break;o=u+l+l%2}if(!r)throw k(`wav`,`missing fmt chunk`);if(!i)throw k(`wav`,`missing data chunk`);return fe(r,i.offset,i.size,i.declared)}async function me(e){let t=await j(e,0,12),n=M(t),r=M(t,8),i;if((n===`RIFF`||n===`RF64`)&&r===`WAVE`)i=await pe(e);else if(n===`FORM`&&(r===`AIFF`||r===`AIFC`))i=await ie(e);else throw new O(`UNSUPPORTED_FORMAT`,`The file's container isn't recognised.`,{details:{container:`unknown`}});if(i.frames===0)throw k(i.container,`no audio frames`);return{layout:i,probe:{container:i.container,codec:`pcm`,sampleRate:i.sampleRate,channels:i.channels,frameBound:i.frames,expectedFrames:i.frames,...i.declaredFrames===void 0?{}:{declaredFrames:i.declaredFrames},frameTolerance:0}}}async function he(e,t,n,r){if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r)||n<0||r<0||n+r>t.frames)throw RangeError(`Frames ${n} to ${n+r} are outside the file.`);let i=r*t.blockAlign,a=await j(e,t.dataOffset+n*t.blockAlign,i);if(a.byteLength<i)throw k(t.container,`file shorter than probed`);return ae(a,t,r)}function ge(e,t){let n=[],r=[];for(let i of e){let e=Math.ceil(i.length/t),a=new Float32Array(e),o=new Float32Array(e);for(let n=0;n<e;n+=1){let e=Math.min(i.length,(n+1)*t),r=1/0,s=-1/0;for(let a=n*t;a<e;a+=1){let e=i[a];e<r&&(r=e),e>s&&(s=e)}a[n]=r,o[n]=s}n.push(a),r.push(o)}return{min:n,max:r}}const N=1<<20;async function _e(e,t,n,r,i,a){let o=t;for(let s=t;s<e.size;s+=N){let t=await e.bytes(s,N+n),c=Math.min(N,e.size-s);for(let e=0;e<c;e+=1){if(t[e]!==255)continue;let n=r(t,e);if(n===void 0)continue;let c=s+e,l=c>=o;l&&(o=c+Math.max(1,i(n))),a(n,l)}}}async function P(e,t,n,r,i,a,o=3){let s=await e.bytes(t,n+65536);for(let c=0;c<Math.min(n,s.length);c+=1){if(s[c]!==255)continue;let n=r(s,c);if(n===void 0)continue;let l=c,u=n;for(let d=1;;d+=1){if(d===o)return{offset:t+c,first:n};let f=l+i(u);if(f===s.length&&t+s.length===e.size)return{offset:t+c,first:n};let p=r(s,f);if(p===void 0||!a(n,p))break;l=f,u=p}}}const ve=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];function ye(e,t){let n=0,r=0,i=0,a=a=>{let o=0;for(let s=0;s<a;s+=1){if(n===0){if(i>=e.length)throw k(t,`truncated AudioSpecificConfig`);r=e[i],i+=1,n=8}--n,o=o*2+(r>>n&1)}return o};a(5)===31&&a(6);let o=a(4),s=o===15?a(24):ve[o];if(s===void 0||s===0)throw k(t,`AAC sample rate out of range`);return{coreRate:s,channelConfiguration:a(4)}}function F(e){return e===0||e===7?8:Math.max(2,e)}function I(e){return e<=24e3?e*2:e}function L(e,t){let n=n=>e[t+n],r=n(1),i=n(2),a=n(3),o=n(4),s=n(5),c=n(6);if(n(0)!==255||r===void 0||i===void 0||a===void 0||o===void 0||s===void 0||c===void 0||(r&246)!=240)return;let l=i>>2&15,u=ve[l];if(u===void 0)return;let d=(i&1)<<2|a>>6,f=(a&3)<<11|o<<3|s>>5;if(!(f<(r&1?7:9)))return{sampleRate:u,channelConfiguration:d,blocks:(c&3)+1,frameLength:f}}const be=(e,t)=>e.sampleRate===t.sampleRate&&e.channelConfiguration===t.channelConfiguration;async function xe(e,t){return P(a(e),t,65536,L,e=>e.frameLength,be)}async function Se(e,t){let n=a(e),r=await P(n,t,65536,L,e=>e.frameLength,be);if(!r)throw k(`adts`,`no frames`);let i=r.first.sampleRate,o=I(i),s=F(r.first.channelConfiguration),c=1024*Math.ceil(o/i),l=0,u=0;if(await _e(n,r.offset,7,L,e=>e.frameLength,(e,t)=>{let n=Math.max(1,Math.ceil(o/e.sampleRate)),r=Math.ceil(F(e.channelConfiguration)/s);l+=e.blocks*1024*n*r,t&&(u+=e.blocks)}),l===0)throw k(`adts`,`no frames`);return{container:`adts`,codec:`aac`,sampleRate:o,channels:s,frameBound:l,expectedFrames:Math.min(u*c,l),frameTolerance:2*c}}function R(e,t){let n=2**(e-1),r=2**e-1,i=/* @__PURE__ */ new Uint32Array(256);for(let a=0;a<256;a+=1){let o=a*2**(e-8);for(let e=0;e<8;e+=1)o=o>=n?(o*2^t)&r:o*2&r,o>>>=0;i[a]=o>>>0}return i}const Ce=R(8,7);R(16,32773),R(32,79764919);function we(e,t=0,n=e.length){let r=0;for(let i=t;i<n;i+=1)r=Ce[r^e[i]];return r}function z(e,t){if(e.length<34)throw k(t,`truncated STREAMINFO`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint16(0),i=n.getUint16(2),a=n.getUint32(10),o=a>>>12,s=(a>>>9&7)+1,c=(a>>>4&31)+1,l=(a&15)*2**32+n.getUint32(14);if(r<16||i<r)throw k(t,`block sizes out of range`);if(o===0)throw k(t,`sample rate is zero`);if(c<4)throw k(t,`sample size out of range`);return{minBlockSize:r,maxBlockSize:i,sampleRate:o,channels:s,bitsPerSample:c,totalFrames:l}}const Te=[void 0,88200,176400,192e3,8e3,16e3,22050,24e3,32e3,44100,48e3,96e3];function B(e,t){let n=n=>e[t+n];if(n(0)!==255||((n(1)??0)&254)!=248)return;let r=n(2),i=n(3);if(r===void 0||i===void 0)return;let a=r>>4,o=r&15,s=i>>4,c=i>>1&7;if(a===0||o===15||s>10||c===3||i&1)return;let l=4,u=n(l);if(u===void 0)return;let d;if(u<128)d=0;else if(u>=192&&u<224)d=1;else if(u>=224&&u<240)d=2;else if(u>=240&&u<248)d=3;else if(u>=248&&u<252)d=4;else if(u>=252&&u<254)d=5;else if(u===254)d=6;else return;l+=1;for(let e=0;e<d;e+=1,l+=1){let e=n(l);if(e===void 0||(e&192)!=128)return}let f;if(a===1)f=192;else if(a<=5)f=576*2**(a-2);else if(a===6||a===7){let e=n(l);if(e===void 0)return;if(a===6)f=e+1,l+=1;else{let t=n(l+1);if(t===void 0)return;f=e*256+t+1,l+=2}}else f=256*2**(a-8);let p=Te[o];if(o>=12){let e=n(l);if(e===void 0)return;if(o===12)p=e*1e3,l+=1;else{let t=n(l+1);if(t===void 0)return;p=o===13?e*256+t:(e*256+t)*10,l+=2}if(p===0)return}let m=n(l);if(m!==void 0&&we(e,t,t+l)===m)return{blockSize:f,sampleRate:p,channels:s<8?s+1:2,length:l+1}}function Ee(e){if(e.length<10||e[0]!==73||e[1]!==68||e[2]!==51)return 0;let t=0;for(let n=6;n<10;n+=1){let r=e[n];if(r&128)return 0;t=t*128+r}let n=e[5]&16?10:0;return 10+t+n}const De=1<<20;function Oe(e,t){let n=e.sampleRate!==void 0&&e.sampleRate<t.sampleRate?Math.ceil(t.sampleRate/e.sampleRate):1,r=Math.ceil(e.channels/t.channels);return e.blockSize*n*r}async function ke(e){let t=a(e),n=Ee(await t.bytes(0,10)),r=await t.bytes(n,4);if(String.fromCharCode(...r)!==`fLaC`)throw k(`flac`,`missing fLaC marker`);n+=4;let i;for(let e=0;;e+=1){if(e>=1024)throw k(`flac`,`too many metadata blocks`);let r=await t.bytes(n,4);if(r.length<4)throw k(`flac`,`truncated metadata`);let a=!!(r[0]&128),o=r[0]&127,s=r[1]<<16|r[2]<<8|r[3];if(o===127)throw k(`flac`,`invalid metadata block type`);if(e===0){if(o!==0||s!==34)throw k(`flac`,`STREAMINFO isn't first`);i=z(await t.bytes(n+4,34),`flac`)}if(n+=4+s,n>t.size)throw k(`flac`,`metadata exceeds the file`);if(a)break}if(!i)throw k(`flac`,`missing STREAMINFO`);let o=0,s=0;for(let e=n;e<t.size;e+=De){let n=await t.bytes(e,1048592),r=Math.min(De,t.size-e);for(let e=0;e<r;e+=1){if(n[e]!==255)continue;let t=B(n,e);t&&(o+=Oe(t,i),s+=1)}}if(s===0)throw k(`flac`,`no audio frames`);if(i.totalFrames>o)throw k(`flac`,`STREAMINFO claims more than the frames carry`);return{container:`flac`,codec:`flac`,sampleRate:i.sampleRate,channels:i.channels,frameBound:o,expectedFrames:i.totalFrames>0?i.totalFrames:o,frameTolerance:i.maxBlockSize}}async function V(e,t){let n=a(e),r,i=-1,o=[],s=0,c=0,l=0;for(;c+27<=n.size;){let e=await n.bytes(c,65307);if(e[0]!==79||e[1]!==103||e[2]!==103||e[3]!==83){if(l===0)throw k(`ogg`,`missing first page`);c+=1;continue}let a=new DataView(e.buffer,e.byteOffset,e.byteLength),u=a.getUint8(4),d=a.getUint8(5),f=a.getUint8(26);if(u!==0||e.length<27+f){if(l===0)throw k(`ogg`,`malformed first page`);c+=1;continue}let p=0;for(let t=0;t<f;t+=1)p+=e[27+t];let m=27+f+p;if(m>e.length)break;let h=a.getUint32(14,!0),g=!!(d&2);if(r===void 0){if(!g)throw k(`ogg`,`first page doesn't begin a stream`);r=h}else if(h!==r){if(g)throw new O(`UNSUPPORTED_FORMAT`,`Ogg files with several streams aren't supported.`,{details:{container:`ogg`,reason:`multiplexed streams`}});c+=m,l+=1;continue}d&1||(o=[],s=0);let _=27+f;for(let n=0;n<f;n+=1){let r=e[27+n];if(o.length<64){let t=Math.min(r,64-o.length);for(let n=0;n<t;n+=1)o.push(e[_+n])}s+=r,_+=r,r<255&&(t({head:Uint8Array.from(o),length:s}),o=[],s=0)}let v=a.getInt32(10,!0),y=a.getUint32(6,!0);(v!==-1||y!==4294967295)&&(i=v*2**32+y),c+=m,l+=1}if(l===0)throw k(`ogg`,`missing first page`);return{lastGranule:i}}function Ae(e){return e[0]===127&&e[1]===70&&e[2]===76&&e[3]===65&&e[4]===67}async function je(e){let t,n=0,r=0,i=0,a=0,{lastGranule:o}=await V(e,({head:e})=>{if(n+=1,n===1){if(!Ae(e)||e[5]!==1)throw k(`ogg`,`not a FLAC mapping version 1`);let n=String.fromCharCode(...e.subarray(9,13)),i=(e[13]??127)&127;if(n!==`fLaC`||i!==0)throw k(`ogg`,`missing FLAC STREAMINFO`);t=z(e.subarray(17,51),`ogg`),r=(e[7]??0)<<8|(e[8]??0);return}if(!t)return;let o=e[0]===255&&((e[1]??0)&254)==248;if(n-1<=r||r===0&&!o&&a===0)return;a+=1;let s=B(e,0);if(!s)i+=t.maxBlockSize;else{if(s.channels!==t.channels)throw k(`ogg`,`a frame's channel count differs from STREAMINFO`);if(s.sampleRate!==void 0&&s.sampleRate!==t.sampleRate)throw k(`ogg`,`a frame's sample rate differs from STREAMINFO`);i+=s.blockSize}});if(!t)throw k(`ogg`,`missing FLAC header`);if(a===0)throw k(`ogg`,`no audio frames`);if(t.totalFrames>i||o>i)throw k(`ogg`,`a declared length exceeds the frames`);let s=o>0?o:t.totalFrames;return{container:`ogg`,codec:`flac`,sampleRate:t.sampleRate,channels:t.channels,frameBound:i,expectedFrames:s>0?s:i,frameTolerance:t.maxBlockSize}}const Me=48e3,H=5760;function Ne(e){return String.fromCharCode(...e.subarray(0,8))===`OpusHead`}function Pe(e){return e<12?[480,960,1920,2880][e%4]:e<16?[480,960][e%2]:[120,240,480,960][e%4]}function Fe(e,t){let n=e[0];if(t===0||n===void 0)return H;let r=Pe(n>>3),i=n&3,a;if(i===0)a=1;else if(i===1||i===2)a=2;else{let t=e[1];if(t===void 0)return H;a=t&63}let o=a*r;return o===0||o>5760?H:o}function Ie(e,t){if(!Ne(e)||e.length<19)throw k(t,`malformed OpusHead`);if(e[8]&240)throw k(t,`unsupported OpusHead version`);let n=e[9],r=e[10]|e[11]<<8,i=e[18];if(n===0)throw k(t,`no channels`);if(i===0?n>2:i!==1||n>8)throw new O(`UNSUPPORTED_FORMAT`,`Unsupported Opus channel mapping.`,{details:{container:t,codec:`opus`,reason:`channel mapping family ${i}`}});return{channels:n,preSkip:r}}async function Le(e){let t=0,n=0,r=0,i=0,{lastGranule:a}=await V(e,({head:e,length:a})=>{if(r+=1,r===1)({channels:t,preSkip:n}=Ie(e,`ogg`));else if(r===2){if(String.fromCharCode(...e.subarray(0,8))!==`OpusTags`)throw k(`ogg`,`missing OpusTags`)}else i+=Fe(e,a)});if(r<2)throw k(`ogg`,`missing Opus headers`);if(i===0)throw k(`ogg`,`no audio packets`);if(a>i)throw k(`ogg`,`a declared length exceeds the packets`);let o=a>0?Math.max(0,a-n):i;return{container:`ogg`,codec:`opus`,sampleRate:Me,channels:t,frameBound:i,expectedFrames:o,frameTolerance:Math.max(H,n)}}const Re=`vorbis`;function ze(e){return e[0]===1&&String.fromCharCode(...e.subarray(1,7))===Re}function Be(e,t){if(!ze(e)||e.length<30)throw k(t,`malformed Vorbis header`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(n.getUint32(7,!0)!==0)throw k(t,`unsupported Vorbis version`);let r=n.getUint8(11),i=n.getUint32(12,!0),a=n.getUint8(28),o=a&15,s=a>>4;if(o<6||s>13||o>s||(n.getUint8(29)&1)!=1)throw k(t,`Vorbis block sizes out of range`);if(r===0||i===0)throw k(t,`Vorbis format out of range`);return{channels:r,sampleRate:i,largeBlock:2**s}}async function Ve(e){let t=0,n=0,r=0,i=0,a=0,{lastGranule:o}=await V(e,({head:e})=>{if(i+=1,i===1)({channels:t,sampleRate:n,largeBlock:r}=Be(e,`ogg`));else if(i===2||i===3){let t=i===2?3:5;if(e[0]!==t||String.fromCharCode(...e.subarray(1,7))!==Re)throw k(`ogg`,`missing Vorbis comment or setup header`)}else a+=1});if(i<3)throw k(`ogg`,`missing Vorbis headers`);if(a===0)throw k(`ogg`,`no audio packets`);let s=r/2*a;if(o>s)throw k(`ogg`,`a declared length exceeds the packets`);return{container:`ogg`,codec:`vorbis`,sampleRate:n,channels:t,frameBound:s,expectedFrames:o>0?o:s,frameTolerance:r}}const U=440786851,He=357149030,Ue=374648427,We=524531317,Ge=/* @__PURE__ */ new Set([We,475249515,307544935,272869232,423732329,290298740,He,Ue,U]);function W(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported Matroska: ${e}.`,{details:t===void 0?{container:`webm`,reason:e}:{container:`webm`,codec:t,reason:e}})}function Ke(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(r>4||t+r>e.length)return;let i=0;for(let n=0;n<r;n+=1)i=i*256+e[t+n];return{id:i,length:r}}function G(e,t){let n=e[t];if(n===void 0||n===0)return;let r=Math.clz32(n)-23;if(t+r>e.length)return;let i=n&255>>r,a=i===255>>r;for(let n=1;n<r;n+=1){let r=e[t+n];i=i*256+r,r!==255&&(a=!1)}return{value:i,length:r,unknown:a}}async function K(e,t){let n=await e.bytes(t,12),r=Ke(n,0);if(!r)return;let i=G(n,r.length);if(i){if(!i.unknown&&!Number.isSafeInteger(i.value))throw k(`webm`,`element size out of range`);return{id:r.id,body:t+r.length+i.length,size:i.unknown?void 0:i.value}}}function q(e){let t=[],n=0;for(;n<e.length;){let r=Ke(e,n),i=r&&G(e,n+r.length);if(!r||!i||i.unknown)throw k(`webm`,`malformed element`);let a=n+r.length+i.length;if(a+i.value>e.length)throw k(`webm`,`element exceeds its parent`);t.push({id:r.id,data:e.subarray(a,a+i.value)}),n=a+i.value}return t}const J=e=>e.reduce((e,t)=>e*256+t,0);function qe(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return e.length===4?t.getFloat32(0):e.length===8?t.getFloat64(0):NaN}function Je(e,t){if(e===`A_OPUS`){if(!t)throw k(`webm`,`missing OpusHead`);let e=Ie(t,`webm`);return{codec:`opus`,sampleRate:Me,channels:e.channels,tolerance:Math.max(H,e.preSkip),frameSamples:Fe}}if(e===`A_VORBIS`){if(t?.[0]!==2)throw k(`webm`,`malformed Vorbis headers`);let e=1;for(let n=0;n<2;n+=1){for(;t[e]===255;)e+=1;if(t[e]===void 0)throw k(`webm`,`malformed Vorbis headers`);e+=1}let n=Be(t.subarray(e),`webm`),r=n.largeBlock/2;return{codec:`vorbis`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.largeBlock,frameSamples:()=>r}}if(e===`A_FLAC`){let e=t&&String.fromCharCode(...t.subarray(0,4));if(!t||e!==`fLaC`||(t[4]??127)&127)throw k(`webm`,`missing FLAC STREAMINFO`);let n=z(t.subarray(8,42),`webm`);return{codec:`flac`,sampleRate:n.sampleRate,channels:n.channels,tolerance:n.maxBlockSize,frameSamples(e){let t=B(e,0);if(!t)return n.maxBlockSize;if(t.channels!==n.channels)throw k(`webm`,`a frame's channel count differs from STREAMINFO`);if(t.sampleRate!==void 0&&t.sampleRate!==n.sampleRate)throw k(`webm`,`a frame's sample rate differs from STREAMINFO`);return t.blockSize}}}if(e.startsWith(`A_AAC`)){if(!t)throw W(`AAC without an AudioSpecificConfig`,`aac`);let e=ye(t,`webm`),n=I(e.coreRate),r=1024*Math.ceil(n/e.coreRate);return{codec:`aac`,sampleRate:n,channels:F(e.channelConfiguration),tolerance:2*r,frameSamples:()=>r}}throw W(`codec ${e}`,e)}function Ye(e){let t=[];for(let n of q(e)){if(n.id!==174)continue;let e=q(n.data),r=t=>e.find(e=>e.id===t)?.data,i=r(131);if(!i||J(i)!==2)continue;let a=r(215),o=r(134);if(!a||!o)throw k(`webm`,`incomplete audio track`);let s=String.fromCharCode(...o).replace(/\\0+$/,``);t.push({number:J(a),codec:Je(s,r(25506))})}if(t.length===0)throw k(`webm`,`no audio track`);if(t.length>1)throw W(`several audio tracks`);return t[0]}function Xe(e,t){let n=G(e,0);if(!n||n.unknown)throw k(`webm`,`malformed block`);if(n.value!==t.number)return 0;let r=n.length+2,i=e[r];if(i===void 0)throw k(`webm`,`truncated block`);r+=1;let a=i>>1&3,o=[];if(a===0)o.push(e.length-r);else{let t=e[r];if(t===void 0)throw k(`webm`,`truncated block`);let n=t+1;if(r+=1,a===1)for(let t=0;t<n-1;t+=1){let t=0;for(;;){let n=e[r];if(n===void 0)throw k(`webm`,`truncated lacing`);if(r+=1,t+=n,n<255)break}o.push(t)}else if(a===3){let t=G(e,r);if(!t||t.unknown)throw k(`webm`,`malformed lacing`);r+=t.length,o.push(t.value);for(let t=1;t<n-1;t+=1){let n=G(e,r);if(!n||n.unknown)throw k(`webm`,`malformed lacing`);r+=n.length;let i=2**(7*n.length-1)-1;o.push(o[t-1]+n.value-i)}}let i=e.length-r;if(a===2){if(i%n!==0)throw k(`webm`,`fixed lacing doesn't divide the block`);for(let e=0;e<n;e+=1)o.push(i/n)}else{let e=o.reduce((e,t)=>e+t,0);o.push(i-e)}}if(o.some(e=>e<0)||r+o.reduce((e,t)=>e+t,0)>e.length)throw k(`webm`,`lacing exceeds the block`);let s=0;for(let n of o)s+=t.codec.frameSamples(e.subarray(r,r+Math.min(n,16)),n),r+=n;return s}async function Ze(e){let t=a(e),n=await K(t,0);if(!n||n.id!==U||n.size===void 0)throw k(`webm`,`missing EBML header`);let r=q(await t.bytes(n.body,n.size)).find(e=>e.id===17026),i=r?String.fromCharCode(...r.data).replace(/\\0+$/,``):``;if(i!==`webm`&&i!==`matroska`)throw W(`document type ${i||`missing`}`);let o=await K(t,n.body+n.size);if(!o||o.id!==408125543)throw k(`webm`,`missing Segment`);let s=Math.min(t.size,o.body+(o.size??t.size)),c,l=1e6,u,d=0,f=0,p,m=o.body;for(;m<s;){let e=await K(t,m);if(!e)throw k(`webm`,`malformed element`);if(p!==void 0&&(m>=p||Ge.has(e.id))&&(p=void 0),p===void 0){if(e.id===U)throw W(`several segments`);if(e.id===We){if(!c)throw k(`webm`,`clusters before the tracks`);if(p=e.size===void 0?1/0:e.body+e.size,p!==1/0&&p>s)throw k(`webm`,`element exceeds its parent`);m=e.body;continue}if(e.size===void 0)throw k(`webm`,`unknown size outside a Segment or Cluster`);let n=e.body+e.size;if(n>s)throw k(`webm`,`element exceeds its parent`);if(e.id===He){let n=q(await t.bytes(e.body,e.size)),r=n.find(e=>e.id===2807729),i=n.find(e=>e.id===17545);r&&(l=J(r.data)),i&&(u=qe(i.data))}else if(e.id===Ue){if(c)throw W(`several Tracks elements`);c=Ye(await t.bytes(e.body,e.size))}m=n;continue}if(e.size===void 0)throw k(`webm`,`unknown size inside a Cluster`);let n=e.body+e.size;if(n>Math.min(p,s))throw k(`webm`,`element exceeds its parent`);let r=c;if(e.id===163)d+=Xe(await t.bytes(e.body,e.size),r),f+=1;else if(e.id===160)for(let n of q(await t.bytes(e.body,e.size)))n.id===161&&(d+=Xe(n.data,r),f+=1);m=n}if(!c)throw k(`webm`,`missing Tracks`);if(f===0||d===0)throw k(`webm`,`no audio blocks`);let{codec:h}=c,g=d;if(u!==void 0){if(!Number.isFinite(u)||u<0)throw k(`webm`,`Duration out of range`);if(g=Math.round(u*l/1e9*h.sampleRate),g>d)throw k(`webm`,`the Duration claims more than the blocks carry`)}return{container:`webm`,codec:h.codec,sampleRate:h.sampleRate,channels:h.channels,frameBound:d,expectedFrames:g,frameTolerance:h.tolerance}}function Y(e,t){return new O(`UNSUPPORTED_FORMAT`,`Unsupported MP4: ${e}.`,{details:t===void 0?{container:`mp4`,reason:e}:{container:`mp4`,codec:t,reason:e}})}var Qe=class{boxes=0;reader;constructor(e){this.reader=e}async u8(e){let t=await this.reader.bytes(e,1);if(t.length<1)throw k(`mp4`,`truncated box`);return t[0]}async view(e,t){let n=await this.reader.bytes(e,t);if(n.length<t)throw k(`mp4`,`truncated box`);return new DataView(n.buffer,n.byteOffset,n.byteLength)}async children(e,t,n=!1){let r=[],i=e;for(;i+8<=t;){if(this.boxes+=1,this.boxes>1e5)throw k(`mp4`,`too many boxes`);let e=await this.view(i,8),a=e.getUint32(0),o=String.fromCharCode(e.getUint8(4),e.getUint8(5),e.getUint8(6),e.getUint8(7)),s=8;if(a===1){let e=await this.view(i+8,8),t=e.getUint32(0);if(t>=2**21)throw k(`mp4`,`box size out of range`);a=t*2**32+e.getUint32(4),s=16}else if(a===0){if(!n)throw k(`mp4`,`open-ended box inside another`);a=t-i}if(a<s||i+a>t)throw k(`mp4`,`box exceeds its parent`);r.push({type:o,body:i+s,end:i+a}),i+=a}return r}async child(e,t){return(await this.children(e.body,e.end)).find(e=>e.type===t)}async need(e,t){let n=await this.child(e,t);if(!n)throw k(`mp4`,`missing ${t} box`);return n}};async function $e(e,t){let n=0;for(let r=0;r<4;r+=1){let i=await e.u8(t+r);if(n=n*128+(i&127),!(i&128))return[n,r+1]}throw k(`mp4`,`malformed descriptor length`)}async function et(e,t){let n=t.body+4,r=async r=>{if(await e.u8(n)!==r)throw Y(`unexpected ES descriptor`);let[i,a]=await $e(e,n+1);if(n+=1+a,n+i>t.end)throw k(`mp4`,`descriptor exceeds its box`)};await r(3);let i=await e.u8(n+2);n+=3,i&128&&(n+=2),i&64&&(n+=1+await e.u8(n)),i&32&&(n+=2),await r(4);let a=await e.u8(n);if(![64,102,103,104].includes(a))throw Y(`object type ${a}`,a===107||a===105?`mp3`:`unknown`);return n+=13,await r(5),ye(await e.reader.bytes(n,Math.min(5,t.end-n)),`mp4`)}async function tt(e){let t=a(e),n=new Qe(t),r=await n.children(0,t.size,!0);if(r.some(e=>e.type===`moof`))throw Y(`fragmented MP4`);let i=r.find(e=>e.type===`moov`);if(!i)throw k(`mp4`,`missing moov box`);let o=[];for(let e of(await n.children(i.body,i.end)).filter(e=>e.type===`trak`)){let t=await n.child(e,`mdia`),r=t&&await n.child(t,`hdlr`);t&&r&&(await n.view(r.body+8,4)).getUint32(0)===1936684398&&o.push({trak:e,mdia:t})}if(o.length===0)throw k(`mp4`,`no audio track`);if(o.length>1)throw Y(`several audio tracks`);let{trak:s,mdia:c}=o[0],l=await n.need(c,`mdhd`),u=await n.u8(l.body),d=await n.view(l.body+4,u===1?28:16),f=d.getUint32(u===1?16:8),p=u===1?d.getUint32(20)*2**32+d.getUint32(24):d.getUint32(12);if(f===0)throw k(`mp4`,`timescale is zero`);let m=await n.need(await n.need(c,`minf`),`stbl`),h=await n.need(m,`stsd`),[g]=await n.children(h.body+8,h.end);if(!g)throw k(`mp4`,`empty sample description`);let _=await n.view(g.body,28),v=_.getUint16(8);if(v>1)throw Y(`sound sample entry version 2`);let y=_.getUint16(16),b=_.getUint32(24)>>>16,x=g.body+28+(v===1?16:0),S,C,w,T;if(g.type===`mp4a`){let e=(await n.children(x,g.end)).find(e=>e.type===`esds`);if(!e)throw k(`mp4`,`missing esds box`);let{coreRate:t,channelConfiguration:r}=await et(n,e);S=`aac`,C=I(t),w=F(r||y),T=1024*Math.ceil(C/t)}else if(g.type===`alac`){let e=(await n.children(x,g.end)).find(e=>e.type===`alac`);if(!e)throw k(`mp4`,`missing ALAC configuration`);let t=await n.view(e.body+4,24);if(S=`alac`,T=t.getUint32(0),w=t.getUint8(9),C=t.getUint32(20)||b,T===0||T>1<<20)throw k(`mp4`,`ALAC frame length out of range`);if(w===0||C===0)throw k(`mp4`,`ALAC format out of range`)}else throw Y(`codec ${g.type}`,g.type);await nt(n,i,s,{timescale:f,duration:p,decodeRate:C,tolerance:2*T});let E=await rt(n,m,t.size);if(E===0)throw k(`mp4`,`no audio samples`);let D=E*T,O=p===0?D:Math.round(p*C/f);if(O>D)throw k(`mp4`,`the duration claims more than the samples carry`);return{container:`mp4`,codec:S,sampleRate:C,channels:w,frameBound:D,expectedFrames:O,frameTolerance:2*T}}async function nt(e,t,n,r){let i=(await e.children(n.body,n.end)).filter(e=>e.type===`edts`);if(i.length===0)return;if(i.length>1)throw Y(`several edit lists`);let a=(await e.children(i[0].body,i[0].end)).filter(e=>e.type===`elst`);if(a.length===0)return;if(a.length>1)throw Y(`several edit lists`);let o=a[0],s=await e.need(t,`mvhd`),c=await e.u8(s.body),l=(await e.view(s.body+(c===1?20:12),4)).getUint32(0);if(l===0)throw k(`mp4`,`movie timescale is zero`);let u=await e.u8(o.body),d=(await e.view(o.body+4,4)).getUint32(0),f=u===1?20:12;if(o.body+8+d*f>o.end)throw k(`mp4`,`edit list exceeds its box`);if(d>2)throw Y(`edit list with more than two edits`);let p=!1;for(let t=0;t<d;t+=1){let n=await e.view(o.body+8+t*f,f),i=u===1?n.getUint32(0)*2**32+n.getUint32(4):n.getUint32(0),a=u===1?n.getInt32(8)*2**32+n.getUint32(12):n.getInt32(4),s=n.getInt16(u===1?16:8),c=n.getUint16(u===1?18:10);if(a===-1){if(p||t>0)throw Y(`edit list with an empty edit after another edit`);if(i*r.decodeRate/l>r.tolerance)throw Y(`edit list with a long empty edit`)}else{if(p)throw Y(`edit list with several media edits`);if(p=!0,s!==1||c!==0)throw Y(`edit list with a media rate other than 1`);if(a<0||r.duration===0||a+Math.ceil(i*r.timescale/l)>r.duration)throw Y(`edit list beyond the media`)}}}async function rt(e,t,n){let r=await e.child(t,`stsz`);if(!r)throw await e.child(t,`stz2`)?Y(`compact sample sizes`):k(`mp4`,`missing stsz box`);let i=await e.view(r.body+4,8),a=i.getUint32(0),o=i.getUint32(4);if(a===0&&r.body+12+o*4>r.end)throw k(`mp4`,`stsz table exceeds its box`);let s=await e.need(t,`stsc`),c=(await e.view(s.body+4,4)).getUint32(0);if(s.body+8+c*12>s.end)throw k(`mp4`,`stsc table exceeds its box`);let l=await e.child(t,`stco`)??await e.child(t,`co64`);if(!l)throw k(`mp4`,`missing chunk offsets`);let u=l.type===`co64`,d=(await e.view(l.body+4,4)).getUint32(0);if(l.body+8+d*(u?8:4)>l.end)throw k(`mp4`,`chunk offsets exceed their box`);let f=0,p=0,m=0;for(let t=1;t<=d;t+=1){for(;p<c;){let n=await e.view(s.body+8+p*12,12);if(n.getUint32(0)>t)break;m=n.getUint32(4),p+=1}let i=await e.view(l.body+8+(t-1)*(u?8:4),u?8:4),d=u?i.getUint32(0)*2**32+i.getUint32(4):i.getUint32(0);for(let t=0;t<m;t+=1){if(f>=o)throw k(`mp4`,`the sample tables disagree`);let t=a===0?(await e.view(r.body+12+f*4,4)).getUint32(0):a;if(d+t>n)throw k(`mp4`,`a sample lies outside the file`);d+=t,f+=1}}if(f!==o)throw k(`mp4`,`the sample tables disagree`);return o}const it={1:[44100,48e3,32e3],2:[22050,24e3,16e3],2.5:[11025,12e3,8e3]},at={\"1-1\":[0,32,64,96,128,160,192,224,256,288,320,352,384,416,448],\"1-2\":[0,32,48,56,64,80,96,112,128,160,192,224,256,320,384],\"1-3\":[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320],\"2-1\":[0,32,48,56,64,80,96,112,128,144,160,176,192,224,256],\"2-2\":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160],\"2-3\":[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160]};function X(e,t){let n=e[t],r=e[t+1],i=e[t+2],a=e[t+3];if(n!==255||r===void 0||i===void 0||a===void 0||(r&224)!=224)return;let o=r>>3&3,s=r>>1&3,c=i>>4,l=i>>2&3;if(o===1||s===0||c===0||c===15||l===3||(a&3)==2)return;let u=o===3?1:o===2?2:2.5,d=4-s,f=it[u]?.[l],p=at[`${u===1?1:2}-${d}`]?.[c]*1e3,m=i>>1&1,h=a>>6==3?1:2,g,_;if(d===1?(g=384,_=(Math.floor(12*p/f)+m)*4):d===2||u===1?(g=1152,_=Math.floor(144*p/f)+m):(g=576,_=Math.floor(72*p/f)+m),!(_<4))return{version:u,layer:d,sampleRate:f,channels:h,samplesPerFrame:g,frameLength:_,protected:!(r&1)}}function ot(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=t=>t+4<=e.length?String.fromCharCode(...e.subarray(t,t+4)):``,i=t.version===1?t.channels===1?17:32:t.channels===1?9:17,a=4+(t.protected?2:0)+i,o=r(a);if(o===`Xing`||o===`Info`){if(a+8>e.length)return;let t=n.getUint32(a+4);a+=8;let i;if(t&1){if(a+4>e.length)return;i=n.getUint32(a),a+=4}if(t&2&&(a+=4),t&4&&(a+=100),t&8&&(a+=4),a+24<=e.length&&r(a)===`LAME`){let t=e[a+21]*65536+e[a+22]*256+e[a+23];return{...i===void 0?{}:{frames:i},delay:t>>12,padding:t&4095}}return i===void 0?{}:{frames:i}}if(r(36)===`VBRI`&&54<=e.length)return{delay:n.getUint16(42),frames:n.getUint32(50)}}const st=65536,ct=(e,t)=>e.version===t.version&&e.layer===t.layer&&e.sampleRate===t.sampleRate;async function lt(e,t){return P(a(e),t,st,X,e=>e.frameLength,ct)}function ut(e,t,n){let r=e.sampleRate<t?Math.ceil(t/e.sampleRate):1;return e.samplesPerFrame*r*Math.ceil(e.channels/n)}async function dt(e,t){let n=a(e),r=await P(n,t,st,X,e=>e.frameLength,ct);if(!r)throw k(`mp3`,`no frames`);let{sampleRate:i,channels:o,samplesPerFrame:s}=r.first,c=ot(await n.bytes(r.offset,r.first.frameLength),r.first),l=0,u=0;if(await _e(n,r.offset,4,X,e=>e.frameLength,(e,t)=>{l+=ut(e,i,o),t&&(u+=1)}),l===0)throw k(`mp3`,`no frames`);let d=c?.delay??0,f=c?.padding??0,p=u*s;if(c?.frames!==void 0){let e=c.frames*s;if(e>l)throw k(`mp3`,`the tag claims more than the frames carry`);p=Math.max(0,e-d-f)}return{container:`mp3`,codec:`mp3`,sampleRate:i,channels:o,frameBound:l,expectedFrames:Math.min(p,l),frameTolerance:2*s+d+f}}function ft(e,t){return new O(`UNSUPPORTED_FORMAT`,`This container or codec isn't supported.`,{details:t===void 0?{container:e}:{container:e,codec:t}})}async function pt(e){let t=a(e),n=await t.bytes(0,64),r=(e,t)=>String.fromCharCode(...n.subarray(e,t)),i=r(0,4),o=r(8,12);if((i===`RIFF`||i===`RF64`)&&o===`WAVE`||i===`FORM`&&(o===`AIFF`||o===`AIFC`))return me(e);if(i===`fLaC`)return{probe:await ke(e)};if(n[0]===26&&n[1]===69&&n[2]===223&&n[3]===163)return{probe:await Ze(e)};if([`ftyp`,`moov`,`mdat`,`free`,`skip`,`wide`].includes(r(4,8)))return{probe:await tt(e)};let s=Ee(n);if(s>0){let n=await t.bytes(s,4);if(String.fromCharCode(...n)===`fLaC`)return{probe:await ke(e)}}if(i===`OggS`){let r=n[26]??0,i=await t.bytes(27+r,8);if(Ae(i))return{probe:await je(e)};if(Ne(i))return{probe:await Le(e)};if(ze(i))return{probe:await Ve(e)};throw ft(`ogg`)}let[c,l]=await Promise.all([lt(e,s),xe(e,s)]);if(c&&(!l||c.offset<=l.offset))return{probe:await dt(e,s)};if(l)return{probe:await Se(e,s)};throw ft(`unknown`)}const mt=.945;function ht(e){let t=1,n=1,r=e*e/4;for(let e=1;n>t*1e-17;e+=1)n*=r/(e*e),t+=n;return t}let Z;function gt(){if(Z)return Z;let e=8192,t=/* @__PURE__ */ new Float64Array(8194),n=ht(9);for(let r=0;r<=e;r+=1){let e=r/512,i=r===0?1:Math.sin(Math.PI*e)/(Math.PI*e),a=e/16,o=ht(9*Math.sqrt(Math.max(0,1-a*a)))/n;t[r]=i*o}return t[e]=0,Z=t,t}const Q=(e,t)=>Number.isSafeInteger(e)&&e>=t;function _t(e,t){return Math.ceil(16/(Math.min(1,t/e)*mt))}function vt(e){let{input:t,inputStart:n,fromRate:r,toRate:i,start:a,frames:o}=e;if(!Q(r,1)||!Q(i,1)||!Q(a,0)||!Q(o,0)||!Q(n,0)||!Number.isSafeInteger((a+o)*r))throw RangeError(`Rates and positions must be whole numbers, and rates positive.`);let s=gt(),c=Math.min(1,i/r)*mt,l=_t(r,i),u=c*512,d=2*l,f=new Float32Array(o),p=t.length,m=i/yt(r,i),h=i/m,g=[],_=e=>{let t=new Float64Array(d),n=e/m,r=0;for(let e=0;e<d;e+=1){let i=Math.abs(n-(e-l+1))*u,a=Math.floor(i);if(a>=s.length-1)continue;let o=s[a],c=o+(s[a+1]-o)*(i-a);t[e]=c,r+=c}for(let e=0;e<d;e+=1)t[e]=t[e]/r;return t};for(let e=0;e<o;e+=1){let o=(a+e)*r,s=Math.floor(o/i),c=(o-s*i)/h,u=g[c];u||(u=_(c),g[c]=u);let m=s-l+1-n,v=Math.max(0,-m),y=Math.min(d,p-m),b=0;for(let e=v;e<y;e+=1)b+=t[m+e]*u[e];f[e]=b}return f}function yt(e,t){let[n,r]=[e,t];for(;r!==0;)[n,r]=[r,n%r];return n}function bt(e){return 10**(e/20)}function xt(e,t){return e===`equalPower`?Math.sin(t*Math.PI/2):t}function St(e,t){let n=e.end-e.start,r=bt(e.gainDb),{fadeIn:i,fadeOut:a}=e;i.frames>0&&t<i.frames&&(r*=xt(i.curve,t/i.frames));let o=n-1-t;return a.frames>0&&o<a.frames&&(r*=xt(a.curve,Math.max(0,o)/a.frames)),r}function Ct(e,t){let n=Array.from({length:t},()=>Array(e).fill(0)),r=(e,t,r)=>{n[e][t]=r},i=Math.SQRT1_2;switch(`${e}>${t}`){case`1>2`:r(0,0,1),r(1,0,1);break;case`1>4`:r(0,0,1),r(1,0,1);break;case`1>6`:r(2,0,1);break;case`2>4`:case`2>6`:r(0,0,1),r(1,1,1);break;case`4>6`:r(0,0,1),r(1,1,1),r(4,2,1),r(5,3,1);break;case`2>1`:r(0,0,.5),r(0,1,.5);break;case`4>1`:for(let e=0;e<4;e+=1)r(0,e,.25);break;case`6>1`:r(0,0,i),r(0,1,i),r(0,2,1),r(0,4,.5),r(0,5,.5);break;case`4>2`:r(0,0,.5),r(0,2,.5),r(1,1,.5),r(1,3,.5);break;case`6>2`:r(0,0,1),r(0,2,i),r(0,4,i),r(1,1,1),r(1,2,i),r(1,5,i);break;case`6>4`:r(0,0,1),r(0,2,i),r(1,1,1),r(1,2,i),r(2,4,1),r(3,5,1);break;default:for(let n=0;n<Math.min(e,t);n+=1)r(n,n,1)}return n}function wt(e){let{channels:t,frames:n,segments:r}=e,i=Array.from({length:t},()=>new Float64Array(n));for(let e of r){let n=Ct(e.samples.length,t);for(let r=0;r<e.samples.length;r+=1){let a=e.samples[r];for(let o=0;o<t;o+=1){let t=n[o][r];if(t===0)continue;let s=i[o];for(let n=0;n<e.frames;n+=1){let r=St(e.clip,e.within+n)*e.gain;s[e.at+n]=s[e.at+n]+t*a[n]*r}}}}let a=Array.from({length:t},()=>new Float32Array(n)),o=0,s=0;for(let r=0;r<n;r+=1){let n=!1;for(let s=0;s<t;s+=1){let t=i[s][r]*e.gain,c=Math.abs(t);c>o&&(o=c),c>1&&(n=!0),a[s][r]=Math.max(-1,Math.min(1,t))}n&&(s+=1)}return{channels:a,peak:o,clipped:s}}const Tt={pcm16:2,pcm24:3,float32:4},Et=[0,0,0,0,16,0,128,0,0,170,0,56,155,113],Dt={1:4,2:3,4:51,6:63},$=4294967295,Ot=[[`title`,`INAM`],[`artist`,`IART`],[`album`,`IPRD`],[`year`,`ICRD`],[`comment`,`ICMT`]];function kt(e){return e.frames*e.channels*Tt[e.sampleFormat]}var At=class{bytes;view;at=0;constructor(e){this.bytes=new Uint8Array(e),this.view=new DataView(this.bytes.buffer)}text(e){for(let t=0;t<e.length;t+=1)this.bytes[this.at+t]=e.charCodeAt(t);this.at+=e.length}u16(e){this.view.setUint16(this.at,e,!0),this.at+=2}u32(e){this.view.setUint32(this.at,e,!0),this.at+=4}u64(e){this.u32(e%2**32),this.u32(Math.floor(e/2**32))}raw(e){this.bytes.set(e,this.at),this.at+=e.length}};function jt(e){let t=new TextEncoder,n=Ot.flatMap(([n,r])=>{let i=e[n];return i===``?[]:[{id:r,value:t.encode(`${i}\\0`)}]});if(n.length===0)return;let r=new At(4+n.reduce((e,{value:t})=>e+8+t.length+t.length%2,0));r.text(`INFO`);for(let{id:e,value:t}of n)r.text(e),r.u32(t.length),r.raw(t),t.length%2==1&&(r.at+=1);return r.bytes}function Mt(e){let{sampleRate:t,channels:n,frames:r,sampleFormat:i,metadata:a}=e,o=Tt[i],s=i===`float32`,c=n>2||o>2,l=c?40:s?18:16,u=jt(a),d=kt(e),f=d%2,p=8+l+(s?12:0)+(u?8+u.length:0)+8+d+f,m=4+p,h=m>$||d>$||r>$,g=new At(12+(h?36:0)+p-d-f);g.text(h?`RF64`:`RIFF`),g.u32(h?$:m),g.text(`WAVE`),h&&(g.text(`ds64`),g.u32(28),g.u64(m+36),g.u64(d),g.u64(r),g.u32(0)),g.text(`fmt `),g.u32(l);let _=s?3:1;if(g.u16(c?65534:_),g.u16(n),g.u32(t),g.u32(t*n*o),g.u16(n*o),g.u16(o*8),c){g.u16(22),g.u16(o*8),g.u32(Dt[n]??0),g.u16(_);for(let e of Et)g.bytes[g.at++]=e}else s&&g.u16(0);return s&&(g.text(`fact`),g.u32(4),g.u32(h?$:r)),u&&(g.text(`LIST`),g.u32(u.length),g.raw(u)),g.text(`data`),g.u32(h?$:d),g.bytes}function Nt(e){return e<0?-Math.round(-e):Math.round(e)}function Pt(e,t){let n=Number.isFinite(e)?Math.max(-1,Math.min(1,e)):0;if(t===`float32`)return Math.fround(n);let r=t===`pcm16`?32768:8388608;return Math.min(r-1,Nt(n*r))+0}function Ft(e,t,n){let r=Tt[n],i=new Uint8Array(t*e.length*r),a=new DataView(i.buffer),o=0;for(let i=0;i<t;i+=1)for(let t of e){let e=Pt(t[i]??0,n);n===`float32`?a.setFloat32(o,e,!0):n===`pcm16`?a.setInt16(o,e,!0):(a.setUint8(o,e&255),a.setUint8(o+1,e>>8&255),a.setUint8(o+2,e>>16&255)),o+=r}return i}function It(e){let{channels:t,peak:n,clipped:r}=wt(e);return{bytes:Ft(t,e.frames,e.sampleFormat),peak:n,clipped:r}}function Lt(e){D({probe:({file:e})=>pt(e),async readBlock({file:e,layout:t,start:n,frames:r,bucket:i}){let a=await he(e,t,n,r);return{channels:a,...ge(a,i)}},peaks:({channels:e,bucket:t})=>ge(e,t),resample:({channels:e,...t})=>e.map(e=>vt({input:e,...t})),wavHeader:e=>Mt(e),renderBlock:e=>It(e)},{...e,packageVersion:`0.6.0`})}Lt();\n";
3
+ var blob = typeof self !== "undefined" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", jsContent], { type: "text/javascript;charset=utf-8" });
4
+ function WorkerWrapper(options) {
5
+ let objURL;
6
+ try {
7
+ objURL = blob && (self.URL || self.webkitURL).createObjectURL(blob);
8
+ if (!objURL) throw "";
9
+ const worker = new Worker(objURL, {
10
+ type: "module",
11
+ name: options?.name
12
+ });
13
+ worker.addEventListener("error", () => {
14
+ (self.URL || self.webkitURL).revokeObjectURL(objURL);
15
+ });
16
+ return worker;
17
+ } catch (e) {
18
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(jsContent), {
19
+ type: "module",
20
+ name: options?.name
21
+ });
22
+ }
23
+ }
24
+ // src/adapters/audio-worker/inline-worker.ts
25
+ function createInlineWorker() {
26
+ return new WorkerWrapper({ name: "hm-audio" });
27
+ }
28
+ export { createInlineWorker };
29
+
30
+ //# sourceMappingURL=inline-worker-D8bxbE-Q.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline-worker-BB2jwrIT.js","names":["AudioWorker"],"sources":["../../src/adapters/audio-worker/inline-worker.ts"],"sourcesContent":["import AudioWorker from \"../../workers/audio.worker.ts?worker&inline\";\n\n/** Starts the inlined audio worker, from its own lazy chunk. */\nexport function createInlineWorker(): Worker {\n return new AudioWorker({ name: \"hm-audio\" });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,qBAA6B;CAC3C,OAAO,IAAIA,cAAY,EAAE,MAAM,WAAW,CAAC;AAC7C"}
1
+ {"version":3,"file":"inline-worker-D8bxbE-Q.js","names":["AudioWorker"],"sources":["../../src/adapters/audio-worker/inline-worker.ts"],"sourcesContent":["import AudioWorker from \"../../workers/audio.worker.ts?worker&inline\";\n\n/** Starts the inlined audio worker, from its own lazy chunk. */\nexport function createInlineWorker(): Worker {\n return new AudioWorker({ name: \"hm-audio\" });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,qBAA6B;CAC3C,OAAO,IAAIA,cAAY,EAAE,MAAM,WAAW,CAAC;AAC7C"}
@@ -0,0 +1,381 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-command/v2.schema.json",
4
+ "title": "hm-audio-command, version 2",
5
+ "description": "One user-level edit to an hm-audio-plan of version 2 (docs/formats/hm-audio-plan.md, docs/adr/0006, sdk-core ADR 0045). Clip edits never move another clip; time edits add or remove time on the tracks they name. The commands undo runs, such as audio.replaceClips, are internal and not part of this format. Beyond this schema, the reducer checks each command against the plan it applies to.",
6
+ "oneOf": [
7
+ {
8
+ "description": "Adds clips to a track, each at its own position, in free space.",
9
+ "type": "object",
10
+ "required": ["type", "track", "clips"],
11
+ "additionalProperties": false,
12
+ "properties": {
13
+ "type": {
14
+ "const": "audio.insertClips"
15
+ },
16
+ "track": {
17
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
18
+ },
19
+ "clips": {
20
+ "type": "array",
21
+ "minItems": 1,
22
+ "items": {
23
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/clip"
24
+ }
25
+ }
26
+ }
27
+ },
28
+ {
29
+ "description": "Removes clips, on any tracks, leaving silence.",
30
+ "type": "object",
31
+ "required": ["type", "keys"],
32
+ "additionalProperties": false,
33
+ "properties": {
34
+ "type": {
35
+ "const": "audio.removeClips"
36
+ },
37
+ "keys": {
38
+ "type": "array",
39
+ "minItems": 1,
40
+ "items": {
41
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
42
+ }
43
+ }
44
+ }
45
+ },
46
+ {
47
+ "description": "Changes the source range a clip plays. The audio stays where it is on the timeline.",
48
+ "type": "object",
49
+ "required": ["type", "key", "start", "end"],
50
+ "additionalProperties": false,
51
+ "properties": {
52
+ "type": {
53
+ "const": "audio.trimClip"
54
+ },
55
+ "key": {
56
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
57
+ },
58
+ "start": {
59
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
60
+ },
61
+ "end": {
62
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
63
+ }
64
+ }
65
+ },
66
+ {
67
+ "description": "Splits a clip at a timeline frame strictly inside it. The second part takes newKey.",
68
+ "type": "object",
69
+ "required": ["type", "key", "at", "newKey"],
70
+ "additionalProperties": false,
71
+ "properties": {
72
+ "type": {
73
+ "const": "audio.splitClip"
74
+ },
75
+ "key": {
76
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
77
+ },
78
+ "at": {
79
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
80
+ },
81
+ "newKey": {
82
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
83
+ }
84
+ }
85
+ },
86
+ {
87
+ "description": "Moves clips by a signed number of frames, and to another track when one is named.",
88
+ "type": "object",
89
+ "required": ["type", "keys", "by"],
90
+ "additionalProperties": false,
91
+ "properties": {
92
+ "type": {
93
+ "const": "audio.moveClips"
94
+ },
95
+ "keys": {
96
+ "type": "array",
97
+ "minItems": 1,
98
+ "items": {
99
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
100
+ }
101
+ },
102
+ "by": {
103
+ "description": "A signed whole number of frames.",
104
+ "type": "integer",
105
+ "minimum": -9007199254740991,
106
+ "maximum": 9007199254740991
107
+ },
108
+ "track": {
109
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
110
+ }
111
+ }
112
+ },
113
+ {
114
+ "description": "Sets the gain of clips.",
115
+ "type": "object",
116
+ "required": ["type", "keys", "gainDb"],
117
+ "additionalProperties": false,
118
+ "properties": {
119
+ "type": {
120
+ "const": "audio.setGain"
121
+ },
122
+ "keys": {
123
+ "type": "array",
124
+ "minItems": 1,
125
+ "items": {
126
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
127
+ }
128
+ },
129
+ "gainDb": {
130
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/gainDb"
131
+ }
132
+ }
133
+ },
134
+ {
135
+ "description": "Sets a clip's fade in or fade out.",
136
+ "type": "object",
137
+ "required": ["type", "key", "edge", "frames", "curve"],
138
+ "additionalProperties": false,
139
+ "properties": {
140
+ "type": {
141
+ "const": "audio.setFade"
142
+ },
143
+ "key": {
144
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
145
+ },
146
+ "edge": {
147
+ "enum": ["in", "out"]
148
+ },
149
+ "frames": {
150
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
151
+ },
152
+ "curve": {
153
+ "enum": ["linear", "equalPower"]
154
+ }
155
+ }
156
+ },
157
+ {
158
+ "description": "Removes a range of time from the named tracks. With ripple, later clips on those tracks move earlier by its length. newKeys gives, by track, the key of the part after the range, where the range lies inside one clip.",
159
+ "type": "object",
160
+ "required": ["type", "start", "end", "tracks", "ripple"],
161
+ "additionalProperties": false,
162
+ "properties": {
163
+ "type": {
164
+ "const": "audio.deleteRange"
165
+ },
166
+ "start": {
167
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
168
+ },
169
+ "end": {
170
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
171
+ },
172
+ "tracks": {
173
+ "type": "array",
174
+ "minItems": 1,
175
+ "items": {
176
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
177
+ }
178
+ },
179
+ "ripple": {
180
+ "type": "boolean"
181
+ },
182
+ "newKeys": {
183
+ "description": "New clip keys, by the key of the track each is for.",
184
+ "type": "object",
185
+ "propertyNames": {
186
+ "minLength": 1
187
+ },
188
+ "additionalProperties": {
189
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
190
+ }
191
+ }
192
+ }
193
+ },
194
+ {
195
+ "description": "Removes everything outside a range, on every track, and moves what's kept to the start.",
196
+ "type": "object",
197
+ "required": ["type", "start", "end"],
198
+ "additionalProperties": false,
199
+ "properties": {
200
+ "type": {
201
+ "const": "audio.keepRange"
202
+ },
203
+ "start": {
204
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
205
+ },
206
+ "end": {
207
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
208
+ }
209
+ }
210
+ },
211
+ {
212
+ "description": "Opens silence on the named tracks, splitting a clip that lies across the frame. newKeys gives, by track, the key of the second part of a split clip.",
213
+ "type": "object",
214
+ "required": ["type", "at", "frames", "tracks"],
215
+ "additionalProperties": false,
216
+ "properties": {
217
+ "type": {
218
+ "const": "audio.insertTime"
219
+ },
220
+ "at": {
221
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/frames"
222
+ },
223
+ "frames": {
224
+ "type": "integer",
225
+ "minimum": 1,
226
+ "maximum": 9007199254740991
227
+ },
228
+ "tracks": {
229
+ "type": "array",
230
+ "minItems": 1,
231
+ "items": {
232
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
233
+ }
234
+ },
235
+ "newKeys": {
236
+ "description": "New clip keys, by the key of the track each is for.",
237
+ "type": "object",
238
+ "propertyNames": {
239
+ "minLength": 1
240
+ },
241
+ "additionalProperties": {
242
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
243
+ }
244
+ }
245
+ }
246
+ },
247
+ {
248
+ "description": "Adds an empty track at an index.",
249
+ "type": "object",
250
+ "required": ["type", "key", "index"],
251
+ "additionalProperties": false,
252
+ "properties": {
253
+ "type": {
254
+ "const": "audio.addTrack"
255
+ },
256
+ "key": {
257
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
258
+ },
259
+ "index": {
260
+ "type": "integer",
261
+ "minimum": 0,
262
+ "maximum": 9007199254740991
263
+ },
264
+ "name": {
265
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/trackName"
266
+ }
267
+ }
268
+ },
269
+ {
270
+ "description": "Removes tracks, with their clips. A plan keeps at least one track.",
271
+ "type": "object",
272
+ "required": ["type", "keys"],
273
+ "additionalProperties": false,
274
+ "properties": {
275
+ "type": {
276
+ "const": "audio.removeTracks"
277
+ },
278
+ "keys": {
279
+ "type": "array",
280
+ "minItems": 1,
281
+ "items": {
282
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
283
+ }
284
+ }
285
+ }
286
+ },
287
+ {
288
+ "description": "Moves a track to an index of the resulting plan.",
289
+ "type": "object",
290
+ "required": ["type", "key", "to"],
291
+ "additionalProperties": false,
292
+ "properties": {
293
+ "type": {
294
+ "const": "audio.moveTrack"
295
+ },
296
+ "key": {
297
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
298
+ },
299
+ "to": {
300
+ "type": "integer",
301
+ "minimum": 0,
302
+ "maximum": 9007199254740991
303
+ }
304
+ }
305
+ },
306
+ {
307
+ "description": "Sets the fields given of a track, at least one.",
308
+ "type": "object",
309
+ "required": ["type", "key"],
310
+ "additionalProperties": false,
311
+ "properties": {
312
+ "type": {
313
+ "const": "audio.setTrack"
314
+ },
315
+ "key": {
316
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/key"
317
+ },
318
+ "name": {
319
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/trackName"
320
+ },
321
+ "gainDb": {
322
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/gainDb"
323
+ },
324
+ "muted": {
325
+ "type": "boolean"
326
+ },
327
+ "soloed": {
328
+ "type": "boolean"
329
+ }
330
+ },
331
+ "minProperties": 3
332
+ },
333
+ {
334
+ "description": "Sets the master gain.",
335
+ "type": "object",
336
+ "required": ["type", "gainDb"],
337
+ "additionalProperties": false,
338
+ "properties": {
339
+ "type": {
340
+ "const": "audio.setMasterGain"
341
+ },
342
+ "gainDb": {
343
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/gainDb"
344
+ }
345
+ }
346
+ },
347
+ {
348
+ "description": "Sets the plan's channel count.",
349
+ "type": "object",
350
+ "required": ["type", "channels"],
351
+ "additionalProperties": false,
352
+ "properties": {
353
+ "type": {
354
+ "const": "audio.setChannels"
355
+ },
356
+ "channels": {
357
+ "type": "integer",
358
+ "minimum": 1,
359
+ "maximum": 9007199254740991
360
+ }
361
+ }
362
+ },
363
+ {
364
+ "description": "Sets one metadata field.",
365
+ "type": "object",
366
+ "required": ["type", "field", "value"],
367
+ "additionalProperties": false,
368
+ "properties": {
369
+ "type": {
370
+ "const": "audio.setMetadata"
371
+ },
372
+ "field": {
373
+ "enum": ["title", "artist", "album", "year", "comment"]
374
+ },
375
+ "value": {
376
+ "$ref": "https://github.com/ie-huss-martinez/audio-sdk/blob/main/formats/hm-audio-plan/v2.schema.json#/$defs/metadataText"
377
+ }
378
+ }
379
+ }
380
+ ]
381
+ }