Files
dante_beacon/test_arecord.sh
2025-12-12 16:27:31 +01:00

91 lines
2.8 KiB
Bash

#!/bin/bash
# Test recording script for Dante DEP loopback channels
# Records from hw:3,1,0 (loopback capture side) - 6 channels at 48kHz
DEVICE="hw:3,1,0"
SAMPLE_RATE=48000
BIT_DEPTH=16
CHANNELS=6
DURATION=10 # seconds
OUTPUT_DIR="./recordings"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
# Create output directory
mkdir -p "$OUTPUT_DIR"
echo "=========================================="
echo "Dante DEP Channel Recording Test"
echo "=========================================="
echo "Device: $DEVICE"
echo "Sample Rate: $SAMPLE_RATE Hz"
echo "Bit Depth: $BIT_DEPTH-bit"
echo "Channels: $CHANNELS"
echo "Duration: $DURATION seconds"
echo "Output Directory: $OUTPUT_DIR"
echo "=========================================="
echo ""
# Check if device is available
if ! arecord -l | grep -q "Loopback"; then
echo "ERROR: Loopback device not found!"
echo "Please ensure snd-aloop module is loaded: sudo modprobe snd-aloop"
exit 1
fi
# Record all channels to a single interleaved file first
TEMP_FILE="$OUTPUT_DIR/temp_${TIMESTAMP}_all_channels.wav"
echo "Recording all $CHANNELS channels to temporary file..."
echo "Command: arecord -D $DEVICE -f S${BIT_DEPTH}_LE -r $SAMPLE_RATE -c $CHANNELS -d $DURATION $TEMP_FILE"
echo ""
arecord -D "$DEVICE" -f S${BIT_DEPTH}_LE -r "$SAMPLE_RATE" -c "$CHANNELS" -d "$DURATION" "$TEMP_FILE"
if [ $? -ne 0 ]; then
echo ""
echo "ERROR: Recording failed!"
echo "Possible reasons:"
echo " - Device is busy (check: sudo fuser -v /dev/snd/pcmC3D1c)"
echo " - DEP is not running or not outputting to loopback"
echo " - Wrong device identifier"
exit 1
fi
echo ""
echo "Recording complete! Splitting into individual channel files..."
echo ""
# Split into individual channel files using sox
if command -v sox &> /dev/null; then
for i in $(seq 1 $CHANNELS); do
OUTPUT_FILE="$OUTPUT_DIR/channel_${i}_${TIMESTAMP}.wav"
echo "Extracting channel $i to: $OUTPUT_FILE"
sox "$TEMP_FILE" "$OUTPUT_FILE" remix $i
done
echo ""
echo "Cleaning up temporary file..."
rm "$TEMP_FILE"
echo ""
echo "=========================================="
echo "SUCCESS! Individual channel files created:"
echo "=========================================="
ls -lh "$OUTPUT_DIR"/channel_*_${TIMESTAMP}.wav
else
echo ""
echo "WARNING: 'sox' not found - keeping interleaved file only"
echo "To split channels, install sox: sudo apt-get install sox"
echo "Interleaved file saved as: $TEMP_FILE"
fi
echo ""
echo "=========================================="
echo "Recording test complete!"
echo "=========================================="
echo ""
echo "To play back a channel file:"
echo " aplay $OUTPUT_DIR/channel_1_${TIMESTAMP}.wav"
echo ""
echo "To analyze audio levels:"
echo " sox $OUTPUT_DIR/channel_1_${TIMESTAMP}.wav -n stat"