Commit Graph
55 Commits
Author SHA1 Message Date
dotCooCoo 44afdcfbe1 Merge main into fix/audio-wav-repair 2026-11-28 02:27:23 -08:00
BFlat ca57833b96 Merge pull request #2600 from dotCooCoo/feat/audio-wav-float-header-bext
craft-audio: wav_float_header_with_bwf writes a growing float WAV with a bext chunk
2026-11-28 11:41:21 +07:00
FredApps 582549275d Merge branch 'main' into claude/packet-encoder-2064de 2026-11-26 10:17:30 +01:00
dotCooCoo d5d1e37f9c Merge main into fix/audio-wav-repair 2026-11-25 19:42:38 -08:00
dotCooCoo 6faceab4a1 Merge main into feat/audio-wav-float-header-bext 2026-11-25 19:08:41 -08:00
dotCooCoo 20a4c50d45 craft-audio: repair_wav refuses a short first ds64 and writes the pad byte last
The WAV reader takes an RF64 file's data size from the first ds64 chunk of
16 bytes or more. repair_wav skipped a first ds64 chunk under 28 bytes and
wrote the sizes into a later one, so the frame count it returned differed
from what decoding gave. It now returns Malformed for a first ds64 chunk of
16 to 27 bytes, before writing anything.

repair_wav wrote the pad byte of odd-length data before the size fields. A
write error after the pad left 8-bit mono data of even length with the old
size, which a second repair refused. The pad byte is now written last.
2026-11-20 15:56:01 -08:00
dotCooCoo 40a85523df craft-audio: repair_wav refuses the extensible fmt fields the reader refuses
An extensible fmt chunk with a cbSize below 22, or with more valid bits
than bits per sample, passed repair_wav's checks and was rewritten,
while the WAV reader rejects it as malformed. repair_wav now returns
AudioError::Malformed for both, and its docs list the case.
2026-11-20 15:23:42 -08:00
dotCooCoo 21d0cd6a4a craft-audio: repair_wav and the WAV reader use the first ds64 and fact chunks
An RF64 file with a second ds64 chunk before its data had repair_wav
write the 24-byte size table over the start of that later chunk, leaving
the leading ds64 with its stale sizes, and the reader took the data size
from the last ds64 it met. EBU Tech 3306 places ds64 first after WAVE,
and both now use the first one. repair_wav also writes the frame count
into the first fact chunk instead of the last.
2026-11-20 15:13:20 -08:00
dotCooCoo 53df8e8c07 craft-audio: repair_wav refuses sample widths the WAV reader cannot decode
repair_wav accepted any bit width for PCM and IEEE float, so a 16-bit
float file or PCM wider than 32 bits had its sizes rewritten and was
reported repaired, though the WAV reader still refuses it. repair_wav
now returns Unsupported unless the file is PCM of 1 to 32 bits or float
of 32 or 64 bits, the widths the reader decodes, and leaves the file
unchanged.
2026-11-20 14:44:15 -08:00
dotCooCoo 3228207a0a craft-audio: repair_wav finishes an interrupted RF64 promotion
When repair_wav turns a RIFF file past 4 GiB into RF64, it renames the
JUNK chunk after WAVE to ds64 before it writes RF64. A write error
between the two left a RIFF file with a ds64 chunk there, and every
later repair returned TooLarge. repair_wav now takes a 28-byte ds64
chunk right after WAVE in a RIFF file as the slot to promote.

In a RIFF file, a ds64 chunk further on is no longer used. Before, a
later ds64 chunk took the place of the leading JUNK chunk, so the file
became RF64 with JUNK as its first chunk and the later chunk's table
length was set to 0.
2026-11-20 11:34:58 -08:00
dotCooCoo d24067aac4 craft-audio: repair_wav reads Ambisonic PCM and empties the ds64 table
repair_wav refused an extensible WAV with the Ambisonic PCM or float
subformat, which the WAV reader reads as PCM. The Ambisonic GUID tail
now lives with the other shared WAVE constants and both sides check it.

