forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

gen-mp3-fixtures.sh69 lines, 2.8 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# MP3 fixtures beyond the family matrix in gen-fixtures.sh: every Layer III
3# sampling frequency (MPEG-1, MPEG-2 LSF and MPEG-2.5), both channel modes,
4# CBR and VBR, on material that forces block switching and a wide spread of
5# Huffman tables.
6#
7# The family matrix only covers 44.1/48 kHz stereo and mono at one bitrate,
8# which leaves the LSF side info, the 8 kHz band layout and the short-block
9# path unexercised — every one of those is a separate table in the decoder.
10#
11# Output: fixtures/audio/mp3ext-<mode>-<rate>-<setting>.mp3 (gitignored).
12set -euo pipefail
13
14here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
15FIXTURES="$here/../fixtures"
16mkdir -p "$FIXTURES/audio"
17
18src="$FIXTURES/audio/.mp3src.wav"
19if [ ! -f "$src" ]; then
20 # A tone with a glide, broadband noise and a click every half second: the
21 # click is what makes an encoder switch to short blocks, and the noise is
22 # what makes it reach for the escape-coded Huffman tables.
23 left="0.35*sin(2*PI*440*t+3*sin(2*PI*1.5*t))+0.12*(random(0)-0.5)+0.7*lt(mod(t\,0.5)\,0.002)"
24 right="0.30*sin(2*PI*443*t)+0.12*(random(1)-0.5)+0.7*lt(mod(t\,0.5)\,0.002)"
25 ffmpeg -v error -y -f lavfi -i "aevalsrc='${left}'|'${right}':d=3:s=48000" \
26 -c:a pcm_s16le "$src"
27fi
28
29# The same material as PCM, mono and stereo, for the encoder's quality table:
30# a tone fixture cannot tell two encoders apart, and this one can.
31for rate in 44100 48000; do
32 for mode in mono stereo; do
33 channels=1
34 [ "$mode" = stereo ] && channels=2
35 ffmpeg -v error -y -i "$src" -ar "$rate" -ac "$channels" -c:a pcm_s16le \
36 "$FIXTURES/audio/mp3src-${mode}-${rate}.wav"
37 done
38done
39
40RATES=(48000 44100 32000 24000 22050 16000 12000 11025 8000)
41made=0
42for rate in "${RATES[@]}"; do
43 for mode in mono stereo; do
44 channels=1
45 [ "$mode" = stereo ] && channels=2
46 for setting in cbr128 cbr320 vbr2; do
47 case "$setting" in
48 cbr128) opts=(-b:a 128k) ;;
49 cbr320) opts=(-b:a 320k) ;;
50 vbr2) opts=(-q:a 2) ;;
51 esac
52 # MPEG-2/2.5 rates cap out well below 320 kbit/s.
53 if [ "$setting" = cbr320 ] && [ "$rate" -lt 32000 ]; then
54 continue
55 fi
56 out="$FIXTURES/audio/mp3ext-${mode}-${rate}-${setting}.mp3"
57 ffmpeg -v error -y -i "$src" -ar "$rate" -ac "$channels" \
58 -c:a libmp3lame "${opts[@]}" "$out"
59 made=$((made + 1))
60 done
61 done
62done
63# One simple-stereo file: LAME picks joint stereo by default, so the plain
64# left/right path would otherwise never be decoded.
65ffmpeg -v error -y -i "$src" -ar 44100 -ac 2 -c:a libmp3lame -b:a 192k \
66 -joint_stereo 0 "$FIXTURES/audio/mp3ext-simplestereo-44100-cbr192.mp3"
67made=$((made + 1))
68
69echo "wrote $made MP3 fixtures to $FIXTURES/audio"