summaryrefslogtreecommitdiff
path: root/scripts/gen_spectrograms.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gen_spectrograms.sh')
-rwxr-xr-xscripts/gen_spectrograms.sh63
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/gen_spectrograms.sh b/scripts/gen_spectrograms.sh
new file mode 100755
index 0000000..7eb6bdc
--- /dev/null
+++ b/scripts/gen_spectrograms.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# This script converts all .wav and .aif files from assets/originals
+# into .spec files in assets/final using the spectool utility.
+
+set -euo pipefail
+
+# --- Configuration ---
+PROJECT_ROOT=$(git rev-parse --show-toplevel)
+SOURCE_DIR="${PROJECT_ROOT}/assets/originals"
+DEST_DIR="${PROJECT_ROOT}/assets/final"
+SPECTOOL_PATH="${PROJECT_ROOT}/build/spectool"
+TEMP_WAV_DIR=$(mktemp -d)
+
+# --- Pre-flight Checks ---
+if ! command -v ffmpeg &> /dev/null; then
+ echo "Error: ffmpeg is not installed or not in your PATH."
+ echo "Please install it to handle .aif files."
+ exit 1
+fi
+
+if [ ! -f "${SPECTOOL_PATH}" ]; then
+ echo "Error: spectool not found at ${SPECTOOL_PATH}"
+ echo "Please build the project first (e.g., cmake -S . -B build && cmake --build build)"
+ exit 1
+fi
+
+echo "Source directory: ${SOURCE_DIR}"
+echo "Destination directory: ${DEST_DIR}"
+echo "Using spectool: ${SPECTOOL_PATH}"
+
+# --- Processing ---
+process_file() {
+ local input_file="$1"
+ local base_name
+ base_name=$(basename "$input_file")
+
+ local output_name
+ output_name=$(echo "${base_name%.*}" | tr '[:lower:]' '[:upper:]' | tr ' ' '_')
+ local spec_file="${DEST_DIR}/${output_name}.spec"
+
+ local file_to_process="$input_file"
+
+ # Convert .aif to .wav if necessary
+ if echo "${base_name}" | tr '[:upper:]' '[:lower:]' | grep -q ".aif$"; then
+ echo "Converting AIF to WAV: ${base_name}"
+ temp_wav="${TEMP_WAV_DIR}/${output_name}.wav"
+ ffmpeg -i "$input_file" -y "$temp_wav" &> /dev/null
+ file_to_process="$temp_wav"
+ fi
+
+ echo "Generating spectrogram: ${base_name} -> ${output_name}.spec"
+ "${SPECTOOL_PATH}" analyze "$file_to_process" "$spec_file"
+}
+
+# Find and process all audio files
+find "$SOURCE_DIR" -type f \( -name "*.wav" -o -name "*.aif" \) | while read -r audio_file; do
+ process_file "$audio_file"
+done
+
+# --- Cleanup ---
+rm -rf "$TEMP_WAV_DIR"
+
+echo "Spectrogram generation complete."