When a RIFF file past 4 GiB becomes RF64, the last 4 bytes of the
leading JUNK chunk become the ds64 table length. repair_wav wrote only
the first 24 bytes, so a JUNK chunk holding other bytes left a table
length that names entries the file does not have. It now writes a
table length of 0.
2026-11-20 11:21:15 -08:00
dotCooCoo 5d9da61dae craft-audio: repair_wav docs name each field it rewrites and every error
The repair_wav doc comment said every chunk before the data keeps its
contents, but repair rewrites the frame count in a fact chunk, the start
of an existing ds64 chunk, and turns the leading 28-byte JUNK chunk into
ds64 when a RIFF file passes 4 GiB. It now lists the fields it writes
and the bytes it leaves alone. The Errors section now names every case:
Malformed also for the data chunk before fmt, a short fmt chunk, 0
channels or bits, a block size that does not match, no data chunk in the
first 100,000 chunks, and RF64 without ds64; Unsupported for an
extensible format whose subformat is not PCM or float; and Io.
2026-11-20 11:11:10 -08:00
dotCooCoo 16db9400e1 craft-audio: repair_wav rewrites the sizes of a WAV left unfinished by a crash
A recorder that writes the WAV header first and rewrites it as the file
grows leaves stale RIFF, data, ds64 and fact sizes when the process dies.
repair_wav walks the chunks up to the data chunk, counts the whole frames
the file holds and rewrites those fields in place, keeping bext and every
other chunk. It writes the pad byte an odd data length needs, turns a file
past 4 GiB into RF64 when it starts with the JUNK chunk FileEncoder and
wav_float_header reserve, and returns the frame count and the length to
truncate the file to. A finished file is left as it is. Compressed formats,
headers whose block size does not match the channels and bit depth, and
unfinished 8-bit mono data of even length (where a pad byte cannot be told
from a sample) are refused.
2026-11-20 10:55:51 -08:00
dotCooCoo 41920cf890 craft-audio: wav_float_header_with_bwf writes a growing float WAV with a bext chunk
wav_float_header always wrote its header without BWF metadata, so a recorder
that wanted a bext chunk had to splice one into the returned bytes at a fixed
offset. wav_float_header_with_bwf takes a BwfInfo and writes the same header
with the bext chunk in place. Its length still does not depend on the frame
count, so the header is rewritten in place as the file grows, and the finished
file matches encode() with the same BWF metadata byte for byte.
2026-11-20 10:36:32 -08:00
alehelandClaude Fable 5.2 931dfdb121 Merge main into claude/packet-encoder-2064de
Conflict in crates/audio/README.md: the feature table keeps the
PacketEncoder notes on the alac-encode and opus rows and takes the new
vorbis-encode row from main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 12:47:28 +01:00
aiongg dffc61a7e0 Merge storytold main 832883b5 (sync 16 Nov)
961 upstream commits since 7bb6c900. Resolutions:
- Test-only conflicts: upstream tests from before the base that our side
  cut stay cut; tests new upstream are kept (audio aac/config, layout,
  encode_format; cms lutfile; media mux; print windows_native, ticket;
  update self_update; xml hostile).
- Code our side moved, with upstream's change carried to the new place:
  craft-media mux roll sample groups (mux/boxes.rs) and writer-start
  offsets with overflow checks (mux/progressive.rs); craft-print's
  shrink-to-fit scale guard (sheets/plan.rs); craft-update's nextest
  archive detection (self_update/detect.rs); craft-vectorcraft-format's
  Tail::write_to_with (container.rs); craft-i18n's pedantic fixes
  (bidi.rs, negotiation.rs).
- craft-ui: the old crate's modules stay removed; gpu_test_lock guarded
  their per-test wgpu renderers, which the snapshot kit does not have.
- New upstream tests in crates that build their integration tests into
  the library's test executable are modules of tests/main.rs (audio
  flac_decode and qoa_oracle, cms, docpath, pcraft-format,
  vectorcraft-format).
