Files
raspberry-pi-mixer/scripts/audio-stack-start
T
shawn 9cd8292acc
Lint & Validate / lint (push) Has been cancelled
Phase 1-4: Audio stack, mixer engine, MIDI, and network API
P2-R1: ALSA + JACK2 low-latency config (scripts, quirks, tuning)
P2-R2: Carla integration (build scripts, 8ch rack config, NAM LV2 support)
P2-R3: Plugin manager, categories, blacklist, NAM model support
P3-R1: Mixer DSP engine (channel strip, routing matrix, bus mgr, automation)
P4-R1: MIDI engine (learn mode, clock sync, HID discovery, mapping store)
P4-R2: Network API (OSC server, FastAPI REST, WebSocket, auth, rate limiter)
P5-R1: Touchscreen UI evaluation + main entry point
docs: Audio stack, Carla integration, MIDI support, UI evaluation
tests: Full test suite (292 passing)
2026-05-19 20:39:17 -04:00

91 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
# audio-stack-start — initialize the full low-latency audio environment
# Run with: sudo audio-stack-start
# Then JACK runs as the 'pi' user (or current user if not root)
set -e
echo ""
echo "╔══════════════════════════════════════════╗"
echo "║ Audio Stack Initialization ║"
echo "╚══════════════════════════════════════════╝"
echo ""
# ── 1. CPU Governor ──────────────────────────────────
echo "1/6 Setting CPU governor → performance..."
for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
if [ -f "$cpu" ]; then
echo performance > "$cpu" 2>/dev/null || true
fi
done
echo " Done."
# ── 2. IRQ Priorities ────────────────────────────────
echo "2/6 Configuring IRQ priorities..."
if command -v rtirq > /dev/null 2>&1; then
if systemctl is-active --quiet rtirq 2>/dev/null; then
systemctl restart rtirq 2>/dev/null || true
else
systemctl start rtirq 2>/dev/null || true
fi
echo " rtirq started."
else
echo " rtirq not installed. Run: sudo apt install rtirq-init"
fi
# ── 3. PAM Limits Check ──────────────────────────────
echo "3/6 Checking PAM limits..."
CURRENT_RTPRIO=$(ulimit -r 2>/dev/null || echo "unknown")
CURRENT_MEMLOCK=$(ulimit -l 2>/dev/null || echo "unknown")
echo " rtprio: $CURRENT_RTPRIO (need 99)"
echo " memlock: $CURRENT_MEMLOCK (need unlimited)"
# ── 4. USB Audio Driver ──────────────────────────────
echo "4/6 Configuring USB audio driver..."
if lsmod 2>/dev/null | grep -q snd_usb_audio; then
modprobe -r snd-usb-audio 2>/dev/null || true
sleep 1
fi
modprobe snd-usb-audio nrpacks=1 2>/dev/null || true
echo " snd-usb-audio loaded with nrpacks=1"
# ── 5. USB Audio Detection ───────────────────────────
echo "5/6 Checking USB audio device..."
sleep 1
if aplay -l 2>/dev/null | grep -qi usb; then
echo " USB audio interface detected:"
aplay -l 2>/dev/null | grep -i usb | head -3 | sed 's/^/ /'
else
echo " WARNING: No USB audio interface found!"
echo " Check: lsusb | grep -i audio"
fi
# ── 6. Start JACK ────────────────────────────────────
echo "6/6 Starting JACK2..."
if pgrep -x jackd > /dev/null; then
echo " JACK is already running. PID: $(pgrep -x jackd)"
else
if [ "$EUID" -eq 0 ] && id pi >/dev/null 2>&1; then
# Running as root, drop to pi user
sudo -u pi jackd -P70 -t2000 -d alsa -d hw:USB -r48000 -p128 -n3 -S > /tmp/jackd.log 2>&1 &
echo " JACK launched as user 'pi' (PID: $!)"
else
jackd -P70 -t2000 -d alsa -d hw:USB -r48000 -p128 -n3 -S > /tmp/jackd.log 2>&1 &
echo " JACK launched (PID: $!)"
fi
sleep 2
fi
# ── Final status ─────────────────────────────────────
echo ""
echo "╔══════════════════════════════════════════╗"
echo "║ Audio Stack Ready ║"
echo "╚══════════════════════════════════════════╝"
echo ""
echo " Check ports: jack_lsp -c system"
echo " Test latency: jack_delay -O system:playback_1 -I system:capture_1"
echo " Auto-route: jack-route-default"
echo " Stop stack: audio-stack-stop"
echo " Xrun monitor: jack_cpu_load"
echo ""