#!/usr/bin/env bash
# Writes fixture.wav: a generated test signal of tone, noise and exact
# digital zero, made by sox. It is not a recording of anything.
#   3.0 s tone, 4.2 s noise, 5.0 s tone, 6.0 s zero, 2.0 s tone,
#   1.5 s noise, 4.0 s tone, 8.0 s noise, 1.0 s tone (34.7 s, 16 kHz, mono)
# Tone is 440 Hz at 0.3 full scale, noise is sox whitenoise at 0.003.
# -D turns dither off so the zero stays exact; -R makes every run the same.
set -euo pipefail
out=${1:-fixture.wav}
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
gen() { sox -R -D -n -r 16000 -b 16 -c 1 "$tmp/$1.wav" "${@:2}"; }
tone() { gen "$1" synth "$2" sine 440 vol 0.3; }
noise() { gen "$1" synth "$2" whitenoise vol 0.003; }
tone t1 3.0
noise n1 4.2
tone t2 5.0
gen z1 trim 0 6.0
tone t3 2.0
noise n2 1.5
tone t4 4.0
noise n3 8.0
tone t5 1.0
cd "$tmp"
sox -R -D t1.wav n1.wav t2.wav z1.wav t3.wav n2.wav t4.wav n3.wav t5.wav joined.wav
cd - >/dev/null
mv "$tmp/joined.wav" "$out"
echo "$out: $(soxi -D "$out") s of generated tone, noise and zero"