- The 22 new crates are optional members of the craft facade.
2026-11-16 01:52:09 +00: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
alehelandClaude Fable 5.2 24c6cd9c5e Merge main into claude/packet-encoder-2064de
Conflicts in crates/audio/Cargo.toml (the encode feature list gains
vorbis-encode, the QOA features sit above opus-encode) and
crates/audio/src/write/mod.rs (pcm stays pub(crate) for PacketEncoder,
next to the new vorbis module).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-15 21:22:39 +01:00
Dylan M. Taylor 92e665a5e8 Exercise Vorbis block boundaries with distinct channel signals 2026-11-14 18:33:24 -05:00
Dylan M. Taylor dc2b83d7f4 Document Vorbis rate semantics and validate standalone options 2026-11-14 18:13:31 -05:00
Dylan M. Taylor 9efb0a1575 Complete standalone Vorbis feature and option validation 2026-11-14 18:12:40 -05:00
Dylan M. Taylor 8ae42d1aeb Merge main and reconcile Vorbis encoding with current audio APIs 2026-11-14 18:12:03 -05:00
alehelandClaude Opus 5.5 6c7f2159ac craft-audio: PacketEncoder, one packet interface over the encoders
PacketEncoder::new(codec, &EncodeOptions, sample_rate, channels) covers AAC-LC, ALAC, MP3,
AC-3, E-AC-3 and Opus, each behind its feature. It takes planar f32 in WAV channel order,
maps the channels onto the codec's order (quantizing for ALAC at the configured depth), and
returns EncodedPacket { data, pts, duration }; finish() drains the rest. The encoder reports
codec_params() (codec, rate, channels, extradata), layout(), priming(), padding(), bitrate()
and bit_depth() for a muxer.

FileEncoder's coded formats now go through it: the codec dispatch, channel maps and rate
selection moved from write/coded.rs to packet.rs, and coded.rs keeps only the M4A and raw
sinks. The files written are byte-identical to before.

