forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits

make-heaac-fixtures.sh67 lines, 3.1 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Deterministic HE-AAC v1 fixture matrix for tests/sbr_real_library.rs's
3# `synthetic_heaac_matrix`: two sample-rate families (48000, 44100) x four
4# bitrates (32k/48k/64k/96k) x two profiles (aac_he, aac_low control) = 16
5# .m4a files, sweeping the SBR crossover (kx/k2) that bitrate controls
6# without depending on any one real file's content.
7#
8# `ffmpeg`'s system libfdk_aac (the `fdk-aac-free` package) has SBR/PS
9# encoding compiled out (patent-restricted tools) -- `-profile:a aac_he`
10# fails with "Unable to set the AOT 5: Invalid config" against it. RPM
11# Fusion's full `fdk-aac` package carries the SBR-capable encoder but
12# installs to its OWN /usr/lib64/fdk-aac dir specifically so it doesn't
13# clobber the system one; this script fetches (no root) and extracts just
14# that .so into a local cache and points ffmpeg at it via
15# LD_LIBRARY_PATH for the encode step only, never touching the system
16# library.
17set -euo pipefail
18
19SCRATCH="${EC_AAC_HEAAC_FIXTURES:-$(cd "$(dirname "$0")/../.." && pwd)/.cache/heaac-fixtures}"
20mkdir -p "$SCRATCH"
21CACHE="$SCRATCH/.fdk-aac-full"
22mkdir -p "$CACHE"
23
24fdk_libdir="$CACHE/usr/lib64/fdk-aac"
25if [ ! -f "$fdk_libdir/libfdk-aac.so.2" ]; then
26 echo "fetching SBR-capable libfdk-aac (no root, local cache only)..."
27 ( cd "$CACHE" && dnf download fdk-aac.x86_64 )
28 rpm_file=$(find "$CACHE" -maxdepth 1 -name 'fdk-aac-*.rpm' | head -1)
29 ( cd "$CACHE" && rpm2cpio "$rpm_file" | cpio -idm --quiet )
30fi
31export LD_LIBRARY_PATH="$fdk_libdir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
32
33# Three summed sweeps 100 Hz -> 18 kHz over the full 30 s (phase(t) =
34# 2*pi*(f0*t + (f1-f0)/(2T)*t^2), f0=100 f1=18000 T=30 ->
35# (f1-f0)/(2T)=298.333), offset in phase per partial and per channel so
36# left/right are correlated but not identical -- plus low-level pink noise
37# (seeded, so every run of this script reproduces bit-identical fixtures).
38sweep() { echo "0.15*sin(2*PI*(100*t+298.333*t*t)+$1)+0.15*sin(2*PI*(100*t+298.333*t*t)+$2)+0.15*sin(2*PI*(100*t+298.333*t*t)+$3)"; }
39L=$(sweep 0 1.047 2.094)
40R=$(sweep 0.5 1.571 2.618)
41
42synth_source() {
43 local rate=$1 out=$2
44 ffmpeg -y -hide_banner -loglevel error -filter_complex "
45 aevalsrc=exprs='${L}|${R}':channel_layout=stereo:sample_rate=${rate}:duration=30 [tone];
46 anoisesrc=color=pink:amplitude=0.05:seed=42:sample_rate=${rate}:duration=30 [n0];
47 anoisesrc=color=pink:amplitude=0.05:seed=43:sample_rate=${rate}:duration=30 [n1];
48 [n0][n1] amerge=inputs=2 [noise];
49 [tone][noise] amix=inputs=2:normalize=0 [out]
50 " -map "[out]" -ar "$rate" -sample_fmt s16 -f wav "$out"
51}
52
53for rate in 48000 44100; do
54 src="$SCRATCH/src_${rate}.wav"
55 [ -f "$src" ] || synth_source "$rate" "$src"
56 for br in 32k 48k 64k 96k; do
57 he="$SCRATCH/heaac_${rate}_${br}.m4a"
58 lc="$SCRATCH/lc_${rate}_${br}.m4a"
59 [ -f "$he" ] || ffmpeg -y -hide_banner -loglevel error -i "$src" \
60 -c:a libfdk_aac -profile:a aac_he -b:a "$br" "$he"
61 [ -f "$lc" ] || ffmpeg -y -hide_banner -loglevel error -i "$src" \
62 -c:a libfdk_aac -profile:a aac_low -b:a "$br" "$lc"
63 done
64done
65
66echo "fixtures in $SCRATCH:"
67ls "$SCRATCH"/*.m4a