#!/usr/bin/env bash # Checks --audio-input, --audio-input-volume and --audio-input-threshold against a private PulseAudio server (never the # desktop's, tools/wecompare/wine/audio_sink.sh): a tone plays into a null sink that stands for a microphone while the # default output stays silent, and the engine's own capture statistics (LWE_AUDIO_STATS) say what it listened to. # Usage: tools/check_audio_input.sh [scene dir] [assets dir] set -uo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BINARY=${1:?engine binary} SCENE=${2:-/workspace/SteamLibrary/steamapps/workshop/content/431960/1509527803} ASSETS=${3:-/workspace/SteamLibrary/steamapps/common/wallpaper_engine/assets} SINK="$HERE/wecompare/wine/audio_sink.sh" work=$(mktemp -d /tmp/lwe-audio-input.XXXXXX) trap 'kill $(jobs -p) 2>/dev/null; "$SINK" stop > /dev/null 2>&1; rm -rf "$work"' EXIT [ -d "$SCENE" ] || { echo "SKIP: $SCENE is not installed"; exit 0; } "$SINK" start || { echo "SKIP: no private PulseAudio"; exit 0; } eval "$("$SINK" env)" export HEADLESS_RENDER_PULSE_SERVER=$PULSE_SERVER unset PULSE_SERVER private_pactl () { PULSE_SERVER=$HEADLESS_RENDER_PULSE_SERVER pactl "$@"; } private_pactl load-module module-null-sink sink_name=lwe_mic rate=44100 channels=2 sink_properties=device.description=lwe_mic > /dev/null || exit 1 failures=0 fail () { echo "FAIL $1"; failures=$((failures + 1)); } # a 440 Hz tone (sine's 1/8 amplitude times the given factor) into the "microphone" sink for 14 seconds play_tone () { PULSE_SERVER=$HEADLESS_RENDER_PULSE_SERVER ffmpeg -loglevel quiet -f lavfi -i "sine=frequency=440:sample_rate=44100" -af "volume=$1,aformat=channel_layouts=stereo" \ -t 14 -f pulse -device lwe_mic tone > /dev/null 2>&1 & } # runs the engine for a few seconds and keeps its capture statistics lines in $work/