"use strict";(self.webpackChunktelegram_t=self.webpackChunktelegram_t||[]).push([[5420],{35420(a,e,t){t.r(e),t.d(e,{WavPackContentError:()=>u,WavPackParser:()=>p});var s=t(4017),i=t(10283),o=t(5031),n=t(74604);const r=[6e3,8e3,9600,11025,12e3,16e3,22050,24e3,32e3,44100,48e3,64e3,88200,96e3,192e3,-1],l={len:32,get:(a,e)=>{const t=s.UINT32_LE.get(a,e+24),i={BlockID:o.e.get(a,e),blockSize:s.UINT32_LE.get(a,e+4),version:s.UINT16_LE.get(a,e+8),totalSamples:s.UINT32_LE.get(a,e+12),blockIndex:s.UINT32_LE.get(a,e+16),blockSamples:s.UINT32_LE.get(a,e+20),flags:{bitsPerSample:8*(1+k(t,0,2)),isMono:d(t,2),isHybrid:d(t,3),isJointStereo:d(t,4),crossChannel:d(t,5),hybridNoiseShaping:d(t,6),floatingPoint:d(t,7),samplingRate:r[k(t,23,4)],isDSD:d(t,31)},crc:new s.Uint8ArrayType(4).get(a,e+28)};return i.flags.isDSD&&(i.totalSamples*=8),i}},c={len:1,get:(a,e)=>({functionId:k(a[e],0,6),isOptional:d(a[e],5),isOddSize:d(a[e],6),largeBlock:d(a[e],7)})};function d(a,e){return 1===k(a,e,1)}function k(a,e,t){return a>>>e&4294967295>>>32-t}var m=t(17833),h=t(78523),g=t(63324);const f=m("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 a=await this.tokenizer.readToken(l);if("wvpk"!==a.BlockID)throw new u("Invalid WavPack Block-ID");f(`WavPack header blockIndex=${a.blockIndex}, len=${l.len}`),0!==a.blockIndex||this.metadata.format.container||(this.metadata.setFormat("container","WavPack"),this.metadata.setFormat("lossless",!a.flags.isHybrid),this.metadata.setFormat("bitsPerSample",a.flags.bitsPerSample),a.flags.isDSD||(this.metadata.setFormat("sampleRate",a.flags.samplingRate),this.metadata.setFormat("duration",a.totalSamples/a.flags.samplingRate)),this.metadata.setFormat("numberOfChannels",a.flags.isMono?1:2),this.metadata.setFormat("numberOfSamples",a.totalSamples),this.metadata.setFormat("codec",a.flags.isDSD?"DSD":"PCM"));const e=a.blockSize-(l.len-8);await(0===a.blockIndex?this.parseMetadataSubBlock(a,e):this.tokenizer.ignore(e)),a.blockSamples>0&&(this.audioDataSize+=a.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(a,e){let t=e;for(;t>c.len;){const e=await this.tokenizer.readToken(c),i=await this.tokenizer.readNumber(e.largeBlock?s.UINT24_LE:s.UINT8),o=new Uint8Array(2*i-(e.isOddSize?1:0));switch(await this.tokenizer.readBuffer(o),f(`Metadata Sub-Blocks functionId=0x${e.functionId.toString(16)}, id.largeBlock=${e.largeBlock},data-size=${o.length}`),e.functionId){case 0:break;case 14:{f("ID_DSD_BLOCK");const e=1<<s.UINT8.get(o,0),t=a.flags.samplingRate*e*8;if(!a.flags.isDSD)throw new u("Only expect DSD block if DSD-flag is set");this.metadata.setFormat("sampleRate",t),this.metadata.setFormat("duration",a.totalSamples/t);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${e.functionId.toString(16)}`)}t-=c.len+(e.largeBlock?s.UINT24_LE.len:s.UINT8.len)+2*i,f(`remainingLength=${t}`),e.isOddSize&&this.tokenizer.ignore(1)}if(0!==t)throw new u("metadata-sub-block should fit it remaining length")}}}}]);
//# sourceMappingURL=5420.291b1251bb16bc5a0751.js.map