Add AIFF / AIFF-C support (read + write)#409
Open
mmamedel wants to merge 3 commits into
Open
Conversation
Adds read support for the AIFF and AIFF-C (AIFC) container formats via a new AiffInputFormat and AiffDemuxer, mirroring the existing WAVE support. AIFF is the big-endian, IFF-based sibling of WAVE and typically wraps uncompressed signed PCM, so no new codec is needed — it maps onto the PCM codecs Mediabunny already decodes: - AIFF / AIFC 'NONE' / 'twos' → pcm-s8 / pcm-s16be / pcm-s24be / pcm-s32be - AIFC 'sowt' → pcm-s16 / pcm-s24 / pcm-s32 (little-endian) - AIFC 'raw ' → pcm-u8 - AIFC 'fl32' / 'fl64' → pcm-f32be / pcm-f64be - AIFC 'ulaw' / 'alaw' → ulaw / alaw The COMM chunk's 80-bit IEEE 754 extended-precision sample rate is decoded. Compressed AIFC payloads we don't decode resolve to a null codec (canDecode is false) rather than throwing. Exports the AIFF singleton and adds it to ALL_FORMATS. Adds read-aiff tests covering 16-bit, 8-bit, AIFC float, and AIFC byte-swapped fixtures, and updates the format docs (read-only).
Adds AiffOutputFormat + AiffMuxer (and a big-endian AiffWriter), mirroring the WAVE output path. Uncompressed signed PCM is written as plain AIFF; floating-point and µ-law/A-law are written as AIFF-C with the matching compression type and an FVER chunk. Supported output codecs: pcm-s8, pcm-s16be, pcm-s24be, pcm-s32be (AIFF) and pcm-f32be, pcm-f64be, ulaw, alaw (AIFF-C). The COMM sample rate is encoded as an 80-bit IEEE 754 extended float (exact for integer rates). Exports AiffOutputFormat + AiffOutputFormatOptions. Renames the test file to aiff.test.ts and adds sample-accurate write→read round-trip tests for pcm-s16be/-s24be/-s8/-f32be. Updates the format docs to bidirectional and adds an AIFF output-formats section.
Writes metadata tags into either native AIFF text chunks (NAME/AUTH/ANNO, the default) or an ID3 chunk for a richer tag set, selected via the new `metadataFormat` option on AiffOutputFormat — mirroring the WAVE muxer. The demuxer now parses NAME/AUTH/ANNO/(c) text chunks and embedded ID3 chunks back into MetadataTags. Adds round-trip tests for both metadata formats and documents the option.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds bidirectional support for the AIFF and AIFF-C (AIFC) container formats — reading via
AiffInputFormat/AiffDemuxerand writing viaAiffOutputFormat/AiffMuxer— mirroring the existing WAVE support.AIFF is the big-endian, IFF-based sibling of WAVE and typically wraps uncompressed signed PCM, so no new codec is required. It maps directly onto the PCM codecs Mediabunny already encodes/decodes.
Reading
NONE/twos(uncompressed BE PCM)pcm-s8/pcm-s16be/pcm-s24be/pcm-s32besowt(byte-swapped)pcm-s16/pcm-s24/pcm-s32rawpcm-u8fl32/fl64pcm-f32be/pcm-f64beulaw/alawulaw/alawNAME/AUTH/ANNO/(c)text chunks and from embeddedID3chunks.nullcodec (socanDecode()isfalse) rather than throwing.WaveDemuxer.Writing
AiffOutputFormatsupportspcm-s8,pcm-s16be,pcm-s24be,pcm-s32be(written as plain AIFF) andpcm-f32be,pcm-f64be,ulaw,alaw(written as AIFF-C with the matching compression type +FVERchunk). The COMM sample rate is encoded as an 80-bit extended float (exact for integer rates).Metadata is written via the
metadataFormatoption, mirroring the WAVE muxer:'text'(default): native AIFF text chunks (NAME/AUTH/ANNO) — title, artist, comment.'id3': anID3chunk for the full, rich tag set (album, genre, track number, images, …).Changes
src/aiff/aiff-demuxer.ts—AiffDemuxer+ audio track backing + metadata parsingsrc/aiff/aiff-muxer.ts—AiffMuxer+ metadata writingsrc/aiff/aiff-writer.ts— big-endian IFF writer (the AIFF counterpart toRiffWriter)src/input-format.ts—AiffInputFormatclass,AIFFsingleton, added toALL_FORMATSsrc/output-format.ts—AiffOutputFormatclass +AiffOutputFormatOptionssrc/index.ts— exportstest/node/aiff.test.ts— read tests (16-bit, 8-bit, AIFCfl32, AIFCsowt), sample-accurate write→read round-trips (pcm-s16be/-s24be/-s8/-f32be), and metadata round-trips (text + ID3)docs/guide/*,README.md— AIFF documented as bidirectional, with an AIFF output-formats sectionNotes
ulaw/alawfor the AIFF-C compression type on write; the demuxer accepts both cases.Testing
eslint,tsc --noEmit,npm run build, docblock check, and theaiffsuite (11 tests) all pass locally.