compare.sh 1.2 KB

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. # compare.sh [work dir]: renders every scenario with OpenAL Soft 1.21.1 and with the engine's port and checks that
  3. # the outputs are bit-identical. OpenAL runs with an empty HOME/XDG dirs: it would otherwise pick up the system's
  4. # alsoft.conf or /usr/share/openal/hrtf (a newer OpenAL's data set) instead of the built-in one WE uses
  5. set -uo pipefail
  6. W=${1:-$HOME/.cache/lwe-openal-1.21.1}
  7. cd "$W" || exit 1
  8. mkdir -p empty out
  9. status=0
  10. for s in moving center impulse stereo; do
  11. env -i HOME=$W/empty XDG_DATA_DIRS=$W/empty XDG_CONFIG_DIRS=$W/empty ./ref $s out/ref_$s.f32 2> out/ref_$s.log
  12. ./ours $s out/ours_$s.f32 2> out/ours_$s.log
  13. python3 - "$s" <<'PY' || status=1
  14. import sys, numpy as np
  15. s = sys.argv[1]
  16. a = np.fromfile(f'out/ref_{s}.f32', np.float32).reshape(-1, 2)
  17. b = np.fromfile(f'out/ours_{s}.f32', np.float32).reshape(-1, 2)
  18. # OpenAL stops a voice whose data ran out, ours keeps mixing the zeros after it, compare up to there
  19. n = 60 * 1024 if s == 'stereo' else len(a)
  20. d = np.abs(a[:n] - b[:n]).max()
  21. print(f'{s:8} peak {np.abs(a).max():.5f} max diff {d:.3g} {"identical" if d == 0 else "DIFFERENT"}')
  22. sys.exit(0 if d == 0 else 1)
  23. PY
  24. done
  25. exit $status