Refs #1230 (point 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 21:59:14 +01:00
Dylan Taylor 630c570789 fix: update tests for vorbis-encode feature (ogg support) 2026-11-14 10:16:33 -05:00
Dylan M. Taylor b9c1dfa18f feat(audio): migrate Ogg Vorbis encoding to craft-audio (PR #26)
- Add vorbis-encode feature with dep:vorbis_rs = "0.5"
- Implement encode_ogg() via VorbisEncoderBuilder matching original behavior:
  - Fixed stream serial 0x4C43_5246, VBR target bitrate (64-500 kbit/s)
  - 4096-frame blocks, panic catch with QualityVbr fallback (target_quality: 0.6)
- Add EncodeFormat::Ogg variant (cfg-gated on vorbis-encode)
- Update ENCODE_EXTENSIONS and encode_format_for() to include .ogg
2026-11-14 10:02:09 -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 e5fa1ac2f9 craft-audio: review round 4 for the coded formats
- craft-media: Mp4Writer counts written bytes with a checked sum, so a
  writer that takes bytes past the last position gets an error, not an
  overflow (correction to round 3, which checked only the header).
- Docs: the AAC bit-rate floor keeps a margin above where the encoder
  codes silence, about half of it.

Refs #1230
2026-11-14 03:22:06 +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
alehel eee76c3fc2 craft-audio: AAC, ALAC, MP3, AC-3 and E-AC-3 as formats of encode and FileEncoder
EncodeFormat gains Aac and Alac (M4A through craft-media's MP4 muxer) and
Mp3, Ac3 and Eac3 (raw streams), so one call writes any of them from
WAV-order f32 audio and EncodeOptions.

- EncodeOptions::rate_control (with_bitrate, with_quality): a bit rate is
  moved to the nearest one the stream can carry; quality is AAC's VBR.
- Channels are mapped onto the codec's order by speaker, from
  EncodeOptions::layout. A layout the format has not is Unsupported
  instead of reaching the wrong speakers.
- M4A: the edit list skips the AAC priming, and the last sample's duration
  is cut so the track ends at the last frame written.
- encode_format_for, ENCODE_EXTENSIONS and EncodeFormat::ALL list the new
  formats; aac-encode and alac-encode now turn on craft-media's isobmff.

Refs #1230
2026-11-14 03:16:51 +01:00
aiongg 25597ecfc7 Media, formats and engine crates: follow-ups from the framework migration 2026-11-12 14:32:38 +00:00
Dylan M. Taylor 119f6e252e craft-audio: integer PCM of WAV and AIFF files bit for bit, and minimal files around it (#917)
wav_pcm and aiff_pcm (feature decode-native) return a file's integer PCM as stored
(RawPcm: little-endian interleaved bytes, 8-bit unsigned, with channels, rate and
bits), built on the existing WAV and AIFF chunk parsers. pcm_wav_file,
pcm_wav_header, pcm_aiff_file and pcm_aiff_header (feature pcm-encode) write the
44-byte canonical WAVE header and the plain AIFF header around such bytes.

For essence embedded in AAF and OMF files, which is moved bit for bit and whose
descriptors hold a bare header as a summary. The writers are FilmCraft's
(filmcraft-interchange wav.rs); the readers replace its second WAV/AIFF parser
with this crate's.
2026-11-11 18:52:13 -05:00
Dylan M. Taylor 56d088bf04 craft-audio: flac::Encoder, the FLAC packet encoder, is public (#809)
* craft-audio: FilmCraft's FLAC encoder and MP1/MP2 decoder speed-ups

FLAC: per-order predictor kernels, merged Rice partition sums, the LPC
window kept per block length, and batches consumed by offset
(filmcraft 5eaff794, d9dad4a5). The output is unchanged: 64 golden cases
hash the same before and after.

MP1/MP2: the faster synthesis filterbank (filmcraft 51c755e5), with its
bit-exact test.

* craft-audio: FilmCraft's AAC and Opus decoder speed-ups and refactors

AAC: table-driven Huffman decoding, per-stage FFT twiddles and fused
stages, reused per-channel work buffers, and the encoder's memoised
per-band work (filmcraft f9627280, d587ceed, 6121635c, dc124ab7,
7a532eca).

Opus: radix-2/3/4 FFT kernels in the CELT IMDCT, the PVQ table built
once, one de-emphasis loop for both channels, the SILK resampler
without per-sample divisions and with eight partial sums, concealment
and FEC capped at 120 ms (filmcraft bf7ac420, 12e32026, c4dc64d1,
eb352ec8, 87b8e22d, 014b5e56, 78d77b72).

The per-frame mid-only flag this crate fixed in the SILK decoder is
kept in the refactored decode.

* craft-media: Ogg CRC-32 by slice-by-16

FilmCraft's 6763f9bf: sixteen independent lookups per 16 input bytes, so
opening a file is several times faster. Checked against a bit-at-a-time
reference on every short length and alignment, and across every split.

* craft-audio: SoundCraft's CAF cookie-size and FLAC vendor-length checks

A CAF magic cookie size above the signed range is refused instead of
passed to symphonia (soundcraft 3bd3965), and a Vorbis comment block
whose vendor string claims more than the block holds is refused
(soundcraft ddfe991). Each with its regression test.

* craft-audio: AC-3 reads bits through the shared BitReader

FilmCraft's 1c9c2e82: the AC-3 decoder's private bit-at-a-time reader is
replaced by craft-media's BitReader, with its two tests: the decoded
output of 2,000 synthetic and 12 real syncframes (and their damaged
variants) hashes the same as before, and the reader agrees with the old
one on random reads, skips and overruns. The three AC-3 features now
turn on craft-media's bitstream module.

* craft-audio: the quantiser rounds without a libm call

SoundCraft's d293336, the audio-io part: round-half-away by integer
arithmetic in the bounce's inner loop, with its test against f64::round
over the quantiser's range.

* craft-audio: flac::Encoder, the FLAC packet encoder, is public

FilmCraft muxes FLAC into its own outputs from integer samples, so it
needs the encoder below FileEncoder: planar samples in, frames out, and
the STREAMINFO to patch in at the end. The module is behind flac-encode,
its errors convert to AudioError::Encode, and pending_samples says how
long the final frame will be.
2026-11-11 11:48:37 -05:00
Dylan M. Taylor 44b4a23137 craft-audio, craft-media: the changes FilmCraft and SoundCraft made to their copies since extraction (#807)
* craft-audio: FilmCraft's FLAC encoder and MP1/MP2 decoder speed-ups

FLAC: per-order predictor kernels, merged Rice partition sums, the LPC
window kept per block length, and batches consumed by offset
(filmcraft 5eaff794, d9dad4a5). The output is unchanged: 64 golden cases
hash the same before and after.

MP1/MP2: the faster synthesis filterbank (filmcraft 51c755e5), with its
bit-exact test.

* craft-audio: FilmCraft's AAC and Opus decoder speed-ups and refactors

AAC: table-driven Huffman decoding, per-stage FFT twiddles and fused
stages, reused per-channel work buffers, and the encoder's memoised
per-band work (filmcraft f9627280, d587ceed, 6121635c, dc124ab7,
7a532eca).

Opus: radix-2/3/4 FFT kernels in the CELT IMDCT, the PVQ table built
once, one de-emphasis loop for both channels, the SILK resampler
without per-sample divisions and with eight partial sums, concealment
and FEC capped at 120 ms (filmcraft bf7ac420, 12e32026, c4dc64d1,
eb352ec8, 87b8e22d, 014b5e56, 78d77b72).

The per-frame mid-only flag this crate fixed in the SILK decoder is
kept in the refactored decode.

* craft-media: Ogg CRC-32 by slice-by-16

FilmCraft's 6763f9bf: sixteen independent lookups per 16 input bytes, so
opening a file is several times faster. Checked against a bit-at-a-time
reference on every short length and alignment, and across every split.

* craft-audio: SoundCraft's CAF cookie-size and FLAC vendor-length checks

A CAF magic cookie size above the signed range is refused instead of
passed to symphonia (soundcraft 3bd3965), and a Vorbis comment block
whose vendor string claims more than the block holds is refused
(soundcraft ddfe991). Each with its regression test.

* craft-audio: AC-3 reads bits through the shared BitReader

FilmCraft's 1c9c2e82: the AC-3 decoder's private bit-at-a-time reader is
replaced by craft-media's BitReader, with its two tests: the decoded
output of 2,000 synthetic and 12 real syncframes (and their damaged
variants) hashes the same as before, and the reader agrees with the old
one on random reads, skips and overruns. The three AC-3 features now
turn on craft-media's bitstream module.

* craft-audio: the quantiser rounds without a libm call

SoundCraft's d293336, the audio-io part: round-half-away by integer
arithmetic in the bounce's inner loop, with its test against f64::round
over the quantiser's range.
2026-11-11 11:32:33 -05:00
alehelandClaude Opus 5.5 542ca365e2 craft-audio: review fixes, round 7 (#443)
Reading:
- an element of another type or a tag a program config does not list is
  refused, not written to another channel; only an LFE coded as an SCE
  is still allowed, as ffmpeg allows it
- an explicit sampling rate of 0 is refused
- a packet's later ADTS frames are searched for SBR
- a multi-frame ADTS packet that fails leaves the decoder as it was, and
  one whose frames change the channel count is an error
- the whole ADTS frames before a damaged end of a packet decode
- a failed read of a raw stream's first frames is an I/O error
- an MP4 sample of several ADTS frames past the lookahead keeps its length
- an Ogg file with leading bytes keeps its track order and mask comments

Writing:
- ProgramConfig::write, AudioSpecificConfig::to_bytes and
  AdtsHeader::write refuse what their fields cannot hold

Tests:
- the routing test checks one alignment for the ffmpeg version under test
- a default decode past an Ogg stream symphonia has no track for

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 06:37:50 +01:00
alehelandClaude Opus 5.5 04df866591 craft-audio: review fixes, round 17 (#442)
The Ogg track tests set their files' serial numbers instead of writing
the files until ffmpeg happens to pick the wanted order. They rewrite
each page's serial and checksum, so both orders run with one ffmpeg call
and do not depend on ffmpeg's serials being random.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 21:06:42 +01:00
alehelandClaude Opus 5.5 e8b7c40ea0 craft-audio: review fixes, round 16 (#442)
The Ogg track tests no longer depend on chance. Each writes its file
until the serial numbers are in the order it asks for, in both orders,
so the reversed order that told the old code apart always runs. A file
this ffmpeg cannot write goes through `skip`, which fails the test when
oracles are required.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 19:45:11 +01:00
alehelandClaude Opus 5.5 a4f02a3854 craft-audio: review fixes, round 15 (#442)
A track index in an Ogg file means the same stream everywhere: the
file's order, as `tracks` lists them. Streams the native path does not
read fell back to symphonia with the same index, but symphonia orders
tracks by serial, which ffmpeg picks at random. A file could decode the
wrong track, or fail on a FLAC stream listed before an Opus one.

The tests write each file eight times, so both serial orders occur, and
cover a track with no mask comment next to one with a mask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 15:32:10 +01:00
alehelandClaude Opus 5.5 2f4fb8bfe0 craft-audio: review fixes, round 14 (#442)
Each FLAC stream in an Ogg file reads its own channel mask comment. The
tags symphonia's reader collects do not say which track they are from,
so a track could get another track's mask. The masks now come from
craft-media's Ogg demuxer, by serial, which is symphonia's track ID.

The Ogg layout test also covers 7 channels with no comment and a zero
mask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 15:09:27 +01:00
alehelandClaude Opus 5.5 99dcf517a4 craft-audio: review fixes, round 13 (#442)
FLAC in Ogg reads its layout the way a FLAC file does: from the mask
comment, or else the one decoders assume for the count. Without this, a
6-channel stream with no comment reported back surrounds in Ogg and side
surrounds in a FLAC file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 14:49:49 +01:00
alehelandClaude Opus 5.5 57f5d063fe craft-audio: review fixes, round 12 (#442)
- FLAC files read their layout from the channel mask comment, or else
  the one decoders assume for the count, which is what the writer omits
  the comment for
- an unbuilt format is Unsupported before the layout is checked
- FLAC encode no longer reserves half the PCM size up front
- flac-encode's lib tests stream a file and compare it with encode
- the seek test compares samples after the seek

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:51:18 +01:00
alehelandClaude Opus 5.5 1a9f579a07 craft-audio: review fixes, round 11 (#442)
No change in output: the 74 oracle test streams are byte-identical.

- The Wasted case is handled in one function, without the unreachable arm
  and the wrapper round 8 added.
- The bitstream writer uses predict::fold, the tested copy, not its own.
- STREAMINFO's MD5 may be 0 (RFC 9639 §8.2), so the comment no longer says
  the RFC requires it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:35:44 +01:00
alehelandClaude Opus 5.5 afdc045e94 craft-audio: review fixes, round 10 (#442)
Tests only; each was confirmed to fail on a mutated encoder.

- Every sample rate code in the frame header table.
- Signals that reach the Rice parameter and LPC shift limits, where a
  value past the limit gives a file decoders refuse.
- ENCODE_EXTENSIONS lists flac.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:35:44 +01:00
alehelandClaude Opus 5.5 5617261fdc craft-audio: review fixes, round 9 (#442)
Refuse a linear predictor whose prediction leaves the i32 range. Such a
stream is valid, but symphonia adds the prediction to the residual as an
i32, which panics in a debug build. The round 8 residual limit made this
reachable at 24 bits; without the override, 13 of 240 clipped 32-bit test
streams failed in a debug build and none do now, for 0.09% more bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:35:44 +01:00
alehelandClaude Opus 5.5 82f63f3a4f craft-audio: review fixes, round 8 (#442)
- Code wasted bits (RFC 9639 §9.2.2): low bits that are zero in every
  sample of a subframe were stored anyway, so 16-bit audio exported at 24
  or 32 bits grew by the padding.
- Allow residuals up to the 32-bit limit (§9.2.7.3). The limit was half
  that, so at 32 bits a transient forced its whole block to verbatim.
- README: 32-bit FLAC codes stereo channels independently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:35:44 +01:00
alehelandClaude Opus 5.5 c008e8ee07 craft-audio: review fixes, round 7 (#442)
- Test the high bits of STREAMINFO's total sample count, and that a total
  past 36 bits is left unknown.
- README limits: the usual 5- and 6-channel layouts depend on the mask
  comment too; say what is outside the streamable subset.
- Comments: 32-bit code 0 does not decode everywhere and leaves the
  subset; the oracle test helper is in craft_media_testkit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:35:44 +01:00
alehelandClaude Opus 5.5 430ad15683 craft-audio: review fixes, round 6 (#442)
Tests only, plus docs; the encoder does not change. Each new check was
confirmed to fail on a mutated encoder.

- Tests: frame numbers count up, LPC and Rice partitions and stereo
  decorrelation save the space they should, FileEncoder records a FLAC
  layout, the smallest frame anywhere reaches STREAMINFO, Writer::write
  applies the frame limit, finish leaves the sink at the end, the exact
  655350 Hz cap, the sample size codes.
- README limits: a FLAC layout decoders would not assume depends on its
  mask comment, and ffmpeg and flac ignore a zero mask.
- The encode example's comment named no referent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:35:44 +01:00
alehelandClaude Opus 5.5 82424e59c3 craft-audio: review fixes, round 5 (#442)
- libFLAC and ffmpeg read a FLAC with 5 or 6 channels and no mask comment
  as having side surrounds, so the comment is now written for anything
  else, including the crate's usual back-surround layouts. The round 3
  check treated back surrounds as FLAC's assignment, which lost them.
- Tests: the mask comment rules, opposite-polarity stereo, STREAMINFO
  block and frame sizes.
- A stale comment said only WAV records the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:35:44 +01:00