"use strict";exports.id=790,exports.ids=[790],exports.modules={8790:(e,t,a)=>{a.r(t),a.d(t,{AIFFParser:()=>w});var s=a(1751),i=a(5753),n=a(8989),o=a(8621),r=a(5031),m=a(4604),h=a(3324);const c={NONE:"not compressed\tPCM\tApple Computer",sowt:"PCM (byte swapped)",fl32:"32-bit floating point IEEE 32-bit float",fl64:"64-bit floating point IEEE 64-bit float\tApple Computer",alaw:"ALaw 2:1\t8-bit ITU-T G.711 A-law",ulaw:"µLaw 2:1\t8-bit ITU-T G.711 µ-law\tApple Computer",ULAW:"CCITT G.711 u-law 8-bit ITU-T G.711 µ-law",ALAW:"CCITT G.711 A-law 8-bit ITU-T G.711 A-law",FL32:"Float 32\tIEEE 32-bit float "};class l extends((0,h.fO)("AIFF")){}class p{constructor(e,t){this.isAifc=t;const a=t?22:18;if(e.chunkSize<a)throw new l(`COMMON CHUNK size should always be at least ${a}`);this.len=e.chunkSize}get(e,t){const a=s.UINT16_BE.get(e,t+8)-16398,i=s.UINT16_BE.get(e,t+8+2),n={numChannels:s.UINT16_BE.get(e,t),numSampleFrames:s.UINT32_BE.get(e,t+2),sampleSize:s.UINT16_BE.get(e,t+6),sampleRate:a<0?i>>Math.abs(a):i<<a};if(this.isAifc){if(n.compressionType=r.e.get(e,t+18),this.len>22){const a=s.UINT8.get(e,t+22);if(a>0){if(23+a+(a+1)%2!==this.len)throw new l("Illegal pstring length");n.compressionName=new s.StringType(a,"latin1").get(e,t+23)}else n.compressionName=void 0}}else n.compressionName="PCM";return n}}const d={len:8,get:(e,t)=>({chunkID:r.e.get(e,t),chunkSize:Number(BigInt(s.UINT32_BE.get(e,t+4)))})},u=i("music-metadata:parser:aiff");class w extends m.s{constructor(){super(...arguments),this.isCompressed=null}async parse(){if("FORM"!==(await this.tokenizer.readToken(d)).chunkID)throw new l("Invalid Chunk-ID, expected 'FORM'");const e=await this.tokenizer.readToken(r.e);switch(e){case"AIFF":this.metadata.setFormat("container",e),this.isCompressed=!1;break;case"AIFC":this.metadata.setFormat("container","AIFF-C"),this.isCompressed=!0;break;default:throw new l(`Unsupported AIFF type: ${e}`)}this.metadata.setFormat("lossless",!this.isCompressed),this.metadata.setAudioOnly();try{for(;!this.tokenizer.fileInfo.size||this.tokenizer.fileInfo.size-this.tokenizer.position>=d.len;){u(`Reading AIFF chunk at offset=${this.tokenizer.position}`);const e=await this.tokenizer.readToken(d),t=2*Math.round(e.chunkSize/2),a=await this.readData(e);await this.tokenizer.ignore(t-a)}}catch(e){if(!(e instanceof n.d1))throw e;u("End-of-stream")}}async readData(e){switch(e.chunkID){case"COMM":{if(null===this.isCompressed)throw new l("Failed to parse AIFF.COMM chunk when compression type is unknown");const t=await this.tokenizer.readToken(new p(e,this.isCompressed));return this.metadata.setFormat("bitsPerSample",t.sampleSize),this.metadata.setFormat("sampleRate",t.sampleRate),this.metadata.setFormat("numberOfChannels",t.numChannels),this.metadata.setFormat("numberOfSamples",t.numSampleFrames),this.metadata.setFormat("duration",t.numSampleFrames/t.sampleRate),(t.compressionName||t.compressionType)&&this.metadata.setFormat("codec",t.compressionName??c[t.compressionType]),e.chunkSize}case"ID3 ":{const t=await this.tokenizer.readToken(new s.Uint8ArrayType(e.chunkSize)),a=n.vY(t);return await(new o.S).parse(this.metadata,a,this.options),e.chunkSize}case"SSND":return this.metadata.format.duration&&this.metadata.setFormat("bitrate",8*e.chunkSize/this.metadata.format.duration),0;case"NAME":case"AUTH":case"(c) ":case"ANNO":return this.readTextChunk(e);default:return u(`Ignore chunk id=${e.chunkID}, size=${e.chunkSize}`),0}}async readTextChunk(e){const t=(await this.tokenizer.readToken(new s.StringType(e.chunkSize,"ascii"))).split("\0").map(e=>e.trim()).filter(e=>e?.length);return await Promise.all(t.map(t=>this.metadata.addTag("AIFF",e.chunkID,t))),e.chunkSize}}}};
//# sourceMappingURL=790.js.map