import{parseOpusTocByte as m}from"../codec-data.js";import{assert as b,ilog as p,toDataView as k}from"../misc.js";export const OGGS=1399285583;const v=79764919,f=new Uint32Array(256);for(let o=0;o<256;o++){let t=o<<24;for(let e=0;e<8;e++)t=t&2147483648?t<<1^v:t<<1;f[o]=t>>>0&4294967295}export const computeOggPageCrc=o=>{const t=k(o),e=t.getUint32(22,!0);t.setUint32(22,0,!0);let r=0;for(let s=0;s<o.length;s++){const n=o[s];r=(r<<8^f[r>>>24^n])>>>0}return t.setUint32(22,e,!0),r},extractSampleMetadata=(o,t,e)=>{let r=0,s=null;if(o.length>0)if(t.codec==="vorbis"){b(t.vorbisInfo);const n=t.vorbisInfo.modeBlockflags.length,l=(1<<p(n-1))-1<<1,c=(o[0]&l)>>1;if(c>=t.vorbisInfo.modeBlockflags.length)throw new Error("Invalid mode number.");let i=e;const u=t.vorbisInfo.modeBlockflags[c];if(s=t.vorbisInfo.blocksizes[u],u===1){const g=(l|1)+1,a=o[0]&g?1:0;i=t.vorbisInfo.blocksizes[a]}r=i!==null?i+s>>2:0}else t.codec==="opus"&&(r=m(o).durationInSamples);return{durationInSamples:r,vorbisBlockSize:s}},buildOggMimeType=o=>{let t="audio/ogg";if(o.codecStrings){const e=[...new Set(o.codecStrings)];t+=`; codecs="${e.join(", ")}"`}return t};
