Files
dante_beacon/test_dep_asrc_onedeviceperchannel.sh

149 lines
3.7 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -euo pipefail
# Quiet locale warnings (optional)
export LC_ALL="${LC_ALL:-C}"
OUTPUT_DIR="./tmp"
DURATION=10
RATE=48000
FORMAT="S16_LE"
CHANNELS=1
TIMESTAMP="$(date +%Y%m%d_%H%M%S)"
mkdir -p "$OUTPUT_DIR"
echo "======================================================"
echo "DEP ASRC -> ALSA Loopback -> dsnoop Test (parallel)"
echo "======================================================"
echo "Recording one channel from each device IN PARALLEL:"
echo " dante_asrc_ch1 .. dante_asrc_ch6"
echo "Duration: $DURATION seconds"
echo "Output directory: $OUTPUT_DIR"
echo "Timestamp: $TIMESTAMP"
echo "======================================================"
echo ""
# Check if DEP is running
if ! pgrep -f "dep_manager" >/dev/null; then
echo "ERROR: DEP is not running!"
echo "Start DEP first: cd /home/caster/dante_beacon && sudo bash dep.sh start"
exit 1
fi
device_exists() {
local dev="$1"
aplay -L 2>/dev/null | grep -qx "$dev" || arecord -L 2>/dev/null | grep -qx "$dev"
}
loopback_present() {
# Hardware device list is more reliable than arecord -L naming
arecord -l 2>/dev/null | grep -qi "Loopback" || aplay -l 2>/dev/null | grep -qi "Loopback"
}
# Warn (dont hard-fail) if Loopback hardware isn't visible
if ! loopback_present; then
echo "WARNING: ALSA Loopback hardware not found in 'arecord -l' / 'aplay -l'."
echo "If you expect Loopback, load it with:"
echo " sudo modprobe snd-aloop"
echo ""
fi
# Ensure our virtual per-channel devices exist (from your asound.conf)
missing=0
for i in $(seq 1 6); do
if ! device_exists "dante_asrc_ch${i}"; then
echo "ERROR: dante_asrc_ch${i} not found (asound.conf not applied?)"
missing=1
fi
done
if [ "$missing" -ne 0 ]; then
echo ""
echo "Hint: list relevant devices with:"
echo " arecord -L | grep -E 'dante_asrc_(shared6|ch[1-6])' -n"
echo ""
exit 1
fi
# Track background jobs
declare -a DEVICES=()
declare -a FILES=()
declare -a PIDS=()
cleanup() {
echo ""
echo "Stopping recordings..."
for pid in "${PIDS[@]:-}"; do
kill "$pid" 2>/dev/null || true
done
wait 2>/dev/null || true
echo "Done."
}
trap cleanup INT TERM
echo "Launching recordings..."
for i in $(seq 1 6); do
DEVICE="dante_asrc_ch${i}"
OUTPUT_FILE="${OUTPUT_DIR}/${DEVICE}_${TIMESTAMP}.wav"
LOG_FILE="${OUTPUT_DIR}/${DEVICE}_${TIMESTAMP}.log"
echo " -> $DEVICE => $OUTPUT_FILE"
arecord -D "$DEVICE" \
-c "$CHANNELS" -f "$FORMAT" -r "$RATE" -d "$DURATION" \
"$OUTPUT_FILE" >"$LOG_FILE" 2>&1 &
pid=$!
DEVICES+=("$DEVICE")
FILES+=("$OUTPUT_FILE")
PIDS+=("$pid")
done
echo ""
echo "All recordings started. Waiting for completion..."
echo ""
SUCCESS_COUNT=0
FAIL_COUNT=0
for idx in "${!PIDS[@]}"; do
pid="${PIDS[$idx]}"
dev="${DEVICES[$idx]}"
out="${FILES[$idx]}"
if wait "$pid"; then
if [ -f "$out" ]; then
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
size="$(ls -lh "$out" | awk '{print $5}')"
echo "OK $dev -> $out ($size)"
else
FAIL_COUNT=$((FAIL_COUNT + 1))
echo "FAIL $dev -> file not created: $out"
fi
else
FAIL_COUNT=$((FAIL_COUNT + 1))
echo "FAIL $dev (arecord exit != 0). See log: ${out%.wav}.log"
fi
done
echo ""
echo "======================================================"
echo "Summary: $SUCCESS_COUNT successful, $FAIL_COUNT failed"
echo "======================================================"
echo ""
if command -v sox &>/dev/null; then
echo "Audio file info (sox stat):"
for out in "${FILES[@]}"; do
if [ -f "$out" ]; then
echo "---- $(basename "$out") ----"
sox "$out" -n stat 2>&1 | grep -E "Sample Rate|Channels|Duration|Length|Maximum amplitude|RMS"
fi
done
echo ""
fi
echo "To play a recording:"
echo " aplay ${OUTPUT_DIR}/dante_asrc_ch1_${TIMESTAMP}.wav"
echo ""