Commit Graph
87 Commits
Author SHA1 Message Date
el-jandDylan M. Taylor 0649a07aa1 craft-audio: ITU-T G.726 ADPCM speech codec (#1531) (#1792)
* craft-audio: ITU-T G.726 ADPCM speech codec (#1531)

* fix(audio): mask G726 sample codewords before adaptation

---------

Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
2026-11-17 12:15:52 -05:00
Dylan M. Taylor 2d6d39f1a9 Merge pull request #1959 from el-j/feat/audio-vorbis-decode
craft-audio: native Vorbis I decoder (#1547)
2026-11-17 11:55:19 -05:00
Dylan M. Taylor 00048fdadf Merge remote-tracking branch 'origin/main' into fix/vorbis-codebook-size
# Conflicts:
#	crates/audio/src/lib.rs
2026-11-17 09:08:44 -05:00
Dylan M. Taylor 363a51967b fix(audio): bound Vorbis decode allocations and strengthen oracles 2026-11-17 09:07:52 -05:00
Dylan M. Taylor e5db2c26b9 Merge remote-tracking branch 'origin/main' into fix/adpcm-layout-overflow
# Conflicts:
#	crates/audio/src/lib.rs
2026-11-17 09:01:31 -05:00
Dylan M. Taylor 90947c57d7 Merge pull request #1460 from alehel/feat/vmd-decoding
feat(media,video,audio): Sierra VMD demuxer and decoders
2026-11-17 08:53:39 -05:00
Dylan M. Taylor 9c4a8a1dd9 Merge main and retain MP2 and ADPCM registrations 2026-11-17 08:49:11 -05:00
Dylan M. Taylor 1291955de9 Merge pull request #1789 from el-j/feat/audio-g722
craft-audio: ITU-T G.722 wideband speech codec (#1530)
2026-11-17 08:33:15 -05:00
el-j e5bde5203c Merge main into feat/audio-mp2-encode 2026-11-17 10:12:38 +01:00
el-j 46587441df Merge main into feat/audio-adpcm 2026-11-17 10:12:32 +01:00
el-j 3d06331fc8 Merge main into feat/audio-g722 2026-11-17 10:12:12 +01:00
el-j de861bef5a Merge main into feat/audio-vorbis-decode 2026-11-17 10:11:58 +01:00
alehel 00e0075184 Merge remote-tracking branch 'origin/main' into m1460-merge
# Conflicts:
#	crates/audio/Cargo.toml
#	crates/audio/README.md
#	crates/audio/src/lib.rs
#	crates/media-testkit/src/lib.rs
2026-11-17 04:06:58 +01:00
el-j d09d31c109 craft-audio: Bluetooth Low Complexity Subband Coding (SBC) audio codec (#1537) (#1839) 2026-11-16 21:30:36 -05:00
el-j 352c06857d craft-audio: GSM 06.10 full-rate speech decoder and encoder (#1534) (#1874) 2026-11-16 21:30:32 -05:00
el-j 3382b9662a craft-audio: native Vorbis I decoder (#1547) 2026-11-17 01:10:43 +01:00
alehel 1676c70cd0 Merge remote-tracking branch 'origin/main' into claude/vmd-format-support-7746c5
# Conflicts:
#	crates/audio/src/lib.rs
#	crates/video/src/lib.rs
2026-11-16 12:43:58 +01:00
el-j 8314189cb0 craft-audio: bound the Microsoft ADPCM step; regression tests for the review findings 2026-11-16 02:26:50 +01:00
el-j 31d3e07999 Merge main into feat/audio-adpcm 2026-11-16 02:23:22 +01:00
el-j c25ac10b88 Merge main into feat/audio-mp2-encode 2026-11-16 02:23:11 +01:00
el-j 6502ca440e craft-audio: ITU-T G.722 wideband speech codec (#1530) 2026-11-16 02:14:12 +01:00
el-j bbe92b892e craft-audio: address review findings on overflow checks and sample bounds 2026-11-16 01:06:06 +01:00
FredApps 1d413b992d Merge pull request #1688 from storytold/codex/flac-main-reconcile
Reconcile native FLAC decoder with merged QOA support
2026-11-16 00:17:47 +01:00
FredApps d1a431c4b5 audio: pure-Rust Vorbis encoder (1-8 channels, quality, tags, wasm) and an Ogg page writer (#1642)
* audio: pure-Rust Vorbis encoder, and an Ogg page writer in craft-media

Replace the libvorbis wrapper (vorbis_rs, C, desktop only) behind
`vorbis-encode` with FilmCraft's clean-room Vorbis I encoder by
@JordyUSA (storytold/filmcraft#4481), and move its Ogg page writer into
craft-media's `ogg` module.

craft-audio:
- `vorbis::encoder::{Encoder, EncoderConfig, Error}`: 1-8 channels in
  Vorbis order, any sample rate, quality -1 to 10 (VBR), streaming
  packets with granule positions.
- `encode_ogg_vorbis` with `OggVorbisOptions` (quality, vendor, tags,
  serial) writes a whole Ogg Vorbis file with a comment header.
- `encode_ogg(buf, kbps)` and `OGG_BITRATES` keep working: the bit rate
  picks the quality whose nominal rate it is (`quality_for_bitrate`).
- `encode` with `EncodeFormat::Ogg` takes 1-8 channel WAV-order layouts
  and writes them in Vorbis order, and `RateControl::Quality`.
- Ogg is built on wasm32 too.
- Residue partitions hold whole sample frames (48, 40, 48 or 56 values
  for 3, 5, 6 and 7 channels): libvorbis decodes each partition from
  channel 0, so 32-value partitions came out scrambled for those counts.
- The first audio packet gets a page of its own, so a short file's
  first audio page is never also its last (ffmpeg then kept the padding).

craft-media: `ogg::PageWriter`, `opus_tags`, `vorbis_comment`.

Part of storytold/craft-libs#778.

* audio, media: address review on the Vorbis encoder and Ogg writer

- Encoder: read cursor into the pending input, compacted once per call,
  so a large encode() call no longer moves the tail on every block.
- Tests: check ffmpeg's libvorbis decoder only when ffmpeg has it.
- PageWriter::finish: the end granule replaces the last page's only when
  a packet completes on it (RFC 7845 4.4); documented and tested.
- README: Ogg Opus packet granules are the samples decoded so far.

* audio: pick Ogg by extension on wasm32 too

The Vorbis encoder is pure Rust now, so encode_format_for("ogg") follows
the vorbis-encode feature alone, as EncodeFormat::Ogg.is_built() and
ENCODE_EXTENSIONS already do.
2026-11-15 22:59:29 +01:00
el-j 485f8e45f4 craft-audio: ADPCM test lints 2026-11-15 22:41:38 +01:00
el-j 9134fff94c craft-audio: ADPCM docs link and ffmpeg rounding variants in the oracle tests
Older ffmpeg releases decode IMA and Flash ADPCM with the
((2 * magnitude + 1) * step) rounding; the tests accept either that or the
recommended-practice one.
2026-11-15 22:41:20 +01:00
el-j 6b059051e5 craft-audio: IMA WAV, Microsoft, Yamaha and Flash ADPCM decoders and encoders (adpcm)
Bit-exact with ffmpeg's decoders on both ffmpeg-made and our own
streams; our encoders match ffmpeg's in SNR.

Closes #1536.
2026-11-15 22:35:46 +01:00
el-j 1648ef05f5 craft-audio: MPEG-1/2 Layer II (MP2) encoder (mpa-encode)
Constant bit rate mono and stereo at 16-48 kHz, written from ISO/IEC
11172-3 and 13818-3. Decoded by our decoder and by ffmpeg as an
oracle.

Closes #1545.
2026-11-15 22:15:58 +01:00
alehel ad5ff4426a Merge remote-tracking branch 'origin/main' into claude/vmd-format-support-7746c5
# Conflicts:
#	crates/audio/src/lib.rs
2026-11-15 21:17:32 +01:00
Dylan M. Taylor affd53bf5f Merge remote-tracking branch 'origin/main' into codex/flac-main-reconcile
# Conflicts:
#	crates/audio/Cargo.toml
#	crates/audio/src/lib.rs
2026-11-15 17:52:06 +00:00
Dylan M. Taylor ad9850f18f fix(audio): validate FLAC stream precision and complete consumption 2026-11-15 11:05:37 -05:00
el-j 2d5f2e4a73 craft-audio: flac_decode tests without index loops (CI clippy) 2026-11-15 15:25:56 +01:00
el-j ee20ae63fd craft-audio: qoa_oracle test without index loops (CI clippy) 2026-11-15 15:24:46 +01:00
el-j cdf4a2fa6e craft-audio: native FLAC decoder (flac-decode)
Adds flac::decode for whole files and flac::Decoder for single frames:
RFC 9639 subframes (constant, verbatim, fixed, LPC), Rice and escaped
partitions, wasted bits, all stereo modes, fixed and variable block
sizes, 4 to 32 bits, CRC-8 and CRC-16 checked. Not yet wired into
craft_audio::decode, which still uses symphonia for FLAC.

Part of #1546
2026-11-15 15:11:43 +01:00
el-j ff61266d63 craft-audio: QOA (Quite OK Audio) decoder and encoder
Adds the qoa module behind the qoa, qoa-decode and qoa-encode features:
whole .qoa files, 16-bit, 1 to 8 channels. Streaming files are
unsupported. An ffmpeg oracle test checks that ffmpeg decodes our files
to exactly the samples our decoder returns.

Closes #1541
2026-11-15 12:38:57 +01:00
alehel 6e95f83178 Merge remote-tracking branch 'origin/main' into claude/vmd-format-support-7746c5
# Conflicts:
#	crates/video/Cargo.toml
#	crates/video/README.md
2026-11-15 07:51:49 +01:00
Dylan M. Taylor c4fb292825 Use canonical parity check in WAV iXML fixture 2026-11-14 23:02:09 -05:00
Dylan M. Taylor 44802bd54d craft-audio: preserve iXML WAV time-reference fallback 2026-11-14 22:57:45 -05:00
alehel fcfb66d0c2 fix(media,video,audio): VMD review round 2
- media: correct round 1's frame placement. The picture's position is
  not one value for a file: it starts at the screen's corner and a
  frame with data that is as large as the picture and not at the corner
  moves it for the frames that follow, as ffmpeg was seen to do.
  `picture_rect` now takes the frame's index; `origin()` is gone.
- audio: unknown frame flags are refused for an empty frame too.
- video: count the unpack buffer in the picture budget.
- docs: which sound frames are bounded by what, which cut-short blocks
  are errors, and why sound needs both the flag and a rate.
- tests: ffmpeg's placement cases, the size of the LZ stop, multi-block
  16-bit stereo frames, and an LZ test that compared half its picture.
2026-11-15 01:50:28 +01:00
alehel 75badac3b6 fix(media,video,audio): VMD review round 1
- media: place video frames by the first frame as large as the picture,
  not by the header's position fields, as ffmpeg was seen to do; a
  frame outside the picture has no rectangle.
- media: a file has sound only with the header flag and a sample rate.
- video: stop LZ unpacking at what a picture can use, so a frame's cost
  no longer goes by a length the file states.
- audio: a flags 1 sound frame plays every whole block it holds.
- docs: how sound lines up with pictures, what the buffer count is, and
  which cut-short blocks are errors.
- tests: the frame-count cap, the 0xFF tag near the end of LZ data,
  palette components over 6 bits, the error conversion and the new
  identifiers.
2026-11-15 01:50:28 +01:00
alehel 6ac5f83bb2 feat(media,video,audio): add Sierra VMD demuxer and decoders
Sierra VMD (Video and Music Data) is the video format of Sierra and
Coktel Vision games of the 1990s. Written clean-room from the public
format description at https://wiki.multimedia.cx/index.php/VMD, with
ffmpeg as a black-box oracle.

- craft-media: `vmd` feature, a demuxer for the 816-byte header and the
  table of contents; `Container::Vmd`, `CodecId::VmdVideo` and
  `CodecId::VmdAudio`.
- craft-video: `vmd` feature, a decoder for 8-bit paletted pictures
  (rendering methods 1 to 3, LZ packing, palette changes).
- craft-audio: `vmd-decode` feature, a decoder for 8-bit PCM and 16-bit
  DPCM sound, mono and stereo.
- craft-media-testkit: a VMD fixture writer, since ffmpeg reads VMD but
  cannot write it.

Tests compare the decoders with ffmpeg on generated files, and on real
files when CRAFT_MEDIA_VMD_SAMPLES names a directory of them. 16-bit,
24-bit and Indeo 3 pictures, IMA ADPCM sound and the later header
revisions are not decoded.
2026-11-15 01:50:28 +01:00
Dylan M. Taylor 354acd6a54 Cover Vorbis in format contract tests and assert streaming refusal 2026-11-14 18:15:14 -05:00
Dylan M. Taylor 8ae42d1aeb Merge main and reconcile Vorbis encoding with current audio APIs 2026-11-14 18:12:03 -05:00
Dylan Taylor 630c570789 fix: update tests for vorbis-encode feature (ogg support) 2026-11-14 10:16:33 -05:00
alehel 4732a89b02 craft-audio: review of the format queries
- EncodeFormat::max_channels gave 65535 for WAV and AIFF, whose headers
  hold 32767 (a WAV fewer at wider samples, which the doc now says).
- Tests pin the AAC and MP3 layouts, each format's channel limit with the
  count above it, and every listed sample rate with its neighbours: the
  agreement test alone compared the tables with a writer that reads them.
- Docs: FileEncoder::bitrate points at the rule RateControl::Bitrate
  states; the README says when check exists.

Refs #1230
2026-11-14 09:37:54 +01:00
alehel 1570d6a29a craft-audio: ask what a format takes before writing a file
- EncodeOptions::check says whether a file can be begun, with the error
  FileEncoder::new would return and nothing written.
- EncodeOptions::bitrate and FileEncoder::bitrate give the constant bit
  rate actually used, after it is moved to one the stream can carry.
- EncodeFormat::sample_rates, max_channels, fixed_layouts, supports_layout
  and supports_quality say what a format takes, also when its feature is
  off. The writer reads its layouts from the same table, and tests hold
  the tables to the encoders and to what the writer accepts.

Refs #1230
2026-11-14 08:48:19 +01:00
alehel 6f7c041a09 craft-audio: tests of the coded formats hold on ffmpeg 8 and without AAC
- ffmpeg 8 skips an AAC M4A's priming but plays the last packet's padding
  (ffmpeg 9 cuts it): the ffmpeg oracle test takes either length, and the
  README says which readers end the audio where.
- With alac-encode and no aac-encode, `m4a` names ALAC: the extension test
  compared it with AAC.

Refs #1230
2026-11-14 08:31:05 +01:00
alehel 098eb2e43a craft-audio: review round 3 for the coded formats
- craft-media: Mp4Writer::new refuses a writer positioned where the header
  would end past u64::MAX instead of overflowing the sum (correction to
  round 2, which let the M4A writer reach that addition).
- AAC is written at 6 kbit/s or a quarter of the sample rate per channel at
  least: the encoder accepts lower rates but codes only silence at them, so
  with_bitrate(128) gave a silent file.
- README: what to do with a layout a coded format refuses, and the names
  encode_format_for takes for M4A.

Refs #1230
2026-11-14 03:16:51 +01:00
alehel 63712c33e6 craft-audio: review round 2 for the coded formats
- craft-media: Mp4Writer counts chunk offsets from the first byte of the
  file, not from position 0 of the writer, so a file begun mid-writer is
  valid. This replaces the seek adapter the M4A writer wrapped its sink in.
- Tests pin the bytes of the roll sample group and each format's feature.
- Docs: ALAC's length comes from the sample durations, not an edit list;
  which readers take an empty AAC file; speaker names as the errors print
  them; craft-media's README lists roll_distance.
- Error messages for a layout a format has not no longer suggest setting
  a layout that was set.

Refs #1230
2026-11-14 03:16:51 +01:00
alehel 3dadce4d7c craft-audio: review round 1 for the coded formats
- craft-media: TrackConfig::roll_distance writes a `roll` sample group
  (sgpd + sbgp) over every sample. The AAC M4A track sets -1: Apple's
  decoders took 2112 frames of priming and dropped the start of the audio
  without it (afinfo now reports the frames written and 1024 priming).
- EncodeFormat::is_built and feature: which formats this build writes.
- Clippy: the writer enum's variants differ in size with flac-encode and
  a codec feature but no pcm-encode.
- Tests for the finished sample entry (AAC bit rate, ALAC cookie), ALAC
  dither and afinfo's reading of the priming.
- README: ffmpeg's reading of 8-channel AAC, and files with no audio.

Refs #1230
2026-11-14 03:16:51 +01:00