mapcreator git · master
SDL3 2.5D game and engine using assets, with map editor
C++ 99.3%git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gzscripts/audio/record.sh raw
#!/bin/bash
set -euo pipefail
show_help() {
echo "Usage: $0 <output_name> <duration_seconds>"
echo
echo "Records audio from the default microphone, applies:"
echo " - high-pass filter (remove low-frequency rumble)"
echo " - mono conversion"
echo " - peak normalization"
echo " - trims first 50ms (remove mic crack)"
echo " - loudness normalization (LUFS)"
echo "Outputs WAV to <output_name>.wav and plays it back."
}
stop_recording() {
echo
echo "Stopping recording..."
# 2. Process the recorded audio with sox
sox "$tmp0" "$tmp1" highpass 120 remix 1,2 gain -n
# 2. Remove mic crack (first 50ms)
ffmpeg -hide_banner -loglevel error -i "$tmp1" -ss 0.05 -c copy "$tmp2"
# 3. Loudness normalize (LUFS) and back to 44100 Hz
ffmpeg -hide_banner -loglevel error -i "$tmp2" \
-af "loudnorm=I=-18:TP=-1.5:LRA=7, aresample=44100, pan=mono|c0=0.5*c0+0.5*c1" \
"${name}.wav"
# Cleanup temporary files
rm -f "$tmp0" "$tmp1" "$tmp2"
# 4. Playback
echo "Done. Playing back..."
aplay "${name}.wav"
echo "Recording saved as ${name}.wav"
}
trap stop_recording SIGINT
if [[ $# -eq 0 || "$1" == "--help" || "$1" == "-h" ]]; then
show_help
exit 0
fi
if [[ $# -lt 2 ]]; then
echo "Error: Missing arguments."
show_help
exit 1
fi
name="$1"
duration="$2"
# Temporary files
tmp0="${name}_raw.wav"
tmp1="${name}_ra1w.wav"
tmp2="${name}_trim.wav"
echo "Recording $duration seconds into $name.wav..."
# 1. Record → high-pass → mono → peak normalize
arecord --duration="$duration" --format=cd "$tmp0"
# Remove trap
trap - SIGINT
stop_recording