Commit Graph
6 Commits
Author SHA1 Message Date
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