"use strict";exports.id=420,exports.ids=[420],exports.modules={5420:(t,a,e)=>{e.r(a),e.d(a,{WavPackContentError:()=>u,WavPackParser:()=>p});var s=e(1751),i=e(283),o=e(5031),n=e(4604);const r=[6e3,8e3,9600,11025,12e3,16e3,22050,24e3,32e3,44100,48e3,64e3,88200,96e3,192e3,-1],l={len:32,get:(t,a)=>{const e=s.UINT32_LE.get(t,a+24),i={BlockID:o.e.get(t,a),blockSize:s.UINT32_LE.get(t,a+4),version:s.UINT16_LE.get(t,a+8),totalSamples:s.UINT32_LE.get(t,a+12),blockIndex:s.UINT32_LE.get(t,a+16),blockSamples:s.UINT32_LE.get(t,a+20),flags:{bitsPerSample:8*(1+m(e,0,2)),isMono:d(e,2),isHybrid:d(e,3),isJointStereo:d(e,4),crossChannel:d(e,5),hybridNoiseShaping:d(e,6),floatingPoint:d(e,7),samplingRate:r[m(e,23,4)],isDSD:d(e,31)},crc:new s.Uint8ArrayType(4).get(t,a+28)};return i.flags.isDSD&&(i.totalSamples*=8),i}},c={len:1,get:(t,a)=>({functionId:m(t[a],0,6),isOptional:d(t[a],5),isOddSize:d(t[a],6),largeBlock:d(t[a],7)})};function d(t,a){return 1===m(t,a,1)}function m(t,a,e){return t>>>a&4294967295>>>32-e}var k=e(5753),h=e(8523),g=e(3324);const f=k("music-metadata:parser:WavPack");class u extends((0,g.fO)("WavPack")){}class p extends n.s{constructor(){super(...arguments),this.audioDataSize=0}async parse(){return this.metadata.setAudioOnly(),this.audioDataSize=0,await this.parseWavPackBlocks(),(0,i.tryParseApeHeader)(this.metadata,this.tokenizer,this.options)}async parseWavPackBlocks(){do{if("wvpk"!==await this.tokenizer.peekToken(o.e))break;const t=await this.tokenizer.readToken(l);if("wvpk"!==t.BlockID)throw new u("Invalid WavPack Block-ID");f(`WavPack header blockIndex=${t.blockIndex}, len=${l.len}`),0!==t.blockIndex||this.metadata.format.container||(this.metadata.setFormat("container","WavPack"),this.metadata.setFormat("lossless",!t.flags.isHybrid),this.metadata.setFormat("bitsPerSample",t.flags.bitsPerSample),t.flags.isDSD||(this.metadata.setFormat("sampleRate",t.flags.samplingRate),this.metadata.setFormat("duration",t.totalSamples/t.flags.samplingRate)),this.metadata.setFormat("numberOfChannels",t.flags.isMono?1:2),this.metadata.setFormat("numberOfSamples",t.totalSamples),this.metadata.setFormat("codec",t.flags.isDSD?"DSD":"PCM"));const a=t.blockSize-(l.len-8);await(0===t.blockIndex?this.parseMetadataSubBlock(t,a):this.tokenizer.ignore(a)),t.blockSamples>0&&(this.audioDataSize+=t.blockSize)}while(!this.tokenizer.fileInfo.size||this.tokenizer.fileInfo.size-this.tokenizer.position>=l.len);this.metadata.format.duration&&this.metadata.setFormat("bitrate",8*this.audioDataSize/this.metadata.format.duration)}async parseMetadataSubBlock(t,a){let e=a;for(;e>c.len;){const a=await this.tokenizer.readToken(c),i=await this.tokenizer.readNumber(a.largeBlock?s.UINT24_LE:s.UINT8),o=new Uint8Array(2*i-(a.isOddSize?1:0));switch(await this.tokenizer.readBuffer(o),f(`Metadata Sub-Blocks functionId=0x${a.functionId.toString(16)}, id.largeBlock=${a.largeBlock},data-size=${o.length}`),a.functionId){case 0:break;case 14:{f("ID_DSD_BLOCK");const a=1<<s.UINT8.get(o,0),e=t.flags.samplingRate*a*8;if(!t.flags.isDSD)throw new u("Only expect DSD block if DSD-flag is set");this.metadata.setFormat("sampleRate",e),this.metadata.setFormat("duration",t.totalSamples/e);break}case 36:f("ID_ALT_TRAILER: trailer for non-wav files");break;case 38:this.metadata.setFormat("audioMD5",o);break;case 47:f(`ID_BLOCK_CHECKSUM: checksum=${(0,h.EY)(o)}`);break;default:f(`Ignore unsupported meta-sub-block-id functionId=0x${a.functionId.toString(16)}`)}e-=c.len+(a.largeBlock?s.UINT24_LE.len:s.UINT8.len)+2*i,f(`remainingLength=${e}`),a.isOddSize&&this.tokenizer.ignore(1)}if(0!==e)throw new u("metadata-sub-block should fit it remaining length")}}}};
//# sourceMappingURL=420.js.map