test: use valid encoded PCE layout for AAC downmix parity

This commit is contained in:
Dylan M. Taylor
2026-11-16 11:09:24 -05:00
parent b842402a83
commit e9d5f37561
5 changed files with 82 additions and 27 deletions
+7 -1
View File
@@ -155,4 +155,10 @@ under [`docs/brand/LICENSE-brand.txt`](docs/brand/LICENSE-brand.txt). Forks and
| `docs/brand/artcraft-mark.png` | ArtCraft Team | Original work: first-party ArtCraft brand mark (ArtCraft symbol ("A" mark), blue) | ArtCraft brand terms, not open source (`docs/brand/LICENSE-brand.txt`) |
| `docs/brand/artcraft-mark.svg` | ArtCraft Team | Original work: first-party ArtCraft brand mark (ArtCraft symbol ("A" mark), blue) | ArtCraft brand terms, not open source (`docs/brand/LICENSE-brand.txt`) |
- Appearance theme previews, drawn procedurally from original shapes: `crates/ui-egui/src/panels/settings.rs` (original work, MIT OR Apache-2.0).
- Appearance theme previews, drawn procedurally from original shapes: `crates/ui-egui/src/panels/settings.rs` (original work, MIT OR Apache-2.0).
## Synthetic test audio
| Asset | Author | Source | Licence |
|---|---|---|---|
| `crates/media/tests/fixtures/pce61-ffmpeg.aac-fixture` | Dylan M. Taylor | Original sine waves; reproducible recipe in `crates/media/tests/fixtures/README.md` | MIT OR Apache-2.0 |
+31
View File
@@ -0,0 +1,31 @@
# Synthetic AAC layout fixture
`pce61-ffmpeg.aac-fixture` contains only original mathematical sine tones generated for these tests by Dylan M. Taylor. No recorded audio or third-party source/assets were copied; the generated fixture is covered by this repository's license. FFmpeg is a generation tool, not a runtime test dependency.
Generator: FFmpeg 7.1.5 (Debian 7.1.5-0+deb13u1, AAC encoder Lavc61.19.101).
SHA-256: `07c460636dce4aa4163df8ef35f3b76f1214c38bf217aacd23243e608d87071e`.
The seven PCM inputs are FL500Hz, FR700Hz, FC300Hz, LFE60Hz, BC900Hz, SL1100Hz, SR1300Hz, each amplitude0.25 at48kHz for2seconds. The real encoder emits its own PCE and matching element tags; unlike the previous synthetic configuration rewrite, no LFE element is mislabeled as an unlisted SCE.
Reproduce using FFmpeg/ffprobe and Python3:
```sh
ffmpeg -hide_banner -loglevel error -f lavfi -i 'aevalsrc=0.25*sin(2*PI*500*t)|0.25*sin(2*PI*700*t)|0.25*sin(2*PI*300*t)|0.25*sin(2*PI*60*t)|0.25*sin(2*PI*900*t)|0.25*sin(2*PI*1100*t)|0.25*sin(2*PI*1300*t):s=48000:d=2:c=6.1' -c:a aac -b:a 672k pce61.m4a
ffprobe -v error -show_streams -show_packets -show_data -of json pce61.m4a > pce61.json
python3 - <<'PY'
import json, struct
x = json.load(open('pce61.json'))
def raw(text):
return bytes.fromhex(''.join(line.split(': ', 1)[1].split(' ', 1)[0].replace(' ', '')
for line in text.strip().splitlines()))
asc = raw(x['streams'][0]['extradata'])
units = [raw(p['data']) for p in x['packets']]
assert len(units) == 95
output = bytearray(b'PCE1')
for record in [asc, *units]:
output += struct.pack('>I', len(record)) + record
open('pce61-ffmpeg.aac-fixture', 'wb').write(output)
PY
```
Envelope: ASCII `PCE1`, then a big-endian32-bit length and ASC bytes, then95 length-prefixed raw AAC access units. Container priming trim is deliberately not retained, matching the existing tests' encoder units; measurements start0.5seconds into decoded audio. Other encoder versions can yield different bytes; preserve actual PCE/AU consistency and all existing tone-gain assertions.
Binary file not shown.
@@ -0,0 +1,7 @@
asset: pce61-ffmpeg.aac-fixture
title: Synthetic seven-channel AAC PCE tone fixture
author: Dylan M. Taylor
source: crates/media/tests/fixtures/README.md (reproducible generation recipe)
license: MIT OR Apache-2.0
added: 2026-11-16
notes: Original sine-wave signals, no recorded audio or copied assets. Encoded using FFmpeg 7.1.5. SHA-256 07c460636dce4aa4163df8ef35f3b76f1214c38bf217aacd23243e608d87071e.
+37 -26
View File
@@ -1,7 +1,8 @@
//! Multichannel AAC reaches stereo by where each channel plays, whatever order its channel
//! configuration decodes in (#1701). Fixtures are tones encoded with craft-audio's AAC encoder (no
//! ffmpeg needed, so nothing is skipped), with the configuration rewritten where the coded
//! elements fit another: configurations 11 and 12 code the same elements as the encoder's 7- and
//! configuration decodes in (#1701). Fixtures are tones encoded with craft-audio's AAC encoder,
//! plus a checked-in genuine FFmpeg-generated 6.1-channel fixture (no external tool at test time, nothing skipped).
//! The configuration is rewritten only where the coded elements fit another: configurations 11
//! and 12 code the same elements as the encoder's 7- and
//! 8-channel output, and a program config element can name any of them.
use std::f64::consts::PI;
@@ -9,7 +10,7 @@ use std::io::Cursor;
use std::path::PathBuf;
use std::sync::Arc;
use craft_audio::aac::{AudioSpecificConfig, Encoder, EncoderConfig, ProgramConfig};
use craft_audio::aac::{AudioSpecificConfig, Encoder, EncoderConfig};
use effectcraft_media::{MediaPool, probe, probe_bytes};
use effectcraft_time::Tick;
@@ -59,13 +60,6 @@ fn lc(config: u8) -> Option<AudioSpecificConfig> {
Some(AudioSpecificConfig::lc(3, config))
}
fn pce(front: Vec<(bool, u8)>, side: Vec<(bool, u8)>, back: Vec<(bool, u8)>, lfe: Vec<u8>, comment: &[u8]) -> Option<AudioSpecificConfig> {
let pce = ProgramConfig { object_type: 1, sf_index: 3, front, side, back, lfe, comment: comment.to_vec(), ..Default::default() };
let mut asc = AudioSpecificConfig::lc(3, 0);
asc.pce = Some(pce);
Some(asc)
}
use Ch::*;
fn cases() -> Vec<Case> {
@@ -80,15 +74,9 @@ fn cases() -> Vec<Case> {
Case { name: "config12", content: &[C, L, R, Ls, Rs, Ls, Rs, Lfe], asc: lc(12) },
// the encoder's own 6.1: a PCE listing the centre first
Case { name: "pce61-centre-first", content: &[C, L, R, Ls, Rs, Cs, Lfe], asc: None },
// ffmpeg's 6.1 PCE: front pair and centre, a side SCE, a back pair and SCE, no LFE
// element, its channels in ffmpeg's order L R C LFE Cs Ls Rs. The decoder places the
// encoder's SCE 0 in the front SCE, pair 0 front, pair 1 back, SCE 1 in the back SCE (tag
// 1) and the LFE in the side SCE left over (tag 5).
Case {
name: "pce61-ffmpeg",
content: &[C, L, R, Cs, Ls, Rs, Lfe],
asc: pce(vec![(true, 0), (false, 0)], vec![(false, 5)], vec![(true, 1), (false, 1)], vec![], b"Lavc62.28.102"),
},
// A genuine FFmpeg-generated 6.1-channel PCE and matching coded elements; rewriting only the ASC of
// our encoder's LFE0 stream to claim a side SCE5 would make an invalid access unit.
Case { name: "pce61-ffmpeg", content: &[C, L, R, Cs, Ls, Rs, Lfe], asc: None },
]
}
@@ -110,6 +98,32 @@ fn encode(content: &[Ch], adts: bool) -> (Vec<u8>, Vec<Vec<u8>>) {
(enc.audio_specific_config(), units)
}
/// Preserve the fixture's real element types/tags instead of changing only its ASC.
/// The envelope and reproducible tone-generation recipe are in `tests/fixtures/README.md`.
fn encode_case(case: &Case) -> (Vec<u8>, Vec<Vec<u8>>) {
if case.name == "pce61-ffmpeg" {
let bytes = include_bytes!("../fixtures/pce61-ffmpeg.aac-fixture");
assert_eq!(&bytes[..4], b"PCE1");
let mut rest = &bytes[4..];
let mut record = || {
let len = u32::from_be_bytes(rest[..4].try_into().unwrap()) as usize;
let (data, tail) = rest[4..].split_at(len);
rest = tail;
data.to_vec()
};
let asc = record();
let mut units = Vec::new();
// The generated fixture contains 95 access units (including encoder priming).
for _ in 0..95 {
units.push(record());
}
assert!(rest.is_empty(), "fixture has no unparsed records");
return (asc, units);
}
let (asc, units) = encode(case.content, false);
(case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC")), units)
}
fn mp4(asc: Vec<u8>, channels: u32, units: &[Vec<u8>]) -> Vec<u8> {
mp4_after(None, asc, channels, units)
}
@@ -211,8 +225,7 @@ fn lfe_is_coded(case: &Case, bytes: Vec<u8>) {
#[test]
fn every_aac_layout_mixes_by_speaker_in_mp4() {
for case in cases() {
let (asc, units) = encode(case.content, false);
let asc = case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC"));
let (asc, units) = encode_case(&case);
let bytes = mp4(asc, case.content.len() as u32, &units);
lfe_is_coded(&case, bytes.clone());
let p = write(&format!("{}.mp4", case.name), &bytes);
@@ -228,8 +241,7 @@ fn every_aac_layout_mixes_by_speaker_in_mp4() {
#[test]
fn matroska_aac_layouts_mix_by_speaker() {
for case in cases().into_iter().filter(|c| matches!(c.name, "config12" | "pce61-centre-first" | "pce61-ffmpeg")) {
let (asc, units) = encode(case.content, false);
let asc = case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC"));
let (asc, units) = encode_case(&case);
let p = write(&format!("{}.mkv", case.name), &mkv(asc, case.content.len() as u32, &units));
check(case.name, case.content, &mix(&MediaPool::new(), &probe(&p).expect("probe")));
}
@@ -254,8 +266,7 @@ fn an_empty_audio_track_lends_its_configuration_to_no_other() {
let case = cases().into_iter().find(|c| c.name == name).expect("case");
let n = case.content.len() as u32;
let empty = Some((AudioSpecificConfig::lc(3, empty).to_bytes().expect("ASC"), n));
let (asc, units) = encode(case.content, false);
let asc = case.asc.as_ref().map_or(asc, |a| a.to_bytes().expect("ASC"));
let (asc, units) = encode_case(&case);
let p = write(&format!("{name}-after-empty.mp4"), &mp4_after(empty.clone(), asc.clone(), n, &units));
check(&format!("{name} MP4"), case.content, &mix(&MediaPool::new(), &probe(&p).expect("probe")));
let p = write(&format!("{name}-after-empty.mkv"), &mkv_after(empty, asc, n, &units));